xref: /titanic_44/usr/src/uts/common/sys/brand.h (revision 7014882c6a3672fd0e5d60200af8643ae53c5928)
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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef _SYS_BRAND_H
27 #define	_SYS_BRAND_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/proc.h>
34 #include <sys/exec.h>
35 #include <sys/modctl.h>
36 #include <sys/types.h>
37 
38 /*
39  * All Brands supported by this kernel must use BRAND_VER_1.
40  */
41 #define	BRAND_VER_1	1
42 
43 /*
44  * sub-commands to brandsys.
45  * 1 - 128 are for common commands
46  * 128+ are available for brand-specific commands.
47  */
48 #define	B_REGISTER		1
49 #define	B_TTYMODES		2
50 #define	B_ELFDATA		3
51 #define	B_EXEC_NATIVE		4
52 #define	B_EXEC_BRAND		5
53 #define	B_TRUSS_POINT		6
54 
55 /*
56  * Structure used by zoneadmd to communicate the name of a brand and the
57  * supporting brand module into the kernel.
58  */
59 struct brand_attr {
60 	char	ba_brandname[MAXNAMELEN];
61 	char	ba_modname[MAXPATHLEN];
62 };
63 
64 /* What we call the native brand. */
65 #define	NATIVE_BRAND_NAME	"native"
66 
67 /* What we call the labeled brand. */
68 #define	LABELED_BRAND_NAME	"labeled"
69 
70 /*
71  * Aux vector containing lddata pointer of brand library linkmap.
72  * Used by common {brand}_librtld_db.
73  */
74 #define	AT_SUN_BRAND_COMMON_LDDATA	AT_SUN_BRAND_AUX1
75 
76 /*
77  * Information needed by the brand library to launch an executable.
78  */
79 typedef struct brand_elf_data {
80 	ulong_t		sed_phdr;
81 	ulong_t		sed_phent;
82 	ulong_t		sed_phnum;
83 	ulong_t		sed_entry;
84 	ulong_t		sed_base;
85 	ulong_t		sed_ldentry;
86 	ulong_t		sed_lddata;
87 } brand_elf_data_t;
88 
89 /*
90  * Common structure used to register a branded processes
91  */
92 typedef struct brand_proc_reg {
93 	uint_t		sbr_version;	/* version number */
94 	caddr_t		sbr_handler;	/* base address of handler */
95 } brand_proc_reg_t;
96 
97 #ifdef	_KERNEL
98 
99 struct proc;
100 struct uarg;
101 struct brand_mach_ops;
102 struct intpdata;
103 struct execa;
104 
105 struct brand_ops {
106 	void	(*b_init_brand_data)(zone_t *);
107 	void	(*b_free_brand_data)(zone_t *);
108 	int	(*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
109 		uintptr_t, uintptr_t, uintptr_t);
110 	void	(*b_setbrand)(struct proc *);
111 	int	(*b_getattr)(zone_t *, int, void *, size_t *);
112 	int	(*b_setattr)(zone_t *, int, void *, size_t);
113 	void	(*b_copy_procdata)(struct proc *, struct proc *);
114 	void	(*b_proc_exit)(struct proc *, klwp_t *);
115 	void	(*b_exec)();
116 	void	(*b_lwp_setrval)(klwp_t *, int, int);
117 	int	(*b_initlwp)(klwp_t *);
118 	void	(*b_forklwp)(klwp_t *, klwp_t *);
119 	void	(*b_freelwp)(klwp_t *);
120 	void	(*b_lwpexit)(klwp_t *);
121 	int	(*b_elfexec)(struct vnode *vp, struct execa *uap,
122 	    struct uarg *args, struct intpdata *idata, int level,
123 	    long *execsz, int setid, caddr_t exec_file,
124 	    struct cred *cred, int brand_action);
125 	void	(*b_sigset_native_to_brand)(sigset_t *);
126 	void	(*b_sigset_brand_to_native)(sigset_t *);
127 	int	b_nsig;
128 };
129 
130 /*
131  * The b_version field must always be the first entry in this struct.
132  */
133 typedef struct brand {
134 	int			b_version;
135 	char    		*b_name;
136 	struct brand_ops	*b_ops;
137 	struct brand_mach_ops	*b_machops;
138 } brand_t;
139 
140 extern brand_t native_brand;
141 
142 /*
143  * Convenience macros
144  */
145 #define	lwptolwpbrand(l)	((l)->lwp_brand)
146 #define	ttolwpbrand(t)		(lwptolwpbrand(ttolwp(t)))
147 #define	PROC_IS_BRANDED(p)	((p)->p_brand != &native_brand)
148 #define	ZONE_IS_BRANDED(z)	((z)->zone_brand != &native_brand)
149 #define	BROP(p)			((p)->p_brand->b_ops)
150 #define	ZBROP(z)		((z)->zone_brand->b_ops)
151 #define	BRMOP(p)		((p)->p_brand->b_machops)
152 #define	SIGSET_NATIVE_TO_BRAND(sigset)				\
153 	if (PROC_IS_BRANDED(curproc) &&				\
154 	    BROP(curproc)->b_sigset_native_to_brand)		\
155 		BROP(curproc)->b_sigset_native_to_brand(sigset)
156 #define	SIGSET_BRAND_TO_NATIVE(sigset)				\
157 	if (PROC_IS_BRANDED(curproc) &&				\
158 	    BROP(curproc)->b_sigset_brand_to_native)		\
159 		BROP(curproc)->b_sigset_brand_to_native(sigset)
160 
161 extern void	brand_init();
162 extern int	brand_register(brand_t *);
163 extern int	brand_unregister(brand_t *);
164 extern brand_t	*brand_register_zone(struct brand_attr *);
165 extern brand_t	*brand_find_name(char *);
166 extern void	brand_unregister_zone(brand_t *);
167 extern int	brand_zone_count(brand_t *);
168 extern void	brand_setbrand(proc_t *);
169 extern void	brand_clearbrand(proc_t *, boolean_t);
170 
171 /*
172  * The following functions can be shared among kernel brand modules which
173  * implement Solaris-derived brands, all of which need to do similar tasks to
174  * manage the brand.
175  */
176 extern int	brand_solaris_cmd(int, uintptr_t, uintptr_t, uintptr_t,
177 		    struct brand *, int);
178 extern void	brand_solaris_copy_procdata(proc_t *, proc_t *,
179 		    struct brand *);
180 extern int	brand_solaris_elfexec(vnode_t *, execa_t *, uarg_t *,
181 		    intpdata_t *, int, long *, int, caddr_t, cred_t *, int,
182 		    struct brand *, char *, char *, char *, char *, char *);
183 extern void	brand_solaris_exec(struct brand *);
184 extern int	brand_solaris_fini(char **, struct modlinkage *,
185 		    struct brand *);
186 extern void	brand_solaris_forklwp(klwp_t *, klwp_t *, struct brand *);
187 extern void	brand_solaris_freelwp(klwp_t *, struct brand *);
188 extern int	brand_solaris_initlwp(klwp_t *, struct brand *);
189 extern void	brand_solaris_lwpexit(klwp_t *, struct brand *);
190 extern void	brand_solaris_proc_exit(struct proc *, klwp_t *,
191 		    struct brand *);
192 extern void	brand_solaris_setbrand(proc_t *, struct brand *);
193 
194 #if defined(_SYSCALL32)
195 typedef struct brand_elf_data32 {
196 	uint32_t	sed_phdr;
197 	uint32_t	sed_phent;
198 	uint32_t	sed_phnum;
199 	uint32_t	sed_entry;
200 	uint32_t	sed_base;
201 	uint32_t	sed_ldentry;
202 	uint32_t	sed_lddata;
203 } brand_elf_data32_t;
204 
205 typedef struct brand_common_reg32 {
206 	uint32_t	sbr_version;	/* version number */
207 	caddr32_t	sbr_handler;	/* base address of handler */
208 } brand_common_reg32_t;
209 #endif /* _SYSCALL32 */
210 
211 /*
212  * Common information associated with all branded processes
213  */
214 typedef struct brand_proc_data {
215 	caddr_t		spd_handler;	/* address of user-space handler */
216 	brand_elf_data_t spd_elf_data;	/* common ELF data for branded app. */
217 } brand_proc_data_t;
218 
219 #define	BRAND_NATIVE_DIR	"/.SUNWnative/"
220 #define	BRAND_NATIVE_LINKER32	BRAND_NATIVE_DIR "lib/ld.so.1"
221 #define	BRAND_NATIVE_LINKER64	BRAND_NATIVE_DIR "lib/64/ld.so.1"
222 
223 #endif	/* _KERNEL */
224 
225 #ifdef	__cplusplus
226 }
227 #endif
228 
229 #endif	/* _SYS_BRAND_H */
230