xref: /illumos-gate/usr/src/uts/common/sys/corectl.h (revision 22de1048)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*22de1048SEdward Pilatowicz  * Common Development and Distribution License (the "License").
6*22de1048SEdward Pilatowicz  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*22de1048SEdward Pilatowicz  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_CORECTL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_CORECTL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/zone.h>
317c478bd9Sstevel@tonic-gate #include <sys/refstr.h>
327c478bd9Sstevel@tonic-gate #include <sys/mutex.h>
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
397c478bd9Sstevel@tonic-gate  * Definitions for corectl() system call.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /* subcodes */
437c478bd9Sstevel@tonic-gate #define	CC_SET_OPTIONS		1
447c478bd9Sstevel@tonic-gate #define	CC_GET_OPTIONS		2
457c478bd9Sstevel@tonic-gate #define	CC_SET_GLOBAL_PATH	3
467c478bd9Sstevel@tonic-gate #define	CC_GET_GLOBAL_PATH	4
477c478bd9Sstevel@tonic-gate #define	CC_SET_PROCESS_PATH	5
487c478bd9Sstevel@tonic-gate #define	CC_GET_PROCESS_PATH	6
497c478bd9Sstevel@tonic-gate #define	CC_SET_GLOBAL_CONTENT	7
507c478bd9Sstevel@tonic-gate #define	CC_GET_GLOBAL_CONTENT	8
517c478bd9Sstevel@tonic-gate #define	CC_SET_PROCESS_CONTENT	9
527c478bd9Sstevel@tonic-gate #define	CC_GET_PROCESS_CONTENT	10
537c478bd9Sstevel@tonic-gate #define	CC_SET_DEFAULT_PATH	11
547c478bd9Sstevel@tonic-gate #define	CC_GET_DEFAULT_PATH	12
557c478bd9Sstevel@tonic-gate #define	CC_SET_DEFAULT_CONTENT	13
567c478bd9Sstevel@tonic-gate #define	CC_GET_DEFAULT_CONTENT	14
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /* options */
597c478bd9Sstevel@tonic-gate #define	CC_GLOBAL_PATH		0x01	/* enable global core files */
607c478bd9Sstevel@tonic-gate #define	CC_PROCESS_PATH		0x02	/* enable per-process core files */
617c478bd9Sstevel@tonic-gate #define	CC_GLOBAL_SETID		0x04	/* allow global setid core files */
627c478bd9Sstevel@tonic-gate #define	CC_PROCESS_SETID	0x08	/* allow per-process setid core files */
637c478bd9Sstevel@tonic-gate #define	CC_GLOBAL_LOG		0x10	/* log global core dumps to syslog */
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /* all of the above */
667c478bd9Sstevel@tonic-gate #define	CC_OPTIONS	\
677c478bd9Sstevel@tonic-gate 	(CC_GLOBAL_PATH | CC_PROCESS_PATH | \
687c478bd9Sstevel@tonic-gate 	CC_GLOBAL_SETID | CC_PROCESS_SETID | CC_GLOBAL_LOG)
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /* contents */
717c478bd9Sstevel@tonic-gate #define	CC_CONTENT_STACK	0x0001ULL /* process stack */
727c478bd9Sstevel@tonic-gate #define	CC_CONTENT_HEAP		0x0002ULL /* process heap */
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /* MAP_SHARED file mappings */
757c478bd9Sstevel@tonic-gate #define	CC_CONTENT_SHFILE	0x0004ULL /* file-backed shared mapping */
767c478bd9Sstevel@tonic-gate #define	CC_CONTENT_SHANON	0x0008ULL /* anonymous shared mapping */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /* MAP_PRIVATE file mappings */
797c478bd9Sstevel@tonic-gate #define	CC_CONTENT_TEXT		0x0010ULL /* read/exec file mappings */
807c478bd9Sstevel@tonic-gate #define	CC_CONTENT_DATA		0x0020ULL /* writable file mappings */
817c478bd9Sstevel@tonic-gate #define	CC_CONTENT_RODATA	0x0040ULL /* read-only file mappings */
827c478bd9Sstevel@tonic-gate #define	CC_CONTENT_ANON		0x0080ULL /* anonymous mappings (MAP_ANON) */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	CC_CONTENT_SHM		0x0100ULL /* System V shared memory */
857c478bd9Sstevel@tonic-gate #define	CC_CONTENT_ISM		0x0200ULL /* intimate shared memory */
867c478bd9Sstevel@tonic-gate #define	CC_CONTENT_DISM		0x0400ULL /* dynamic intimate shared memory */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	CC_CONTENT_CTF		0x0800ULL /* CTF data */
897c478bd9Sstevel@tonic-gate #define	CC_CONTENT_SYMTAB	0x1000ULL /* symbol table */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	CC_CONTENT_ALL		0x1fffULL
927c478bd9Sstevel@tonic-gate #define	CC_CONTENT_NONE		0ULL
937c478bd9Sstevel@tonic-gate #define	CC_CONTENT_DEFAULT	(CC_CONTENT_STACK | CC_CONTENT_HEAP | \
947c478bd9Sstevel@tonic-gate 	CC_CONTENT_ISM | CC_CONTENT_DISM | CC_CONTENT_SHM | \
957c478bd9Sstevel@tonic-gate 	CC_CONTENT_SHANON | CC_CONTENT_TEXT | CC_CONTENT_DATA | \
96*22de1048SEdward Pilatowicz 	CC_CONTENT_RODATA | CC_CONTENT_ANON | CC_CONTENT_CTF | \
97*22de1048SEdward Pilatowicz 	CC_CONTENT_SYMTAB)
987c478bd9Sstevel@tonic-gate #define	CC_CONTENT_INVALID	(-1ULL)
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate typedef u_longlong_t	core_content_t;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate typedef struct corectl_content {
1037c478bd9Sstevel@tonic-gate 	core_content_t	ccc_content;
1047c478bd9Sstevel@tonic-gate 	kmutex_t	ccc_mtx;
1057c478bd9Sstevel@tonic-gate 	uint32_t	ccc_refcnt;
1067c478bd9Sstevel@tonic-gate } corectl_content_t;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate typedef struct corectl_path {
1097c478bd9Sstevel@tonic-gate 	refstr_t	*ccp_path;
1107c478bd9Sstevel@tonic-gate 	kmutex_t	ccp_mtx;
1117c478bd9Sstevel@tonic-gate 	uint32_t	ccp_refcnt;
1127c478bd9Sstevel@tonic-gate } corectl_path_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate struct core_globals {
1177c478bd9Sstevel@tonic-gate 	kmutex_t		core_lock;
1187c478bd9Sstevel@tonic-gate 	refstr_t		*core_file;
1197c478bd9Sstevel@tonic-gate 	uint32_t		core_options;
1207c478bd9Sstevel@tonic-gate 	core_content_t		core_content;
1217c478bd9Sstevel@tonic-gate 	rlim64_t		core_rlimit;
1227c478bd9Sstevel@tonic-gate 	corectl_path_t		*core_default_path;
1237c478bd9Sstevel@tonic-gate 	corectl_content_t	*core_default_content;
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate extern	zone_key_t	core_zone_key;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate extern void init_core(void);
1297c478bd9Sstevel@tonic-gate extern void set_core_defaults(void);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern core_content_t corectl_content_value(corectl_content_t *);
1327c478bd9Sstevel@tonic-gate extern void corectl_content_hold(corectl_content_t *);
1337c478bd9Sstevel@tonic-gate extern void corectl_content_rele(corectl_content_t *);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate extern refstr_t *corectl_path_value(corectl_path_t *);
1367c478bd9Sstevel@tonic-gate extern void corectl_path_hold(corectl_path_t *);
1377c478bd9Sstevel@tonic-gate extern void corectl_path_rele(corectl_path_t *);
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate #else	/* _KERNEL */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate extern	int	core_set_options(int);
1427c478bd9Sstevel@tonic-gate extern	int	core_get_options(void);
1437c478bd9Sstevel@tonic-gate extern	int	core_set_global_path(const char *, size_t);
1447c478bd9Sstevel@tonic-gate extern	int	core_get_global_path(char *, size_t);
1457c478bd9Sstevel@tonic-gate extern	int	core_set_default_path(const char *, size_t);
1467c478bd9Sstevel@tonic-gate extern	int	core_get_default_path(char *, size_t);
1477c478bd9Sstevel@tonic-gate extern	int	core_set_process_path(const char *, size_t, pid_t);
1487c478bd9Sstevel@tonic-gate extern	int	core_get_process_path(char *, size_t, pid_t);
1497c478bd9Sstevel@tonic-gate extern	int	core_set_global_content(const core_content_t *);
1507c478bd9Sstevel@tonic-gate extern	int	core_get_global_content(core_content_t *);
1517c478bd9Sstevel@tonic-gate extern	int	core_set_default_content(const core_content_t *);
1527c478bd9Sstevel@tonic-gate extern	int	core_get_default_content(core_content_t *);
1537c478bd9Sstevel@tonic-gate extern	int	core_set_process_content(const core_content_t *, pid_t);
1547c478bd9Sstevel@tonic-gate extern	int	core_get_process_content(core_content_t *, pid_t);
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1597c478bd9Sstevel@tonic-gate }
1607c478bd9Sstevel@tonic-gate #endif
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate #endif	/* _SYS_CORECTL_H */
163