blob: 4de12a39b07506e04fff9d658144b2feee136d50 [file] [log] [blame]
Greg Kroah-Hartman6f52b162017-11-01 15:08:43 +01001/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
David Howells607ca462012-10-13 10:46:48 +01002#ifndef _UAPI_LINUX_SHM_H_
3#define _UAPI_LINUX_SHM_H_
4
5#include <linux/ipc.h>
6#include <linux/errno.h>
Mike Kravetz4da243a2017-09-06 16:23:33 -07007#include <asm-generic/hugetlb_encode.h>
David Howells607ca462012-10-13 10:46:48 +01008#ifndef __KERNEL__
9#include <unistd.h>
10#endif
11
12/*
Davidlohr Buesof57a19a2014-06-06 14:37:43 -070013 * SHMMNI, SHMMAX and SHMALL are default upper limits which can be
14 * modified by sysctl. The SHMMAX and SHMALL values have been chosen to
15 * be as large possible without facilitating scenarios where userspace
16 * causes overflows when adjusting the limits via operations of the form
17 * "retrieve current limit; add X; update limit". It is therefore not
18 * advised to make SHMMAX and SHMALL any larger. These limits are
19 * suitable for both 32 and 64-bit systems.
David Howells607ca462012-10-13 10:46:48 +010020 */
David Howells607ca462012-10-13 10:46:48 +010021#define SHMMIN 1 /* min shared seg size (bytes) */
22#define SHMMNI 4096 /* max num of segs system wide */
Davidlohr Buesof57a19a2014-06-06 14:37:43 -070023#define SHMMAX (ULONG_MAX - (1UL << 24)) /* max shared seg size (bytes) */
24#define SHMALL (ULONG_MAX - (1UL << 24)) /* max shm system wide (pages) */
David Howells607ca462012-10-13 10:46:48 +010025#define SHMSEG SHMMNI /* max shared segs per process */
26
David Howells607ca462012-10-13 10:46:48 +010027/* Obsolete, used only for backwards compatibility and libc5 compiles */
28struct shmid_ds {
29 struct ipc_perm shm_perm; /* operation perms */
30 int shm_segsz; /* size of segment (bytes) */
31 __kernel_time_t shm_atime; /* last attach time */
32 __kernel_time_t shm_dtime; /* last detach time */
33 __kernel_time_t shm_ctime; /* last change time */
34 __kernel_ipc_pid_t shm_cpid; /* pid of creator */
35 __kernel_ipc_pid_t shm_lpid; /* pid of last operator */
36 unsigned short shm_nattch; /* no. of current attaches */
37 unsigned short shm_unused; /* compatibility */
38 void *shm_unused2; /* ditto - used by DIPC */
39 void *shm_unused3; /* unused */
40};
41
42/* Include the definition of shmid64_ds and shminfo64 */
43#include <asm/shmbuf.h>
44
Mike Kravetz4da243a2017-09-06 16:23:33 -070045/*
46 * shmget() shmflg values.
47 */
48/* The bottom nine bits are the same as open(2) mode flags */
David Howells607ca462012-10-13 10:46:48 +010049#define SHM_R 0400 /* or S_IRUGO from <linux/stat.h> */
50#define SHM_W 0200 /* or S_IWUGO from <linux/stat.h> */
Mike Kravetz4da243a2017-09-06 16:23:33 -070051/* Bits 9 & 10 are IPC_CREAT and IPC_EXCL */
52#define SHM_HUGETLB 04000 /* segment will use huge TLB pages */
53#define SHM_NORESERVE 010000 /* don't check for reservations */
David Howells607ca462012-10-13 10:46:48 +010054
Mike Kravetz4da243a2017-09-06 16:23:33 -070055/*
56 * Huge page size encoding when SHM_HUGETLB is specified, and a huge page
57 * size other than the default is desired. See hugetlb_encode.h
58 */
59#define SHM_HUGE_SHIFT HUGETLB_FLAG_ENCODE_SHIFT
60#define SHM_HUGE_MASK HUGETLB_FLAG_ENCODE_MASK
61
62#define SHM_HUGE_64KB HUGETLB_FLAG_ENCODE_64KB
63#define SHM_HUGE_512KB HUGETLB_FLAG_ENCODE_512KB
64#define SHM_HUGE_1MB HUGETLB_FLAG_ENCODE_1MB
65#define SHM_HUGE_2MB HUGETLB_FLAG_ENCODE_2MB
66#define SHM_HUGE_8MB HUGETLB_FLAG_ENCODE_8MB
67#define SHM_HUGE_16MB HUGETLB_FLAG_ENCODE_16MB
68#define SHM_HUGE_256MB HUGETLB_FLAG_ENCODE_256MB
69#define SHM_HUGE_1GB HUGETLB_FLAG_ENCODE_1GB
70#define SHM_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB
71#define SHM_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB
72
73/*
74 * shmat() shmflg values
75 */
David Howells607ca462012-10-13 10:46:48 +010076#define SHM_RDONLY 010000 /* read-only access */
77#define SHM_RND 020000 /* round attach address to SHMLBA boundary */
78#define SHM_REMAP 040000 /* take-over region on attach */
79#define SHM_EXEC 0100000 /* execution access */
80
81/* super user shmctl commands */
82#define SHM_LOCK 11
83#define SHM_UNLOCK 12
84
85/* ipcs ctl commands */
86#define SHM_STAT 13
87#define SHM_INFO 14
88
89/* Obsolete, used only for backwards compatibility */
90struct shminfo {
91 int shmmax;
92 int shmmin;
93 int shmmni;
94 int shmseg;
95 int shmall;
96};
97
98struct shm_info {
99 int used_ids;
H.J. Luf8dcdf02013-12-27 14:14:23 -0800100 __kernel_ulong_t shm_tot; /* total allocated shm */
101 __kernel_ulong_t shm_rss; /* total resident shm */
102 __kernel_ulong_t shm_swp; /* total swapped shm */
103 __kernel_ulong_t swap_attempts;
104 __kernel_ulong_t swap_successes;
David Howells607ca462012-10-13 10:46:48 +0100105};
106
107
108#endif /* _UAPI_LINUX_SHM_H_ */