sn1_brand.c revision 12613:4c5722bc28dc
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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25#include <sys/errno.h>
26#include <sys/exec.h>
27#include <sys/kmem.h>
28#include <sys/modctl.h>
29#include <sys/model.h>
30#include <sys/proc.h>
31#include <sys/syscall.h>
32#include <sys/systm.h>
33#include <sys/thread.h>
34#include <sys/cmn_err.h>
35#include <sys/archsystm.h>
36#include <sys/pathname.h>
37
38#include <sys/machbrand.h>
39#include <sys/brand.h>
40#include "sn1_brand.h"
41
42char *sn1_emulation_table = NULL;
43
44void	sn1_init_brand_data(zone_t *);
45void	sn1_free_brand_data(zone_t *);
46void	sn1_setbrand(proc_t *);
47int	sn1_getattr(zone_t *, int, void *, size_t *);
48int	sn1_setattr(zone_t *, int, void *, size_t);
49int	sn1_brandsys(int, int64_t *, uintptr_t, uintptr_t, uintptr_t,
50		uintptr_t, uintptr_t, uintptr_t);
51void	sn1_copy_procdata(proc_t *, proc_t *);
52void	sn1_proc_exit(struct proc *, klwp_t *);
53void	sn1_exec();
54int	sn1_initlwp(klwp_t *);
55void	sn1_forklwp(klwp_t *, klwp_t *);
56void	sn1_freelwp(klwp_t *);
57void	sn1_lwpexit(klwp_t *);
58int	sn1_elfexec(vnode_t *, execa_t *, uarg_t *, intpdata_t *, int,
59	long *, int, caddr_t, cred_t *, int);
60
61/* sn1 brand */
62struct brand_ops sn1_brops = {
63	sn1_init_brand_data,
64	sn1_free_brand_data,
65	sn1_brandsys,
66	sn1_setbrand,
67	sn1_getattr,
68	sn1_setattr,
69	sn1_copy_procdata,
70	sn1_proc_exit,
71	sn1_exec,
72	lwp_setrval,
73	sn1_initlwp,
74	sn1_forklwp,
75	sn1_freelwp,
76	sn1_lwpexit,
77	sn1_elfexec,
78	NULL,
79	NULL,
80	NSIG,
81};
82
83#ifdef	sparc
84
85struct brand_mach_ops sn1_mops = {
86	sn1_brand_syscall_callback,
87	sn1_brand_syscall32_callback
88};
89
90#else	/* sparc */
91
92#ifdef	__amd64
93
94struct brand_mach_ops sn1_mops = {
95	sn1_brand_sysenter_callback,
96	sn1_brand_int91_callback,
97	sn1_brand_syscall_callback,
98	sn1_brand_syscall32_callback
99};
100
101#else	/* ! __amd64 */
102
103struct brand_mach_ops sn1_mops = {
104	sn1_brand_sysenter_callback,
105	NULL,
106	sn1_brand_syscall_callback,
107	NULL
108};
109#endif	/* __amd64 */
110
111#endif	/* _sparc */
112
113struct brand	sn1_brand = {
114	BRAND_VER_1,
115	"sn1",
116	&sn1_brops,
117	&sn1_mops
118};
119
120static struct modlbrand modlbrand = {
121	&mod_brandops,		/* type of module */
122	"Solaris N-1 Brand",	/* description of module */
123	&sn1_brand		/* driver ops */
124};
125
126static struct modlinkage modlinkage = {
127	MODREV_1, (void *)&modlbrand, NULL
128};
129
130void
131sn1_setbrand(proc_t *p)
132{
133	brand_solaris_setbrand(p, &sn1_brand);
134}
135
136/* ARGSUSED */
137int
138sn1_getattr(zone_t *zone, int attr, void *buf, size_t *bufsize)
139{
140	return (EINVAL);
141}
142
143/* ARGSUSED */
144int
145sn1_setattr(zone_t *zone, int attr, void *buf, size_t bufsize)
146{
147	return (EINVAL);
148}
149
150/*ARGSUSED*/
151int
152sn1_brandsys(int cmd, int64_t *rval, uintptr_t arg1, uintptr_t arg2,
153    uintptr_t arg3, uintptr_t arg4, uintptr_t arg5, uintptr_t arg6)
154{
155	int	res;
156
157	*rval = 0;
158
159	res = brand_solaris_cmd(cmd, arg1, arg2, arg3, &sn1_brand, SN1_VERSION);
160	if (res >= 0)
161		return (res);
162
163	return (EINVAL);
164}
165
166void
167sn1_copy_procdata(proc_t *child, proc_t *parent)
168{
169	brand_solaris_copy_procdata(child, parent, &sn1_brand);
170}
171
172void
173sn1_proc_exit(struct proc *p, klwp_t *l)
174{
175	brand_solaris_proc_exit(p, l, &sn1_brand);
176}
177
178void
179sn1_exec()
180{
181	brand_solaris_exec(&sn1_brand);
182}
183
184int
185sn1_initlwp(klwp_t *l)
186{
187	return (brand_solaris_initlwp(l, &sn1_brand));
188}
189
190void
191sn1_forklwp(klwp_t *p, klwp_t *c)
192{
193	brand_solaris_forklwp(p, c, &sn1_brand);
194}
195
196void
197sn1_freelwp(klwp_t *l)
198{
199	brand_solaris_freelwp(l, &sn1_brand);
200}
201
202void
203sn1_lwpexit(klwp_t *l)
204{
205	brand_solaris_lwpexit(l, &sn1_brand);
206}
207
208/*ARGSUSED*/
209void
210sn1_free_brand_data(zone_t *zone)
211{
212}
213
214/*ARGSUSED*/
215void
216sn1_init_brand_data(zone_t *zone)
217{
218}
219
220int
221sn1_elfexec(vnode_t *vp, execa_t *uap, uarg_t *args, intpdata_t *idatap,
222	int level, long *execsz, int setid, caddr_t exec_file, cred_t *cred,
223	int brand_action)
224{
225	return (brand_solaris_elfexec(vp, uap, args, idatap, level, execsz,
226	    setid, exec_file, cred, brand_action, &sn1_brand, SN1_BRANDNAME,
227	    SN1_LIB, SN1_LIB32, SN1_LINKER, SN1_LINKER32));
228}
229
230int
231_init(void)
232{
233	int err;
234
235	/*
236	 * Set up the table indicating which system calls we want to
237	 * interpose on.  We should probably build this automatically from
238	 * a list of system calls that is shared with the user-space
239	 * library.
240	 */
241	sn1_emulation_table = kmem_zalloc(NSYSCALL, KM_SLEEP);
242	sn1_emulation_table[SYS_read] = 1;			/*   3 */
243	sn1_emulation_table[SYS_write] = 1;			/*   4 */
244	sn1_emulation_table[SYS_time] = 1;			/*  13 */
245	sn1_emulation_table[SYS_getpid] = 1;			/*  20 */
246	sn1_emulation_table[SYS_mount] = 1;			/*  21 */
247	sn1_emulation_table[SYS_getuid] = 1;			/*  24 */
248	sn1_emulation_table[SYS_times] = 1;			/*  43 */
249	sn1_emulation_table[SYS_getgid] = 1;			/*  47 */
250	sn1_emulation_table[SYS_utssys] = 1;			/*  57 */
251	sn1_emulation_table[SYS_readlink] = 1;			/*  90 */
252	sn1_emulation_table[SYS_waitid] = 1;			/* 107 */
253	sn1_emulation_table[SYS_uname] = 1;			/* 135 */
254
255	err = mod_install(&modlinkage);
256	if (err) {
257		cmn_err(CE_WARN, "Couldn't install brand module");
258		kmem_free(sn1_emulation_table, NSYSCALL);
259	}
260
261	return (err);
262}
263
264int
265_info(struct modinfo *modinfop)
266{
267	return (mod_info(&modlinkage, modinfop));
268}
269
270int
271_fini(void)
272{
273	return (brand_solaris_fini(&sn1_emulation_table, &modlinkage,
274	    &sn1_brand));
275}
276