mman.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
  2. /*
  3. * mm definition for NOLIBC
  4. * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
  5. */
  6. /* make sure to include all global symbols */
  7. #include "../nolibc.h"
  8. #ifndef _NOLIBC_SYS_MMAN_H
  9. #define _NOLIBC_SYS_MMAN_H
  10. #include "../arch.h"
  11. #include "../sys.h"
  12. #ifndef sys_mmap
  13. static __attribute__((unused))
  14. void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
  15. off_t offset)
  16. {
  17. int n;
  18. #if defined(__NR_mmap2)
  19. n = __NR_mmap2;
  20. offset >>= 12;
  21. #else
  22. n = __NR_mmap;
  23. #endif
  24. return (void *)my_syscall6(n, addr, length, prot, flags, fd, offset);
  25. }
  26. #endif
  27. static __attribute__((unused))
  28. void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
  29. {
  30. void *ret = sys_mmap(addr, length, prot, flags, fd, offset);
  31. if ((unsigned long)ret >= -4095UL) {
  32. SET_ERRNO(-(long)ret);
  33. ret = MAP_FAILED;
  34. }
  35. return ret;
  36. }
  37. static __attribute__((unused))
  38. void *sys_mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address)
  39. {
  40. return (void *)my_syscall5(__NR_mremap, old_address, old_size,
  41. new_size, flags, new_address);
  42. }
  43. static __attribute__((unused))
  44. void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, void *new_address)
  45. {
  46. void *ret = sys_mremap(old_address, old_size, new_size, flags, new_address);
  47. if ((unsigned long)ret >= -4095UL) {
  48. SET_ERRNO(-(long)ret);
  49. ret = MAP_FAILED;
  50. }
  51. return ret;
  52. }
  53. static __attribute__((unused))
  54. int sys_munmap(void *addr, size_t length)
  55. {
  56. return my_syscall2(__NR_munmap, addr, length);
  57. }
  58. static __attribute__((unused))
  59. int munmap(void *addr, size_t length)
  60. {
  61. return __sysret(sys_munmap(addr, length));
  62. }
  63. #endif /* _NOLIBC_SYS_MMAN_H */