shm.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef _LINUX_SHM_H_
  2. #define _LINUX_SHM_H_
  3. #include <linux/ipc.h>
  4. #include <linux/errno.h>
  5. #ifdef __KERNEL__
  6. #include <asm/page.h>
  7. #else
  8. #include <unistd.h>
  9. #endif
  10. /*
  11. * SHMMAX, SHMMNI and SHMALL are upper limits are defaults which can
  12. * be increased by sysctl
  13. */
  14. #define SHMMAX 0x2000000 /* max shared seg size (bytes) */
  15. #define SHMMIN 1 /* min shared seg size (bytes) */
  16. #define SHMMNI 4096 /* max num of segs system wide */
  17. #ifdef __KERNEL__
  18. #define SHMALL (SHMMAX/PAGE_SIZE*(SHMMNI/16)) /* max shm system wide (pages) */
  19. #else
  20. #define SHMALL (SHMMAX/getpagesize()*(SHMMNI/16))
  21. #endif
  22. #define SHMSEG SHMMNI /* max shared segs per process */
  23. #ifdef __KERNEL__
  24. #include <asm/shmparam.h>
  25. #endif
  26. /* Obsolete, used only for backwards compatibility and libc5 compiles */
  27. struct shmid_ds {
  28. struct ipc_perm shm_perm; /* operation perms */
  29. int shm_segsz; /* size of segment (bytes) */
  30. __kernel_time_t shm_atime; /* last attach time */
  31. __kernel_time_t shm_dtime; /* last detach time */
  32. __kernel_time_t shm_ctime; /* last change time */
  33. __kernel_ipc_pid_t shm_cpid; /* pid of creator */
  34. __kernel_ipc_pid_t shm_lpid; /* pid of last operator */
  35. unsigned short shm_nattch; /* no. of current attaches */
  36. unsigned short shm_unused; /* compatibility */
  37. void *shm_unused2; /* ditto - used by DIPC */
  38. void *shm_unused3; /* unused */
  39. };
  40. /* Include the definition of shmid64_ds and shminfo64 */
  41. #include <asm/shmbuf.h>
  42. /* permission flag for shmget */
  43. #define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
  44. #define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
  45. /* mode for attach */
  46. #define SHM_RDONLY 010000 /* read-only access */
  47. #define SHM_RND 020000 /* round attach address to SHMLBA boundary */
  48. #define SHM_REMAP 040000 /* take-over region on attach */
  49. #define SHM_EXEC 0100000 /* execution access */
  50. /* super user shmctl commands */
  51. #define SHM_LOCK 11
  52. #define SHM_UNLOCK 12
  53. /* ipcs ctl commands */
  54. #define SHM_STAT 13
  55. #define SHM_INFO 14
  56. /* Obsolete, used only for backwards compatibility */
  57. struct shminfo {
  58. int shmmax;
  59. int shmmin;
  60. int shmmni;
  61. int shmseg;
  62. int shmall;
  63. };
  64. struct shm_info {
  65. int used_ids;
  66. unsigned long shm_tot; /* total allocated shm */
  67. unsigned long shm_rss; /* total resident shm */
  68. unsigned long shm_swp; /* total swapped shm */
  69. unsigned long swap_attempts;
  70. unsigned long swap_successes;
  71. };
  72. #ifdef __KERNEL__
  73. struct shmid_kernel /* private to the kernel */
  74. {
  75. struct kern_ipc_perm shm_perm;
  76. struct file * shm_file;
  77. unsigned long shm_nattch;
  78. unsigned long shm_segsz;
  79. time_t shm_atim;
  80. time_t shm_dtim;
  81. time_t shm_ctim;
  82. pid_t shm_cprid;
  83. pid_t shm_lprid;
  84. struct user_struct *mlock_user;
  85. /* The task created the shm object. NULL if the task is dead. */
  86. struct task_struct *shm_creator;
  87. };
  88. /* shm_mode upper byte flags */
  89. #define SHM_DEST 01000 /* segment will be destroyed on last detach */
  90. #define SHM_LOCKED 02000 /* segment will not be swapped */
  91. #define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
  92. #define SHM_NORESERVE 010000 /* don't check for reservations */
  93. #ifdef CONFIG_SYSVIPC
  94. long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr,
  95. unsigned long shmlba);
  96. extern int is_file_shm_hugepages(struct file *file);
  97. extern void exit_shm(struct task_struct *task);
  98. #else
  99. static inline long do_shmat(int shmid, char __user *shmaddr,
  100. int shmflg, unsigned long *addr,
  101. unsigned long shmlba)
  102. {
  103. return -ENOSYS;
  104. }
  105. static inline int is_file_shm_hugepages(struct file *file)
  106. {
  107. return 0;
  108. }
  109. static inline void exit_shm(struct task_struct *task)
  110. {
  111. }
  112. #endif
  113. #endif /* __KERNEL__ */
  114. #endif /* _LINUX_SHM_H_ */