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