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