Add linux-compatible memfd_create

memfd_create is effectively a SHM_ANON shm_open(2) mapping with optional
CLOEXEC and file sealing support. This is used by some mesa parts, some
linux libs, and qemu can also take advantage of it and uses the sealing to
prevent resizing the region.

This reimplements shm_open in terms of shm_open2(2) at the same time.

shm_open(2) will be moved to COMPAT12 shortly.

Reviewed by:	markj, kib
Differential Revision:	https://reviews.freebsd.org/D21393
This commit is contained in:
Kyle Evans 2019-09-25 18:03:18 +00:00 committed by Sebastian Huber
parent 99b66f5315
commit 9243caa8d3
1 changed files with 27 additions and 0 deletions

View File

@ -182,6 +182,30 @@
*/
#define SHM_ALLOW_SEALING 0x00000001
/*
* Flags for memfd_create().
*/
#define MFD_ALLOW_SEALING 0x00000001
#define MFD_CLOEXEC 0x00000002
/* UNSUPPORTED */
#define MFD_HUGETLB 0x00000004
#define MFD_HUGE_MASK 0xFC000000
#define MFD_HUGE_SHIFT 26
#define MFD_HUGE_64KB (16 << MFD_HUGE_SHIFT)
#define MFD_HUGE_512KB (19 << MFD_HUGE_SHIFT)
#define MFD_HUGE_1MB (20 << MFD_HUGE_SHIFT)
#define MFD_HUGE_2MB (21 << MFD_HUGE_SHIFT)
#define MFD_HUGE_8MB (23 << MFD_HUGE_SHIFT)
#define MFD_HUGE_16MB (24 << MFD_HUGE_SHIFT)
#define MFD_HUGE_32MB (25 << MFD_HUGE_SHIFT)
#define MFD_HUGE_256MB (28 << MFD_HUGE_SHIFT)
#define MFD_HUGE_512MB (29 << MFD_HUGE_SHIFT)
#define MFD_HUGE_1GB (30 << MFD_HUGE_SHIFT)
#define MFD_HUGE_2GB (31 << MFD_HUGE_SHIFT)
#define MFD_HUGE_16GB (34 << MFD_HUGE_SHIFT)
#endif /* __BSD_VISIBLE */
/*
@ -242,6 +266,9 @@ int munlockall(void);
int shm_open(const char *, int, mode_t);
int shm_unlink(const char *);
#endif
#if __BSD_VISIBLE
int memfd_create(const char *, unsigned int);
#endif
__END_DECLS
#endif /* !_KERNEL */