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

Syscalls: add support for memfd_create #2005

Merged
merged 8 commits into from
Mar 7, 2024
Merged

Conversation

francescolavra
Copy link
Member

This syscall creates an anonymous file that behaves like a regular file, and so can be modified, truncated, memory-mapped, and so on, but, unlike a regular file, lives in RAM and has a volatile backing storage.
This syscall is implemented in a new "shmem" klib, which is meant to contain the implementation of all shared-memory features in the kernel. The memfd implementation relies on an underlying tmpfs filesystem, which is implemented in another new klib named "tmpfs" (which in the future can be used to create arbitrary RAM-backed filesystems and mount them at arbitrary locations in the root filesystem).

Closes #1986.

This change moves the call to filesystem_update_mtime() from the
truncate callback of filesystem drivers to the generic filesystem
code that invokes the callback. Beside removing duplicated code,
this change will allow building filesystem drivers as klibs (which
cannot call the now() function directly because it references the
__vdso_vdso_dat hidden symbol).
This change allows creating temporary files (i.e. files that are
not associated to a directory entry and are deleted when closed) on
filesystems other than TFS. The create callback of existing
filesystem drivers has been amended to be able to create temporary
files (or return FS_STATUS_INVAL if this feature is not supported).
This change will be needed when support for memfd_create() is
added.
This function undoes what filesystem_init() does; it is used in the
TFS code when destroying a filesystem, instead of calling directly
pagecache_dealloc_volume().
Code that uses a file table to enumerate file metadata tuples and
to establish a correspondence between metadata tuples and fsfile
structs has been moved from tfs.c to fs.c and fs.h. It will be
reused when implementing tmpfs.
The body of this new function has been extracted from
open_internal(). This change will allow userspace to open regular
files via syscalls other than open() and similar, i.e. syscalls
that do not reference a filesystem path, such as memfd_create().

The file struct has been modified to embed all fdesc closures, so
that individual allocations and deallocations for each closure when
opening and closing a file are no longer necessary.
This macro is a more lightweight version of register_syscall(), and
can be used to initialize the name and flags of a syscall without
configuring a handler. It is now used for all non-supported
syscalls.
If a klib implementing additional syscalls is loaded, it can call
swap_syscall_handler() instead of register_syscall().
This dependency is already listed in the run targets of the top-
level Makefile; having this dependency also in the platform
Makefiles causes the disk image to be created twice at each
execution of a runtime test.
This syscall creates an anonymous file that behaves like a regular
file, and so can be modified, truncated, memory-mapped, and so on,
but, unlike a regular file, lives in RAM and has a volatile backing
storage.
This syscall is implemented in a new "shmem" klib, which is meant
to contain the implementation of all shared-memory features in the
kernel. The memfd implementation relies on an underlying tmpfs
filesystem, which is implemented in another new klib named "tmpfs"
(which in the future can be used to create arbitrary RAM-backed
filesystems and mount them at arbitrary locations in the root
filesystem).

Closes #1986.
@francescolavra francescolavra merged commit b869f60 into master Mar 7, 2024
5 checks passed
@francescolavra francescolavra deleted the feature/memfd branch March 7, 2024 15:45
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.

Is the memfd_create syscall supported?
1 participant