Reputation: 2356
I am writing native shared library, which needs Android support, and i need to share some data (UID and some additional fields) between all processes, which use this library. In Linux good opportunity for this is POSIX shared memory for this. But Android NDK doesn't support POSIX shared memory. There is ashmem, but for access to shared memory region from other process i need to use binder IPC to transfer opened file descriptor. But this is not
reasonably, because process, which create region, may be terminated, when other process want access to shared data.
Is there any way to solve my problem wioth Android shared memory?
Upvotes: 1
Views: 1485
Reputation: 2113
First of all, you don't need Binder, you can pass a file descriptor using sendmsg() and recvmsg() through a Unix local socket. For an example, see the SendFd() and ReceiveFd() functions in [1]
Second ashmem regions are reference-counted, as long as one file descriptor is opened on an ashmem region, it will not disappear, even if the process that created is killed.
Hope this helps.
Upvotes: 3