mirror of
https://github.com/systemd/systemd.git
synced 2025-01-05 13:18:06 +03:00
memfd-util: trivial modernizations
This commit is contained in:
parent
5d1e57b820
commit
d54bbc4cdc
@ -75,13 +75,13 @@ int memfd_new_full(const char *name, unsigned extra_flags) {
|
|||||||
MFD_CLOEXEC | MFD_NOEXEC_SEAL | extra_flags);
|
MFD_CLOEXEC | MFD_NOEXEC_SEAL | extra_flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_add_seals(int fd, unsigned int seals) {
|
int memfd_add_seals(int fd, unsigned seals) {
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
|
|
||||||
return RET_NERRNO(fcntl(fd, F_ADD_SEALS, seals));
|
return RET_NERRNO(fcntl(fd, F_ADD_SEALS, seals));
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_get_seals(int fd, unsigned int *ret_seals) {
|
int memfd_get_seals(int fd, unsigned *ret_seals) {
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
@ -95,14 +95,14 @@ int memfd_get_seals(int fd, unsigned int *ret_seals) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
|
int memfd_map(int fd, uint64_t offset, size_t size, void **ret) {
|
||||||
unsigned int seals;
|
unsigned int seals;
|
||||||
void *q;
|
void *q;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
assert(size > 0);
|
assert(size > 0);
|
||||||
assert(p);
|
assert(ret);
|
||||||
|
|
||||||
r = memfd_get_seals(fd, &seals);
|
r = memfd_get_seals(fd, &seals);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@ -115,7 +115,7 @@ int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
|
|||||||
if (q == MAP_FAILED)
|
if (q == MAP_FAILED)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
*p = q;
|
*ret = q;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,16 +135,16 @@ int memfd_get_sealed(int fd) {
|
|||||||
return FLAGS_SET(seals, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
|
return FLAGS_SET(seals, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_get_size(int fd, uint64_t *sz) {
|
int memfd_get_size(int fd, uint64_t *ret) {
|
||||||
struct stat stat;
|
struct stat stat;
|
||||||
|
|
||||||
assert(fd >= 0);
|
assert(fd >= 0);
|
||||||
assert(sz);
|
assert(ret);
|
||||||
|
|
||||||
if (fstat(fd, &stat) < 0)
|
if (fstat(fd, &stat) < 0)
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
*sz = stat.st_size;
|
*ret = stat.st_size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,12 +154,12 @@ int memfd_set_size(int fd, uint64_t sz) {
|
|||||||
return RET_NERRNO(ftruncate(fd, sz));
|
return RET_NERRNO(ftruncate(fd, sz));
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_new_and_map(const char *name, size_t sz, void **p) {
|
int memfd_new_and_map(const char *name, size_t sz, void **ret) {
|
||||||
_cleanup_close_ int fd = -EBADF;
|
_cleanup_close_ int fd = -EBADF;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(sz > 0);
|
assert(sz > 0);
|
||||||
assert(p);
|
assert(ret);
|
||||||
|
|
||||||
fd = memfd_new(name);
|
fd = memfd_new(name);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@ -169,7 +169,7 @@ int memfd_new_and_map(const char *name, size_t sz, void **p) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = memfd_map(fd, 0, sz, p);
|
r = memfd_map(fd, 0, sz, ret);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -13,19 +13,19 @@ static inline int memfd_new(const char *name) {
|
|||||||
return memfd_new_full(name, 0);
|
return memfd_new_full(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_new_and_map(const char *name, size_t sz, void **p);
|
int memfd_new_and_map(const char *name, size_t sz, void **ret);
|
||||||
|
|
||||||
int memfd_new_and_seal(const char *name, const void *data, size_t sz);
|
int memfd_new_and_seal(const char *name, const void *data, size_t sz);
|
||||||
static inline int memfd_new_and_seal_string(const char *name, const char *s) {
|
static inline int memfd_new_and_seal_string(const char *name, const char *s) {
|
||||||
return memfd_new_and_seal(name, s, SIZE_MAX);
|
return memfd_new_and_seal(name, s, SIZE_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
int memfd_add_seals(int fd, unsigned int seals);
|
int memfd_add_seals(int fd, unsigned seals);
|
||||||
int memfd_get_seals(int fd, unsigned int *ret_seals);
|
int memfd_get_seals(int fd, unsigned *ret_seals);
|
||||||
int memfd_map(int fd, uint64_t offset, size_t size, void **p);
|
int memfd_map(int fd, uint64_t offset, size_t size, void **ret);
|
||||||
|
|
||||||
int memfd_set_sealed(int fd);
|
int memfd_set_sealed(int fd);
|
||||||
int memfd_get_sealed(int fd);
|
int memfd_get_sealed(int fd);
|
||||||
|
|
||||||
int memfd_get_size(int fd, uint64_t *sz);
|
int memfd_get_size(int fd, uint64_t *ret);
|
||||||
int memfd_set_size(int fd, uint64_t sz);
|
int memfd_set_size(int fd, uint64_t sz);
|
||||||
|
Loading…
Reference in New Issue
Block a user