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