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 2010 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LX_BRAND_H 27 #define _LX_BRAND_H 28 29 #ifndef _ASM 30 #include <sys/types.h> 31 #include <sys/cpuvar.h> 32 #include <sys/zone.h> 33 #endif 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 #define LX_BRANDNAME "lx" 40 41 /* 42 * Brand uname info 43 */ 44 #define LX_UNAME_SYSNAME "Linux" 45 #define LX_UNAME_RELEASE_2_6 "2.6.18" 46 #define LX_UNAME_RELEASE_2_4 "2.4.21" 47 #define LX_UNAME_VERSION "BrandZ fake linux" 48 #define LX_UNAME_MACHINE "i686" 49 50 #define LX_LINKER_NAME "ld-linux.so.2" 51 #define LX_LINKER "/lib/" LX_LINKER_NAME 52 #define LX_LIBC_NAME "libc.so.6" 53 #define LIB_PATH "/native/usr/lib/" 54 #define LX_LIB "lx_brand.so.1" 55 #define LX_LIB_PATH LIB_PATH LX_LIB 56 57 #define LX_NSYSCALLS_2_4 270 58 #define LX_NSYSCALLS_2_6 317 59 #define LX_NSYSCALLS LX_NSYSCALLS_2_6 60 61 #define LX_KERN_2_4 0 62 #define LX_KERN_2_6 1 63 64 /* 65 * brand(2) subcommands 66 * 67 * Everything >= 128 is a brand-specific subcommand. 68 * 192 to 462 are reserved for system calls, although most of that space is 69 * unused. 70 */ 71 #define B_LPID_TO_SPAIR 128 72 #define B_SYSENTRY 129 73 #define B_SYSRETURN 130 74 #define B_PTRACE_SYSCALL 131 75 #define B_SET_AFFINITY_MASK 132 76 #define B_GET_AFFINITY_MASK 133 77 78 #define B_EMULATE_SYSCALL 192 79 80 #define LX_VERSION_1 1 81 #define LX_VERSION LX_VERSION_1 82 83 #define LX_ATTR_RESTART_INIT ZONE_ATTR_BRAND_ATTRS 84 #define LX_KERN_VERSION_NUM (ZONE_ATTR_BRAND_ATTRS + 1) 85 86 /* Aux vector containing phdr of linux executable, used by lx_librtld_db */ 87 #define AT_SUN_BRAND_LX_PHDR AT_SUN_BRAND_AUX1 88 89 /* Aux vector containing hz value */ 90 #define AT_CLKTCK 17 91 92 #ifndef _ASM 93 94 typedef struct lx_brand_registration { 95 uint_t lxbr_version; /* version number */ 96 void *lxbr_handler; /* base address of handler */ 97 void *lxbr_tracehandler; /* base address of trace handler */ 98 void *lxbr_traceflag; /* address of trace flag */ 99 } lx_brand_registration_t; 100 101 #ifdef _SYSCALL32 102 typedef struct lx_brand_registration32 { 103 uint32_t lxbr_version; /* version number */ 104 caddr32_t lxbr_handler; /* base address of handler */ 105 caddr32_t lxbr_tracehandler; /* base address of trace handler */ 106 caddr32_t lxbr_traceflag; /* address of trace flag */ 107 } lx_brand_registration32_t; 108 #endif 109 110 typedef struct lx_regs { 111 long lxr_gs; 112 long lxr_edi; 113 long lxr_esi; 114 long lxr_ebp; 115 long lxr_esp; 116 long lxr_ebx; 117 long lxr_edx; 118 long lxr_ecx; 119 long lxr_eax; 120 long lxr_eip; 121 122 long lxr_orig_eax; 123 } lx_regs_t; 124 125 #endif /* _ASM */ 126 127 /* 128 * GDT usage 129 */ 130 #define GDT_TLSMIN (GDT_BRANDMIN) 131 #define GDT_TLSMAX (GDT_TLSMIN + 2) 132 #define LX_TLSNUM (GDT_TLSMAX - GDT_TLSMIN) 133 134 #ifndef _ASM 135 136 /* 137 * Stores information needed by the lx linker to launch the main 138 * lx executable. 139 */ 140 typedef struct lx_elf_data { 141 int ed_phdr; 142 int ed_phent; 143 int ed_phnum; 144 int ed_entry; 145 int ed_base; 146 int ed_ldentry; 147 } lx_elf_data_t; 148 149 #ifdef _KERNEL 150 151 typedef struct lx_proc_data { 152 uintptr_t l_handler; /* address of user-space handler */ 153 uintptr_t l_tracehandler; /* address of user-space traced handler */ 154 uintptr_t l_traceflag; /* address of 32-bit tracing flag */ 155 void (*l_sigrestorer[MAXSIG])(void); /* array of sigrestorer fns */ 156 pid_t l_ppid; /* pid of originating parent proc */ 157 uint64_t l_ptrace; /* process being observed with ptrace */ 158 lx_elf_data_t l_elf_data; /* ELF data for linux executable */ 159 } lx_proc_data_t; 160 161 #endif /* _KERNEL */ 162 163 /* 164 * A data type big enough to bitmap all Linux possible cpus. 165 * The bitmap size is defined as 1024 cpus in the Linux 2.4 and 2.6 man pages 166 * for sched_getaffinity() and sched_getaffinity(). 167 */ 168 #define LX_NCPU (1024) 169 #define LX_AFF_ULONGS (LX_NCPU / (8 * sizeof (ulong_t))) 170 typedef ulong_t lx_affmask_t[LX_AFF_ULONGS]; 171 172 #ifdef _KERNEL 173 174 /* 175 * lx-specific data in the klwp_t 176 */ 177 typedef struct lx_lwp_data { 178 uint_t br_lwp_flags; /* misc. flags */ 179 klwp_t *br_lwp; /* back pointer to container lwp */ 180 int br_signal; /* signal to send to parent when */ 181 /* clone()'ed child terminates */ 182 int br_exitwhy; /* reason for thread (process) exit */ 183 int br_exitwhat; /* exit code / killing signal */ 184 lx_affmask_t br_affinitymask; /* bitmask of CPU sched affinities */ 185 struct user_desc br_tls[LX_TLSNUM]; 186 /* descriptors used by libc for TLS */ 187 pid_t br_pid; /* converted pid for this thread */ 188 pid_t br_tgid; /* thread group ID for this thread */ 189 pid_t br_ppid; /* parent pid for this thread */ 190 id_t br_ptid; /* parent tid for this thread */ 191 void *br_clear_ctidp; /* clone thread id ptr */ 192 void *br_set_ctidp; /* clone thread id ptr */ 193 194 /* 195 * The following struct is used by lx_clone() 196 * to pass info into fork() 197 */ 198 void *br_clone_args; 199 200 uint_t br_ptrace; /* ptrace is active for this LWP */ 201 } lx_lwp_data_t; 202 203 /* brand specific data */ 204 typedef struct lx_zone_data { 205 int lxzd_kernel_version; 206 int lxzd_max_syscall; 207 } lx_zone_data_t; 208 209 #define BR_CPU_BOUND 0x0001 210 211 #define ttolxlwp(t) ((struct lx_lwp_data *)ttolwpbrand(t)) 212 #define lwptolxlwp(l) ((struct lx_lwp_data *)lwptolwpbrand(l)) 213 #define ttolxproc(t) ((struct lx_proc_data *)(t)->t_procp->p_brand_data) 214 215 void lx_brand_int80_callback(void); 216 int64_t lx_emulate_syscall(int, uintptr_t, uintptr_t, uintptr_t, uintptr_t, 217 uintptr_t, uintptr_t); 218 219 extern int lx_get_zone_kern_version(zone_t *); 220 extern int lx_get_kern_version(void); 221 222 extern int lx_debug; 223 #define lx_print if (lx_debug) printf 224 225 #endif /* _KERNEL */ 226 #endif /* _ASM */ 227 228 #ifdef __cplusplus 229 } 230 #endif 231 232 #endif /* _LX_BRAND_H */