xref: /titanic_52/usr/src/uts/common/sys/brand.h (revision b6c3f7863936abeae522e48a13887dddeb691a45)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/proc.h>
36 #include <sys/exec.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 
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 #ifdef	_KERNEL
67 
68 /* Root for branded zone's native binaries */
69 #define	NATIVE_ROOT	"/native/"
70 
71 struct proc;
72 struct uarg;
73 struct brand_mach_ops;
74 struct intpdata;
75 struct execa;
76 
77 struct brand_ops {
78 	void	(*b_init_brand_data)(zone_t *);
79 	void	(*b_free_brand_data)(zone_t *);
80 	int	(*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
81 		uintptr_t, uintptr_t, uintptr_t);
82 	void	(*b_setbrand)(struct proc *);
83 	int	(*b_getattr)(zone_t *, int, void *, size_t *);
84 	int	(*b_setattr)(zone_t *, int, void *, size_t);
85 	void	(*b_copy_procdata)(struct proc *, struct proc *);
86 	void	(*b_proc_exit)(struct proc *, klwp_t *);
87 	void	(*b_exec)();
88 	void	(*b_lwp_setrval)(klwp_t *, int, int);
89 	int	(*b_initlwp)(klwp_t *);
90 	void	(*b_forklwp)(klwp_t *, klwp_t *);
91 	void	(*b_freelwp)(klwp_t *);
92 	void	(*b_lwpexit)(klwp_t *);
93 	int	(*b_elfexec)(struct vnode *vp, struct execa *uap,
94 	    struct uarg *args, struct intpdata *idata, int level,
95 	    long *execsz, int setid, caddr_t exec_file,
96 	    struct cred *cred, int brand_action);
97 };
98 
99 /*
100  * The b_version field must always be the first entry in this struct.
101  */
102 typedef struct brand {
103 	int			b_version;
104 	char    		*b_name;
105 	struct brand_ops	*b_ops;
106 	struct brand_mach_ops	*b_machops;
107 } brand_t;
108 
109 extern brand_t native_brand;
110 
111 /*
112  * Convenience macros
113  */
114 #define	lwptolwpbrand(l)	((l)->lwp_brand)
115 #define	ttolwpbrand(t)		(lwptolwpbrand(ttolwp(t)))
116 #define	PROC_IS_BRANDED(p)	((p)->p_brand != &native_brand)
117 #define	ZONE_IS_BRANDED(z)	((z)->zone_brand != &native_brand)
118 #define	BROP(p)			((p)->p_brand->b_ops)
119 #define	ZBROP(z)		((z)->zone_brand->b_ops)
120 #define	BRMOP(p)		((p)->p_brand->b_machops)
121 
122 extern void	brand_init();
123 extern int	brand_register(brand_t *);
124 extern int	brand_unregister(brand_t *);
125 extern brand_t	*brand_register_zone(struct brand_attr *);
126 extern brand_t	*brand_find_name(char *);
127 extern void	brand_unregister_zone(brand_t *);
128 extern int	brand_zone_count(brand_t *);
129 extern void	brand_setbrand(proc_t *);
130 #endif	/* _KERNEL */
131 
132 #ifdef	__cplusplus
133 }
134 #endif
135 
136 #endif	/* _SYS_BRAND_H */
137