shm.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_SHM_H_
  3. #define _UAPI_LINUX_SHM_H_
  4. #include <linux/ipc.h>
  5. #include <linux/errno.h>
  6. #include <asm-generic/hugetlb_encode.h>
  7. #ifndef __KERNEL__
  8. #include <unistd.h>
  9. #endif
  10. /*
  11. * SHMMNI, SHMMAX and SHMALL are default upper limits which can be
  12. * modified by sysctl. The SHMMAX and SHMALL values have been chosen to
  13. * be as large possible without facilitating scenarios where userspace
  14. * causes overflows when adjusting the limits via operations of the form
  15. * "retrieve current limit; add X; update limit". It is therefore not
  16. * advised to make SHMMAX and SHMALL any larger. These limits are
  17. * suitable for both 32 and 64-bit systems.
  18. */
  19. #define SHMMIN 1 /* min shared seg size (bytes) */
  20. #define SHMMNI 4096 /* max num of segs system wide */
  21. #define SHMMAX (ULONG_MAX - (1UL << 24)) /* max shared seg size (bytes) */
  22. #define SHMALL (ULONG_MAX - (1UL << 24)) /* max shm system wide (pages) */
  23. #define SHMSEG SHMMNI /* max shared segs per process */
  24. /* Obsolete, used only for backwards compatibility and libc5 compiles */
  25. struct shmid_ds {
  26. struct ipc_perm shm_perm; /* operation perms */
  27. int shm_segsz; /* size of segment (bytes) */
  28. __kernel_old_time_t shm_atime; /* last attach time */
  29. __kernel_old_time_t shm_dtime; /* last detach time */
  30. __kernel_old_time_t shm_ctime; /* last change time */
  31. __kernel_ipc_pid_t shm_cpid; /* pid of creator */
  32. __kernel_ipc_pid_t shm_lpid; /* pid of last operator */
  33. unsigned short shm_nattch; /* no. of current attaches */
  34. unsigned short shm_unused; /* compatibility */
  35. void *shm_unused2; /* ditto - used by DIPC */
  36. void *shm_unused3; /* unused */
  37. };
  38. /* Include the definition of shmid64_ds and shminfo64 */
  39. #include <asm/shmbuf.h>
  40. /*
  41. * shmget() shmflg values.
  42. */
  43. /* The bottom nine bits are the same as open(2) mode flags */
  44. #define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
  45. #define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
  46. /* Bits 9 & 10 are IPC_CREAT and IPC_EXCL */
  47. #define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
  48. #define SHM_NORESERVE 010000 /* don't check for reservations */
  49. /*
  50. * Huge page size encoding when SHM_HUGETLB is specified, and a huge page
  51. * size other than the default is desired. See hugetlb_encode.h
  52. */
  53. #define SHM_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
  54. #define SHM_HUGE_MASK HUGETLB_FLAG_ENCODE_MASK
  55. #define SHM_HUGE_64KB HUGETLB_FLAG_ENCODE_64KB
  56. #define SHM_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
  57. #define SHM_HUGE_1MB HUGETLB_FLAG_ENCODE_1MB
  58. #define SHM_HUGE_2MB HUGETLB_FLAG_ENCODE_2MB
  59. #define SHM_HUGE_8MB HUGETLB_FLAG_ENCODE_8MB
  60. #define SHM_HUGE_16MB HUGETLB_FLAG_ENCODE_16MB
  61. #define SHM_HUGE_32MB HUGETLB_FLAG_ENCODE_32MB
  62. #define SHM_HUGE_256MB HUGETLB_FLAG_ENCODE_256MB
  63. #define SHM_HUGE_512MB HUGETLB_FLAG_ENCODE_512MB
  64. #define SHM_HUGE_1GB HUGETLB_FLAG_ENCODE_1GB
  65. #define SHM_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB
  66. #define SHM_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB
  67. /*
  68. * shmat() shmflg values
  69. */
  70. #define SHM_RDONLY 010000 /* read-only access */
  71. #define SHM_RND 020000 /* round attach address to SHMLBA boundary */
  72. #define SHM_REMAP 040000 /* take-over region on attach */
  73. #define SHM_EXEC 0100000 /* execution access */
  74. /* super user shmctl commands */
  75. #define SHM_LOCK 11
  76. #define SHM_UNLOCK 12
  77. /* ipcs ctl commands */
  78. #define SHM_STAT 13
  79. #define SHM_INFO 14
  80. #define SHM_STAT_ANY 15
  81. /* Obsolete, used only for backwards compatibility */
  82. struct shminfo {
  83. int shmmax;
  84. int shmmin;
  85. int shmmni;
  86. int shmseg;
  87. int shmall;
  88. };
  89. struct shm_info {
  90. int used_ids;
  91. __kernel_ulong_t shm_tot; /* total allocated shm */
  92. __kernel_ulong_t shm_rss; /* total resident shm */
  93. __kernel_ulong_t shm_swp; /* total swapped shm */
  94. __kernel_ulong_t swap_attempts;
  95. __kernel_ulong_t swap_successes;
  96. };
  97. #endif /* _UAPI_LINUX_SHM_H_ */