Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ndk: Add bindings for ASharedMemory #427

Merged
merged 1 commit into from
Oct 14, 2023

Conversation

MarijnS95
Copy link
Member

ASharedMemory allows allocating shared memory as a file descriptor that can be mmaped or shared to other processes via parcels or Unix domain sockets.

Its Java counterpart is android.os.SharedMemory from which (when available as a JNI jobject) an owned file descriptor clone can be created to access the memory object in native code.

Common Rust traits such as FromRawFd are provided so that a SharedMemory object can also be created from a received file descriptor.

Comment on lines +51 to +56
# Only for use in documentation and doc-tests
libc = "0.2"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this - if folks find this a good idea at all - I'd like to go over existing documentation and replace their mentions of e.g. mmap and other flags with libc intradoc links.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appears this is not true at all. dev-dependencies applies to (doc!) tests, but not to documentation itself.

I can add it behind the docsrs cfg then... :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note too that many of these constants - except the PROT_ ones, are (accidentally?) included in the ndk-sys ffi bindings...

But better to reference public/obvious ones from libc unless there's a "kernel header" target?

/// `sendmsg` and `SCM_RIGHTS`. See `sendmsg(3)` and `cmsg(3)` man pages for more information.
///
/// If you intend to share this file descriptor with a child process after calling `exec(3)`,
/// note that you will need to use `fcntl(2)` with `FD_SETFD` to clear the `FD_CLOEXEC` flag
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And through the magic of intradoc links I learned that FD_SETFD must be a typo in the AOSP documentation; it is F_SETFD :)

`ASharedMemory` allows allocating shared memory as a file descriptor
that can be `mmap`ed or shared to other processes via parcels or Unix
domain sockets.

Its Java counterpart is `android.os.SharedMemory` from which (when
available as a JNI `jobject`) an owned file descriptor clone can be
created to access the memory object in native code.

Common Rust traits such as `FromRawFd` are provided so that a
`SharedMemory` object can also be created from a received file
descriptor.
@MarijnS95 MarijnS95 merged commit a7ce644 into rust-mobile:master Oct 14, 2023
18 checks passed
@MarijnS95 MarijnS95 deleted the ndk-shared-memory branch October 14, 2023 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant