xref: /illumos-gate/usr/src/uts/common/sys/shm_impl.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_SHM_IMPL_H
27 #define	_SYS_SHM_IMPL_H
28 
29 #include <sys/ipc_impl.h>
30 #if defined(_KERNEL) || defined(_KMEMUSER)
31 #include <sys/shm.h>
32 #include <sys/avl.h>
33 #include <sys/t_lock.h>
34 #endif
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /*
41  * shmsys system call subcodes
42  */
43 #define	SHMAT	0
44 #define	SHMCTL	1
45 #define	SHMDT	2
46 #define	SHMGET	3
47 #define	SHMIDS	4
48 
49 /*
50  *	There is a shared mem id data structure (shmid_ds) for each
51  *	segment in the system.
52  */
53 #if defined(_KERNEL) || defined(_KMEMUSER)
54 typedef struct kshmid {
55 	kipc_perm_t	shm_perm;	/* operation permission struct */
56 	size_t		shm_segsz;	/* size of segment in bytes */
57 	struct anon_map	*shm_amp;	/* segment anon_map pointer */
58 	ushort_t	shm_lkcnt;	/* number of times it is being locked */
59 	pgcnt_t		shm_lkpages;	/* number of pages locked by shmctl */
60 	kmutex_t	shm_mlock;	/* held when locking physical pages */
61 					/* Therefore, protects p_lckcnt for */
62 					/* pages that back shm */
63 	pid_t		shm_lpid;	/* pid of last shmop */
64 	pid_t		shm_cpid;	/* pid of creator */
65 	ulong_t		shm_ismattch;	/* number of ISM attaches */
66 	time_t		shm_atime;	/* last shmat time */
67 	time_t		shm_dtime;	/* last shmdt time */
68 	time_t		shm_ctime;	/* last change time */
69 	struct sptinfo	*shm_sptinfo;	/* info about ISM segment */
70 	struct seg	*shm_sptseg;	/* pointer to ISM segment */
71 	long		shm_sptprot;	/* was reserved (still a "long") */
72 } kshmid_t;
73 
74 /*
75  *	Segacct Flags.
76  */
77 #define	SHMSA_ISM	1	/* uses shared page table */
78 
79 typedef struct sptinfo {
80 	struct as	*sptas;		/* dummy as ptr. for spt segment */
81 } sptinfo_t;
82 
83 /*
84  * Protected by p->p_lock
85  */
86 typedef struct segacct {
87 	avl_node_t	sa_tree;
88 	caddr_t		sa_addr;
89 	size_t		sa_len;
90 	ulong_t		sa_flags;
91 	kshmid_t	*sa_id;
92 } segacct_t;
93 
94 /*
95  * Error codes for shmgetid().
96  */
97 #define	SHMID_NONE	(-1)
98 #define	SHMID_FREE	(-2)
99 
100 extern void shminit(void);
101 extern void shmfork(struct proc *, struct proc *);
102 extern void shmexit(struct proc *);
103 extern int shmgetid(struct proc *, caddr_t);
104 
105 #endif	/* _KERNEL */
106 
107 #if defined(_SYSCALL32)
108 /*
109  * LP64 view of the ILP32 shmid_ds structure
110  */
111 struct shmid_ds32 {
112 	struct ipc_perm32 shm_perm;	/* operation permission struct */
113 	size32_t	shm_segsz;	/* size of segment in bytes */
114 	caddr32_t	shm_amp;	/* segment anon_map pointer */
115 	uint16_t	shm_lkcnt;	/* number of times it is being locked */
116 	pid32_t		shm_lpid;	/* pid of last shmop */
117 	pid32_t		shm_cpid;	/* pid of creator */
118 	uint32_t	shm_nattch;	/* number of attaches */
119 	uint32_t	shm_cnattch;	/* number of ISM attaches */
120 	time32_t	shm_atime;	/* last shmat time */
121 	int32_t		shm_pad1;	/* reserved for time_t expansion */
122 	time32_t	shm_dtime;	/* last shmdt time */
123 	int32_t		shm_pad2;	/* reserved for time_t expansion */
124 	time32_t	shm_ctime;	/* last change time */
125 	int32_t		shm_pad3;	/* reserved for time_t expansion */
126 	int32_t		shm_pad4[4];	/* reserve area  */
127 };
128 #endif
129 
130 #ifdef	__cplusplus
131 }
132 #endif
133 
134 #endif	/* _SYS_SHM_IMPL_H */
135