memfd-util: add wrapper for memfd_create
The wrapper removes the flags MFD_EXEC and MFD_NOEXEC_SEAL when running on kernels not understanding those flags.
This commit is contained in:
@@ -20,6 +20,22 @@
|
||||
#include "string-util.h"
|
||||
#include "utf8.h"
|
||||
|
||||
int memfd_create_wrapper(const char *name, unsigned mode) {
|
||||
unsigned mode_compat;
|
||||
int mfd;
|
||||
|
||||
mfd = RET_NERRNO(memfd_create(name, mode));
|
||||
if (mfd != -EINVAL)
|
||||
return mfd;
|
||||
|
||||
mode_compat = mode & ~(MFD_EXEC | MFD_NOEXEC_SEAL);
|
||||
|
||||
if (mode == mode_compat)
|
||||
return mfd;
|
||||
|
||||
return RET_NERRNO(memfd_create(name, mode_compat));
|
||||
}
|
||||
|
||||
int memfd_new(const char *name) {
|
||||
_cleanup_free_ char *g = NULL;
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
int memfd_create_wrapper(const char *name, unsigned mode);
|
||||
|
||||
int memfd_new(const char *name);
|
||||
int memfd_new_and_map(const char *name, size_t sz, void **p);
|
||||
int memfd_new_and_seal(const char *name, const void *data, size_t sz);
|
||||
|
||||
Reference in New Issue
Block a user