diff options
| author | Thomas Weißschuh <thomas.weissschuh@linutronix.de> | 2025-04-16 15:06:20 +0300 |
|---|---|---|
| committer | Thomas Weißschuh <linux@weissschuh.net> | 2025-04-19 15:22:23 +0300 |
| commit | cce273161e7895f45208066154d6726bedba35e5 (patch) | |
| tree | fb1c96d44feb6fd5a481bb8777947c1c7d4d8e78 /tools/include/nolibc/sys | |
| parent | 9e67941dde6e7f2b0e46ca8e2c87d3fb12e5ead5 (diff) | |
| download | linux-cce273161e7895f45208066154d6726bedba35e5.tar.xz | |
tools/nolibc: move mmap() and friends to sys/mman.h
This is the location regular userspace expects these definitions.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20250416-nolibc-split-sys-v1-5-a069a3f1d145@linutronix.de
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to 'tools/include/nolibc/sys')
| -rw-r--r-- | tools/include/nolibc/sys/mman.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tools/include/nolibc/sys/mman.h b/tools/include/nolibc/sys/mman.h new file mode 100644 index 000000000000..ad9d06b6b791 --- /dev/null +++ b/tools/include/nolibc/sys/mman.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: LGPL-2.1 OR MIT */ +/* + * mm definition for NOLIBC + * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu> + */ + +#ifndef _NOLIBC_SYS_MMAN_H +#define _NOLIBC_SYS_MMAN_H + +#include "../arch.h" +#include "../sys.h" + +#ifndef sys_mmap +static __attribute__((unused)) +void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd, + off_t offset) +{ + int n; + +#if defined(__NR_mmap2) + n = __NR_mmap2; + offset >>= 12; +#else + n = __NR_mmap; +#endif + + return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset); +} +#endif + +/* Note that on Linux, MAP_FAILED is -1 so we can use the generic __sysret() + * which returns -1 upon error and still satisfy user land that checks for + * MAP_FAILED. + */ + +static __attribute__((unused)) +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + void *ret = sys_mmap(addr, length, prot, flags, fd, offset); + + if ((unsigned long)ret >= -4095UL) { + SET_ERRNO(-(long)ret); + ret = MAP_FAILED; + } + return ret; +} + +static __attribute__((unused)) +int sys_munmap(void *addr, size_t length) +{ + return my_syscall2(__NR_munmap, addr, length); +} + +static __attribute__((unused)) +int munmap(void *addr, size_t length) +{ + return __sysret(sys_munmap(addr, length)); +} + +/* make sure to include all global symbols */ +#include "../nolibc.h" + +#endif /* _NOLIBC_SYS_MMAN_H */ |
