1 #ifndef _LINUX_SHM_H_ 2 #define _LINUX_SHM_H_ 3 #include <linux/ipc.h> 4 5 struct shmid_ds { 6 struct ipc_perm shm_perm; /* operation perms */ 7 int shm_segsz; /* size of segment (bytes) */ 8 time_t shm_atime; /* last attach time */ 9 time_t shm_dtime; /* last detach time */ 10 time_t shm_ctime; /* last change time */ 11 unsigned short shm_cpid; /* pid of creator */ 12 unsigned short shm_lpid; /* pid of last operator */ 13 short shm_nattch; /* no. of current attaches */ 14 /* the following are private */ 15 unsigned short shm_npages; /* size of segment (pages) */ 16 unsigned long *shm_pages; /* array of ptrs to frames -> SHMMAX */ 17 struct vm_area_struct *attaches; /* descriptors for attaches */ 18 }; 19 20 /* permission flag for shmget */ 21 #define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */ 22 #define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */ 23 24 /* mode for attach */ 25 #define SHM_RDONLY 010000 /* read-only access */ 26 #define SHM_RND 020000 /* round attach address to SHMLBA boundary */ 27 #define SHM_REMAP 040000 /* take-over region on attach */ 28 29 /* super user shmctl commands */ 30 #define SHM_LOCK 11 31 #define SHM_UNLOCK 12 32 33 struct shminfo { 34 int shmmax; 35 int shmmin; 36 int shmmni; 37 int shmseg; 38 int shmall; 39 }; 40 41 /* address range for shared memory attaches if no address passed to shmat() */ 42 #define SHM_RANGE_START 0x50000000 43 #define SHM_RANGE_END 0x60000000 44 45 /* format of page table entries that correspond to shared memory pages 46 currently out in swap space (see also mm/swap.c): 47 bit 0 (PAGE_PRESENT) is = 0 48 bits 7..1 (SWP_TYPE) are = SHM_SWP_TYPE 49 bits 31..8 are used like this: 50 bits 14..8 (SHM_ID) the id of the shared memory segment 51 bits 29..15 (SHM_IDX) the index of the page within the shared memory segment 52 (actually only bits 24..15 get used since SHMMAX is so low) 53 bit 31 (SHM_READ_ONLY) flag whether the page belongs to a read-only attach 54 */ 55 56 #define SHM_ID_SHIFT 8 57 /* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and 58 there is a static array of size SHMMNI. */ 59 #define _SHM_ID_BITS 7 60 #define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) 61 62 #define SHM_IDX_SHIFT (SHM_ID_SHIFT+_SHM_ID_BITS) 63 #define _SHM_IDX_BITS 15 64 #define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) 65 66 #define SHM_READ_ONLY (1<<31) 67 68 /* We must have SHM_ID_SHIFT + _SHM_ID_BITS + _SHM_IDX_BITS + 1 <= 32 69 and SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). */ 70 71 #define SHMMAX 0x3fa000 /* max shared seg size (bytes) */ 72 #define SHMMIN 1 /* really PAGE_SIZE */ /* min shared seg size (bytes) */ 73 #define SHMMNI (1<<_SHM_ID_BITS) /* max num of segs system wide */ 74 #define SHMALL (1<<(_SHM_IDX_BITS+_SHM_ID_BITS))/* max shm system wide (pages) */ 75 #define SHMLBA 0x1000 /* attach addr a multiple of this */ 76 #define SHMSEG SHMMNI /* max shared segs per process */ 77 78 #ifdef __KERNEL__ 79 80 /* shm_mode upper byte flags */ 81 #define SHM_DEST 01000 /* segment will be destroyed on last detach */ 82 #define SHM_LOCKED 02000 /* segment will not be swapped */ 83 84 /* ipcs ctl commands */ 85 #define SHM_STAT 13 86 #define SHM_INFO 14 87 struct shm_info { 88 int used_ids; 89 ulong shm_tot; /* total allocated shm */ 90 ulong shm_rss; /* total resident shm */ 91 ulong shm_swp; /* total swapped shm */ 92 ulong swap_attempts; 93 ulong swap_successes; 94 }; 95 96 #endif /* __KERNEL__ */ 97 98 #endif /* _LINUX_SHM_H_ */ 99