19acbbeafSnn35248 /* 29acbbeafSnn35248 * CDDL HEADER START 39acbbeafSnn35248 * 49acbbeafSnn35248 * The contents of this file are subject to the terms of the 59acbbeafSnn35248 * Common Development and Distribution License (the "License"). 69acbbeafSnn35248 * You may not use this file except in compliance with the License. 79acbbeafSnn35248 * 89acbbeafSnn35248 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 99acbbeafSnn35248 * or http://www.opensolaris.org/os/licensing. 109acbbeafSnn35248 * See the License for the specific language governing permissions 119acbbeafSnn35248 * and limitations under the License. 129acbbeafSnn35248 * 139acbbeafSnn35248 * When distributing Covered Code, include this CDDL HEADER in each 149acbbeafSnn35248 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 159acbbeafSnn35248 * If applicable, add the following below this CDDL HEADER, with the 169acbbeafSnn35248 * fields enclosed by brackets "[]" replaced with your own identifying 179acbbeafSnn35248 * information: Portions Copyright [yyyy] [name of copyright owner] 189acbbeafSnn35248 * 199acbbeafSnn35248 * CDDL HEADER END 209acbbeafSnn35248 */ 21eb9dbf0cSRoger A. Faulkner 229acbbeafSnn35248 /* 2380e2ca85S * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 249acbbeafSnn35248 */ 259acbbeafSnn35248 269acbbeafSnn35248 #ifndef _SYS_BRAND_H 279acbbeafSnn35248 #define _SYS_BRAND_H 289acbbeafSnn35248 299acbbeafSnn35248 #ifdef __cplusplus 309acbbeafSnn35248 extern "C" { 319acbbeafSnn35248 #endif 329acbbeafSnn35248 339acbbeafSnn35248 #include <sys/proc.h> 349acbbeafSnn35248 #include <sys/exec.h> 3580e2ca85S #include <sys/modctl.h> 36*e9f7cbf0SVamsi Nagineni #include <sys/types.h> 379acbbeafSnn35248 389acbbeafSnn35248 /* 399acbbeafSnn35248 * All Brands supported by this kernel must use BRAND_VER_1. 409acbbeafSnn35248 */ 419acbbeafSnn35248 #define BRAND_VER_1 1 429acbbeafSnn35248 439acbbeafSnn35248 /* 449acbbeafSnn35248 * sub-commands to brandsys. 459acbbeafSnn35248 * 1 - 128 are for common commands 469acbbeafSnn35248 * 128+ are available for brand-specific commands. 479acbbeafSnn35248 */ 489acbbeafSnn35248 #define B_REGISTER 1 499acbbeafSnn35248 #define B_TTYMODES 2 509acbbeafSnn35248 #define B_ELFDATA 3 519acbbeafSnn35248 #define B_EXEC_NATIVE 4 529acbbeafSnn35248 #define B_EXEC_BRAND 5 5380e2ca85S #define B_TRUSS_POINT 6 549acbbeafSnn35248 559acbbeafSnn35248 /* 569acbbeafSnn35248 * Structure used by zoneadmd to communicate the name of a brand and the 579acbbeafSnn35248 * supporting brand module into the kernel. 589acbbeafSnn35248 */ 599acbbeafSnn35248 struct brand_attr { 609acbbeafSnn35248 char ba_brandname[MAXNAMELEN]; 619acbbeafSnn35248 char ba_modname[MAXPATHLEN]; 629acbbeafSnn35248 }; 639acbbeafSnn35248 649acbbeafSnn35248 /* What we call the native brand. */ 659acbbeafSnn35248 #define NATIVE_BRAND_NAME "native" 669acbbeafSnn35248 679a5d73e0SRic Aleshire /* What we call the labeled brand. */ 689a5d73e0SRic Aleshire #define LABELED_BRAND_NAME "labeled" 699a5d73e0SRic Aleshire 7080e2ca85S /* 7180e2ca85S * Aux vector containing lddata pointer of brand library linkmap. 7280e2ca85S * Used by common {brand}_librtld_db. 7380e2ca85S */ 7480e2ca85S #define AT_SUN_BRAND_COMMON_LDDATA AT_SUN_BRAND_AUX1 759acbbeafSnn35248 7680e2ca85S /* 7780e2ca85S * Information needed by the brand library to launch an executable. 7880e2ca85S */ 7980e2ca85S typedef struct brand_elf_data { 8080e2ca85S ulong_t sed_phdr; 8180e2ca85S ulong_t sed_phent; 8280e2ca85S ulong_t sed_phnum; 8380e2ca85S ulong_t sed_entry; 8480e2ca85S ulong_t sed_base; 8580e2ca85S ulong_t sed_ldentry; 8680e2ca85S ulong_t sed_lddata; 8780e2ca85S } brand_elf_data_t; 8880e2ca85S 8980e2ca85S /* 9080e2ca85S * Common structure used to register a branded processes 9180e2ca85S */ 9280e2ca85S typedef struct brand_proc_reg { 9380e2ca85S uint_t sbr_version; /* version number */ 9480e2ca85S caddr_t sbr_handler; /* base address of handler */ 9580e2ca85S } brand_proc_reg_t; 9680e2ca85S 9780e2ca85S #ifdef _KERNEL 989acbbeafSnn35248 999acbbeafSnn35248 struct proc; 1009acbbeafSnn35248 struct uarg; 1019acbbeafSnn35248 struct brand_mach_ops; 1029acbbeafSnn35248 struct intpdata; 1039acbbeafSnn35248 struct execa; 1049acbbeafSnn35248 1059acbbeafSnn35248 struct brand_ops { 106319378d9Seh208807 void (*b_init_brand_data)(zone_t *); 107319378d9Seh208807 void (*b_free_brand_data)(zone_t *); 1089acbbeafSnn35248 int (*b_brandsys)(int, int64_t *, uintptr_t, uintptr_t, uintptr_t, 1099acbbeafSnn35248 uintptr_t, uintptr_t, uintptr_t); 1109acbbeafSnn35248 void (*b_setbrand)(struct proc *); 1119acbbeafSnn35248 int (*b_getattr)(zone_t *, int, void *, size_t *); 1129acbbeafSnn35248 int (*b_setattr)(zone_t *, int, void *, size_t); 1139acbbeafSnn35248 void (*b_copy_procdata)(struct proc *, struct proc *); 1149acbbeafSnn35248 void (*b_proc_exit)(struct proc *, klwp_t *); 1159acbbeafSnn35248 void (*b_exec)(); 1169acbbeafSnn35248 void (*b_lwp_setrval)(klwp_t *, int, int); 1179acbbeafSnn35248 int (*b_initlwp)(klwp_t *); 1189acbbeafSnn35248 void (*b_forklwp)(klwp_t *, klwp_t *); 1199acbbeafSnn35248 void (*b_freelwp)(klwp_t *); 1209acbbeafSnn35248 void (*b_lwpexit)(klwp_t *); 1219acbbeafSnn35248 int (*b_elfexec)(struct vnode *vp, struct execa *uap, 1229acbbeafSnn35248 struct uarg *args, struct intpdata *idata, int level, 1239acbbeafSnn35248 long *execsz, int setid, caddr_t exec_file, 1249acbbeafSnn35248 struct cred *cred, int brand_action); 1258f798d3aSRoger A. Faulkner void (*b_sigset_native_to_brand)(sigset_t *); 1268f798d3aSRoger A. Faulkner void (*b_sigset_brand_to_native)(sigset_t *); 127eb9dbf0cSRoger A. Faulkner int b_nsig; 1289acbbeafSnn35248 }; 1299acbbeafSnn35248 1309acbbeafSnn35248 /* 1319acbbeafSnn35248 * The b_version field must always be the first entry in this struct. 1329acbbeafSnn35248 */ 1339acbbeafSnn35248 typedef struct brand { 1349acbbeafSnn35248 int b_version; 1359acbbeafSnn35248 char *b_name; 1369acbbeafSnn35248 struct brand_ops *b_ops; 1379acbbeafSnn35248 struct brand_mach_ops *b_machops; 1389acbbeafSnn35248 } brand_t; 1399acbbeafSnn35248 1409acbbeafSnn35248 extern brand_t native_brand; 1419acbbeafSnn35248 1429acbbeafSnn35248 /* 1439acbbeafSnn35248 * Convenience macros 1449acbbeafSnn35248 */ 1459acbbeafSnn35248 #define lwptolwpbrand(l) ((l)->lwp_brand) 1469acbbeafSnn35248 #define ttolwpbrand(t) (lwptolwpbrand(ttolwp(t))) 1479acbbeafSnn35248 #define PROC_IS_BRANDED(p) ((p)->p_brand != &native_brand) 1489acbbeafSnn35248 #define ZONE_IS_BRANDED(z) ((z)->zone_brand != &native_brand) 1499acbbeafSnn35248 #define BROP(p) ((p)->p_brand->b_ops) 1509acbbeafSnn35248 #define ZBROP(z) ((z)->zone_brand->b_ops) 1519acbbeafSnn35248 #define BRMOP(p) ((p)->p_brand->b_machops) 1528f798d3aSRoger A. Faulkner #define SIGSET_NATIVE_TO_BRAND(sigset) \ 1538f798d3aSRoger A. Faulkner if (PROC_IS_BRANDED(curproc) && \ 1548f798d3aSRoger A. Faulkner BROP(curproc)->b_sigset_native_to_brand) \ 1558f798d3aSRoger A. Faulkner BROP(curproc)->b_sigset_native_to_brand(sigset) 1568f798d3aSRoger A. Faulkner #define SIGSET_BRAND_TO_NATIVE(sigset) \ 1578f798d3aSRoger A. Faulkner if (PROC_IS_BRANDED(curproc) && \ 1588f798d3aSRoger A. Faulkner BROP(curproc)->b_sigset_brand_to_native) \ 1598f798d3aSRoger A. Faulkner BROP(curproc)->b_sigset_brand_to_native(sigset) 1609acbbeafSnn35248 1619acbbeafSnn35248 extern void brand_init(); 1629acbbeafSnn35248 extern int brand_register(brand_t *); 1639acbbeafSnn35248 extern int brand_unregister(brand_t *); 1649acbbeafSnn35248 extern brand_t *brand_register_zone(struct brand_attr *); 1659acbbeafSnn35248 extern brand_t *brand_find_name(char *); 1669acbbeafSnn35248 extern void brand_unregister_zone(brand_t *); 1679acbbeafSnn35248 extern int brand_zone_count(brand_t *); 1689acbbeafSnn35248 extern void brand_setbrand(proc_t *); 169*e9f7cbf0SVamsi Nagineni extern void brand_clearbrand(proc_t *, boolean_t); 17080e2ca85S 17180e2ca85S /* 17280e2ca85S * The following functions can be shared among kernel brand modules which 17380e2ca85S * implement Solaris-derived brands, all of which need to do similar tasks to 17480e2ca85S * manage the brand. 17580e2ca85S */ 17680e2ca85S extern int brand_solaris_cmd(int, uintptr_t, uintptr_t, uintptr_t, 17780e2ca85S struct brand *, int); 17880e2ca85S extern void brand_solaris_copy_procdata(proc_t *, proc_t *, 17980e2ca85S struct brand *); 18080e2ca85S extern int brand_solaris_elfexec(vnode_t *, execa_t *, uarg_t *, 18180e2ca85S intpdata_t *, int, long *, int, caddr_t, cred_t *, int, 18280e2ca85S struct brand *, char *, char *, char *, char *, char *); 18380e2ca85S extern void brand_solaris_exec(struct brand *); 18480e2ca85S extern int brand_solaris_fini(char **, struct modlinkage *, 18580e2ca85S struct brand *); 18680e2ca85S extern void brand_solaris_forklwp(klwp_t *, klwp_t *, struct brand *); 18780e2ca85S extern void brand_solaris_freelwp(klwp_t *, struct brand *); 18880e2ca85S extern int brand_solaris_initlwp(klwp_t *, struct brand *); 18980e2ca85S extern void brand_solaris_lwpexit(klwp_t *, struct brand *); 19080e2ca85S extern void brand_solaris_proc_exit(struct proc *, klwp_t *, 19180e2ca85S struct brand *); 19280e2ca85S extern void brand_solaris_setbrand(proc_t *, struct brand *); 19380e2ca85S 19480e2ca85S #if defined(_SYSCALL32) 19580e2ca85S typedef struct brand_elf_data32 { 19680e2ca85S uint32_t sed_phdr; 19780e2ca85S uint32_t sed_phent; 19880e2ca85S uint32_t sed_phnum; 19980e2ca85S uint32_t sed_entry; 20080e2ca85S uint32_t sed_base; 20180e2ca85S uint32_t sed_ldentry; 20280e2ca85S uint32_t sed_lddata; 20380e2ca85S } brand_elf_data32_t; 20480e2ca85S 20580e2ca85S typedef struct brand_common_reg32 { 20680e2ca85S uint32_t sbr_version; /* version number */ 20780e2ca85S caddr32_t sbr_handler; /* base address of handler */ 20880e2ca85S } brand_common_reg32_t; 20980e2ca85S #endif /* _SYSCALL32 */ 21080e2ca85S 21180e2ca85S /* 21280e2ca85S * Common information associated with all branded processes 21380e2ca85S */ 21480e2ca85S typedef struct brand_proc_data { 21580e2ca85S caddr_t spd_handler; /* address of user-space handler */ 21680e2ca85S brand_elf_data_t spd_elf_data; /* common ELF data for branded app. */ 21780e2ca85S } brand_proc_data_t; 21880e2ca85S 21980e2ca85S #define BRAND_NATIVE_DIR "/.SUNWnative/" 22080e2ca85S #define BRAND_NATIVE_LINKER32 BRAND_NATIVE_DIR "lib/ld.so.1" 22180e2ca85S #define BRAND_NATIVE_LINKER64 BRAND_NATIVE_DIR "lib/64/ld.so.1" 22280e2ca85S 2239acbbeafSnn35248 #endif /* _KERNEL */ 2249acbbeafSnn35248 2259acbbeafSnn35248 #ifdef __cplusplus 2269acbbeafSnn35248 } 2279acbbeafSnn35248 #endif 2289acbbeafSnn35248 2299acbbeafSnn35248 #endif /* _SYS_BRAND_H */ 230