xref: /titanic_50/usr/src/uts/common/sys/shm_impl.h (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/ipc_impl.h>
32 #if defined(_KERNEL) || defined(_KMEMUSER)
33 #include <sys/shm.h>
34 #include <sys/avl.h>
35 #include <sys/t_lock.h>
36 #endif
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * shmsys system call subcodes
44  */
45 #define	SHMAT	0
46 #define	SHMCTL	1
47 #define	SHMDT	2
48 #define	SHMGET	3
49 #define	SHMIDS	4
50 
51 /*
52  *	There is a shared mem id data structure (shmid_ds) for each
53  *	segment in the system.
54  */
55 #if defined(_KERNEL) || defined(_KMEMUSER)
56 typedef struct kshmid {
57 	kipc_perm_t	shm_perm;	/* operation permission struct */
58 	size_t		shm_segsz;	/* size of segment in bytes */
59 	struct anon_map	*shm_amp;	/* segment anon_map pointer */
60 	ushort_t	shm_lkcnt;	/* number of times it is being locked */
61 	pgcnt_t		shm_lkpages;	/* number of pages locked by shmctl */
62 	kmutex_t	shm_mlock;	/* held when locking physical pages */
63 					/* Therefore, protects p_lckcnt for */
64 					/* pages that back shm */
65 	pid_t		shm_lpid;	/* pid of last shmop */
66 	pid_t		shm_cpid;	/* pid of creator */
67 	ulong_t		shm_ismattch;	/* number of ISM attaches */
68 	time_t		shm_atime;	/* last shmat time */
69 	time_t		shm_dtime;	/* last shmdt time */
70 	time_t		shm_ctime;	/* last change time */
71 	struct sptinfo	*shm_sptinfo;	/* info about ISM segment */
72 	struct seg	*shm_sptseg;	/* pointer to ISM segment */
73 	long		shm_sptprot;	/* was reserved (still a "long") */
74 } kshmid_t;
75 
76 /*
77  *	Segacct Flags.
78  */
79 #define	SHMSA_ISM	1	/* uses shared page table */
80 
81 typedef struct sptinfo {
82 	struct as	*sptas;		/* dummy as ptr. for spt segment */
83 } sptinfo_t;
84 
85 /*
86  * Protected by p->p_lock
87  */
88 typedef struct segacct {
89 	avl_node_t	sa_tree;
90 	caddr_t		sa_addr;
91 	size_t		sa_len;
92 	ulong_t		sa_flags;
93 	kshmid_t	*sa_id;
94 } segacct_t;
95 
96 /*
97  * Error codes for shmgetid().
98  */
99 #define	SHMID_NONE	(-1)
100 #define	SHMID_FREE	(-2)
101 
102 extern void shminit(void);
103 extern void shmfork(struct proc *, struct proc *);
104 extern void shmexit(struct proc *);
105 extern int shmgetid(struct proc *, caddr_t);
106 
107 #endif	/* _KERNEL */
108 
109 #if defined(_SYSCALL32)
110 /*
111  * LP64 view of the ILP32 shmid_ds structure
112  */
113 struct shmid_ds32 {
114 	struct ipc_perm32 shm_perm;	/* operation permission struct */
115 	size32_t	shm_segsz;	/* size of segment in bytes */
116 	caddr32_t	shm_amp;	/* segment anon_map pointer */
117 	uint16_t	shm_lkcnt;	/* number of times it is being locked */
118 	pid32_t		shm_lpid;	/* pid of last shmop */
119 	pid32_t		shm_cpid;	/* pid of creator */
120 	uint32_t	shm_nattch;	/* number of attaches */
121 	uint32_t	shm_cnattch;	/* number of ISM attaches */
122 	time32_t	shm_atime;	/* last shmat time */
123 	int32_t		shm_pad1;	/* reserved for time_t expansion */
124 	time32_t	shm_dtime;	/* last shmdt time */
125 	int32_t		shm_pad2;	/* reserved for time_t expansion */
126 	time32_t	shm_ctime;	/* last change time */
127 	int32_t		shm_pad3;	/* reserved for time_t expansion */
128 	int32_t		shm_pad4[4];	/* reserve area  */
129 };
130 #endif
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif	/* _SYS_SHM_IMPL_H */
137