xref: /illumos-gate/usr/src/uts/common/sys/corectl.h (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_CORECTL_H
28 #define	_SYS_CORECTL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 #include <sys/zone.h>
34 #include <sys/refstr.h>
35 #include <sys/mutex.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * Definitions for corectl() system call.
43  */
44 
45 /* subcodes */
46 #define	CC_SET_OPTIONS		1
47 #define	CC_GET_OPTIONS		2
48 #define	CC_SET_GLOBAL_PATH	3
49 #define	CC_GET_GLOBAL_PATH	4
50 #define	CC_SET_PROCESS_PATH	5
51 #define	CC_GET_PROCESS_PATH	6
52 #define	CC_SET_GLOBAL_CONTENT	7
53 #define	CC_GET_GLOBAL_CONTENT	8
54 #define	CC_SET_PROCESS_CONTENT	9
55 #define	CC_GET_PROCESS_CONTENT	10
56 #define	CC_SET_DEFAULT_PATH	11
57 #define	CC_GET_DEFAULT_PATH	12
58 #define	CC_SET_DEFAULT_CONTENT	13
59 #define	CC_GET_DEFAULT_CONTENT	14
60 
61 /* options */
62 #define	CC_GLOBAL_PATH		0x01	/* enable global core files */
63 #define	CC_PROCESS_PATH		0x02	/* enable per-process core files */
64 #define	CC_GLOBAL_SETID		0x04	/* allow global setid core files */
65 #define	CC_PROCESS_SETID	0x08	/* allow per-process setid core files */
66 #define	CC_GLOBAL_LOG		0x10	/* log global core dumps to syslog */
67 
68 /* all of the above */
69 #define	CC_OPTIONS	\
70 	(CC_GLOBAL_PATH | CC_PROCESS_PATH | \
71 	CC_GLOBAL_SETID | CC_PROCESS_SETID | CC_GLOBAL_LOG)
72 
73 /* contents */
74 #define	CC_CONTENT_STACK	0x0001ULL /* process stack */
75 #define	CC_CONTENT_HEAP		0x0002ULL /* process heap */
76 
77 /* MAP_SHARED file mappings */
78 #define	CC_CONTENT_SHFILE	0x0004ULL /* file-backed shared mapping */
79 #define	CC_CONTENT_SHANON	0x0008ULL /* anonymous shared mapping */
80 
81 /* MAP_PRIVATE file mappings */
82 #define	CC_CONTENT_TEXT		0x0010ULL /* read/exec file mappings */
83 #define	CC_CONTENT_DATA		0x0020ULL /* writable file mappings */
84 #define	CC_CONTENT_RODATA	0x0040ULL /* read-only file mappings */
85 #define	CC_CONTENT_ANON		0x0080ULL /* anonymous mappings (MAP_ANON) */
86 
87 #define	CC_CONTENT_SHM		0x0100ULL /* System V shared memory */
88 #define	CC_CONTENT_ISM		0x0200ULL /* intimate shared memory */
89 #define	CC_CONTENT_DISM		0x0400ULL /* dynamic intimate shared memory */
90 
91 #define	CC_CONTENT_CTF		0x0800ULL /* CTF data */
92 #define	CC_CONTENT_SYMTAB	0x1000ULL /* symbol table */
93 
94 #define	CC_CONTENT_ALL		0x1fffULL
95 #define	CC_CONTENT_NONE		0ULL
96 #define	CC_CONTENT_DEFAULT	(CC_CONTENT_STACK | CC_CONTENT_HEAP | \
97 	CC_CONTENT_ISM | CC_CONTENT_DISM | CC_CONTENT_SHM | \
98 	CC_CONTENT_SHANON | CC_CONTENT_TEXT | CC_CONTENT_DATA | \
99 	CC_CONTENT_RODATA | CC_CONTENT_ANON | CC_CONTENT_CTF)
100 #define	CC_CONTENT_INVALID	(-1ULL)
101 
102 typedef u_longlong_t	core_content_t;
103 
104 typedef struct corectl_content {
105 	core_content_t	ccc_content;
106 	kmutex_t	ccc_mtx;
107 	uint32_t	ccc_refcnt;
108 } corectl_content_t;
109 
110 typedef struct corectl_path {
111 	refstr_t	*ccp_path;
112 	kmutex_t	ccp_mtx;
113 	uint32_t	ccp_refcnt;
114 } corectl_path_t;
115 
116 #ifdef _KERNEL
117 
118 struct core_globals {
119 	kmutex_t		core_lock;
120 	refstr_t		*core_file;
121 	uint32_t		core_options;
122 	core_content_t		core_content;
123 	rlim64_t		core_rlimit;
124 	corectl_path_t		*core_default_path;
125 	corectl_content_t	*core_default_content;
126 };
127 
128 extern	zone_key_t	core_zone_key;
129 
130 extern void init_core(void);
131 extern void set_core_defaults(void);
132 
133 extern core_content_t corectl_content_value(corectl_content_t *);
134 extern void corectl_content_hold(corectl_content_t *);
135 extern void corectl_content_rele(corectl_content_t *);
136 
137 extern refstr_t *corectl_path_value(corectl_path_t *);
138 extern void corectl_path_hold(corectl_path_t *);
139 extern void corectl_path_rele(corectl_path_t *);
140 
141 #else	/* _KERNEL */
142 
143 extern	int	core_set_options(int);
144 extern	int	core_get_options(void);
145 extern	int	core_set_global_path(const char *, size_t);
146 extern	int	core_get_global_path(char *, size_t);
147 extern	int	core_set_default_path(const char *, size_t);
148 extern	int	core_get_default_path(char *, size_t);
149 extern	int	core_set_process_path(const char *, size_t, pid_t);
150 extern	int	core_get_process_path(char *, size_t, pid_t);
151 extern	int	core_set_global_content(const core_content_t *);
152 extern	int	core_get_global_content(core_content_t *);
153 extern	int	core_set_default_content(const core_content_t *);
154 extern	int	core_get_default_content(core_content_t *);
155 extern	int	core_set_process_content(const core_content_t *, pid_t);
156 extern	int	core_get_process_content(core_content_t *, pid_t);
157 
158 #endif	/* _KERNEL */
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _SYS_CORECTL_H */
165