blob: 92808b86703ba7a63f786407144ec28f10ad13bc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_SHM_H_
2#define _LINUX_SHM_H_
3
4#include <linux/ipc.h>
5#include <linux/errno.h>
Kirill A. Shutemoved7b1882008-02-07 00:15:56 -08006#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <asm/page.h>
Kirill A. Shutemoved7b1882008-02-07 00:15:56 -08008#else
9#include <unistd.h>
10#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
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 */
Kirill A. Shutemoved7b1882008-02-07 00:15:56 -080020#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define SHMALL (SHMMAX/PAGE_SIZE*(SHMMNI/16)) /* max shm system wide (pages) */
Kirill A. Shutemoved7b1882008-02-07 00:15:56 -080022#else
23#define SHMALL (SHMMAX/getpagesize()*(SHMMNI/16))
24#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#define SHMSEG SHMMNI /* max shared segs per process */
26
Olaf Hering4029a9172007-10-16 23:26:12 -070027#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <asm/shmparam.h>
Olaf Hering4029a9172007-10-16 23:26:12 -070029#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* Obsolete, used only for backwards compatibility and libc5 compiles */
32struct 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 */
68struct shminfo {
69 int shmmax;
70 int shmmin;
71 int shmmni;
72 int shmseg;
73 int shmall;
74};
75
76struct 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__
86struct shmid_kernel /* private to the kernel */
87{
88 struct kern_ipc_perm shm_perm;
89 struct file * shm_file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 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;
Vasiliy Kulikov5774ed02011-07-29 03:55:31 +040098
99 /* The task created the shm object. NULL if the task is dead. */
100 struct task_struct *shm_creator;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101};
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 */
Badari Pulavartybf8f9722005-11-07 00:59:27 -0800107#define SHM_NORESERVE 010000 /* don't check for reservations */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109#ifdef CONFIG_SYSVIPC
110long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr);
Adam Litke516dffd2007-03-01 15:46:08 -0800111extern int is_file_shm_hugepages(struct file *file);
Vasiliy Kulikovb34a6b12011-07-26 16:08:48 -0700112extern void exit_shm(struct task_struct *task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113#else
114static inline long do_shmat(int shmid, char __user *shmaddr,
115 int shmflg, unsigned long *addr)
116{
117 return -ENOSYS;
118}
Adam Litke516dffd2007-03-01 15:46:08 -0800119static inline int is_file_shm_hugepages(struct file *file)
120{
121 return 0;
122}
Vasiliy Kulikovb34a6b12011-07-26 16:08:48 -0700123static inline void exit_shm(struct task_struct *task)
124{
125}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#endif
127
128#endif /* __KERNEL__ */
129
130#endif /* _LINUX_SHM_H_ */