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 2008 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef _SYS_CORECTL_H
27#define	_SYS_CORECTL_H
28
29#include <sys/types.h>
30#include <sys/zone.h>
31#include <sys/refstr.h>
32#include <sys/mutex.h>
33
34#ifdef	__cplusplus
35extern "C" {
36#endif
37
38/*
39 * Definitions for corectl() system call.
40 */
41
42/* subcodes */
43#define	CC_SET_OPTIONS		1
44#define	CC_GET_OPTIONS		2
45#define	CC_SET_GLOBAL_PATH	3
46#define	CC_GET_GLOBAL_PATH	4
47#define	CC_SET_PROCESS_PATH	5
48#define	CC_GET_PROCESS_PATH	6
49#define	CC_SET_GLOBAL_CONTENT	7
50#define	CC_GET_GLOBAL_CONTENT	8
51#define	CC_SET_PROCESS_CONTENT	9
52#define	CC_GET_PROCESS_CONTENT	10
53#define	CC_SET_DEFAULT_PATH	11
54#define	CC_GET_DEFAULT_PATH	12
55#define	CC_SET_DEFAULT_CONTENT	13
56#define	CC_GET_DEFAULT_CONTENT	14
57
58/* options */
59#define	CC_GLOBAL_PATH		0x01	/* enable global core files */
60#define	CC_PROCESS_PATH		0x02	/* enable per-process core files */
61#define	CC_GLOBAL_SETID		0x04	/* allow global setid core files */
62#define	CC_PROCESS_SETID	0x08	/* allow per-process setid core files */
63#define	CC_GLOBAL_LOG		0x10	/* log global core dumps to syslog */
64
65/* all of the above */
66#define	CC_OPTIONS	\
67	(CC_GLOBAL_PATH | CC_PROCESS_PATH | \
68	CC_GLOBAL_SETID | CC_PROCESS_SETID | CC_GLOBAL_LOG)
69
70/* contents */
71#define	CC_CONTENT_STACK	0x0001ULL /* process stack */
72#define	CC_CONTENT_HEAP		0x0002ULL /* process heap */
73
74/* MAP_SHARED file mappings */
75#define	CC_CONTENT_SHFILE	0x0004ULL /* file-backed shared mapping */
76#define	CC_CONTENT_SHANON	0x0008ULL /* anonymous shared mapping */
77
78/* MAP_PRIVATE file mappings */
79#define	CC_CONTENT_TEXT		0x0010ULL /* read/exec file mappings */
80#define	CC_CONTENT_DATA		0x0020ULL /* writable file mappings */
81#define	CC_CONTENT_RODATA	0x0040ULL /* read-only file mappings */
82#define	CC_CONTENT_ANON		0x0080ULL /* anonymous mappings (MAP_ANON) */
83
84#define	CC_CONTENT_SHM		0x0100ULL /* System V shared memory */
85#define	CC_CONTENT_ISM		0x0200ULL /* intimate shared memory */
86#define	CC_CONTENT_DISM		0x0400ULL /* dynamic intimate shared memory */
87
88#define	CC_CONTENT_CTF		0x0800ULL /* CTF data */
89#define	CC_CONTENT_SYMTAB	0x1000ULL /* symbol table */
90
91#define	CC_CONTENT_ALL		0x1fffULL
92#define	CC_CONTENT_NONE		0ULL
93#define	CC_CONTENT_DEFAULT	(CC_CONTENT_STACK | CC_CONTENT_HEAP | \
94	CC_CONTENT_ISM | CC_CONTENT_DISM | CC_CONTENT_SHM | \
95	CC_CONTENT_SHANON | CC_CONTENT_TEXT | CC_CONTENT_DATA | \
96	CC_CONTENT_RODATA | CC_CONTENT_ANON | CC_CONTENT_CTF | \
97	CC_CONTENT_SYMTAB)
98#define	CC_CONTENT_INVALID	(-1ULL)
99
100typedef u_longlong_t	core_content_t;
101
102typedef struct corectl_content {
103	core_content_t	ccc_content;
104	kmutex_t	ccc_mtx;
105	uint32_t	ccc_refcnt;
106} corectl_content_t;
107
108typedef struct corectl_path {
109	refstr_t	*ccp_path;
110	kmutex_t	ccp_mtx;
111	uint32_t	ccp_refcnt;
112} corectl_path_t;
113
114#ifdef _KERNEL
115
116struct core_globals {
117	kmutex_t		core_lock;
118	refstr_t		*core_file;
119	uint32_t		core_options;
120	core_content_t		core_content;
121	rlim64_t		core_rlimit;
122	corectl_path_t		*core_default_path;
123	corectl_content_t	*core_default_content;
124};
125
126extern	zone_key_t	core_zone_key;
127
128extern void init_core(void);
129extern void set_core_defaults(void);
130
131extern core_content_t corectl_content_value(corectl_content_t *);
132extern void corectl_content_hold(corectl_content_t *);
133extern void corectl_content_rele(corectl_content_t *);
134
135extern refstr_t *corectl_path_value(corectl_path_t *);
136extern void corectl_path_hold(corectl_path_t *);
137extern void corectl_path_rele(corectl_path_t *);
138
139#else	/* _KERNEL */
140
141extern	int	core_set_options(int);
142extern	int	core_get_options(void);
143extern	int	core_set_global_path(const char *, size_t);
144extern	int	core_get_global_path(char *, size_t);
145extern	int	core_set_default_path(const char *, size_t);
146extern	int	core_get_default_path(char *, size_t);
147extern	int	core_set_process_path(const char *, size_t, pid_t);
148extern	int	core_get_process_path(char *, size_t, pid_t);
149extern	int	core_set_global_content(const core_content_t *);
150extern	int	core_get_global_content(core_content_t *);
151extern	int	core_set_default_content(const core_content_t *);
152extern	int	core_get_default_content(core_content_t *);
153extern	int	core_set_process_content(const core_content_t *, pid_t);
154extern	int	core_get_process_content(core_content_t *, pid_t);
155
156#endif	/* _KERNEL */
157
158#ifdef	__cplusplus
159}
160#endif
161
162#endif	/* _SYS_CORECTL_H */
163