-
Notifications
You must be signed in to change notification settings - Fork 7.8k
posix: add support for mmap, memlock, shared memory, and mprotect #73799
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
Conversation
608e2b7
to
36362dd
Compare
d4c7c6e
to
8332cf3
Compare
aeb71a9
to
5c13a6d
Compare
File offset actually varies on a per-file-descriptor basis, and not with the resource that is abstracted behind the file descriptor. This is consistent with both the POSIX model and also the ISO C/C++ model, so Zephyr should follow suit. This is very work-around-y, but it's necessary to ensure that shared memory objects, block devices, files and directories all behave consistently. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Implement shm_open() and shm_unlink() to complete support for the _POSIX_SHARED_MEMORY_OBJECTS Option. Since mmap() support is not yet implemented in Zephyr, I/O is limited to read(), write(), ftruncate(), lseek(), close(), for now. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Add tests for shared memory objects. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark _POSIX_SHARED_MEMORY_OBJECTS as supported. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Make POSIX_PAGE_SIZE_BITS not user-configurable and tie it to CONFIG_MMU_PAGE_SIZE if there is an MMU. Otherwise, simply default it to something small. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Provide a stub for mprotect() to satisfy the requirement for the base definitions / system interfaces and subsequently PSE51, PSE52, PSE52, etc. Currently, Zephyr's virtual memory-management API does not seem to support modifying memory protection bits after pages have already been mapped. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
Mark _POSIX_MEMORY_PROTECTION as supported (i.e. a conformant application will link). Zephyr's mm API does not currently support modifying memory protection bits after pages have been mapped, so use of this function may result in undefined behaviour. Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
b2fdc90
to
275de80
Compare
Still working on my desk twister -T tests/posix/shm/
...
INFO - Total complete: 40/ 40 100% skipped: 15, failed: 0, error: 0 |
re-ping @andyross @vaishnavachath @ycsin @dkalowsk |
Sorry, but the POSIX layer you're creating (and that's highly appreciated Knowing how many times a particular object has been mapped and unmapped is So it should be no different with Am I missing something that would prevents such implementation? |
No Let me open a bug about this and bring the prefix discussion back so we can do something about it. |
actually you can use zvfs which is being used already, better than z_ for sure. |
@nashif - I think a |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still haven't combed through as well as I'd like, but +1 to everything I saw earlier. And it seems like this has excellent review coverage from others anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still thinking this is better than what we have today. Reviewing I don't see anything obvious standing out.
Of course I am. But you have another problem here. And yet So to say that |
`msync()` has been implemented in zephyrproject-rtos#73799. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
`msync()` has been implemented in #73799. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
`msync()` has been implemented in zephyrproject-rtos#73799. (cherry picked from commit 11bd1da) Original-Signed-off-by: Yong Cong Sin <ycsin@meta.com> GitOrigin-RevId: 11bd1da Change-Id: Ib1eb7d1bcfda25185bfbd08aa32c0deb97cceff2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5748672 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com> Tested-by: Fabio Baltieri <fabiobaltieri@google.com> Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com> Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
`msync()` has been implemented in zephyrproject-rtos#73799. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
_POSIX_MAPPED_FILES
_POSIX_MEMLOCK_RANGE
_POSIX_MEMLOCK
(currently unimplemented / fails withENOSYS
)_POSIX_SHARED_MEMORY_OBJECTS
_POSIX_MEMORY_PROTECTION
(currently unimplemented / fails withENOSYS
)Shared Memory Objects and Memory-Mapped Files
On systems that support mapping anonymous memory (i.e. have an MMU and lots of RAM), shared memory objects are implemented using
k_mem_map()
and friends (i.e. a shared memory object is comprised of a number of blocks of virtual memory that areCONFIG_MMU_PAGE_SIZE
in size). On systems that do not have an MMU, shared memory objects are implemented with heap allocation.Note: it is up to the particular vtable implementor, to support the
ZFD_IOCTL_MMAP
operation. However, there would still need to be some integration withmsync()
in order to synchronize writes to e.g. a regular file. From that perspective, shared memory objects were an easy prototyping option.A potential future improvement on shared memory objects would be to support a separate
ioctl()
to attach statically allocated memory.z_finalize_typed_fd()
A particular change to highlight in this case though, is adding a
mode
field tostruct fd_entry
, which allows fdtable code to identify which subsystem or API a file descriptor belongs to, and to react accordingly. Thez_finalize_typed_fd()
function allows us to differentiate between fifo, char device, message queue, directory, semaphore, block device, shared memory, regular file, symbolic link, and socket.In fact, the same 32-bit
mode
field should also have the file access mode tied to it, rather than the physical file (which is currently the case now for the FS subsystem, and should be considered a bug). It's trivial to consider a case where one file descriptor is used for writing to a file and another file descriptor is used for reading from a file. Both file descriptors point to the same physical file, but each has different access modes and offsets (addressed below).Per-file Offsets
Another similar adjustment to
struct fd_entry
is to have a per-fd (perFILE*
) offset, which is just consistent with the C/C++, POSIX (all?) programming models of "files".A few drive-by fixes aside from that, shuffling things between zvfs, posix, and fs, as-needed.
Doc Preview
Fixes #59950
Fixes #59951
Fixes #59952
Fixes #59953