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