xref: /titanic_41/usr/src/uts/common/sys/brand.h (revision 0db3240d392634cfff2f95fb6da34b56b8dc574f)
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 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_BRAND_H
28 #define	_SYS_BRAND_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/proc.h>
35 #include <sys/exec.h>
36 
37 /*
38  * All Brands supported by this kernel must use BRAND_VER_1.
39  */
40 #define	BRAND_VER_1	1
41 
42 /*
43  * sub-commands to brandsys.
44  * 1 - 128 are for common commands
45  * 128+ are available for brand-specific commands.
46  */
47 #define	B_REGISTER		1
48 #define	B_TTYMODES		2
49 #define	B_ELFDATA		3
50 #define	B_EXEC_NATIVE		4
51 #define	B_EXEC_BRAND		5
52 
53 /*
54  * Structure used by zoneadmd to communicate the name of a brand and the
55  * supporting brand module into the kernel.
56  */
57 struct brand_attr {
58 	char	ba_brandname[MAXNAMELEN];
59 	char	ba_modname[MAXPATHLEN];
60 };
61 
62 /* What we call the native brand. */
63 #define	NATIVE_BRAND_NAME	"native"
64 
65 /* What we call the labeled brand. */
66 #define	LABELED_BRAND_NAME	"labeled"
67 
68 #ifdef	_KERNEL
69 
70 /* Root for branded zone's native binaries */
71 #define	NATIVE_ROOT	"/native/"
72 
73 struct proc;
74 struct uarg;
75 struct brand_mach_ops;
76 struct intpdata;
77 struct execa;
78 
79 struct brand_ops {
80 	void	(*b_init_brand_data)(zone_t *);
81 	void	(*b_free_brand_data)(zone_t *);
82 	int	(*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
83 		uintptr_t, uintptr_t, uintptr_t);
84 	void	(*b_setbrand)(struct proc *);
85 	int	(*b_getattr)(zone_t *, int, void *, size_t *);
86 	int	(*b_setattr)(zone_t *, int, void *, size_t);
87 	void	(*b_copy_procdata)(struct proc *, struct proc *);
88 	void	(*b_proc_exit)(struct proc *, klwp_t *);
89 	void	(*b_exec)();
90 	void	(*b_lwp_setrval)(klwp_t *, int, int);
91 	int	(*b_initlwp)(klwp_t *);
92 	void	(*b_forklwp)(klwp_t *, klwp_t *);
93 	void	(*b_freelwp)(klwp_t *);
94 	void	(*b_lwpexit)(klwp_t *);
95 	int	(*b_elfexec)(struct vnode *vp, struct execa *uap,
96 	    struct uarg *args, struct intpdata *idata, int level,
97 	    long *execsz, int setid, caddr_t exec_file,
98 	    struct cred *cred, int brand_action);
99 	void	(*b_sigset_native_to_brand)(sigset_t *);
100 	void	(*b_sigset_brand_to_native)(sigset_t *);
101 	int	b_nsig;
102 };
103 
104 /*
105  * The b_version field must always be the first entry in this struct.
106  */
107 typedef struct brand {
108 	int			b_version;
109 	char    		*b_name;
110 	struct brand_ops	*b_ops;
111 	struct brand_mach_ops	*b_machops;
112 } brand_t;
113 
114 extern brand_t native_brand;
115 
116 /*
117  * Convenience macros
118  */
119 #define	lwptolwpbrand(l)	((l)->lwp_brand)
120 #define	ttolwpbrand(t)		(lwptolwpbrand(ttolwp(t)))
121 #define	PROC_IS_BRANDED(p)	((p)->p_brand != &native_brand)
122 #define	ZONE_IS_BRANDED(z)	((z)->zone_brand != &native_brand)
123 #define	BROP(p)			((p)->p_brand->b_ops)
124 #define	ZBROP(z)		((z)->zone_brand->b_ops)
125 #define	BRMOP(p)		((p)->p_brand->b_machops)
126 #define	SIGSET_NATIVE_TO_BRAND(sigset)				\
127 	if (PROC_IS_BRANDED(curproc) &&				\
128 	    BROP(curproc)->b_sigset_native_to_brand)		\
129 		BROP(curproc)->b_sigset_native_to_brand(sigset)
130 #define	SIGSET_BRAND_TO_NATIVE(sigset)				\
131 	if (PROC_IS_BRANDED(curproc) &&				\
132 	    BROP(curproc)->b_sigset_brand_to_native)		\
133 		BROP(curproc)->b_sigset_brand_to_native(sigset)
134 
135 extern void	brand_init();
136 extern int	brand_register(brand_t *);
137 extern int	brand_unregister(brand_t *);
138 extern brand_t	*brand_register_zone(struct brand_attr *);
139 extern brand_t	*brand_find_name(char *);
140 extern void	brand_unregister_zone(brand_t *);
141 extern int	brand_zone_count(brand_t *);
142 extern void	brand_setbrand(proc_t *);
143 extern void	brand_clearbrand(proc_t *);
144 #endif	/* _KERNEL */
145 
146 #ifdef	__cplusplus
147 }
148 #endif
149 
150 #endif	/* _SYS_BRAND_H */
151