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