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 shm_desc *attaches; /* descriptors for attaches */ 18 }; 19 20 /* mode for attach */ 21 #define SHM_RDONLY 010000 /* read-only access */ 22 #define SHM_RND 020000 /* round attach address to SHMLBA boundary */ 23 #define SHM_REMAP 040000 /* take-over region on attach */ 24 25 /* super user shmctl commands */ 26 #define SHM_LOCK 11 27 #define SHM_UNLOCK 12 28 29 struct shminfo { 30 int shmmax; 31 int shmmin; 32 int shmmni; 33 int shmseg; 34 int shmall; 35 }; 36 37 /* address range for shared memory attaches if no address passed to shmat() */ 38 #define SHM_RANGE_START 0x40000000 39 #define SHM_RANGE_END 0x60000000 40 41 /* format of page table entries that correspond to shared memory pages 42 currently out in swap space (see also mm/swap.c): 43 bit 0 (PAGE_PRESENT) is = 0 44 bits 7..1 (SWP_TYPE) are = SHM_SWP_TYPE 45 bits 31..8 are used like this: 46 bits 14..8 (SHM_ID) the id of the shared memory segment 47 bits 29..15 (SHM_IDX) the index of the page within the shared memory segment 48 (actually only bits 24..15 get used since SHMMAX is so low) 49 bit 31 (SHM_READ_ONLY) flag whether the page belongs to a read-only attach 50 */ 51 52 #define SHM_ID_SHIFT 8 53 /* Keep _SHM_ID_BITS as low as possible since SHMMNI depends on it and 54 there is a static array of size SHMMNI. */ 55 #define _SHM_ID_BITS 7 56 #define SHM_ID_MASK ((1<<_SHM_ID_BITS)-1) 57 58 #define SHM_IDX_SHIFT (SHM_ID_SHIFT+_SHM_ID_BITS) 59 #define _SHM_IDX_BITS 15 60 #define SHM_IDX_MASK ((1<<_SHM_IDX_BITS)-1) 61 62 #define SHM_READ_ONLY (1<<31) 63 64 /* We must have SHM_ID_SHIFT + _SHM_ID_BITS + _SHM_IDX_BITS + 1 <= 32 65 and SHMMAX <= (PAGE_SIZE << _SHM_IDX_BITS). */ 66 67 #define SHMMAX 0x3fa000 /* max shared seg size (bytes) */ 68 #define SHMMIN 1 /* really PAGE_SIZE */ /* min shared seg size (bytes) */ 69 #define SHMMNI (1<<_SHM_ID_BITS) /* max num of segs system wide */ 70 #define SHMALL (1<<(_SHM_IDX_BITS+_SHM_ID_BITS))/* max shm system wide (pages) */ 71 #define SHMLBA 0x1000 /* attach addr a multiple of this */ 72 #define SHMSEG SHMMNI /* max shared segs per process */ 73 74 #ifdef __KERNEL__ 75 76 /* shm_mode upper byte flags */ 77 #define SHM_DEST 01000 /* segment will be destroyed on last detach */ 78 #define SHM_LOCKED 02000 /* segment will not be swapped */ 79 80 /* ipcs ctl commands */ 81 #define SHM_STAT 13 82 #define SHM_INFO 14 83 struct shm_info { 84 int used_ids; 85 ulong shm_tot; /* total allocated shm */ 86 ulong shm_rss; /* total resident shm */ 87 ulong shm_swp; /* total swapped shm */ 88 ulong swap_attempts; 89 ulong swap_successes; 90 }; 91 92 93 /* 94 * Per process internal structure for managing segments. 95 * A shmat will add to and shmdt will remove from the list. 96 */ 97 struct shm_desc { 98 struct task_struct *task; /* attacher */ 99 unsigned long shm_sgn; /* signature for this attach */ 100 unsigned long start; /* virt addr of attach, multiple of SHMLBA */ 101 unsigned long end; /* multiple of SHMLBA */ 102 struct shm_desc *task_next; /* next attach for task */ 103 struct shm_desc *seg_next; /* next attach for segment */ 104 }; 105 106 #endif /* __KERNEL__ */ 107 108 #endif /* _LINUX_SHM_H_ */ 109