bsd-user updates to run hello world
cover bsd-user updates to run hello world
This series of patches gets me to the point that I can run "Hello World" on i386 and x86_64. This is for static binaries only, that are relatively small, but it's better than the 100% instant mmap failre that is the current state of all things bsd-user in upstream qemu. Future patch sets will refine this, add the missing system calls, fix bugs preventing more sophisticated programms from running and add a bunch of new architecture support.
There's three large themes in these patches, though the changes that represent them are interrelated making it hard to separate out further.
1. Reorganization to support multiple OS and architectures (though I've only tested FreeBSD, other BSDs might not even compile yet).
2. Diff reduction with the bsd-user fork for several files. These diffs include changes that borrowed from linux-user as well as changes to make things work on FreeBSD. The records keeping when this was done, however, was poor at best, so many of the specific borrowings are going unacknowledged here, apart from this general ack. These diffs also include some minor code shuffling. Some of the changes are done specifically to make it easier to rebase the bsd-user fork's changes when these land in the tree (a number of changes have been pushed there to make this more possible).
3. Filling in the missing pieces to make things work. There's many changes to elfload to make it load things in the right places, to find the interpreter better, etc. There's changes to mmap.c to make the mappings work better and there's changes to main.c that were inspired, at least, by now-ancient changes to linux-user's main.c.
I ran checkpatch.pl on this, and there's 350-odd errors it identifies (the vast majoirty come from BSD's fetish for tabs), so there will need to be a V2 to fix this at the very least. In addition, the change set is big (about +~4.5k/-~2.5k lines), so I anticipate some iteration as well just based on its sheer size. I've tried to keep each set small to make it easy to review in isolation, but I've also allowed some interrelated ones to get a little bigger than I'd normally like. I've not done the customary documentation of the expected checkpatch.pl output because it is large, and because I wanted to get review of the other parts rolling to get this project unstuck. Future versions of the patch will document the expected output.
In addition, I noticed a number of places where I could modernize to make the code match things like linux-user better. I've resisted the urge to do these at this time, since it would complicate merging the other ~30k lines of diff that remains after this batch. Future batches should generally be smaller once this one has landed since they are, by and large, either a bunch of new files to support armv7, aarch64, riscv64, mips, mipsel, mips64, ppc, ppc64 and ppc64le, or are adding system calls, which can be done individually or small groups. I've removed sparc and sparc64 support as they've been removed from FreeBSD and have been near totally busted for years.
Stacey Son did the bulk of this work originally, but since I had to move things around so much and/or retool that work in non-trivial ways, I've kept myself as author, and added his signed-off-by line. I'm unsure of the qemu standard practice for this, but am happy to learn if this is too far outside its current mainstream. For a while Sean Bruno did the merges from upstream, and he's credited using his signed-off-by in appropriate places, though for this patch set there's only a few. I've tried to ensure that others who have work in individual patches that I've aggregated together also are reflected in their signed-off-by. Given the chaotic stat of the upstream repo for its early history, this may be the best that can be reconstructed at this late date. Most of these files are 'foundational' so have existed from the earliest days when record keeping wasn't quite what I'd wish for in hindsight. There was only really one change that I could easily cherry-pick (Colin's), so I did that.
Colin Percival (1):
bsd-user: Add '-0 argv0' option to bsd-user/main.c
Warner Losh (48):
bsd-user: remove sparc and sparc64
bsd-user: add copyright header to elfload.c
bsd-user: Add Stacey's copyright to main.c
bsd-user: Remove all non-x86 code from elfload.c
bsd-user: move arch specific defines out of elfload.c
bsd-user: merge comments and guards from bsd-user fork
bsd-user: style nits: apply qemu style to these files
bsd-user: style nits: fix whitespace issues to be qemu standard
bsd-user: add license
bsd-user: pass the bsd_param into loader_exec
bsd-user: Fix calculation of size to allocate
bsd-user: implement path searching
bsd-user: Eliminate elf personality
bsd-user: remove a.out support
bsd-user: TARGET_NGROUPS unused in this file, remove
bsd-user: elfload: simplify bswap a bit.
bsd-user: assume pthreads and support of __thread
bsd-user: add host-os.h
bsd-user: Include host-os.h from main
bsd-user: save the path the qemu emulator
bsd-user: start to move target CPU functions to target_arch*
bsd-user: Move per-cpu code into target_arch_cpu.h
bsd-user: pull in target_arch_thread.h update target_arch_elf.h
bsd-user: Include more things in qemu.h
bsd-user: define max args in terms of pages
bsd-user: Create target specific vmparam.h
bsd-user: Add architecture specific signal tramp code
bsd-user: Move stack initializtion into a per-os file.
bsd-user: Add system independent stack, data and text limiting
bsd-user: elf cleanup
bsd-user: Remove dead #ifdefs from elfload.c
bsd-user: *BSD specific siginfo defintions
bsd-user: Rewrite target system call definintion glue
bsd-user: Fix initializtion of task state
bsd-user: remove error_init
bsd-user: Make cpu_model and cpu_type visible to all of main.c
bsd-user: update debugging in mmap.c
bsd-user: Update mapping to handle reserved and starting conditions
bsd-user: Need to reset CPU after creation.
bsd-user: Add target_arch_reg to describe a target's register set
bsd-user: Add target_os_user.h to capture the user/kernel structures
bsd-user: add stubbed out core dump support
bsd-user: elfload.c style catch up patch
bsd-user: Refactor load_elf_sections and is_target_elf_binary
bsd-user: Make guest_base an unsigned long
bsd-user: move qemu_log to later in the file
bsd-user: Implement interlock for atomic operations
bsd-user: Implement cpu_copy() helper routine
bsd-user/bsd-mman.h | 121 --
bsd-user/bsdload.c | 141 +-
bsd-user/elfcore.c | 10 +
bsd-user/elfload.c | 1464 +++++------------
bsd-user/freebsd/host-os.h | 25 +
bsd-user/freebsd/target_os_elf.h | 149 ++
bsd-user/freebsd/target_os_siginfo.h | 145 ++
bsd-user/freebsd/target_os_signal.h | 78 +
bsd-user/freebsd/target_os_stack.h | 181 ++
bsd-user/freebsd/target_os_thread.h | 25 +
bsd-user/freebsd/target_os_user.h | 429 +++++
bsd-user/freebsd/target_os_vmparam.h | 38 +
.../target_syscall.h => i386/target_arch.h} | 27 +-
bsd-user/i386/target_arch_cpu.c | 76 +
bsd-user/i386/target_arch_cpu.h | 306 ++++
.../target_arch_elf.h} | 30 +-
bsd-user/i386/target_arch_reg.h | 82 +
bsd-user/i386/target_arch_signal.h | 94 ++
bsd-user/i386/target_arch_sigtramp.h | 29 +
bsd-user/i386/target_arch_thread.h | 47 +
bsd-user/i386/target_arch_vmparam.h | 46 +
bsd-user/main.c | 831 ++--------
bsd-user/mmap.c | 421 ++++-
bsd-user/netbsd/host-os.h | 25 +
bsd-user/netbsd/target_os_elf.h | 143 ++
bsd-user/netbsd/target_os_siginfo.h | 82 +
bsd-user/netbsd/target_os_signal.h | 70 +
bsd-user/netbsd/target_os_stack.h | 56 +
bsd-user/netbsd/target_os_thread.h | 25 +
bsd-user/openbsd/host-os.h | 25 +
bsd-user/openbsd/target_os_elf.h | 143 ++
bsd-user/openbsd/target_os_siginfo.h | 82 +
bsd-user/openbsd/target_os_signal.h | 70 +
bsd-user/openbsd/target_os_stack.h | 56 +
bsd-user/openbsd/target_os_thread.h | 25 +
bsd-user/qemu.h | 62 +-
bsd-user/sparc/target_arch_sysarch.h | 52 -
bsd-user/sparc64/target_arch_sysarch.h | 52 -
bsd-user/syscall.c | 11 -
bsd-user/syscall_defs.h | 255 +--
bsd-user/x86_64/target_arch.h | 31 +
bsd-user/x86_64/target_arch_cpu.c | 76 +
bsd-user/x86_64/target_arch_cpu.h | 328 ++++
bsd-user/x86_64/target_arch_elf.h | 33 +
bsd-user/x86_64/target_arch_reg.h | 92 ++
bsd-user/x86_64/target_arch_signal.h | 94 ++
bsd-user/x86_64/target_arch_sigtramp.h | 29 +
bsd-user/x86_64/target_arch_thread.h | 40 +
bsd-user/x86_64/target_arch_vmparam.h | 46 +
meson.build | 8 +-
50 files changed, 4555 insertions(+), 2251 deletions(-)
delete mode 100644 bsd-user/bsd-mman.h
create mode 100644 bsd-user/elfcore.c
create mode 100644 bsd-user/freebsd/host-os.h
create mode 100644 bsd-user/freebsd/target_os_elf.h
create mode 100644 bsd-user/freebsd/target_os_siginfo.h
create mode 100644 bsd-user/freebsd/target_os_signal.h
create mode 100644 bsd-user/freebsd/target_os_stack.h
create mode 100644 bsd-user/freebsd/target_os_thread.h
create mode 100644 bsd-user/freebsd/target_os_user.h
create mode 100644 bsd-user/freebsd/target_os_vmparam.h
rename bsd-user/{sparc/target_syscall.h => i386/target_arch.h} (60%)
create mode 100644 bsd-user/i386/target_arch_cpu.c
create mode 100644 bsd-user/i386/target_arch_cpu.h
rename bsd-user/{sparc64/target_syscall.h => i386/target_arch_elf.h} (59%)
create mode 100644 bsd-user/i386/target_arch_reg.h
create mode 100644 bsd-user/i386/target_arch_signal.h
create mode 100644 bsd-user/i386/target_arch_sigtramp.h
create mode 100644 bsd-user/i386/target_arch_thread.h
create mode 100644 bsd-user/i386/target_arch_vmparam.h
create mode 100644 bsd-user/netbsd/host-os.h
create mode 100644 bsd-user/netbsd/target_os_elf.h
create mode 100644 bsd-user/netbsd/target_os_siginfo.h
create mode 100644 bsd-user/netbsd/target_os_signal.h
create mode 100644 bsd-user/netbsd/target_os_stack.h
create mode 100644 bsd-user/netbsd/target_os_thread.h
create mode 100644 bsd-user/openbsd/host-os.h
create mode 100644 bsd-user/openbsd/target_os_elf.h
create mode 100644 bsd-user/openbsd/target_os_siginfo.h
create mode 100644 bsd-user/openbsd/target_os_signal.h
create mode 100644 bsd-user/openbsd/target_os_stack.h
create mode 100644 bsd-user/openbsd/target_os_thread.h
delete mode 100644 bsd-user/sparc/target_arch_sysarch.h
delete mode 100644 bsd-user/sparc64/target_arch_sysarch.h
create mode 100644 bsd-user/x86_64/target_arch.h
create mode 100644 bsd-user/x86_64/target_arch_cpu.c
create mode 100644 bsd-user/x86_64/target_arch_cpu.h
create mode 100644 bsd-user/x86_64/target_arch_elf.h
create mode 100644 bsd-user/x86_64/target_arch_reg.h
create mode 100644 bsd-user/x86_64/target_arch_signal.h
create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h
create mode 100644 bsd-user/x86_64/target_arch_thread.h
create mode 100644 bsd-user/x86_64/target_arch_vmparam.hSignature · 1 line
2.32.0
PATCH 1/49 bsd-user: remove sparc and sparc64
From: Warner Losh <[email protected]>
These are broken here and in the bsd-user fork. They won't be fixed as FreeBSD has dropped support for sparc. If people wish to support this in other BSDs, you're better off starting over than starting from these files.
--- bsd-user/main.c | 290 ------------------------- bsd-user/sparc/target_arch_sysarch.h | 52 ----- bsd-user/sparc/target_syscall.h | 36 --- bsd-user/sparc64/target_arch_sysarch.h | 52 ----- bsd-user/sparc64/target_syscall.h | 37 ---- bsd-user/syscall.c | 11 - 6 files changed, 478 deletions(-) delete mode 100644 bsd-user/sparc/target_arch_sysarch.h delete mode 100644 bsd-user/sparc/target_syscall.h delete mode 100644 bsd-user/sparc64/target_arch_sysarch.h delete mode 100644 bsd-user/sparc64/target_syscall.h
bsd-user/main.c +0 -290
@@ -261,274 +261,6 @@ void cpu_loop(CPUX86State *env) }#endif -#ifdef TARGET_SPARC -#define SPARC64_STACK_BIAS 2047 - -/* #define DEBUG_WIN */ -/* -* WARNING: dealing with register windows _is_ complicated. More info -* can be found at http://www.sics.se/~psm/sparcstack.html -*/ -static inline int get_reg_index (CPUSPARCState *env,int cwp,int index) -{ - index = (index + cwp *16 ) % (16 * env->nwindows); -/* -* wrap handling : if cwp is on the last window, then we use the -* registers 'after' the end -*/ -if (index <8 && env->cwp == env->nwindows -1 ) { - index +=16 * env->nwindows; - } -return index; -} - -/* save the register window 'cwp1' */ -static inline void save_window_offset (CPUSPARCState *env,int cwp1) -{ -unsigned int i; -abi_ulong sp_ptr; - - sp_ptr = env->regbase[get_reg_index (env, cwp1,6 )]; -#ifdef TARGET_SPARC64 -if (sp_ptr &3 ) { - sp_ptr +=SPARC64_STACK_BIAS ; - } -#endif -#if defined(DEBUG_WIN ) -printf ("win_overflow: sp_ptr=0x" TARGET_ABI_FMT_lx" save_cwp=%d\n" , - sp_ptr, cwp1); -#endif -for (i =0 ; i <16 ; i++) { -/* FIXME - what to do if put_user() fails? */ -put_user_ual (env->regbase[get_reg_index (env, cwp1,8 + i)], sp_ptr); - sp_ptr +=sizeof (abi_ulong); - } -} - -static void save_window (CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 -unsigned int new_wim; - new_wim = ((env->wim >>1 ) | (env->wim << (env->nwindows -1 ))) & - ((1LL << env->nwindows) -1 ); -save_window_offset (env,cpu_cwp_dec (env, env->cwp -2 )); - env->wim = new_wim; -#else -/* -* cansave is zero if the spill trap handler is triggered by `save` and -* nonzero if triggered by a `flushw` -*/ -save_window_offset (env,cpu_cwp_dec (env, env->cwp - env->cansave -2 )); - env->cansave++; - env->canrestore--; -#endif -} - -static void restore_window (CPUSPARCState *env) -{ -#ifndef TARGET_SPARC64 -unsigned int new_wim; -#endif -unsigned int i, cwp1; -abi_ulong sp_ptr; - -#ifndef TARGET_SPARC64 - new_wim = ((env->wim <<1 ) | (env->wim >> (env->nwindows -1 ))) & - ((1LL << env->nwindows) -1 ); -#endif - -/* restore the invalid window */ - cwp1 =cpu_cwp_inc (env, env->cwp +1 ); - sp_ptr = env->regbase[get_reg_index (env, cwp1,6 )]; -#ifdef TARGET_SPARC64 -if (sp_ptr &3 ) { - sp_ptr +=SPARC64_STACK_BIAS ; - } -#endif -#if defined(DEBUG_WIN ) -printf ("win_underflow: sp_ptr=0x" TARGET_ABI_FMT_lx" load_cwp=%d\n" , - sp_ptr, cwp1); -#endif -for (i =0 ; i <16 ; i++) { -/* FIXME - what to do if get_user() fails? */ -get_user_ual (env->regbase[get_reg_index (env, cwp1,8 + i)], sp_ptr); - sp_ptr +=sizeof (abi_ulong); - } -#ifdef TARGET_SPARC64 - env->canrestore++; -if (env->cleanwin < env->nwindows -1 ) { - env->cleanwin++; - } - env->cansave--; -#else - env->wim = new_wim; -#endif -} - -static void flush_windows (CPUSPARCState *env) -{ -int offset, cwp1; - - offset =1 ; -for (;;) { -/* if restore would invoke restore_window(), then we can stop */ - cwp1 =cpu_cwp_inc (env, env->cwp + offset); -#ifndef TARGET_SPARC64 -if (env->wim & (1 << cwp1)) { -break ; - } -#else -if (env->canrestore ==0 ) { -break ; - } - env->cansave++; - env->canrestore--; -#endif -save_window_offset (env, cwp1); - offset++; - } - cwp1 =cpu_cwp_inc (env, env->cwp +1 ); -#ifndef TARGET_SPARC64 -/* set wim so that restore will reload the registers */ - env->wim =1 << cwp1; -#endif -#if defined(DEBUG_WIN ) -printf ("flush_windows: nb=%d\n" , offset -1 ); -#endif -} - -void cpu_loop (CPUSPARCState *env) -{ -CPUState *cs =env_cpu (env); -int trapnr, ret, syscall_nr; -/* target_siginfo_t info; */ - -while (1 ) { -cpu_exec_start (cs); - trapnr =cpu_exec (cs); -cpu_exec_end (cs); -process_queued_cpu_work (cs); - -switch (trapnr) { -#ifndef TARGET_SPARC64 -case 0x80 : -#else -/* FreeBSD uses 0x141 for syscalls too */ -case 0x141 : -if (bsd_type != target_freebsd) { - goto badtrap; - } -/* fallthrough */ -case 0x100 : -#endif - syscall_nr = env->gregs[1 ]; -if (bsd_type == target_freebsd) - ret =do_freebsd_syscall (env, syscall_nr, - env->regwptr[0 ], env->regwptr[1 ], - env->regwptr[2 ], env->regwptr[3 ], - env->regwptr[4 ], env->regwptr[5 ], -0 ,0 ); -else if (bsd_type == target_netbsd) - ret =do_netbsd_syscall (env, syscall_nr, - env->regwptr[0 ], env->regwptr[1 ], - env->regwptr[2 ], env->regwptr[3 ], - env->regwptr[4 ], env->regwptr[5 ]); -else {/* if (bsd_type == target_openbsd) */ -#if defined(TARGET_SPARC64 ) - syscall_nr &= ~(TARGET_OPENBSD_SYSCALL_G7RFLAG | -TARGET_OPENBSD_SYSCALL_G2RFLAG ); -#endif - ret =do_openbsd_syscall (env, syscall_nr, - env->regwptr[0 ], env->regwptr[1 ], - env->regwptr[2 ], env->regwptr[3 ], - env->regwptr[4 ], env->regwptr[5 ]); - } -if ((unsigned int )ret >= (unsigned int )(-515 )) { - ret = -ret; -#if defined(TARGET_SPARC64 ) && !defined(TARGET_ABI32 ) - env->xcc |=PSR_CARRY ; -#else - env->psr |=PSR_CARRY ; -#endif - }else { -#if defined(TARGET_SPARC64 ) && !defined(TARGET_ABI32 ) - env->xcc &= ~PSR_CARRY ; -#else - env->psr &= ~PSR_CARRY ; -#endif - } - env->regwptr[0 ] = ret; -/* next instruction */ -#if defined(TARGET_SPARC64 ) -if (bsd_type == target_openbsd && - env->gregs[1 ] &TARGET_OPENBSD_SYSCALL_G2RFLAG ) { - env->pc = env->gregs[2 ]; - env->npc = env->pc +4 ; - }else if (bsd_type == target_openbsd && - env->gregs[1 ] &TARGET_OPENBSD_SYSCALL_G7RFLAG ) { - env->pc = env->gregs[7 ]; - env->npc = env->pc +4 ; - }else { - env->pc = env->npc; - env->npc = env->npc +4 ; - } -#else - env->pc = env->npc; - env->npc = env->npc +4 ; -#endif -break ; -case 0x83 :/* flush windows */ -#ifdef TARGET_ABI32 -case 0x103 : -#endif -flush_windows (env); -/* next instruction */ - env->pc = env->npc; - env->npc = env->npc +4 ; -break ; -#ifndef TARGET_SPARC64 -case TT_WIN_OVF :/* window overflow */ -save_window (env); -break ; -case TT_WIN_UNF :/* window underflow */ -restore_window (env); -break ; -case TT_TFAULT : -case TT_DFAULT : -break ; -#else -case TT_SPILL :/* window overflow */ -save_window (env); -break ; -case TT_FILL :/* window underflow */ -restore_window (env); -break ; -case TT_TFAULT : -case TT_DFAULT : -break ; -#endif -case EXCP_INTERRUPT : -/* just indicate that signals should be handled asap */ -break ; -case EXCP_DEBUG : - { -gdb_handlesig (cs,TARGET_SIGTRAP ); - } -break ; -default : -#ifdef TARGET_SPARC64 - badtrap: -#endif -printf ("Unhandled trap: 0x%x\n" , trapnr); -cpu_dump_state (cs, stderr,0 ); -exit (1 ); - } -process_pending_signals (env); - } -} - -#endif -static void usage (void ) { printf("qemu-" TARGET_NAME " version " QEMU_FULL_VERSION
@@ -779,12 +511,6 @@ int main(int argc, char **argv)#else cpu_model ="qemu32" ;#endif -#elif defined(TARGET_SPARC ) -#ifdef TARGET_SPARC64 - cpu_model ="TI UltraSparc II" ; -#else - cpu_model ="Fujitsu MB86904" ; -#endif #else cpu_model ="any" ;#endif
@@ -800,9 +526,6 @@ int main(int argc, char **argv) } cpu =cpu_create (cpu_type); env = cpu->env_ptr; -#if defined(TARGET_SPARC ) || defined(TARGET_PPC ) -cpu_reset (cpu); -#endif thread_cpu = cpu;if (getenv ("QEMU_STRACE" )) {
@@ -1001,19 +724,6 @@ int main(int argc, char **argv)cpu_x86_load_seg (env,R_FS ,0 );cpu_x86_load_seg (env,R_GS ,0 );#endif -#elif defined(TARGET_SPARC ) - { -int i; - env->pc = regs->pc; - env->npc = regs->npc; - env->y = regs->y; -for (i =0 ; i <8 ; i++) { - env->gregs[i] = regs->u_regs[i]; - } -for (i =0 ; i <8 ; i++) { - env->regwptr[i] = regs->u_regs[i +8 ]; - } - }#else #error unsupported target CPU#endif
bsd-user/sparc/target_arch_sysarch.h deleted +0 -52
52 lines not on this page · raw message
bsd-user/sparc/target_syscall.h deleted +0 -36
@@ -1,36 +0,0 @@ -/* -* sparc dependent system call definitions -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ -#ifndef TARGET_SYSCALL_H -#define TARGET_SYSCALL_H - -struct target_pt_regs { -abi_ulong psr; -abi_ulong pc; -abi_ulong npc; -abi_ulong y; -abi_ulong u_regs[16 ]; -}; - -#define UNAME_MACHINE "sun4" -#define TARGET_HW_MACHINE "sparc" -#define TARGET_HW_MACHINE_ARCH "sparc" - -#define TARGET_SPARC_UTRAP_INSTALL 1 -#define TARGET_SPARC_SIGTRAMP_INSTALL 2 - -#endif /* TARGET_SYSCALL_H */
bsd-user/sparc64/target_arch_sysarch.h deleted +0 -52
52 lines not on this page · raw message
bsd-user/sparc64/target_syscall.h deleted +0 -37
@@ -1,37 +0,0 @@ -/* -* sparc64 dependent system call definitions -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, see <http://www.gnu.org/licenses/>. -*/ -#ifndef TARGET_SYSCALL_H -#define TARGET_SYSCALL_H - -struct target_pt_regs { -abi_ulong u_regs[16 ]; -abi_ulong tstate; -abi_ulong pc; -abi_ulong npc; -abi_ulong y; -abi_ulong fprs; -}; - -#define UNAME_MACHINE "sun4u" -#define TARGET_HW_MACHINE "sparc" -#define TARGET_HW_MACHINE_ARCH "sparc64" - -#define TARGET_SPARC_UTRAP_INSTALL 1 -#define TARGET_SPARC_SIGTRAMP_INSTALL 2 - -#endif /* TARGET_SYSCALL_H */
bsd-user/syscall.c +0 -11
@@ -138,17 +138,6 @@ static abi_long do_freebsd_sysarch(CPUX86State *env, int op, abi_ulong parms) }#endif -#ifdef TARGET_SPARC -static abi_long do_freebsd_sysarch (void *env,int op,abi_ulong parms) -{ -/* XXX handle -* TARGET_FREEBSD_SPARC_UTRAP_INSTALL, -* TARGET_FREEBSD_SPARC_SIGTRAMP_INSTALL -*/ -return -TARGET_EINVAL ; -} -#endif -#ifdef __FreeBSD__/* * XXX this uses the undocumented oidfmt interface to find the kind of
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 01/49] bsd-user: remove sparc and sparc64
Quoted 16 lines · Warner Losh
From: Warner Losh<[email protected]>
These are broken here and in the bsd-user fork. They won't be fixed as FreeBSD has dropped support for sparc. If people wish to support this in other BSDs, you're better off starting over than starting from these files.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 290 ------------------------- bsd-user/sparc/target_arch_sysarch.h | 52 ----- bsd-user/sparc/target_syscall.h | 36 --- bsd-user/sparc64/target_arch_sysarch.h | 52 ----- bsd-user/sparc64/target_syscall.h | 37 ---- bsd-user/syscall.c | 11 - 6 files changed, 478 deletions(-)
Quoted 5 lines
delete mode 100644
bsd-user/sparc/target_arch_sysarch.hdelete mode 100644bsd-user/sparc/target_syscall.hdelete mode 100644bsd-user/sparc64/target_arch_sysarch.hdelete mode 100644bsd-user/sparc64/target_syscall.h
r~
PATCH 2/49 bsd-user: add copyright header to elfload.c
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Add Stacey's copyright to elfload.c
--- bsd-user/elfload.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
bsd-user/elfload.c +18 -1
@@ -1,4 +1,21 @@ -/* This is the Linux kernel elf-loading code, ported into user space */ +/* +* ELF loading code +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ #include "qemu/osdep.h"
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 02/49] bsd-user: add copyright header to elfload.c
Quoted 9 lines · Warner Losh
From: Warner Losh<[email protected]>
Add Stacey's copyright to
elfload.cSigned-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
r~
PATCH 3/49 bsd-user: Add Stacey's copyright to main.c
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Add Stacey's updated copyright to main.c
Sponsored by: Netflix
--- bsd-user/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
bsd-user/main.c +2 -1
@@ -1,7 +1,8 @@/* -* qemu user main +* qemu bsd user main * * Copyright (c) 2003-2008 Fabrice Bellard +* Copyright (c) 2013-14 Stacey Son * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 03/49] bsd-user: Add Stacey's copyright to main.c
Quoted 11 lines · Warner Losh
From: Warner Losh<[email protected]>
Add Stacey's updated copyright to
main.cSigned-off-by Warner Losh<[email protected]>Signed-off-by Stacey Son<[email protected]>Sponsored by: Netflix
--- bsd-user/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
r~
PATCH 4/49 bsd-user: Remove all non-x86 code from elfload.c
In reply to Warner Loshbsd-user only builds x86 at the moment. Remove all non x86 code from elfload.c. We'll move the x86 code to {i386,x86_64}/target_arch_elf.h and bring it that support code from the forked bsd-user when the time comes.
--- bsd-user/elfload.c | 347 +-------------------------------------------- 1 file changed, 2 insertions(+), 345 deletions(-)
bsd-user/elfload.c +2 -345
@@ -23,15 +23,6 @@#include "disas/disas.h" #include "qemu/path.h" -#ifdef _ARCH_PPC64 -#undef ARCH_DLINFO -#undef ELF_PLATFORM -#undef ELF_HWCAP -#undef ELF_CLASS -#undef ELF_DATA -#undef ELF_ARCH -#endif -/* from personality.h */ /*
@@ -144,7 +135,7 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i } } -#else +#else /* !TARGET_X86_64 */ #define ELF_START_MMAP 0x80000000
@@ -174,343 +165,13 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *iA value of 0 tells we have no such handler. */ regs->edx =0 ; } -#endif - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif - -#ifdef TARGET_ARM - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_ARM) - -#define ELF_CLASS ELFCLASS32 -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_ARM - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ -abi_long stack = infop->start_stack; -memset (regs,0 ,sizeof (*regs)); - regs->ARM_cpsr =0x10 ; -if (infop->entry &1 ) - regs->ARM_cpsr |=CPSR_T ; - regs->ARM_pc = infop->entry &0xfffffffe ; - regs->ARM_sp = infop->start_stack; -/* FIXME - what to for failure of get_user()? */ -get_user_ual (regs->ARM_r2, stack +8 );/* envp */ -get_user_ual (regs->ARM_r1, stack +4 );/* envp */ -/* XXX: it seems that r0 is zeroed after ! */ - regs->ARM_r0 =0 ; -/* For uClinux PIC binaries. */ -/* XXX: Linux does this only on ARM with no MMU (do we care ?) */ - regs->ARM_r10 = infop->start_data; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -enum -{ -ARM_HWCAP_ARM_SWP =1 <<0 , -ARM_HWCAP_ARM_HALF =1 <<1 , -ARM_HWCAP_ARM_THUMB =1 <<2 , -ARM_HWCAP_ARM_26BIT =1 <<3 , -ARM_HWCAP_ARM_FAST_MULT =1 <<4 , -ARM_HWCAP_ARM_FPA =1 <<5 , -ARM_HWCAP_ARM_VFP =1 <<6 , -ARM_HWCAP_ARM_EDSP =1 <<7 , -}; - -#define ELF_HWCAP (ARM_HWCAP_ARM_SWP | ARM_HWCAP_ARM_HALF \ - | ARM_HWCAP_ARM_THUMB | ARM_HWCAP_ARM_FAST_MULT \ - | ARM_HWCAP_ARM_FPA | ARM_HWCAP_ARM_VFP) - -#endif - -#ifdef TARGET_SPARC -#ifdef TARGET_SPARC64 - -#define ELF_START_MMAP 0x80000000 - -#ifndef TARGET_ABI32 -#define elf_check_arch (x) ((x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS) -#else -#define elf_check_arch (x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC) -#endif - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_SPARCV9 - -#define STACK_BIAS 2047 - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ -#ifndef TARGET_ABI32 - regs->tstate =0 ; -#endif - regs->pc = infop->entry; - regs->npc = regs->pc +4 ; - regs->y =0 ; -#ifdef TARGET_ABI32 - regs->u_regs[14 ] = infop->start_stack -16 *4 ; -#else -if (personality (infop->personality) ==PER_LINUX32 ) - regs->u_regs[14 ] = infop->start_stack -16 *4 ; -else { - regs->u_regs[14 ] = infop->start_stack -16 *8 -STACK_BIAS ; -if (bsd_type == target_freebsd) { - regs->u_regs[8 ] = infop->start_stack; - regs->u_regs[11 ] = infop->start_stack; - } - } -#endif -} - -#else -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_SPARC) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_SPARC - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->psr =0 ; - regs->pc = infop->entry; - regs->npc = regs->pc +4 ; - regs->y =0 ; - regs->u_regs[14 ] = infop->start_stack -16 *4 ; -} - -#endif -#endif - -#ifdef TARGET_PPC - -#define ELF_START_MMAP 0x80000000 - -#if defined(TARGET_PPC64 ) && !defined(TARGET_ABI32 ) - -#define elf_check_arch (x) ((x) == EM_PPC64) - -#define ELF_CLASS ELFCLASS64 - -#else - -#define elf_check_arch (x) ((x) == EM_PPC) - -#define ELF_CLASS ELFCLASS32 - -#endif - -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_PPC - -/* -* We need to put in some extra aux table entries to tell glibc what -* the cache block size is, so it can use the dcbz instruction safely. -*/ -#define AT_DCACHEBSIZE 19 -#define AT_ICACHEBSIZE 20 -#define AT_UCACHEBSIZE 21 -/* A special ignored type value for PPC, for glibc compatibility. */ -#define AT_IGNOREPPC 22 -/* -* The requirements here are: -* - keep the final alignment of sp (sp & 0xf) -* - make sure the 32-bit value at the first 16 byte aligned position of -* AUXV is greater than 16 for glibc compatibility. -* AT_IGNOREPPC is used for that. -* - for compatibility with glibc ARCH_DLINFO must always be defined on PPC, -* even if DLINFO_ARCH_ITEMS goes to zero or is undefined. -*/ -#define DLINFO_ARCH_ITEMS 5 -#define ARCH_DLINFO \ -do { \ - NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20); \ - NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20); \ - NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \ -/* \ -* Now handle glibc compatibility. \ -*/ \ -NEW_AUX_ENT (AT_IGNOREPPC ,AT_IGNOREPPC ); \ -NEW_AUX_ENT (AT_IGNOREPPC ,AT_IGNOREPPC ); \ - } while (0) - -static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop) -{ -abi_ulong pos = infop->start_stack; -abi_ulong tmp; -#if defined(TARGET_PPC64 ) && !defined(TARGET_ABI32 ) -abi_ulong entry, toc; -#endif - - _regs->gpr[1 ] = infop->start_stack; -#if defined(TARGET_PPC64 ) && !defined(TARGET_ABI32 ) -get_user_u64 (entry, infop->entry); - entry += infop->load_addr; -get_user_u64 (toc, infop->entry +8 ); - toc += infop->load_addr; - _regs->gpr[2 ] = toc; - infop->entry = entry; -#endif - _regs->nip = infop->entry; -/* Note that isn't exactly what regular kernel does -* but this is what the ABI wants and is needed to allow -* execution of PPC BSD programs. -*/ -/* FIXME - what to for failure of get_user()? */ -get_user_ual (_regs->gpr[3 ], pos); - pos +=sizeof (abi_ulong); - _regs->gpr[4 ] = pos; -for (tmp =1 ; tmp !=0 ; pos +=sizeof (abi_ulong)) { -get_user_ual (tmp, pos); - } - _regs->gpr[5 ] = pos; -} +#endif /* !TARGET_X86_64 */ #define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096#endif -#ifdef TARGET_MIPS - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_MIPS) - -#ifdef TARGET_MIPS64 -#define ELF_CLASS ELFCLASS64 -#else -#define ELF_CLASS ELFCLASS32 -#endif -#ifdef TARGET_WORDS_BIGENDIAN -#define ELF_DATA ELFDATA2MSB -#else -#define ELF_DATA ELFDATA2LSB -#endif -#define ELF_ARCH EM_MIPS - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->cp0_status =2 << CP0St_KSU; - regs->cp0_epc = infop->entry; - regs->regs[29 ] = infop->start_stack; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif /* TARGET_MIPS */ - -#ifdef TARGET_SH4 - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_SH) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_SH - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ -/* Check other registers XXXXX */ - regs->pc = infop->entry; - regs->regs[15 ] = infop->start_stack; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif - -#ifdef TARGET_CRIS - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_CRIS) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_CRIS - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->erp = infop->entry; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif - -#ifdef TARGET_M68K - -#define ELF_START_MMAP 0x80000000 - -#define elf_check_arch (x) ((x) == EM_68K) - -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_68K - -/* ??? Does this need to do anything? -#define ELF_PLAT_INIT(_r) */ - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->usp = infop->start_stack; - regs->sr =0 ; - regs->pc = infop->entry; -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif - -#ifdef TARGET_ALPHA - -#define ELF_START_MMAP (0x30000000000ULL) - -#define elf_check_arch (x) ((x) == ELF_ARCH) - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2MSB -#define ELF_ARCH EM_ALPHA - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->pc = infop->entry; - regs->ps =8 ; - regs->usp = infop->start_stack; - regs->unique = infop->start_data;/* ? */ -printf ("Set unique value to " TARGET_FMT_lx" (" TARGET_FMT_lx")\n" , - regs->unique, infop->start_data); -} - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 8192 - -#endif /* TARGET_ALPHA */ -#ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL)#endif
@@ -1119,10 +780,6 @@ static void load_symbols(struct elfhdr *hdr, int fd) }continue ; } -#if defined(TARGET_ARM ) || defined(TARGET_MIPS ) -/* The bottom address bit marks a Thumb or MIPS16 symbol. */ - syms[i].st_value &= ~(target_ulong )1 ; -#endif i++; }
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 04/49] bsd-user: Remove all non-x86 code from elfload.c
Quoted 9 lines · Warner Losh
bsd-user only builds x86 at the moment. Remove all non x86 code from
elfload.c. We'll move the x86 code to {i386,x86_64}/target_arch_elf.hand bring it that support code from the forked bsd-user when the time comes.Signed-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 347 +-------------------------------------------- 1 file changed, 2 insertions(+), 345 deletions(-)
r~
PATCH 5/49 bsd-user: move arch specific defines out of elfload.c
In reply to Warner LoshMove the arcitecture specific defines to target_arch_elf.h and delete them from elfload.c. unifdef as appropriate for i386 vs x86_64 versions.
--- bsd-user/elfload.c | 81 +------------------------------ bsd-user/i386/target_arch_elf.h | 54 +++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 41 ++++++++++++++++ 3 files changed, 97 insertions(+), 79 deletions(-) create mode 100644 bsd-user/i386/target_arch_elf.h create mode 100644 bsd-user/x86_64/target_arch_elf.h
bsd-user/elfload.c +2 -79
@@ -23,6 +23,8 @@#include "disas/disas.h" #include "qemu/path.h" +#include "target_arch_elf.h" +/* from personality.h */ /*
@@ -93,85 +95,6 @@ enum {#define ELIBBAD 80#endif -#ifdef TARGET_I386 - -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform (void ) -{ -static char elf_platform[] ="i386" ; -int family =object_property_get_int (OBJECT (thread_cpu),"family" ,NULL ); -if (family >6 ) - family =6 ; -if (family >=3 ) - elf_platform[1 ] ='0' + family; -return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap (void ) -{ -X86CPU *cpu =X86_CPU (thread_cpu); - -return cpu->env.features[FEAT_1_EDX ]; -} - -#ifdef TARGET_X86_64 -#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) (((x) == ELF_ARCH)) - -#define ELF_CLASS ELFCLASS64 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_X86_64 - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->rax =0 ; - regs->rsp = infop->start_stack; - regs->rip = infop->entry; -if (bsd_type == target_freebsd) { - regs->rdi = infop->start_stack; - } -} - -#else /* !TARGET_X86_64 */ - -#define ELF_START_MMAP 0x80000000 - -/* -* This is used to ensure we don't load something for the wrong architecture. -*/ -#define elf_check_arch (x) (((x) == EM_386) || ((x) == EM_486)) - -/* -* These are used to set parameters in the core dumps. -*/ -#define ELF_CLASS ELFCLASS32 -#define ELF_DATA ELFDATA2LSB -#define ELF_ARCH EM_386 - -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) -{ - regs->esp = infop->start_stack; - regs->eip = infop->entry; - -/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program -starts %edx contains a pointer to a function which might be -registered using `atexit'. This provides a mean for the -dynamic linker to call DT_FINI functions for shared libraries -that have been loaded before the code runs. - -A value of 0 tells we have no such handler. */ - regs->edx =0 ; -} -#endif /* !TARGET_X86_64 */ - -#define USE_ELF_CORE_DUMP -#define ELF_EXEC_PAGESIZE 4096 - -#endif -#ifndef ELF_PLATFORM #define ELF_PLATFORM (NULL)#endif
bsd-user/i386/target_arch_elf.h new file +54 -0
54 lines not on this page · raw message
bsd-user/x86_64/target_arch_elf.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 05/49] bsd-user: move arch specific defines out of elfload.c
Quoted 11 lines · Warner Losh
Move the arcitecture specific defines to
target_arch_elf.hand delete them fromelfload.c. unifdef as appropriate for i386 vsx86_64versions.Signed-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 81 +------------------------------ bsd-user/i386/target_arch_elf.h | 54 +++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 41 ++++++++++++++++ 3 files changed, 97 insertions(+), 79 deletions(-)create mode 100644
bsd-user/i386/target_arch_elf.hcreate mode 100644bsd-user/x86_64/target_arch_elf.h
r~
PATCH 6/49 bsd-user: merge comments and guards from bsd-user fork
In reply to Warner LoshDiff reduction against bsd-user fork: bring in the copyright/license comments, and guard ifdefs.
--- bsd-user/i386/target_arch_elf.h | 22 ++++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+)
bsd-user/i386/target_arch_elf.h +22 -0
@@ -1,3 +1,23 @@ +/* +* i386 ELF definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _TARGET_ARCH_ELF_H_ +#define _TARGET_ARCH_ELF_H_#define ELF_PLATFORM get_elf_platform()
@@ -52,3 +72,5 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i#define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 + +#endif /* _TARGET_ARCH_ELF_H_ */
bsd-user/x86_64/target_arch_elf.h +23 -0
@@ -1,3 +1,24 @@ +/* +* x86_64 ELF definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _TARGET_ARCH_ELF_H_ +#define _TARGET_ARCH_ELF_H_ +#define ELF_PLATFORM get_elf_platform()static const char *get_elf_platform (void )
@@ -39,3 +60,5 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i#define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096 + +#endif /* _TARGET_ARCH_ELF_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 06/49] bsd-user: merge comments and guards from bsd-user fork
Quoted 8 lines · Warner Losh
Diff reduction against bsd-user fork: bring in the copyright/license comments, and guard ifdefs.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/i386/target_arch_elf.h | 22 ++++++++++++++++++++++ bsd-user/x86_64/target_arch_elf.h | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+)
Could reasonably be squashed with previous, but not required.
r~
PATCH 7/49 bsd-user: style nits: apply qemu style to these files
In reply to Warner LoshFix style wrt {} placement, spaces around () and line lengths.
--- bsd-user/i386/target_arch_elf.h | 27 ++++++++++++++++----------- bsd-user/x86_64/target_arch_elf.h | 11 +++++++---- 2 files changed, 23 insertions(+), 15 deletions(-)
bsd-user/i386/target_arch_elf.h +16 -11
@@ -25,10 +25,12 @@ static const char *get_elf_platform(void) {static char elf_platform[] ="i386" ;int family =object_property_get_int (OBJECT (thread_cpu),"family" ,NULL ); -if (family >6 ) +if (family >6 ) { family =6 ; -if (family >=3 ) + } +if (family >=3 ) { elf_platform[1 ] ='0' + family; + }return elf_platform; }
@@ -46,7 +48,7 @@ static uint32_t get_elf_hwcap(void)/* * This is used to ensure we don't load something for the wrong architecture. */ -#define elf_check_arch (x) ( ((x) == EM_386) || ((x) == EM_486) ) +#define elf_check_arch (x) (((x) == EM_386) || ((x) == EM_486))/* * These are used to set parameters in the core dumps.
@@ -55,18 +57,21 @@ static uint32_t get_elf_hwcap(void)#define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_386 -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) +static inline void init_thread (struct target_pt_regs *regs, +struct image_info *infop) { regs->esp = infop->start_stack; regs->eip = infop->entry; -/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program -starts %edx contains a pointer to a function which might be -registered using `atexit'. This provides a mean for the -dynamic linker to call DT_FINI functions for shared libraries -that have been loaded before the code runs. - -A value of 0 tells we have no such handler. */ +/* +* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program starts %edx +* contains a pointer to a function which might be registered using +* `atexit'. This provides a mean for the dynamic linker to call DT_FINI +* functions for shared libraries that have been loaded before the code +* runs. +* +* A value of 0 tells we have no such handler. +*/ regs->edx =0 ; }
bsd-user/x86_64/target_arch_elf.h +7 -4
@@ -25,10 +25,12 @@ static const char *get_elf_platform(void) {static char elf_platform[] ="i386" ;int family =object_property_get_int (OBJECT (thread_cpu),"family" ,NULL ); -if (family >6 ) +if (family >6 ) { family =6 ; -if (family >=3 ) + } +if (family >=3 ) { elf_platform[1 ] ='0' + family; + }return elf_platform; }
@@ -42,13 +44,14 @@ static uint32_t get_elf_hwcap(void) }#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) ( ((x) == ELF_ARCH) ) +#define elf_check_arch (x) (((x) == ELF_ARCH))#define ELF_CLASS ELFCLASS64#define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_X86_64 -static inline void init_thread (struct target_pt_regs *regs,struct image_info *infop) +static inline void init_thread (struct target_pt_regs *regs, +struct image_info *infop) { regs->rax =0 ; regs->rsp = infop->start_stack;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 07/49] bsd-user: style nits: apply qemu style to these files
Quoted 7 lines · Warner Losh
Fix style wrt {} placement, spaces around () and line lengths.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/i386/target_arch_elf.h | 27 ++++++++++++++++----------- bsd-user/x86_64/target_arch_elf.h | 11 +++++++---- 2 files changed, 23 insertions(+), 15 deletions(-)
r~
PATCH 8/49 bsd-user: style nits: fix whitespace issues to be qemu standard
In reply to Warner Losh--- bsd-user/bsdload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
bsd-user/bsdload.c +2 -2
@@ -125,7 +125,7 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, }int loader_exec (const char *filename,char **argv,char **envp, -struct target_pt_regs *regs,struct image_info *infop) +struct target_pt_regs *regs,struct image_info *infop) {struct bsd_binprm bprm;int retval;
@@ -133,7 +133,7 @@ int loader_exec(const char *filename, char **argv, char **envp, bprm.p =TARGET_PAGE_SIZE *MAX_ARG_PAGES -sizeof (unsigned int );for (i =0 ; i <MAX_ARG_PAGES ; i++) {/* clear page-table */ - bprm.page[i] =NULL ; + bprm.page[i] =NULL ; } retval =open (filename,O_RDONLY );if (retval <0 ) {
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 08/49] bsd-user: style nits: fix whitespace issues to be qemu standard
Quoted 4 lines · Warner Losh
Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 9/49 bsd-user: add license
In reply to Warner LoshPull in the license statement at the top of the bsdload.c file from the bsd-user fork version of this file. No functional changes.
--- bsd-user/bsdload.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
bsd-user/bsdload.c +16 -1
@@ -1,4 +1,19 @@ -/* Code for loading BSD executables. Mostly linux kernel code. */ +/* +* Load BSD executables. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ #include "qemu/osdep.h"
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 09/49] bsd-user: add license
Quoted 7 lines · Warner Losh
Pull in the license statement at the top of the
bsdload.cfile from the bsd-user fork version of this file. No functional changes.Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
r~
PATCH 10/49 bsd-user: pass the bsd_param into loader_exec
In reply to Warner LoshPass the bsd_param into loader_exec, and adjust.
--- bsd-user/bsdload.c | 37 +++++++++++++++++++------------------ bsd-user/main.c | 7 ++++++- bsd-user/qemu.h | 3 ++- 3 files changed, 27 insertions(+), 20 deletions(-)
bsd-user/bsdload.c +19 -18
@@ -140,35 +140,36 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, }int loader_exec (const char *filename,char **argv,char **envp, -struct target_pt_regs *regs,struct image_info *infop) +struct target_pt_regs *regs,struct image_info *infop, +struct bsd_binprm *bprm) { -struct bsd_binprm bprm;int retval;int i; - bprm.p =TARGET_PAGE_SIZE *MAX_ARG_PAGES -sizeof (unsigned int ); -for (i =0 ; i <MAX_ARG_PAGES ; i++) {/* clear page-table */ - bprm.page[i] =NULL ; + bprm->p =TARGET_PAGE_SIZE *MAX_ARG_PAGES -sizeof (unsigned int ); +for (i =0 ; i <MAX_ARG_PAGES ; i++) {/* clear page-table */ + bprm->page[i] =NULL ; } retval =open (filename,O_RDONLY );if (retval <0 ) {return retval; } - bprm.fd = retval; - bprm.filename = (char *)filename; - bprm.argc =count (argv); - bprm.argv = argv; - bprm.envc =count (envp); - bprm.envp = envp; - retval =prepare_binprm (&bprm); + bprm->fd = retval; + bprm->filename = (char *)filename; + bprm->argc =count (argv); + bprm->argv = argv; + bprm->envc =count (envp); + bprm->envp = envp; + + retval =prepare_binprm (bprm);if (retval >=0 ) { -if (bprm.buf[0 ] ==0x7f - && bprm.buf[1 ] =='E' - && bprm.buf[2 ] =='L' - && bprm.buf[3 ] =='F' ) { - retval =load_elf_binary (&bprm, regs, infop); +if (bprm->buf[0 ] ==0x7f + && bprm->buf[1 ] =='E' + && bprm->buf[2 ] =='L' + && bprm->buf[3 ] =='F' ) { + retval =load_elf_binary (bprm, regs, infop); }else {fprintf (stderr,"Unknown binary format\n" );return -1 ;
@@ -183,7 +184,7 @@ int loader_exec(const char *filename, char **argv, char **envp,/* Something went wrong, return the inode and free the argument pages*/ for (i =0 ; i <MAX_ARG_PAGES ; i++) { -g_free (bprm.page[i]); +g_free (bprm->page[i]); }return retval; }
bsd-user/main.c +6 -1
@@ -343,6 +343,7 @@ int main(int argc, char **argv)const char *log_mask =NULL ;struct target_pt_regs regs1, *regs = ®s1;struct image_info info1, *info = &info1; +struct bsd_binprm bprm;TaskState ts1, *ts = &ts1;CPUArchState *env;CPUState *cpu;
@@ -499,6 +500,9 @@ int main(int argc, char **argv)/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs )); +/* Zero bsd params */ +memset (&bprm,0 ,sizeof (bprm)); +/* Zero out image_info */ memset (info,0 ,sizeof (struct image_info ));
@@ -565,7 +569,8 @@ int main(int argc, char **argv) } } -if (loader_exec (filename, argv + optind, target_environ, regs, info) !=0 ) { +if (loader_exec (filename, argv+optind, target_environ, regs, info, + &bprm) !=0 ) {printf ("Error loading %s\n" , filename);_exit (1 ); }
bsd-user/qemu.h +2 -1
@@ -131,7 +131,8 @@ void do_init_thread(struct target_pt_regs *regs, struct image_info *infop);abi_ulong loader_build_argptr (int envc,int argc,abi_ulong sp,abi_ulong stringp,int push_ptr);int loader_exec (const char *filename,char **argv,char **envp, -struct target_pt_regs *regs,struct image_info *infop); +struct target_pt_regs *regs,struct image_info *infop, +struct bsd_binprm *bprm);int load_elf_binary (struct bsd_binprm *bprm,struct target_pt_regs *regs,struct image_info *info);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 10/49] bsd-user: pass the bsd_param into loader_exec
Quoted 8 lines · Warner Losh
Pass the
bsd_paramintoloader_exec, and adjust.Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 37 +++++++++++++++++++------------------ bsd-user/main.c | 7 ++++++- bsd-user/qemu.h | 3 ++- 3 files changed, 27 insertions(+), 20 deletions(-)
r~
PATCH 11/49 bsd-user: Fix calculation of size to allocate
In reply to Warner LoshIt was incorrect to subtract off the size of an unsigned int here. In bsd-user fork, this change was made when moving the arch specific items to specific files. The size in BSD that's available for the arguments does not need a return address subtracted from it.
--- bsd-user/bsdload.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
bsd-user/bsdload.c +2 -3
@@ -143,10 +143,9 @@ int loader_exec(const char *filename, char **argv, char **envp, struct target_pt_regs *regs, struct image_info *infop, struct bsd_binprm *bprm) { - int retval; -int i; + int retval, i; - bprm->p =TARGET_PAGE_SIZE *MAX_ARG_PAGES -sizeof (unsigned int ); + bprm->p =TARGET_PAGE_SIZE *MAX_ARG_PAGES ;for (i =0 ; i <MAX_ARG_PAGES ; i++) {/* clear page-table */ bprm->page[i] =NULL ; }
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 11/49] bsd-user: Fix calculation of size to allocate
Quoted 9 lines · Warner Losh
It was incorrect to subtract off the size of an unsigned int here. In bsd-user fork, this change was made when moving the arch specific items to specific files. The size in BSD that's available for the arguments does not need a return address subtracted from it.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
r~
PATCH 12/49 bsd-user: implement path searching
In reply to Warner LoshUse the PATH to find the executable given a bare argument.
--- bsd-user/bsdload.c | 73 +++++++++++++++++++++++++++++++++++++++++++++- bsd-user/qemu.h | 3 +- 2 files changed, 74 insertions(+), 2 deletions(-)
bsd-user/bsdload.c +72 -1
@@ -139,17 +139,88 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,return sp; } +static bool is_there (const char *candidate) +{ +struct stat fin; + +/* XXX work around access(2) false positives for superuser */ +if (access (candidate,X_OK ) ==0 &&stat (candidate, &fin) ==0 && +S_ISREG (fin.st_mode) && (getuid () !=0 || + (fin.st_mode & (S_IXUSR |S_IXGRP |S_IXOTH )) !=0 )) { +return true; + } + +return false; +} + +static bool find_in_path (char *path,const char *filename,char *retpath, +size_t rpsize) +{ +const char *d; + +while ((d =strsep (&path,":" )) !=NULL ) { +if (*d =='\0' ) { + d ="." ; + } +if (snprintf (retpath, rpsize,"%s/%s" , d, filename) >= (int )rpsize) { +continue ; + } +if (is_there ((const char *)retpath)) { +return true; + } + } +return false; +} +int loader_exec (const char *filename,char **argv,char **envp,struct target_pt_regs *regs,struct image_info *infop,struct bsd_binprm *bprm) { +char *p, *path =NULL , fullpath[PATH_MAX ];int retval, i; bprm->p =TARGET_PAGE_SIZE *MAX_ARG_PAGES ;for (i =0 ; i <MAX_ARG_PAGES ; i++) {/* clear page-table */ bprm->page[i] =NULL ; } - retval =open (filename,O_RDONLY ); + +if (strchr (filename,'/' ) !=NULL ) { + path =realpath (filename, fullpath); +if (path ==NULL ) { +/* Failed to resolve. */ +return -1 ; + } +if (!is_there (path)) { +return -1 ; + } + retval =open (path,O_RDONLY ); + bprm->fullpath =g_strdup (path); + }else { + p =getenv ("PATH" ); +if (p ==NULL ) { +return -1 ; + } + + path =g_strdup (p); +if (path ==NULL ) { +fprintf (stderr,"Out of memory\n" ); +return -1 ; + } + +if (!find_in_path (path, filename, fullpath,sizeof (fullpath))) { +return -1 ; + } + retval =open (fullpath,O_RDONLY ); + bprm->fullpath =g_strdup (fullpath); + +g_free (path); + } + +/* bprm->fullpath must be populated. */ +if (bprm->fullpath ==NULL ) { +fprintf (stderr,"Out of memory\n" ); +return -1 ; + }if (retval <0 ) {return retval; }
bsd-user/qemu.h +2 -1
@@ -124,7 +124,8 @@ struct bsd_binprm {int argc, envc;char **argv;char **envp; -char *filename;/* Name of binary */ +char *filename;/* (Given) Name of binary */ +char *fullpath;/* Full path of binary */ };void do_init_thread (struct target_pt_regs *regs,struct image_info *infop);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 12/49] bsd-user: implement path searching
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, · line 205
Quoted 2 lines · Warner Losh
bsd-user/bsdload.c +2
-0+ path =g_strdup (p); +if (path ==NULL ) {
Only returns null when the input is null, which you've already eliminated.
Quoted 7 lines
bsd-user/bsdload.c +7
-0+static bool find_in_path (char *path,const char *filename,char *retpath, +size_t rpsize) +{ +const char *d; + +while ((d =strsep (&path,":" )) !=NULL ) { +if (*d =='\0' ) {
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, · line 172
Quoted 10 lines
bsd-user/bsdload.c +10
-0+ d ="." ; + } +if (snprintf (retpath, rpsize,"%s/%s" , d, filename) >= (int )rpsize) { +continue ; + } +if (is_there ((const char *)retpath)) { +return true; + } + } +return false;
Hmm. Fixed size retpath buffer isn't ideal.
Any reason not to use g_find_program_in_path?
I note that we don't search the path at all in linux-user/.
r~
Re: [PATCH for 6.2 12/49] bsd-user: implement path searching
Quoted 19 lines · Richard Henderson
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, · line 205
Quoted 2 lines · Warner Losh
bsd-user/bsdload.c +2
-0+ path =g_strdup (p); +if (path ==NULL ) {Only returns null when the input is null, which you've already eliminated.
Quoted 12 lines
bsd-user/bsdload.c +12
-0+static bool find_in_path (char *path,const char *filename,char *retpath, +size_t rpsize) +{ +const char *d; + +while ((d =strsep (&path,":" )) !=NULL ) { +if (*d =='\0' ) { + d ="." ; + } +if (snprintf (retpath, rpsize,"%s/%s" , d, filename) >= (int )rpsize) { +continue ; + }
Quoted 9 lines
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, · line 172
Quoted 5 lines
bsd-user/bsdload.c +5
-0+if (is_there ((const char *)retpath)) { +return true; + } + } +return false;Hmm. Fixed size retpath buffer isn't ideal.
Any reason not to useg_find_program_in_path?
g_find_program_in_path may work well here, as well...
Quoted 2 lines
I note that we don't search the path at all in linux-user/.
IIRC imgact_binmisc will have the resolved path but preserve argv as it should have been were it not emulated, so we have to re-evaluate the PATH search here because we try to be faithful to the context.
Thanks,
Kyle Evans
Re: [PATCH for 6.2 12/49] bsd-user: implement path searching
Quoted 30 lines · Kyle Evans
Quoted 6 lines · Richard Henderson
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, · line 205
Quoted 2 lines · Warner Losh
bsd-user/bsdload.c +2
-0+ path =g_strdup (p); +if (path ==NULL ) {Only returns null when the input is null, which you've already
eliminated.
Quoted 2 lines
Quoted 2 lines
+static bool find_in_path(char *path, const char *filename, char
*retpath,
Quoted 9 lines
bsd-user/bsdload.c abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp,
Quoted 9 lines
bsd-user/bsdload.c +9
-0+ size_t rpsize) +{ +const char *d; + +while ((d =strsep (&path,":" )) !=NULL ) { +if (*d =='\0' ) { + d ="." ; + } + if (snprintf(retpath, rpsize, "%s/%s", d, filename) >=(int)rpsize) {
Quoted 8 lines
Quoted 7 lines
bsd-user/bsdload.c +7
-0+continue ; + } +if (is_there ((const char *)retpath)) { +return true; + } + } +return false;
Quoted 6 lines
Quoted 3 lines
Hmm. Fixed size retpath buffer isn't ideal.
Any reason not to useg_find_program_in_path?
g_find_program_in_pathmay work well here, as well...
Quite well: 1 file changed, 5 insertions(+), 42 deletions(-) so a nice reduction in code when the unnecessary stuff is removed. I'll have that in v2 of the series.
Quoted 7 lines
I note that we don't search the path at all in linux-user/.
Quoted 1 line
IIRC
imgact_binmiscwill have the resolved path but preserve argv as it should have been were it not emulated, so we have to re-evaluate the PATH search here because we try to be faithful to the context.
I just looked at the imgact_binmisc code, and that's what it does, so that sounds reasonable to me as well.
Warner
PATCH 13/49 bsd-user: Eliminate elf personality
In reply to Warner LoshThe linux kernel supports a number of different ELF binaries. The Linux userland emulator inheritted some of that. And we inheritted it from there. However, for BSD there's only one kind of ELF file supported per platform, so there's no need to cope with historical quirks. Simply the code as a result.
--- bsd-user/elfload.c | 87 ---------------------------------------------- bsd-user/qemu.h | 1 - 2 files changed, 88 deletions(-)
bsd-user/elfload.c +0 -87
@@ -25,66 +25,6 @@#include "target_arch_elf.h" -/* from personality.h */ - -/* -* Flags for bug emulation. -* -* These occupy the top three bytes. -*/ -enum { -ADDR_NO_RANDOMIZE =0x0040000 ,/* disable randomization of VA space */ -FDPIC_FUNCPTRS =0x0080000 ,/* userspace function ptrs point to descriptors -* (signal handling) -*/ -MMAP_PAGE_ZERO =0x0100000 , -ADDR_COMPAT_LAYOUT =0x0200000 , -READ_IMPLIES_EXEC =0x0400000 , -ADDR_LIMIT_32BIT =0x0800000 , -SHORT_INODE =0x1000000 , -WHOLE_SECONDS =0x2000000 , -STICKY_TIMEOUTS =0x4000000 , -ADDR_LIMIT_3GB =0x8000000 , -}; - -/* -* Personality types. -* -* These go in the low byte. Avoid using the top bit, it will -* conflict with error returns. -*/ -enum { -PER_LINUX =0x0000 , -PER_LINUX_32BIT =0x0000 |ADDR_LIMIT_32BIT , -PER_LINUX_FDPIC =0x0000 |FDPIC_FUNCPTRS , -PER_SVR4 =0x0001 |STICKY_TIMEOUTS |MMAP_PAGE_ZERO , -PER_SVR3 =0x0002 |STICKY_TIMEOUTS |SHORT_INODE , -PER_SCOSVR3 =0x0003 |STICKY_TIMEOUTS | -WHOLE_SECONDS |SHORT_INODE , -PER_OSR5 =0x0003 |STICKY_TIMEOUTS |WHOLE_SECONDS , -PER_WYSEV386 =0x0004 |STICKY_TIMEOUTS |SHORT_INODE , -PER_ISCR4 =0x0005 |STICKY_TIMEOUTS , -PER_BSD =0x0006 , -PER_SUNOS =0x0006 |STICKY_TIMEOUTS , -PER_XENIX =0x0007 |STICKY_TIMEOUTS |SHORT_INODE , -PER_LINUX32 =0x0008 , -PER_LINUX32_3GB =0x0008 |ADDR_LIMIT_3GB , -PER_IRIX32 =0x0009 |STICKY_TIMEOUTS ,/* IRIX5 32-bit */ -PER_IRIXN32 =0x000a |STICKY_TIMEOUTS ,/* IRIX6 new 32-bit */ -PER_IRIX64 =0x000b |STICKY_TIMEOUTS ,/* IRIX6 64-bit */ -PER_RISCOS =0x000c , -PER_SOLARIS =0x000d |STICKY_TIMEOUTS , -PER_UW7 =0x000e |STICKY_TIMEOUTS |MMAP_PAGE_ZERO , -PER_OSF4 =0x000f ,/* OSF/1 v4 */ -PER_HPUX =0x0010 , -PER_MASK =0x00ff , -}; - -/* -* Return the base personality without flags. -*/ -#define personality (pers) (pers & PER_MASK) -/* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE #define MAP_DENYWRITE 0
@@ -750,7 +690,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,abi_ulong load_addr, load_bias;int load_addr_set =0 ;unsigned int interpreter_type =INTERPRETER_NONE ; -unsigned char ibcs2_interpreter;int i;struct elf_phdr * elf_ppnt;struct elf_phdr *elf_phdata;
@@ -765,7 +704,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,#endif char passed_fileno[6 ]; - ibcs2_interpreter =0 ; load_addr =0 ; load_bias =0 ; elf_ex = *((struct elfhdr *) bprm->buf);/* exec-header */
@@ -856,20 +794,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,exit (-1 ); } -/* If the program interpreter is one of these two, -then assume an iBCS2 image. Otherwise assume -a native linux image. */ - -/* JRP - Need to add X86 lib dir stuff here... */ - -if (strcmp (elf_interpreter,"/usr/lib/libc.so.1" ) ==0 || -strcmp (elf_interpreter,"/usr/lib/ld.so.1" ) ==0 ) { - ibcs2_interpreter =1 ; - } - -#if 0 -printf ("Using ELF interpreter %s\n" ,path (elf_interpreter)); -#endif if (retval >=0 ) { retval =open (path (elf_interpreter),O_RDONLY );if (retval >=0 ) {
@@ -1099,7 +1023,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,load_symbols (&elf_ex, bprm->fd);if (interpreter_type !=INTERPRETER_AOUT )close (bprm->fd); - info->personality = (ibcs2_interpreter ?PER_SVR4 :PER_LINUX );#ifdef LOW_ELF_STACK info->start_stack = bprm->p = elf_stack -4 ;
@@ -1135,16 +1058,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,printf ("(brk) %x\n" , info->brk);#endif -if (info->personality ==PER_SVR4 ) - { -/* Why this, you ask??? Well SVr4 maps page 0 as read-only, -and some applications "depend" upon this behavior. -Since we do not have the power to recompile these, we -emulate the SVr4 behavior. Sigh. */ -target_mmap (0 , qemu_host_page_size,PROT_READ |PROT_EXEC , -MAP_FIXED |MAP_PRIVATE ,-1 ,0 ); - } - info->entry = elf_entry;return 0 ;
bsd-user/qemu.h +0 -1
@@ -66,7 +66,6 @@ struct image_info {abi_ulong entry;abi_ulong code_offset;abi_ulong data_offset; -int personality; };#define MAX_SIGQUEUE_SIZE 1024
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 13/49] bsd-user: Eliminate elf personality
Quoted 10 lines · Warner Losh
The linux kernel supports a number of different ELF binaries. The Linux userland emulator inheritted some of that. And we inheritted it from there. However, for BSD there's only one kind of ELF file supported per platform, so there's no need to cope with historical quirks. Simply the code as a result.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 87 ---------------------------------------------- bsd-user/qemu.h | 1 - 2 files changed, 88 deletions(-)
r~
PATCH 14/49 bsd-user: remove a.out support
In reply to Warner LoshRemove still-born a.out support. The BSDs switched from a.out to ELF 20+ years ago. It's out of scope for bsd-user, and what little support there was would simply wind up at a not-implemented message. Simplify the whole mess by removing it entirely. Should future support be required, it would be better to start from scratch.
--- bsd-user/bsdload.c | 9 +--- bsd-user/elfload.c | 105 ++++++++------------------------------------- bsd-user/qemu.h | 2 +- 3 files changed, 21 insertions(+), 95 deletions(-)
bsd-user/bsdload.c +1 -8
@@ -98,7 +98,7 @@ static int prepare_binprm(struct bsd_binprm *bprm)/* Construct the envp and argv tables on the target stack. */ abi_ulong loader_build_argptr (int envc,int argc,abi_ulong sp, -abi_ulong stringp,int push_ptr) +abi_ulong stringp) {int n =sizeof (abi_ulong);abi_ulong envp;
@@ -108,13 +108,6 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, envp = sp; sp -= (argc +1 ) * n; argv = sp; -if (push_ptr) { -/* FIXME - handle put_user() failures */ - sp -= n; -put_user_ual (envp, sp); - sp -= n; -put_user_ual (argv, sp); - } sp -= n;/* FIXME - handle put_user() failures */ put_user_ual (argc, sp);
bsd-user/elfload.c +19 -86
210 lines not on this page · raw message
bsd-user/qemu.h +1 -1
@@ -129,7 +129,7 @@ struct bsd_binprm {void do_init_thread (struct target_pt_regs *regs,struct image_info *infop);abi_ulong loader_build_argptr (int envc,int argc,abi_ulong sp, -abi_ulong stringp,int push_ptr); +abi_ulong stringp);int loader_exec (const char *filename,char **argv,char **envp,struct target_pt_regs *regs,struct image_info *infop,struct bsd_binprm *bprm);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 14/49] bsd-user: remove a.out support
Quoted 6 lines · Warner Losh
Remove still-born a.out support. The BSDs switched from a.out to ELF 20+ years ago. It's out of scope for bsd-user, and what little support there was would simply wind up at a not-implemented message. Simplify the whole mess by removing it entirely. Should future support be required, it would be better to start from scratch.
Quoted 6 lines
Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 9 +--- bsd-user/elfload.c | 105 ++++++++------------------------------------- bsd-user/qemu.h | 2 +- 3 files changed, 21 insertions(+), 95 deletions(-)
r~
PATCH 15/49 bsd-user: TARGET_NGROUPS unused in this file, remove
In reply to Warner Losh--- bsd-user/bsdload.c | 2 -- 1 file changed, 2 deletions(-)
bsd-user/bsdload.c +0 -2
@@ -19,8 +19,6 @@#include "qemu.h" -#define TARGET_NGROUPS 32 -/* ??? This should really be somewhere else. */ abi_long memcpy_to_target (abi_ulong dest,const void *src,unsigned long len)
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 15/49] bsd-user: TARGET_NGROUPS unused in this file, remove
Quoted 4 lines · Warner Losh
Signed-off-by Warner Losh<[email protected]>--- bsd-user/bsdload.c | 2 -- 1 file changed, 2 deletions(-)
r~
PATCH 16/49 bsd-user: elfload: simplify bswap a bit.
In reply to Warner LoshReduce the number of ifdefs by always calling the swapping routine, but making them empty when swapping isn't needed.
--- bsd-user/elfload.c | 97 ++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 50 deletions(-)
bsd-user/elfload.c +47 -50
@@ -67,13 +67,13 @@static inline void memcpy_fromfs (void *to,const void *from,unsigned long n) { -memcpy (to, from, n); +memcpy (to, from, n); }#ifdef BSWAP_NEEDED static void bswap_ehdr (struct elfhdr *ehdr) { -bswap16s (&ehdr->e_type);/* Object file type */ +bswap16s (&ehdr->e_type);/* Object file type */ bswap16s (&ehdr->e_machine);/* Architecture */ bswap32s (&ehdr->e_version);/* Object file version */ bswaptls (&ehdr->e_entry);/* Entry point virtual address */
@@ -81,37 +81,45 @@ static void bswap_ehdr(struct elfhdr *ehdr)bswaptls (&ehdr->e_shoff);/* Section header table file offset */ bswap32s (&ehdr->e_flags);/* Processor-specific flags */ bswap16s (&ehdr->e_ehsize);/* ELF header size in bytes */ -bswap16s (&ehdr->e_phentsize);/* Program header table entry size */ +bswap16s (&ehdr->e_phentsize);/* Program header table entry size */ bswap16s (&ehdr->e_phnum);/* Program header table entry count */ -bswap16s (&ehdr->e_shentsize);/* Section header table entry size */ +bswap16s (&ehdr->e_shentsize);/* Section header table entry size */ bswap16s (&ehdr->e_shnum);/* Section header table entry count */ -bswap16s (&ehdr->e_shstrndx);/* Section header string table index */ +bswap16s (&ehdr->e_shstrndx);/* Section header string table index */ } -static void bswap_phdr (struct elf_phdr *phdr) +static void bswap_phdr (struct elf_phdr *phdr,int phnum) { -bswap32s (&phdr->p_type);/* Segment type */ -bswaptls (&phdr->p_offset);/* Segment file offset */ -bswaptls (&phdr->p_vaddr);/* Segment virtual address */ -bswaptls (&phdr->p_paddr);/* Segment physical address */ -bswaptls (&phdr->p_filesz);/* Segment size in file */ -bswaptls (&phdr->p_memsz);/* Segment size in memory */ -bswap32s (&phdr->p_flags);/* Segment flags */ -bswaptls (&phdr->p_align);/* Segment alignment */ +int i; + +for (i =0 ; i < phnum; i++, phdr++) { +bswap32s (&phdr->p_type);/* Segment type */ +bswap32s (&phdr->p_flags);/* Segment flags */ +bswaptls (&phdr->p_offset);/* Segment file offset */ +bswaptls (&phdr->p_vaddr);/* Segment virtual address */ +bswaptls (&phdr->p_paddr);/* Segment physical address */ +bswaptls (&phdr->p_filesz);/* Segment size in file */ +bswaptls (&phdr->p_memsz);/* Segment size in memory */ +bswaptls (&phdr->p_align);/* Segment alignment */ + } } -static void bswap_shdr (struct elf_shdr *shdr) +static void bswap_shdr (struct elf_shdr *shdr,int shnum) { -bswap32s (&shdr->sh_name); -bswap32s (&shdr->sh_type); -bswaptls (&shdr->sh_flags); -bswaptls (&shdr->sh_addr); -bswaptls (&shdr->sh_offset); -bswaptls (&shdr->sh_size); -bswap32s (&shdr->sh_link); -bswap32s (&shdr->sh_info); -bswaptls (&shdr->sh_addralign); -bswaptls (&shdr->sh_entsize); +int i; + +for (i =0 ; i < shnum; i++, shdr++) { +bswap32s (&shdr->sh_name); +bswap32s (&shdr->sh_type); +bswaptls (&shdr->sh_flags); +bswaptls (&shdr->sh_addr); +bswaptls (&shdr->sh_offset); +bswaptls (&shdr->sh_size); +bswap32s (&shdr->sh_link); +bswap32s (&shdr->sh_info); +bswaptls (&shdr->sh_addralign); +bswaptls (&shdr->sh_entsize); + } }static void bswap_sym (struct elf_sym *sym)
@@ -121,7 +129,15 @@ static void bswap_sym(struct elf_sym *sym)bswaptls (&sym->st_size); bswap16s(&sym->st_shndx); } -#endif + +#else /* ! BSWAP_NEEDED */ + +static void bswap_ehdr (struct elfhdr *ehdr) { } +static void bswap_phdr (struct elf_phdr *phdr,int phnum) { } +static void bswap_shdr (struct elf_shdr *shdr,int shnum) { } +static void bswap_sym (struct elf_sym *sym) { } + +#endif /* ! BSWAP_NEEDED */ /* * 'copy_elf_strings()' copies argument/envelope strings from user
@@ -367,9 +383,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, last_bss =0 ; error =0 ; -#ifdef BSWAP_NEEDED bswap_ehdr (interp_elf_ex); -#endif /* First of all, some simple consistency checks */ if ((interp_elf_ex->e_type != ET_EXEC && interp_elf_ex->e_type != ET_DYN) ||
@@ -410,12 +424,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,free (elf_phdata);return retval; } -#ifdef BSWAP_NEEDED - eppnt = elf_phdata; -for (i =0 ; i<interp_elf_ex->e_phnum; i++, eppnt++) { -bswap_phdr (eppnt); - } -#endif +bswap_phdr (elf_phdata, interp_elf_ex->e_phnum);if (interp_elf_ex->e_type ==ET_DYN ) {/* in order to avoid hardcoding the interpreter load
@@ -560,9 +569,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)for (i =0 ; i < hdr->e_shnum; i++) {if (read (fd, &sechdr,sizeof (sechdr)) !=sizeof (sechdr))return ; -#ifdef BSWAP_NEEDED -bswap_shdr (&sechdr); -#endif +bswap_shdr (&sechdr,1 );if (sechdr.sh_type ==SHT_SYMTAB ) { symtab = sechdr; lseek(fd, hdr->e_shoff
@@ -570,9 +577,7 @@ static void load_symbols(struct elfhdr *hdr, int fd)if (read (fd, &strtab,sizeof (strtab)) !=sizeof (strtab))return ; -#ifdef BSWAP_NEEDED -bswap_shdr (&strtab); -#endif +bswap_shdr (&strtab,1 ); goto found; } }
@@ -605,9 +610,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) i =0 ;while (i < nsyms) { -#ifdef BSWAP_NEEDED bswap_sym (syms + i); -#endif // Throw away entries which we do not need. if (syms[i].st_shndx == SHN_UNDEF || syms[i].st_shndx >= SHN_LORESERVE ||
@@ -679,9 +682,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, load_addr =0 ; load_bias =0 ; elf_ex = *((struct elfhdr *) bprm->buf);/* exec-header */ -#ifdef BSWAP_NEEDED bswap_ehdr (&elf_ex); -#endif /* First of all, some simple consistency checks */ if ((elf_ex.e_type != ET_EXEC && elf_ex.e_type != ET_DYN) ||
@@ -715,12 +716,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,return -errno; } -#ifdef BSWAP_NEEDED - elf_ppnt = elf_phdata; -for (i =0 ; i < elf_ex.e_phnum; i++, elf_ppnt++) { -bswap_phdr (elf_ppnt); - } -#endif +bswap_phdr (elf_phdata, elf_ex.e_phnum); + elf_ppnt = elf_phdata; elf_bss =0 ;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 16/49] bsd-user: elfload: simplify bswap a bit.
Quoted 7 lines · Warner Losh
Reduce the number of ifdefs by always calling the swapping routine, but making them empty when swapping isn't needed.
Signed-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 97 ++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 50 deletions(-)
r~
Re: [PATCH for 6.2 16/49] bsd-user: elfload: simplify bswap a bit.
In reply to Warner Loshbsd-user/elfload.c static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, · line 389
Quoted 10 lines · Warner Losh
bsd-user/elfload.c +0
-2@@ -367,9 +383,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, last_bss =0 ; error =0 ; -#ifdef BSWAP_NEEDED bswap_ehdr (interp_elf_ex); -#endif /* First of all, some simple consistency checks */ if ((interp_elf_ex->e_type != ET_EXEC && interp_elf_ex->e_type != ET_DYN) ||
Existing bug here: You should be checking, at minimum, EI_CLASS and EI_DATA before bswap.
Otherwise you don't even know you're swapping the correct structure.
I noticed this much later in the series.
r~
PATCH 17/49 bsd-user: assume pthreads and support of __thread
In reply to Warner LoshAll compilers for some time have supported this. Follow linux-user and eliminate the #define THREAD and unconditionally insert __thread where needed.
--- bsd-user/main.c | 2 +- bsd-user/qemu.h | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-)
bsd-user/main.c +1 -1
@@ -309,7 +309,7 @@ static void usage(void)exit (1 ); } -THREAD CPUState *thread_cpu; +__threadCPUState *thread_cpu;bool qemu_cpu_is_self (CPUState *cpu) {
bsd-user/qemu.h +1 -9
@@ -40,12 +40,6 @@ extern enum BSDType bsd_type;#include "target_syscall.h" #include "exec/gdbstub.h" -#if defined(CONFIG_USE_NPTL ) -#define THREAD __thread -#else -#define THREAD -#endif -/* * This struct is used to hold certain information about the image. Basically, * it replicates in user space what would be certain task_struct fields in the
@@ -155,7 +149,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6); void gemu_log(const char *fmt, ...) GCC_FMT_ATTR(1, 2); -extern THREAD CPUState *thread_cpu; +extern __threadCPUState *thread_cpu;void cpu_loop (CPUArchState *env);char *target_strerror (int err);int get_osversion (void );
@@ -422,8 +416,6 @@ static inline void *lock_user_string(abi_ulong guest_addr)#define unlock_user_struct (host_ptr, guest_addr, copy) \ unlock_user(host_ptr, guest_addr, (copy) ? sizeof(*host_ptr) : 0) -#if defined(CONFIG_USE_NPTL )#include <pthread.h> -#endif #endif /* QEMU_H */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 17/49] bsd-user: assume pthreads and support of __thread
Quoted 9 lines · Warner Losh
All compilers for some time have supported this. Follow linux-user and eliminate the #define THREAD and unconditionally insert
__threadwhere needed.Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 2 +- bsd-user/qemu.h | 10 +--------- 2 files changed, 2 insertions(+), 10 deletions(-)
r~
PATCH 18/49 bsd-user: add host-os.h
In reply to Warner LoshHost OS specific bits for this implementation go in this file.
--- bsd-user/freebsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/netbsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/openbsd/host-os.h | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 bsd-user/freebsd/host-os.h create mode 100644 bsd-user/netbsd/host-os.h create mode 100644 bsd-user/openbsd/host-os.h
bsd-user/freebsd/host-os.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* FreeBSD host dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __HOST_OS_H_ +#define __HOST_OS_H_ + +#endif /*!__HOST_OS_H_ */
bsd-user/netbsd/host-os.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* NetBSD host dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __HOST_OS_H_ +#define __HOST_OS_H_ + +#endif /*!__HOST_OS_H_ */
bsd-user/openbsd/host-os.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* OpenBSD host dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __HOST_OS_H_ +#define __HOST_OS_H_ + +#endif /*!__HOST_OS_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 18/49] bsd-user: add host-os.h
Quoted 4 lines · Warner Losh
Host OS specific bits for this implementation go in this file.
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>
Quoted 8 lines
--- bsd-user/freebsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/netbsd/host-os.h | 23 +++++++++++++++++++++++ bsd-user/openbsd/host-os.h | 23 +++++++++++++++++++++++ 3 files changed, 69 insertions(+)create mode 100644
bsd-user/freebsd/host-os.h
create mode 100644bsd-user/netbsd/host-os.h
create mode 100644bsd-user/openbsd/host-os.h
r~
PATCH 19/49 bsd-user: Include host-os.h from main
In reply to Warner LoshInclude host-os.h from main.c to pick up the default OS to emulate. Set that default in main().
--- bsd-user/freebsd/host-os.h | 2 ++ bsd-user/main.c | 4 +++- bsd-user/netbsd/host-os.h | 2 ++ bsd-user/openbsd/host-os.h | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-)
bsd-user/freebsd/host-os.h +2 -0
@@ -20,4 +20,6 @@#ifndef __HOST_OS_H_#define __HOST_OS_H_ +#define HOST_DEFAULT_BSD_TYPE target_freebsd +#endif /*!__HOST_OS_H_ */
bsd-user/main.c +3 -1
@@ -41,6 +41,8 @@#include "exec/log.h" #include "trace/control.h" +#include "host-os.h" +int singlestep;unsigned long mmap_min_addr;uintptr_t guest_base;
@@ -352,7 +354,7 @@ int main(int argc, char **argv)const char *gdbstub =NULL ;char **target_environ, **wrk;envlist_t *envlist =NULL ; - bsd_type = target_openbsd; + bsd_type =HOST_DEFAULT_BSD_TYPE ;if (argc <=1 ) {usage ();
bsd-user/netbsd/host-os.h +2 -0
@@ -20,4 +20,6 @@#ifndef __HOST_OS_H_#define __HOST_OS_H_ +#define HOST_DEFAULT_BSD_TYPE target_netbsd +#endif /*!__HOST_OS_H_ */
bsd-user/openbsd/host-os.h +2 -0
@@ -20,4 +20,6 @@#ifndef __HOST_OS_H_#define __HOST_OS_H_ +#define HOST_DEFAULT_BSD_TYPE target_openbsd +#endif /*!__HOST_OS_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 19/49] bsd-user: Include host-os.h from main
Quoted 11 lines · Warner Losh
Include
host-os.hfrommain.cto pick up the default OS to emulate. Set that default inmain().Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/freebsd/host-os.h | 2 ++ bsd-user/main.c | 4 +++- bsd-user/netbsd/host-os.h | 2 ++ bsd-user/openbsd/host-os.h | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-)
r~
PATCH 20/49 bsd-user: save the path the qemu emulator
In reply to Warner LoshSave the path to the qemu emulator. This will be used later when we have a more complete implementation of exec.
--- bsd-user/main.c | 21 +++++++++++++++++++++ bsd-user/qemu.h | 1 + 2 files changed, 22 insertions(+)
bsd-user/main.c +21 -0
@@ -43,6 +43,8 @@#include "host-os.h" +#include <sys/sysctl.h> +int singlestep;unsigned long mmap_min_addr;uintptr_t guest_base;
@@ -52,6 +54,7 @@ unsigned long reserved_va;static const char *interp_prefix =CONFIG_QEMU_INTERP_PREFIX ;const char *qemu_uname_release;enum BSDType bsd_type; +char qemu_proc_pathname[PATH_MAX ];/* full path to exeutable */ /* * XXX: on x86 MAP_GROWSDOWN only works if ESP <= address + 32, so
@@ -336,6 +339,22 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =NULL ; } +static void save_proc_pathname (char *argv0) +{ +int mib[4 ]; +size_t len; + + mib[0 ] =CTL_KERN ; + mib[1 ] =KERN_PROC ; + mib[2 ] =KERN_PROC_PATHNAME ; + mib[3 ] =-1 ; + + len =PATH_MAX ; +if (sysctl (mib,4 , qemu_proc_pathname, &len,NULL ,0 )) { +perror ("sysctl" ); + } +} +int main (int argc,char **argv) {const char *filename;
@@ -360,6 +379,8 @@ int main(int argc, char **argv)usage (); } +save_proc_pathname (argv[0 ]); +error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();
bsd-user/qemu.h +1 -0
@@ -207,6 +207,7 @@ void mmap_fork_start(void);void mmap_fork_end (int child);/* main.c */ +extern char qemu_proc_pathname[];extern unsigned long x86_stack_size;/* user access */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 20/49] bsd-user: save the path the qemu emulator
Quoted 9 lines · Warner Losh
Save the path to the qemu emulator. This will be used later when we have a more complete implementation of exec.
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/main.c | 21 +++++++++++++++++++++ bsd-user/qemu.h | 1 + 2 files changed, 22 insertions(+)
Quoted 1 line
+char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */
...
Quoted 1 line
+ len =
PATH_MAX;
Maybe better with sizeof?
r~
Re: [PATCH for 6.2 20/49] bsd-user: save the path the qemu emulator
Quoted 11 lines · Richard Henderson
Quoted 9 lines · Warner Losh
Save the path to the qemu emulator. This will be used later when we have a more complete implementation of exec.
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/main.c | 21 +++++++++++++++++++++ bsd-user/qemu.h | 1 + 2 files changed, 22 insertions(+)
Quoted 8 lines
Quoted 1 line
+char qemu_proc_pathname[PATH_MAX]; /* full path to exeutable */
...
Quoted 1 line
+ len =
PATH_MAX;Maybe better with sizeof?
It is. Thanks! Will make the change.
Warner
PATCH 21/49 bsd-user: start to move target CPU functions to target_arch*
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Move the CPU functons into target_arch_cpu.c that are unique to each CPU. These are defined in target_arch.h.
--- bsd-user/i386/target_arch.h | 31 +++++++++++++ bsd-user/i386/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ bsd-user/main.c | 12 ----- bsd-user/x86_64/target_arch.h | 31 +++++++++++++ bsd-user/x86_64/target_arch_cpu.c | 75 +++++++++++++++++++++++++++++++ meson.build | 8 +++- 6 files changed, 218 insertions(+), 14 deletions(-) create mode 100644 bsd-user/i386/target_arch.h create mode 100644 bsd-user/i386/target_arch_cpu.c create mode 100644 bsd-user/x86_64/target_arch.h create mode 100644 bsd-user/x86_64/target_arch_cpu.c
bsd-user/i386/target_arch.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Intel x86 specific prototypes for bsd-user +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_ARCH_H_ +#define _TARGET_ARCH_H_ + +/* target_arch_cpu.c */ +void bsd_i386_write_dt (void *ptr,unsigned long addr,unsigned long limit, +int flags); +void bsd_i386_set_idt (int n,unsigned int dpl); +void bsd_i386_set_idt_base (uint64_t base); + +#define target_cpu_set_tls (env, newtls) + +#endif /* ! _TARGET_ARCH_H_ */
bsd-user/i386/target_arch_cpu.c new file +75 -0
75 lines not on this page · raw message
bsd-user/main.c +0 -12
@@ -72,13 +72,6 @@ void gemu_log(const char *fmt, ...)va_end (ap); } -#if defined(TARGET_I386 ) -int cpu_get_pic_interrupt (CPUX86State *env) -{ -return -1 ; -} -#endif -void fork_start (void ) { }
@@ -94,11 +87,6 @@ void fork_end(int child)/***********************************************************/ /* CPUX86 core interface */ -uint64_t cpu_get_tsc (CPUX86State *env) -{ -return cpu_get_host_ticks (); -} -static void write_dt (void *ptr,unsigned long addr,unsigned long limit,int flags) {
bsd-user/x86_64/target_arch.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Intel x86_64 specific prototypes for bsd-user +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_ARCH_H_ +#define _TARGET_ARCH_H_ + +/* target_arch_cpu.c */ +void bsd_x86_64_write_dt (void *ptr,unsigned long addr,unsigned long limit, +int flags); +void bsd_x86_64_set_idt (int n,unsigned int dpl); +void bsd_x86_64_set_idt_base (uint64_t base); + +#define target_cpu_set_tls (env, newtls) + +#endif /* !_TARGET_ARCH_H_ */
bsd-user/x86_64/target_arch_cpu.c new file +75 -0
75 lines not on this page · raw message
meson.build +6 -2
@@ -2560,9 +2560,13 @@ foreach target : target_dirs if 'CONFIG_LINUX_USER' in config_target base_dir = 'linux-user' target_inc += include_directories('linux-user/host/' / config_host['ARCH']) - else + endif + if 'CONFIG_BSD_USER' in config_target base_dir = 'bsd-user' - target_inc += include_directories('bsd-user/freebsd') + target_inc += include_directories('bsd-user/' / targetos) +# target_inc += include_directories('bsd-user/host/' / config_host['ARCH']) + dir = base_dir / abi + arch_srcs += files(dir / 'target_arch_cpu.c') endif target_inc += include_directories( base_dir,
Signature · 1 line
2.32.0
PATCH 22/49 bsd-user: Move per-cpu code into target_arch_cpu.h
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Move cpu_loop() into target_cpu_loop(), and put that in target_arch_cpu.h for each architecture.
--- bsd-user/i386/target_arch_cpu.c | 1 + bsd-user/i386/target_arch_cpu.h | 306 ++++++++++++++++++++++++++++ bsd-user/main.c | 309 ++-------------------------- bsd-user/x86_64/target_arch_cpu.c | 1 + bsd-user/x86_64/target_arch_cpu.h | 328 ++++++++++++++++++++++++++++++ 5 files changed, 651 insertions(+), 294 deletions(-) create mode 100644 bsd-user/i386/target_arch_cpu.h create mode 100644 bsd-user/x86_64/target_arch_cpu.h
bsd-user/i386/target_arch_cpu.c +1 -0
@@ -1,6 +1,7 @@/* * i386 cpu related code * +* Copyright (c) 2013 Stacey Son <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
bsd-user/i386/target_arch_cpu.h new file +306 -0
306 lines not on this page · raw message
bsd-user/main.c +15 -294
340 lines not on this page · raw message
bsd-user/x86_64/target_arch_cpu.c +1 -0
@@ -1,6 +1,7 @@/* * x86_64 cpu related code * +* Copyright (c) 2013 Stacey Son <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
bsd-user/x86_64/target_arch_cpu.h new file +328 -0
328 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 22/49] bsd-user: Move per-cpu code into target_arch_cpu.h
bsd-user/i386/target_arch_cpu.c line 7
Quoted 12 lines · Warner Losh
bsd-user/i386/target_arch_cpu.c +1
-0@@ -1,6 +1,7 @@/* * i386 cpu related code * +* Copyright (c) 2013 Stacey Son <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by
Should be in previous.
Quoted 255 lines
bsd-user/i386/target_arch_cpu.c +255
-0+static inline void target_cpu_init (CPUX86State *env, +struct target_pt_regs *regs) +{ +uint64_t *gdt_table; + + env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; + env->hflags |=HF_PE_MASK |HF_CPL_MASK ; +if (env->features[FEAT_1_EDX ] &CPUID_SSE ) { + env->cr[4 ] |=CR4_OSFXSR_MASK ; + env->hflags |=HF_OSFXSR_MASK ; + } + +/* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |=IF_MASK ; + +/* register setup */ + env->regs[R_EAX ] = regs->eax; + env->regs[R_EBX ] = regs->ebx; + env->regs[R_ECX ] = regs->ecx; + env->regs[R_EDX ] = regs->edx; + env->regs[R_ESI ] = regs->esi; + env->regs[R_EDI ] = regs->edi; + env->regs[R_EBP ] = regs->ebp; + env->regs[R_ESP ] = regs->esp; + env->eip = regs->eip; + +/* interrupt setup */ + env->idt.limit =255 ; + + env->idt.base =target_mmap (0 ,sizeof (uint64_t ) * (env->idt.limit +1 ), +PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); +bsd_i386_set_idt_base (env->idt.base); +bsd_i386_set_idt (0 ,0 ); +bsd_i386_set_idt (1 ,0 ); +bsd_i386_set_idt (2 ,0 ); +bsd_i386_set_idt (3 ,3 ); +bsd_i386_set_idt (4 ,3 ); +bsd_i386_set_idt (5 ,0 ); +bsd_i386_set_idt (6 ,0 ); +bsd_i386_set_idt (7 ,0 ); +bsd_i386_set_idt (8 ,0 ); +bsd_i386_set_idt (9 ,0 ); +bsd_i386_set_idt (10 ,0 ); +bsd_i386_set_idt (11 ,0 ); +bsd_i386_set_idt (12 ,0 ); +bsd_i386_set_idt (13 ,0 ); +bsd_i386_set_idt (14 ,0 ); +bsd_i386_set_idt (15 ,0 ); +bsd_i386_set_idt (16 ,0 ); +bsd_i386_set_idt (17 ,0 ); +bsd_i386_set_idt (18 ,0 ); +bsd_i386_set_idt (19 ,0 ); +bsd_i386_set_idt (0x80 ,3 ); + +/* segment setup */ + env->gdt.base =target_mmap (0 ,sizeof (uint64_t ) *TARGET_GDT_ENTRIES , +PROT_READ |PROT_WRITE ,MAP_ANONYMOUS |MAP_PRIVATE ,-1 ,0 ); + env->gdt.limit =sizeof (uint64_t ) *TARGET_GDT_ENTRIES -1 ; + gdt_table =g2h_untagged (env->gdt.base); + +bsd_i386_write_dt (&gdt_table[__USER_CS >>3 ],0 ,0xfffff , +DESC_G_MASK |DESC_B_MASK |DESC_P_MASK |DESC_S_MASK | + (3 <<DESC_DPL_SHIFT ) | (0xa <<DESC_TYPE_SHIFT )); + +bsd_i386_write_dt (&gdt_table[__USER_DS >>3 ],0 ,0xfffff , +DESC_G_MASK |DESC_B_MASK |DESC_P_MASK |DESC_S_MASK | + (3 <<DESC_DPL_SHIFT ) | (0x2 <<DESC_TYPE_SHIFT )); + +cpu_x86_load_seg (env,R_CS , __USER_CS); +cpu_x86_load_seg (env,R_SS , __USER_DS); +cpu_x86_load_seg (env,R_DS , __USER_DS); +cpu_x86_load_seg (env,R_ES , __USER_DS); +cpu_x86_load_seg (env,R_FS , __USER_DS); +cpu_x86_load_seg (env,R_GS , __USER_DS); +/* This hack makes Wine work... */ + env->segs[R_FS ].selector =0 ; +} + +static inline void target_cpu_loop (CPUX86State *env) +{ +CPUState *cs =env_cpu (env); +int trapnr; +abi_ulong pc; +/* target_siginfo_t info; */ + +for (;;) { +cpu_exec_start (cs); + trapnr =cpu_exec (cs); +cpu_exec_end (cs); +process_queued_cpu_work (cs); + +switch (trapnr) { +case 0x80 : +/* syscall from int $0x80 */ +if (bsd_type == target_freebsd) { +abi_ulong params = (abi_ulong ) env->regs[R_ESP ] + +sizeof (int32_t ); +int32_t syscall_nr = env->regs[R_EAX ]; +int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + +if (syscall_nr == TARGET_FREEBSD_NR_syscall) { +get_user_s32 (syscall_nr, params); + params +=sizeof (int32_t ); + }else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { +get_user_s32 (syscall_nr, params); + params +=sizeof (int64_t ); + } +get_user_s32 (arg1, params); + params +=sizeof (int32_t ); +get_user_s32 (arg2, params); + params +=sizeof (int32_t ); +get_user_s32 (arg3, params); + params +=sizeof (int32_t ); +get_user_s32 (arg4, params); + params +=sizeof (int32_t ); +get_user_s32 (arg5, params); + params +=sizeof (int32_t ); +get_user_s32 (arg6, params); + params +=sizeof (int32_t ); +get_user_s32 (arg7, params); + params +=sizeof (int32_t ); +get_user_s32 (arg8, params); + env->regs[R_EAX ] =do_freebsd_syscall (env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + }else {/* if (bsd_type == target_openbsd) */ + env->regs[R_EAX ] =do_openbsd_syscall (env, + env->regs[R_EAX ], + env->regs[R_EBX ], + env->regs[R_ECX ], + env->regs[R_EDX ], + env->regs[R_ESI ], + env->regs[R_EDI ], + env->regs[R_EBP ]); + } +if (((abi_ulong )env->regs[R_EAX ]) >= (abi_ulong)(-515 )) { + env->regs[R_EAX ] = -env->regs[R_EAX ]; + env->eflags |=CC_C ; + }else { + env->eflags &= ~CC_C ; + } +break ; + +#if 0 +case EXCP0B_NOSEG : +case EXCP0C_STACK : + info.si_signo =TARGET_SIGBUS ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); +break ; + +case EXCP0D_GPF : +/* XXX: potential problem if ABI32 */ +if (env->eflags &VM_MASK ) { +handle_vm86_fault (env); + }else { + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP0E_PAGE : + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; +if (!(env->error_code &1 )) { + info.si_code =TARGET_SEGV_MAPERR ; + }else { + info.si_code =TARGET_SEGV_ACCERR ; + } + info._sifields._sigfault._addr = env->cr[2 ]; +queue_signal (env, info.si_signo, &info); +break ; + +case EXCP00_DIVZ : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { +/* division by zero */ + info.si_signo =TARGET_SIGFPE ; + info.si_errno =0 ; + info.si_code =TARGET_FPE_INTDIV ; + info._sifields._sigfault._addr = env->eip; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP01_DB : +case EXCP03_INT3 : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; +if (trapnr ==EXCP01_DB ) { + info.si_code =TARGET_TRAP_BRKPT ; + info._sifields._sigfault._addr = env->eip; + }else { + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; + } +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP04_INTO : +case EXCP05_BOUND : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP06_ILLOP : + info.si_signo =TARGET_SIGILL ; + info.si_errno =0 ; + info.si_code =TARGET_ILL_ILLOPN ; + info._sifields._sigfault._addr = env->eip; +queue_signal (env, info.si_signo, &info); +break ; +#endif +case EXCP_INTERRUPT : +/* just indicate that signals should be handled asap */ +break ; +#if 0 +case EXCP_DEBUG : + { + + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; + info.si_code =TARGET_TRAP_BRKPT ; +queue_signal (env, info.si_signo, &info); + } +break ; +#endif + +case EXCP_ATOMIC : +cpu_exec_step_atomic (cs); +break ;
bsd-user/i386/target_arch_cpu.c
Quoted 10 lines
bsd-user/i386/target_arch_cpu.c +10
-0+ +default : + pc = env->segs[R_CS ].base + env->eip; +fprintf (stderr,"qemu: 0x%08lx: unhandled CPU exception 0x%x - " +"aborting\n" , (long )pc, trapnr); +abort (); + } +process_pending_signals (env); + } +}
Those are some really big functions to want to inline. Any reason for that? At first glance they could live just fine in target_arch_cpu.c.
r~
Re: [PATCH for 6.2 22/49] bsd-user: Move per-cpu code into target_arch_cpu.h
Quoted 14 lines · Richard Henderson
Review
Quoted 1 line · Warner Losh
(quoted diff) +0
-0
b/bsd-user/i386/target_arch_cpu.cbsd-user/i386/target_arch_cpu.c line 6
Quoted 10 lines
index
7f2f755a11..71998e5ba5100644bsd-user/i386/target_arch_cpu.c +1
-0@@ -1,6 +1,7 @@/* * i386 cpu related code * +* Copyright (c) 2013 Stacey Son <[email protected]> * * This program is free software; you can redistribute it and/or modify
Quoted 5 lines
bsd-user/i386/target_arch_cpu.c line 7
Quoted 1 line
bsd-user/i386/target_arch_cpu.c +0
-0* it under the terms of the GNU General Public License as published by
Should be in previous.
Gotcha.
Quoted 269 lines
Quoted 20 lines
bsd-user/i386/target_arch_cpu.c +20
-0+static inline void target_cpu_init (CPUX86State *env, +struct target_pt_regs *regs) +{ +uint64_t *gdt_table; + + env->cr[0 ] =CR0_PG_MASK |CR0_WP_MASK |CR0_PE_MASK ; + env->hflags |=HF_PE_MASK |HF_CPL_MASK ; +if (env->features[FEAT_1_EDX ] &CPUID_SSE ) { + env->cr[4 ] |=CR4_OSFXSR_MASK ; + env->hflags |=HF_OSFXSR_MASK ; + } + +/* flags setup : we activate the IRQs by default as in user mode */ + env->eflags |=IF_MASK ; + +/* register setup */ + env->regs[R_EAX ] = regs->eax; + env->regs[R_EBX ] = regs->ebx; + env->regs[R_ECX ] = regs->ecx; + env->regs[R_EDX ] = regs->edx;bsd-user/i386/target_arch_cpu.c
Quoted 10 lines
bsd-user/i386/target_arch_cpu.c +10
-0+ env->regs[R_ESI ] = regs->esi; + env->regs[R_EDI ] = regs->edi; + env->regs[R_EBP ] = regs->ebp; + env->regs[R_ESP ] = regs->esp; + env->eip = regs->eip; + +/* interrupt setup */ + env->idt.limit =255 ; + + env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit +1),
Quoted 16 lines
bsd-user/i386/target_arch_cpu.c +16
-0+ PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); +bsd_i386_set_idt_base (env->idt.base); +bsd_i386_set_idt (0 ,0 ); +bsd_i386_set_idt (1 ,0 ); +bsd_i386_set_idt (2 ,0 ); +bsd_i386_set_idt (3 ,3 ); +bsd_i386_set_idt (4 ,3 ); +bsd_i386_set_idt (5 ,0 ); +bsd_i386_set_idt (6 ,0 ); +bsd_i386_set_idt (7 ,0 ); +bsd_i386_set_idt (8 ,0 ); +bsd_i386_set_idt (9 ,0 ); +bsd_i386_set_idt (10 ,0 ); +bsd_i386_set_idt (11 ,0 ); +bsd_i386_set_idt (12 ,0 ); +bsd_i386_set_idt (13 ,0 );bsd-user/i386/target_arch_cpu.c
Quoted 10 lines
bsd-user/i386/target_arch_cpu.c +10
-0+bsd_i386_set_idt (14 ,0 ); +bsd_i386_set_idt (15 ,0 ); +bsd_i386_set_idt (16 ,0 ); +bsd_i386_set_idt (17 ,0 ); +bsd_i386_set_idt (18 ,0 ); +bsd_i386_set_idt (19 ,0 ); +bsd_i386_set_idt (0x80 ,3 ); + +/* segment setup */ + env->gdt.base = target_mmap(0, sizeof(uint64_t) *
TARGET_GDT_ENTRIES,Quoted 193 lines
bsd-user/i386/target_arch_cpu.c +193
-0+ PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + env->gdt.limit =sizeof (uint64_t ) *TARGET_GDT_ENTRIES -1 ; + gdt_table =g2h_untagged (env->gdt.base); + +bsd_i386_write_dt (&gdt_table[__USER_CS >>3 ],0 ,0xfffff , +DESC_G_MASK |DESC_B_MASK |DESC_P_MASK |DESC_S_MASK | + (3 <<DESC_DPL_SHIFT ) | (0xa <<DESC_TYPE_SHIFT )); + +bsd_i386_write_dt (&gdt_table[__USER_DS >>3 ],0 ,0xfffff , +DESC_G_MASK |DESC_B_MASK |DESC_P_MASK |DESC_S_MASK | + (3 <<DESC_DPL_SHIFT ) | (0x2 <<DESC_TYPE_SHIFT )); + +cpu_x86_load_seg (env,R_CS , __USER_CS); +cpu_x86_load_seg (env,R_SS , __USER_DS); +cpu_x86_load_seg (env,R_DS , __USER_DS); +cpu_x86_load_seg (env,R_ES , __USER_DS); +cpu_x86_load_seg (env,R_FS , __USER_DS); +cpu_x86_load_seg (env,R_GS , __USER_DS); +/* This hack makes Wine work... */ + env->segs[R_FS ].selector =0 ; +} + +static inline void target_cpu_loop (CPUX86State *env) +{ +CPUState *cs =env_cpu (env); +int trapnr; +abi_ulong pc; +/* target_siginfo_t info; */ + +for (;;) { +cpu_exec_start (cs); + trapnr =cpu_exec (cs); +cpu_exec_end (cs); +process_queued_cpu_work (cs); + +switch (trapnr) { +case 0x80 : +/* syscall from int $0x80 */ +if (bsd_type == target_freebsd) { +abi_ulong params = (abi_ulong ) env->regs[R_ESP ] + +sizeof (int32_t ); +int32_t syscall_nr = env->regs[R_EAX ]; +int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; + +if (syscall_nr == TARGET_FREEBSD_NR_syscall) { +get_user_s32 (syscall_nr, params); + params +=sizeof (int32_t ); + }else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { +get_user_s32 (syscall_nr, params); + params +=sizeof (int64_t ); + } +get_user_s32 (arg1, params); + params +=sizeof (int32_t ); +get_user_s32 (arg2, params); + params +=sizeof (int32_t ); +get_user_s32 (arg3, params); + params +=sizeof (int32_t ); +get_user_s32 (arg4, params); + params +=sizeof (int32_t ); +get_user_s32 (arg5, params); + params +=sizeof (int32_t ); +get_user_s32 (arg6, params); + params +=sizeof (int32_t ); +get_user_s32 (arg7, params); + params +=sizeof (int32_t ); +get_user_s32 (arg8, params); + env->regs[R_EAX ] =do_freebsd_syscall (env, + syscall_nr, + arg1, + arg2, + arg3, + arg4, + arg5, + arg6, + arg7, + arg8); + }else {/* if (bsd_type == target_openbsd) */ + env->regs[R_EAX ] =do_openbsd_syscall (env, + env->regs[R_EAX ], + env->regs[R_EBX ], + env->regs[R_ECX ], + env->regs[R_EDX ], + env->regs[R_ESI ], + env->regs[R_EDI ], + env->regs[R_EBP ]); + } +if (((abi_ulong )env->regs[R_EAX ]) >= (abi_ulong)(-515 )) { + env->regs[R_EAX ] = -env->regs[R_EAX ]; + env->eflags |=CC_C ; + }else { + env->eflags &= ~CC_C ; + } +break ; + +#if 0 +case EXCP0B_NOSEG : +case EXCP0C_STACK : + info.si_signo =TARGET_SIGBUS ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); +break ; + +case EXCP0D_GPF : +/* XXX: potential problem if ABI32 */ +if (env->eflags &VM_MASK ) { +handle_vm86_fault (env); + }else { + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP0E_PAGE : + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; +if (!(env->error_code &1 )) { + info.si_code =TARGET_SEGV_MAPERR ; + }else { + info.si_code =TARGET_SEGV_ACCERR ; + } + info._sifields._sigfault._addr = env->cr[2 ]; +queue_signal (env, info.si_signo, &info); +break ; + +case EXCP00_DIVZ : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { +/* division by zero */ + info.si_signo =TARGET_SIGFPE ; + info.si_errno =0 ; + info.si_code =TARGET_FPE_INTDIV ; + info._sifields._sigfault._addr = env->eip; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP01_DB : +case EXCP03_INT3 : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; +if (trapnr ==EXCP01_DB ) { + info.si_code =TARGET_TRAP_BRKPT ; + info._sifields._sigfault._addr = env->eip; + }else { + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; + } +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP04_INTO : +case EXCP05_BOUND : +if (env->eflags &VM_MASK ) { +handle_vm86_trap (env, trapnr); + }else { + info.si_signo =TARGET_SIGSEGV ; + info.si_errno =0 ; + info.si_code =TARGET_SI_KERNEL ; + info._sifields._sigfault._addr =0 ; +queue_signal (env, info.si_signo, &info); + } +break ; + +case EXCP06_ILLOP : + info.si_signo =TARGET_SIGILL ; + info.si_errno =0 ; + info.si_code =TARGET_ILL_ILLOPN ; + info._sifields._sigfault._addr = env->eip; +queue_signal (env, info.si_signo, &info); +break ; +#endif +case EXCP_INTERRUPT : +/* just indicate that signals should be handled asap */ +break ; +#if 0 +case EXCP_DEBUG : + { + + info.si_signo =TARGET_SIGTRAP ; + info.si_errno =0 ; + info.si_code =TARGET_TRAP_BRKPT ; +queue_signal (env, info.si_signo, &info); + }bsd-user/i386/target_arch_cpu.c
Quoted 10 lines
bsd-user/i386/target_arch_cpu.c +10
-0+break ; +#endif + +case EXCP_ATOMIC : +cpu_exec_step_atomic (cs); +break ; + +default : + pc = env->segs[R_CS ].base + env->eip; + fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception0x%x - "
bsd-user/i386/target_arch_cpu.c
Quoted 6 lines
bsd-user/i386/target_arch_cpu.c +6
-0+ "aborting\n", (long)pc, trapnr); +abort (); + } +process_pending_signals (env); + } +}
Quoted 4 lines
Those are some really big functions to want to inline. Any reason for that? At first
glance they could live just fine intarget_arch_cpu.c.
Mostly because that's how Stacey wrote it and we have half a dozen implementations
already. I'll see how hard it would be to transition to this structure. I worried about
this being so different than linux-user, but at the same time I worried about regressions
that may be introduced in the effort since our testing story isn't what I'd like. I'm also
a bit worried because we have two branches: the tip that we're trying to release from
and this effort which needs any changes also merged to that tip branch.
Having said that, I'll see what I can do.
Warner
Re: [PATCH for 6.2 22/49] bsd-user: Move per-cpu code into target_arch_cpu.h
Quoted 293 lines · Warner Losh
On Sat, Aug 7, 2021 at 11:35 PM Richard Henderson <[email protected] <mailto:[email protected]>> wrote:
On 8/7/21 11:42 AM, Warner Losh wrote:
> diff --gita/bsd-user/i386/target_arch_cpu.cb/bsd-user/i386/target_arch_cpu.c> index7f2f755a11..71998e5ba5100644
> ---a/bsd-user/i386/target_arch_cpu.c
> +++b/bsd-user/i386/target_arch_cpu.c
> @@ -1,6 +1,7 @@
> /*
> * i386 cpu related code
> *
> + * Copyright (c) 2013 Stacey Son <[email protected]>
> *
> * This program is free software; you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published byShould be in previous.
Gotcha.
> +static inline void target_cpu_init(CPUX86State *env, > + struct target_pt_regs *regs) > +{ > + uint64_t *gdt_table; > + > + env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; > + env->hflags |= HF_PE_MASK | HF_CPL_MASK; > + if (env->features[FEAT_1_EDX] & CPUID_SSE) { > + env->cr[4] |= CR4_OSFXSR_MASK; > + env->hflags |= HF_OSFXSR_MASK; > + } > + > + /* flags setup : we activate the IRQs by default as in user mode */ > + env->eflags |= IF_MASK; > + > + /* register setup */ > + env->regs[R_EAX] = regs->eax; > + env->regs[R_EBX] = regs->ebx; > + env->regs[R_ECX] = regs->ecx; > + env->regs[R_EDX] = regs->edx; > + env->regs[R_ESI] = regs->esi; > + env->regs[R_EDI] = regs->edi; > + env->regs[R_EBP] = regs->ebp; > + env->regs[R_ESP] = regs->esp; > + env->eip = regs->eip; > + > + /* interrupt setup */ > + env->idt.limit = 255; > + > + env->idt.base = target_mmap(0, sizeof(uint64_t) * (env->idt.limit + 1), > + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > + bsd_i386_set_idt_base(env->idt.base); > + bsd_i386_set_idt(0, 0); > + bsd_i386_set_idt(1, 0); > + bsd_i386_set_idt(2, 0); > + bsd_i386_set_idt(3, 3); > + bsd_i386_set_idt(4, 3); > + bsd_i386_set_idt(5, 0); > + bsd_i386_set_idt(6, 0); > + bsd_i386_set_idt(7, 0); > + bsd_i386_set_idt(8, 0); > + bsd_i386_set_idt(9, 0); > + bsd_i386_set_idt(10, 0); > + bsd_i386_set_idt(11, 0); > + bsd_i386_set_idt(12, 0); > + bsd_i386_set_idt(13, 0); > + bsd_i386_set_idt(14, 0); > + bsd_i386_set_idt(15, 0); > + bsd_i386_set_idt(16, 0); > + bsd_i386_set_idt(17, 0); > + bsd_i386_set_idt(18, 0); > + bsd_i386_set_idt(19, 0); > + bsd_i386_set_idt(0x80, 3); > + > + /* segment setup */ > + env->gdt.base = target_mmap(0, sizeof(uint64_t) * TARGET_GDT_ENTRIES, > + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > + env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; > + gdt_table = g2h_untagged(env->gdt.base); > + > + bsd_i386_write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, > + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | > + (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); > + > + bsd_i386_write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, > + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK | > + (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); > + > + cpu_x86_load_seg(env, R_CS, __USER_CS); > + cpu_x86_load_seg(env, R_SS, __USER_DS); > + cpu_x86_load_seg(env, R_DS, __USER_DS); > + cpu_x86_load_seg(env, R_ES, __USER_DS); > + cpu_x86_load_seg(env, R_FS, __USER_DS); > + cpu_x86_load_seg(env, R_GS, __USER_DS); > + /* This hack makes Wine work... */ > + env->segs[R_FS].selector = 0; > +} > + > +static inline void target_cpu_loop(CPUX86State *env) > +{ > + CPUState *cs = env_cpu(env); > + int trapnr; > + abi_ulong pc; > + /* target_siginfo_t info; */ > + > + for (;;) { > + cpu_exec_start(cs); > + trapnr = cpu_exec(cs); > + cpu_exec_end(cs); > + process_queued_cpu_work(cs); > + > + switch (trapnr) { > + case 0x80: > + /* syscall from int $0x80 */ > + if (bsd_type == target_freebsd) { > + abi_ulong params = (abi_ulong) env->regs[R_ESP] + > + sizeof(int32_t); > + int32_t syscall_nr = env->regs[R_EAX]; > + int32_t arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8; > + > + if (syscall_nr == TARGET_FREEBSD_NR_syscall) { > + get_user_s32(syscall_nr, params); > + params += sizeof(int32_t); > + } else if (syscall_nr == TARGET_FREEBSD_NR___syscall) { > + get_user_s32(syscall_nr, params); > + params += sizeof(int64_t); > + } > + get_user_s32(arg1, params); > + params += sizeof(int32_t); > + get_user_s32(arg2, params); > + params += sizeof(int32_t); > + get_user_s32(arg3, params); > + params += sizeof(int32_t); > + get_user_s32(arg4, params); > + params += sizeof(int32_t); > + get_user_s32(arg5, params); > + params += sizeof(int32_t); > + get_user_s32(arg6, params); > + params += sizeof(int32_t); > + get_user_s32(arg7, params); > + params += sizeof(int32_t); > + get_user_s32(arg8, params); > + env->regs[R_EAX] = do_freebsd_syscall(env, > + syscall_nr, > + arg1, > + arg2, > + arg3, > + arg4, > + arg5, > + arg6, > + arg7, > + arg8); > + } else { /* if (bsd_type == target_openbsd) */ > + env->regs[R_EAX] = do_openbsd_syscall(env, > + env->regs[R_EAX], > + env->regs[R_EBX], > + env->regs[R_ECX], > + env->regs[R_EDX], > + env->regs[R_ESI], > + env->regs[R_EDI], > + env->regs[R_EBP]); > + } > + if (((abi_ulong)env->regs[R_EAX]) >= (abi_ulong)(-515)) { > + env->regs[R_EAX] = -env->regs[R_EAX]; > + env->eflags |= CC_C; > + } else { > + env->eflags &= ~CC_C; > + } > + break; > + > +#if 0 > + case EXCP0B_NOSEG: > + case EXCP0C_STACK: > + info.si_signo = TARGET_SIGBUS; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + break; > + > + case EXCP0D_GPF: > + /* XXX: potential problem if ABI32 */ > + if (env->eflags & VM_MASK) { > + handle_vm86_fault(env); > + } else { > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP0E_PAGE: > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + if (!(env->error_code & 1)) { > + info.si_code = TARGET_SEGV_MAPERR; > + } else { > + info.si_code = TARGET_SEGV_ACCERR; > + } > + info._sifields._sigfault._addr = env->cr[2]; > + queue_signal(env, info.si_signo, &info); > + break; > + > + case EXCP00_DIVZ: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + /* division by zero */ > + info.si_signo = TARGET_SIGFPE; > + info.si_errno = 0; > + info.si_code = TARGET_FPE_INTDIV; > + info._sifields._sigfault._addr = env->eip; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP01_DB: > + case EXCP03_INT3: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + info.si_signo = TARGET_SIGTRAP; > + info.si_errno = 0; > + if (trapnr == EXCP01_DB) { > + info.si_code = TARGET_TRAP_BRKPT; > + info._sifields._sigfault._addr = env->eip; > + } else { > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + } > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP04_INTO: > + case EXCP05_BOUND: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP06_ILLOP: > + info.si_signo = TARGET_SIGILL; > + info.si_errno = 0; > + info.si_code = TARGET_ILL_ILLOPN; > + info._sifields._sigfault._addr = env->eip; > + queue_signal(env, info.si_signo, &info); > + break; > +#endif > + case EXCP_INTERRUPT: > + /* just indicate that signals should be handled asap */ > + break; > +#if 0 > + case EXCP_DEBUG: > + { > + > + info.si_signo = TARGET_SIGTRAP; > + info.si_errno = 0; > + info.si_code = TARGET_TRAP_BRKPT; > + queue_signal(env, info.si_signo, &info); > + } > + break; > +#endif > + > + case EXCP_ATOMIC: > + cpu_exec_step_atomic(cs); > + break; > + > + default: > + pc = env->segs[R_CS].base + env->eip; > + fprintf(stderr, "qemu: 0x%08lx: unhandled CPU exception 0x%x - " > + "aborting\n", (long)pc, trapnr); > + abort(); > + } > + process_pending_signals(env); > + } > +} Those are some really big functions to want to inline. Any reason for that? At first glance they could live just fine in target_arch_cpu.c.
Quoted 8 lines
Mostly because that's how Stacey wrote it and we have half a dozen implementations already. I'll see how hard it would be to transition to this structure. I worried about this being so different than linux-user, but at the same time I worried about regressions that may be introduced in the effort since our testing story isn't what I'd like. I'm also a bit worried because we have two branches: the tip that we're trying to release from and this effort which needs any changes also merged to that tip branch.
Having said that, I'll see what I can do.
I guess I'm happy to have them in the header for now, but just add something to the to-do list once you're not juggling multiple branches.
I'll not say that linux-user is ideal either, btw. Just stuff you see doing new patch review.
r~
Re: [PATCH for 6.2 22/49] bsd-user: Move per-cpu code into target_arch_cpu.h
Quoted 330 lines · Richard Henderson
Quoted 3 lines · Warner Losh
On Sat, Aug 7, 2021 at 11:35 PM Richard Henderson <
Quoted 4 lines
<mailto:[email protected]>> wrote:
On 8/7/21 11:42 AM, Warner Losh wrote: > diff --git a/bsd-user/i386/target_arch_cpu.c
b/bsd-user/i386/target_arch_cpu.cQuoted 10 lines
> index 7f2f755a11..71998e5ba5 100644 > --- a/bsd-user/i386/target_arch_cpu.c > +++ b/bsd-user/i386/target_arch_cpu.c > @@ -1,6 +1,7 @@ > /* > * i386 cpu related code > * > + * Copyright (c) 2013 Stacey Son <[email protected]> > * > * This program is free software; you can redistribute itand/or modify
Quoted 1 line
> * it under the terms of the GNU General Public License as
published by
Quoted 6 lines
Should be in previous.
Gotcha.
Quoted 13 lines
> +static inline void target_cpu_init(CPUX86State *env, > + struct target_pt_regs *regs) > +{ > + uint64_t *gdt_table; > + > + env->cr[0] = CR0_PG_MASK | CR0_WP_MASK | CR0_PE_MASK; > + env->hflags |= HF_PE_MASK | HF_CPL_MASK; > + if (env->features[FEAT_1_EDX] & CPUID_SSE) { > + env->cr[4] |= CR4_OSFXSR_MASK; > + env->hflags |= HF_OSFXSR_MASK; > + } > + > + /* flags setup : we activate the IRQs by default as in usermode */
Quoted 9 lines
> + env->eflags |= IF_MASK; > + > + /* register setup */ > + env->regs[R_EAX] = regs->eax; > + env->regs[R_EBX] = regs->ebx; > + env->regs[R_ECX] = regs->ecx; > + env->regs[R_EDX] = regs->edx; > + env->regs[R_ESI] = regs->esi; > + env->regs[R_EDI] = regs->edi;Quoted 8 lines
> + env->regs[R_EBP] = regs->ebp; > + env->regs[R_ESP] = regs->esp; > + env->eip = regs->eip; > + > + /* interrupt setup */ > + env->idt.limit = 255; > + > + env->idt.base = target_mmap(0, sizeof(uint64_t) *(
env->idt.limit+ 1),Quoted 18 lines
> + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > + bsd_i386_set_idt_base(env->idt.base); > + bsd_i386_set_idt(0, 0); > + bsd_i386_set_idt(1, 0); > + bsd_i386_set_idt(2, 0); > + bsd_i386_set_idt(3, 3); > + bsd_i386_set_idt(4, 3); > + bsd_i386_set_idt(5, 0); > + bsd_i386_set_idt(6, 0); > + bsd_i386_set_idt(7, 0); > + bsd_i386_set_idt(8, 0); > + bsd_i386_set_idt(9, 0); > + bsd_i386_set_idt(10, 0); > + bsd_i386_set_idt(11, 0); > + bsd_i386_set_idt(12, 0); > + bsd_i386_set_idt(13, 0); > + bsd_i386_set_idt(14, 0); > + bsd_i386_set_idt(15, 0);Quoted 8 lines
> + bsd_i386_set_idt(16, 0); > + bsd_i386_set_idt(17, 0); > + bsd_i386_set_idt(18, 0); > + bsd_i386_set_idt(19, 0); > + bsd_i386_set_idt(0x80, 3); > + > + /* segment setup */ > + env->gdt.base = target_mmap(0, sizeof(uint64_t) *
TARGET_GDT_ENTRIES,Quoted 1 line
> + PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1,
0);
Quoted 5 lines
> + env->gdt.limit = sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; > + gdt_table = g2h_untagged(env->gdt.base); > + > + bsd_i386_write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, > + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
DESC_S_MASK|Quoted 4 lines
> + (3 << DESC_DPL_SHIFT) | (0xa << DESC_TYPE_SHIFT)); > + > + bsd_i386_write_dt(&gdt_table[__USER_DS >> 3], 0, 0xfffff, > + DESC_G_MASK | DESC_B_MASK | DESC_P_MASK |
DESC_S_MASK|Quoted 25 lines
> + (3 << DESC_DPL_SHIFT) | (0x2 << DESC_TYPE_SHIFT)); > + > + cpu_x86_load_seg(env, R_CS, __USER_CS); > + cpu_x86_load_seg(env, R_SS, __USER_DS); > + cpu_x86_load_seg(env, R_DS, __USER_DS); > + cpu_x86_load_seg(env, R_ES, __USER_DS); > + cpu_x86_load_seg(env, R_FS, __USER_DS); > + cpu_x86_load_seg(env, R_GS, __USER_DS); > + /* This hack makes Wine work... */ > + env->segs[R_FS].selector = 0; > +} > + > +static inline void target_cpu_loop(CPUX86State *env) > +{ > + CPUState *cs = env_cpu(env); > + int trapnr; > + abi_ulong pc; > + /* target_siginfo_t info; */ > + > + for (;;) { > + cpu_exec_start(cs); > + trapnr = cpu_exec(cs); > + cpu_exec_end(cs); > + process_queued_cpu_work(cs); > +Quoted 8 lines
> + switch (trapnr) { > + case 0x80: > + /* syscall from int $0x80 */ > + if (bsd_type == target_freebsd) { > + abi_ulong params = (abi_ulong) env->regs[R_ESP] + > + sizeof(int32_t); > + int32_t syscall_nr = env->regs[R_EAX]; > + int32_t arg1, arg2, arg3, arg4, arg5, arg6,arg7, arg8;
Quoted 5 lines
> + > + if (syscall_nr == TARGET_FREEBSD_NR_syscall) { > + get_user_s32(syscall_nr, params); > + params += sizeof(int32_t); > + } else if (syscall_nr ==
TARGET_FREEBSD_NR___syscall) {Quoted 23 lines
> + get_user_s32(syscall_nr, params); > + params += sizeof(int64_t); > + } > + get_user_s32(arg1, params); > + params += sizeof(int32_t); > + get_user_s32(arg2, params); > + params += sizeof(int32_t); > + get_user_s32(arg3, params); > + params += sizeof(int32_t); > + get_user_s32(arg4, params); > + params += sizeof(int32_t); > + get_user_s32(arg5, params); > + params += sizeof(int32_t); > + get_user_s32(arg6, params); > + params += sizeof(int32_t); > + get_user_s32(arg7, params); > + params += sizeof(int32_t); > + get_user_s32(arg8, params); > + env->regs[R_EAX] = do_freebsd_syscall(env, > + syscall_nr, > + arg1, > + arg2, > + arg3,Quoted 8 lines
> + arg4, > + arg5, > + arg6, > + arg7, > + arg8); > + } else { /* if (bsd_type == target_openbsd) */ > + env->regs[R_EAX] = do_openbsd_syscall(env, > +env->regs[R_EAX],
Quoted 1 line
> +env->regs[R_EBX],
Quoted 1 line
> +env->regs[R_ECX],
Quoted 1 line
> +env->regs[R_EDX],
Quoted 1 line
> +env->regs[R_ESI],
Quoted 1 line
> +env->regs[R_EDI],
Quoted 1 line
> +env->regs[R_EBP]);
Quoted 2 lines
> + } > + if (((abi_ulong)env->regs[R_EAX]) >=(abi_ulong)(-515)) {
Quoted 88 lines
> + env->regs[R_EAX] = -env->regs[R_EAX]; > + env->eflags |= CC_C; > + } else { > + env->eflags &= ~CC_C; > + } > + break; > + > +#if 0 > + case EXCP0B_NOSEG: > + case EXCP0C_STACK: > + info.si_signo = TARGET_SIGBUS; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + break; > + > + case EXCP0D_GPF: > + /* XXX: potential problem if ABI32 */ > + if (env->eflags & VM_MASK) { > + handle_vm86_fault(env); > + } else { > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP0E_PAGE: > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + if (!(env->error_code & 1)) { > + info.si_code = TARGET_SEGV_MAPERR; > + } else { > + info.si_code = TARGET_SEGV_ACCERR; > + } > + info._sifields._sigfault._addr = env->cr[2]; > + queue_signal(env, info.si_signo, &info); > + break; > + > + case EXCP00_DIVZ: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + /* division by zero */ > + info.si_signo = TARGET_SIGFPE; > + info.si_errno = 0; > + info.si_code = TARGET_FPE_INTDIV; > + info._sifields._sigfault._addr = env->eip; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP01_DB: > + case EXCP03_INT3: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + info.si_signo = TARGET_SIGTRAP; > + info.si_errno = 0; > + if (trapnr == EXCP01_DB) { > + info.si_code = TARGET_TRAP_BRKPT; > + info._sifields._sigfault._addr = env->eip; > + } else { > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + } > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP04_INTO: > + case EXCP05_BOUND: > + if (env->eflags & VM_MASK) { > + handle_vm86_trap(env, trapnr); > + } else { > + info.si_signo = TARGET_SIGSEGV; > + info.si_errno = 0; > + info.si_code = TARGET_SI_KERNEL; > + info._sifields._sigfault._addr = 0; > + queue_signal(env, info.si_signo, &info); > + } > + break; > + > + case EXCP06_ILLOP: > + info.si_signo = TARGET_SIGILL;Quoted 8 lines
> + info.si_errno = 0; > + info.si_code = TARGET_ILL_ILLOPN; > + info._sifields._sigfault._addr = env->eip; > + queue_signal(env, info.si_signo, &info); > + break; > +#endif > + case EXCP_INTERRUPT: > + /* just indicate that signals should be handled asap*/
Quoted 12 lines
> + break; > +#if 0 > + case EXCP_DEBUG: > + { > + > + info.si_signo = TARGET_SIGTRAP; > + info.si_errno = 0; > + info.si_code = TARGET_TRAP_BRKPT; > + queue_signal(env, info.si_signo, &info); > + } > + break; > +#endifQuoted 8 lines
> + > + case EXCP_ATOMIC: > + cpu_exec_step_atomic(cs); > + break; > + > + default: > + pc = env->segs[R_CS].base + env->eip; > + fprintf(stderr, "qemu: 0x%08lx: unhandled CPUexception 0x%x - "
Quoted 8 lines
> + "aborting\n", (long)pc, trapnr); > + abort(); > + } > + process_pending_signals(env); > + } > +} Those are some really big functions to want to inline. Any reasonfor that? At first
Quoted 4 lines
glance they could live just fine in
target_arch_cpu.c.Mostly because that's how Stacey wrote it and we have half a dozen
implementations
Quoted 1 line
already. I'll see how hard it would be to transition to this structure.
I worried about
Quoted 1 line
this being so different than linux-user, but at the same time I worried
about regressions
Quoted 1 line
that may be introduced in the effort since our testing story isn't what
I'd like. I'm also
Quoted 1 line
a bit worried because we have two branches: the tip that we're trying to
release from
Quoted 2 lines
and this effort which needs any changes also merged to that tip branch.
Quoted 9 lines
Quoted 1 line
Having said that, I'll see what I can do.
I guess I'm happy to have them in the header for now, but just add something to the to-do
list once you're not juggling multiple branches.I'll not say that linux-user is ideal either, btw. Just stuff you see doing new patch review.
I think I'll take you up on that offer. It's a pattern that Stacey Son used a lot when writing
this code, and I'd need to do it to many different files. If it were just this one, I'd definitely
do that in a heart-beat. But since there's a lot, I think I'd get bogged down with so
many changes. There's a number of things you see when upstreaming the code too
that suggest themselves as cleanup, and so far I've just been keeping a list for later
on the larger of those items (eg command line parsing). In general, there was a preference
for having lots of inline functions, some quite long, so that they could be swapped out
more easily by including an alternative header (per arch, per bsd flavor, etc). With LTO
here or on the horizon, I'm thinking having the interface in the .h file and the code in a .c file
and having LTO eliminate the extra calls that would create may be acceptable. But
I think the optimal solution needs some time for thought and study as well.
Warner
PATCH 23/49 bsd-user: pull in target_arch_thread.h update target_arch_elf.h
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Update target_arch_elf.h to remove thread_init. Move its contents to target_arch_thread.h and rename to target_thread_init(). Update elfload.c to call it. Create thread_os_thread.h to hold the os specific parts of the thread and threat manipulation routines. Currently, it just includes target_arch_thread.h. target_arch_thread.h contains the at the moment unused target_thread_set_upcall which will be used in the future when creating actual thread (i386 has this stubbed, but other architectures in the bsd-user tree have real ones).
These changes are all interrelated and could be brokend own, but seem to represent a reviewable changeset since most of the change is boiler plate.
--- bsd-user/elfload.c | 4 ++- bsd-user/freebsd/target_os_thread.h | 25 +++++++++++++ bsd-user/i386/target_arch_elf.h | 52 ++-------------------------- bsd-user/i386/target_arch_thread.h | 47 +++++++++++++++++++++++++ bsd-user/netbsd/target_os_thread.h | 25 +++++++++++++ bsd-user/openbsd/target_os_thread.h | 25 +++++++++++++ bsd-user/x86_64/target_arch_elf.h | 38 ++------------------ bsd-user/x86_64/target_arch_thread.h | 40 +++++++++++++++++++++ 8 files changed, 169 insertions(+), 87 deletions(-) create mode 100644 bsd-user/freebsd/target_os_thread.h create mode 100644 bsd-user/i386/target_arch_thread.h create mode 100644 bsd-user/netbsd/target_os_thread.h create mode 100644 bsd-user/openbsd/target_os_thread.h create mode 100644 bsd-user/x86_64/target_arch_thread.h
bsd-user/elfload.c +3 -1
@@ -24,6 +24,7 @@#include "qemu/path.h" #include "target_arch_elf.h" +#include "target_os_thread.h" /* this flag is uneffective under linux too, should be deleted */ #ifndef MAP_DENYWRITE
@@ -1001,5 +1002,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,void do_init_thread (struct target_pt_regs *regs,struct image_info *infop) { -init_thread (regs, infop); + +target_thread_init (regs, infop); }
bsd-user/freebsd/target_os_thread.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* FreeBSD thread dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */
bsd-user/i386/target_arch_elf.h +2 -50
64 lines not on this page · raw message
bsd-user/i386/target_arch_thread.h new file +47 -0
47 lines not on this page · raw message
bsd-user/netbsd/target_os_thread.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* NetBSD thread dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */
bsd-user/openbsd/target_os_thread.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* OpenBSD thread dependent code and definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_OS_THREAD_H_ +#define _TARGET_OS_THREAD_H_ + +#include "target_arch_thread.h" + +#endif /* !_TARGET_OS_THREAD_H_ */
bsd-user/x86_64/target_arch_elf.h +2 -36
@@ -19,48 +19,14 @@#ifndef _TARGET_ARCH_ELF_H_#define _TARGET_ARCH_ELF_H_ -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform (void ) -{ -static char elf_platform[] ="i386" ; -int family =object_property_get_int (OBJECT (thread_cpu),"family" ,NULL ); -if (family >6 ) { - family =6 ; - } -if (family >=3 ) { - elf_platform[1 ] ='0' + family; - } -return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap (void ) -{ -X86CPU *cpu =X86_CPU (thread_cpu); - -return cpu->env.features[FEAT_1_EDX ]; -} -#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) (((x) == ELF_ARCH)) +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 +#define elf_check_arch (x) ( ((x) == ELF_ARCH) )#define ELF_CLASS ELFCLASS64#define ELF_DATA ELFDATA2LSB#define ELF_ARCH EM_X86_64 -static inline void init_thread (struct target_pt_regs *regs, -struct image_info *infop) -{ - regs->rax =0 ; - regs->rsp = infop->start_stack; - regs->rip = infop->entry; -if (bsd_type == target_freebsd) { - regs->rdi = infop->start_stack; - } -} -#define USE_ELF_CORE_DUMP #define ELF_EXEC_PAGESIZE 4096
bsd-user/x86_64/target_arch_thread.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* x86_64 thread support +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _TARGET_ARCH_THREAD_H_ +#define _TARGET_ARCH_THREAD_H_ + +/* Compare to vm_machdep.c cpu_set_upcall_kse() */ +static inline void target_thread_set_upcall (CPUX86State *regs,abi_ulong entry, +abi_ulong arg,abi_ulong stack_base,abi_ulong stack_size) +{ +/* XXX */ +} + +static inline void target_thread_init (struct target_pt_regs *regs, +struct image_info *infop) +{ + regs->rax =0 ; + regs->rsp = infop->start_stack; + regs->rip = infop->entry; +if (bsd_type == target_freebsd) { + regs->rdi = infop->start_stack; + } +} + +#endif /* !_TARGET_ARCH_THREAD_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 23/49] bsd-user: pull in target_arch_thread.h update target_arch_elf.h
Quoted 23 lines · Warner Losh
+++
b/bsd-user/x86_64/target_arch_elf.hbsd-user/x86_64/target_arch_elf.h +0
-18@@ -19,48 +19,14 @@#ifndef_TARGET_ARCH_ELF_H_ #define_TARGET_ARCH_ELF_H_ -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform (void ) -{ -static char elf_platform[] ="i386" ; -int family =object_property_get_int (OBJECT (thread_cpu),"family" ,NULL ); -if (family >6 ) { - family =6 ; - } -if (family >=3 ) { - elf_platform[1 ] ='0' + family; - } -return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap (void )
bsd-user/x86_64/target_arch_elf.h line 24
Quoted 10 lines
bsd-user/x86_64/target_arch_elf.h +2
-7-{ -X86CPU *cpu =X86_CPU (thread_cpu); - -return cpu->env.features[FEAT_1_EDX ]; -} -#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) (((x) == ELF_ARCH)) +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 +#define elf_check_arch (x) ( ((x) == ELF_ARCH) )
This appears to be unrelated? Should this have been in a previous patch? Or is this a rebase mistake that gets corrected later?
I'll trust the target_os_thread.h thing becomes useful later. So, modulo the target_arch_elf.h weirdness,
r~
Re: [PATCH for 6.2 23/49] bsd-user: pull in target_arch_thread.h update target_arch_elf.h
Quoted 31 lines · Richard Henderson
bsd-user/i386/target_arch_elf.h line 27
Quoted 11 lines · Warner Losh
+++
b/bsd-user/x86_64/target_arch_elf.hbsd-user/i386/target_arch_elf.h +0
-6@@ -19,48 +19,14 @@#ifndef_TARGET_ARCH_ELF_H_ #define_TARGET_ARCH_ELF_H_ -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform (void ) -{ -static char elf_platform[] ="i386" ; - int family = object_property_get_int(OBJECT(thread_cpu), "family",NULL);
Quoted 18 lines
bsd-user/i386/target_arch_elf.h +0
-18-if (family >6 ) { - family =6 ; - } -if (family >=3 ) { - elf_platform[1 ] ='0' + family; - } -return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap (void ) -{ -X86CPU *cpu =X86_CPU (thread_cpu); - -return cpu->env.features[FEAT_1_EDX ]; -} -
Quoted 9 lines
bsd-user/x86_64/target_arch_elf.h line 24
Quoted 4 lines
bsd-user/x86_64/target_arch_elf.h +2
-1#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) (((x) == ELF_ARCH)) +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 +#define elf_check_arch (x) ( ((x) == ELF_ARCH) )This appears to be unrelated? Should this have been in a previous patch? Or is this a
rebase mistake that gets corrected later?
This turns out to be a very good question. It's exactly what I intended to do. It's a
copy of the latest development branch. However, digging into it shows that it is
none-the-less incorrect. It wasn't a mismerge, but it was code commented out 8
years ago which I removed in the merge. I had thought this meant it was unused.
In fact, it had been for some time. However, it's been wrong all that time and that
code should be restored not only here, but for other architectures I've not submitted.
It was unused, but not unneeded...
Quoted 3 lines
I'll trust the
target_os_thread.hthing becomes useful later. So, modulo thetarget_arch_elf.hweirdness,
Yes. It works well enough on x86, but since x86 isn't used by our project for more
than a basic sanity check, this breakage went unnoticed for some time...
I'll update with the next round. BTW, I've started to notice that many of the
items flagged by the style commitcheck.pl script originated in the linux-user
code and it's still that way today... Do you have any advice for what I should
do about that, if anything?
Warner
Quoted 4 lines
Reviewed-by Richard Henderson <[email protected]>r~
Re: [PATCH for 6.2 23/49] bsd-user: pull in target_arch_thread.h update target_arch_elf.h
Quoted 46 lines · Warner Losh
Quoted 31 lines · Richard Henderson
bsd-user/i386/target_arch_elf.h line 27
Quoted 11 lines · Warner Losh
+++
b/bsd-user/x86_64/target_arch_elf.hbsd-user/i386/target_arch_elf.h +0
-6@@ -19,48 +19,14 @@#ifndef_TARGET_ARCH_ELF_H_ #define_TARGET_ARCH_ELF_H_ -#define ELF_PLATFORM get_elf_platform() - -static const char *get_elf_platform (void ) -{ -static char elf_platform[] ="i386" ; - int family = object_property_get_int(OBJECT(thread_cpu), "family",NULL);
Quoted 18 lines
bsd-user/i386/target_arch_elf.h +0
-18-if (family >6 ) { - family =6 ; - } -if (family >=3 ) { - elf_platform[1 ] ='0' + family; - } -return elf_platform; -} - -#define ELF_HWCAP get_elf_hwcap() - -static uint32_t get_elf_hwcap (void ) -{ -X86CPU *cpu =X86_CPU (thread_cpu); - -return cpu->env.features[FEAT_1_EDX ]; -} -Quoted 9 lines
bsd-user/x86_64/target_arch_elf.h line 24
Quoted 4 lines
bsd-user/x86_64/target_arch_elf.h +2
-1#define ELF_START_MMAP 0x2aaaaab000ULL -#define elf_check_arch (x) (((x) == ELF_ARCH)) +#define ELF_ET_DYN_LOAD_ADDR 0x01021000 +#define elf_check_arch (x) ( ((x) == ELF_ARCH) )This appears to be unrelated? Should this have been in a previous patch? Or is this a
rebase mistake that gets corrected later?
Quoted 14 lines
This turns out to be a very good question. It's exactly what I intended to do. It's a
copy of the latest development branch. However, digging into it shows that it is
none-the-less incorrect. It wasn't a mismerge, but it was code commented out 8
years ago which I removed in the merge. I had thought this meant it was unused.
In fact, it had been for some time. However, it's been wrong all that time and that
code should be restored not only here, but for other architectures I've not submitted.
It was unused, but not unneeded...
Ah, it turns out this showed problems only in arm* and riscv on FreeBSD. The others
publish HWCAP = 0 for some reason. And ELF_PLATFORM() is used in the most-recent
bsd-user code. Some tweaks are needed, and I'll do those in V2 with the other style
fixes.
Warner
Quoted 24 lines
I'll trust the
target_os_thread.hthing becomes useful later.Quoted 2 lines
So, modulo the
target_arch_elf.hweirdness,Yes. It works well enough on x86, but since x86 isn't used by our project for more
than a basic sanity check, this breakage went unnoticed for some time...I'll update with the next round. BTW, I've started to notice that many of the
items flagged by the style commitcheck.pl script originated in the linux-user
code and it's still that way today... Do you have any advice for what I should
do about that, if anything?Warner
Quoted 4 lines
Reviewed-by Richard Henderson <[email protected]>r~
Re: [PATCH for 6.2 23/49] bsd-user: pull in target_arch_thread.h update target_arch_elf.h
In reply to Warner LoshQuoted 4 lines · Warner Losh
BTW, I've started to notice that many of the
items flagged by the style commitcheck.pl <http://commitcheck.pl> script originated in the linux-user code and it's still that way today... Do you have any advice for what I should
do about that, if anything?
Fix em on the bsd side.
We have so far resisted style fixes for their own sake, only fixing them up locally when we have to make nearby changes for some other reason.
r~
PATCH 24/49 bsd-user: Include more things in qemu.h
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Include more header files to match bsd-user fork.
--- bsd-user/qemu.h | 9 +++++++++ 1 file changed, 9 insertions(+)
bsd-user/qemu.h +9 -0
@@ -18,11 +18,15 @@#define QEMU_H +#include "qemu/osdep.h" #include "cpu.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +//#include "trace/trace-bsd_user.h" #undef DEBUG_REMAP#ifdef DEBUG_REMAP +#include <stdio.h> #endif /* DEBUG_REMAP */ #include "exec/user/abitypes.h"
@@ -36,8 +40,13 @@ enum BSDType { };extern enum BSDType bsd_type; +#include "exec/user/thunk.h" +#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" +//#include "target_os_vmparam.h" +//#include "target_os_signal.h" +//#include "hostdep.h" #include "exec/gdbstub.h" /*
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 24/49] bsd-user: Include more things in qemu.h
Quoted 17 lines · Warner Losh
From: Warner Losh <[email protected]>
Include more header files to match bsd-user fork.
Signed-off-by Warner Losh <[email protected]>--- bsd-user/qemu.h | 9 +++++++++ 1 file changed, 9 insertions(+)bsd-user/qemu.h +0
-0@@ -18,11 +18,15 @@#define QEMU_H
bsd-user/qemu.h line 30
Quoted 10 lines
bsd-user/qemu.h +4
-0+#include "qemu/osdep.h" #include "cpu.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +//#include "trace/trace-bsd_user.h" #undef DEBUG_REMAP#ifdef DEBUG_REMAP +#include <stdio.h> #endif /* DEBUG_REMAP */
osdep.h will have included stdio.h.
bsd-user/qemu.h enum BSDType { · line 49
Quoted 3 lines
bsd-user/qemu.h +3
-0+//#include "target_os_vmparam.h" +//#include "target_os_signal.h" +//#include "hostdep.h"
Delete these?
r~
Re: [PATCH for 6.2 24/49] bsd-user: Include more things in qemu.h
Quoted 31 lines · Richard Henderson
Quoted 17 lines · Warner Losh
From: Warner Losh <[email protected]>
Include more header files to match bsd-user fork.
Signed-off-by Warner Losh <[email protected]>--- bsd-user/qemu.h | 9 +++++++++ 1 file changed, 9 insertions(+)bsd-user/qemu.h +0
-0@@ -18,11 +18,15 @@#define QEMU_H bsd-user/qemu.h line 30
Quoted 10 lines
bsd-user/qemu.h +4
-0+#include "qemu/osdep.h" #include "cpu.h" #include "exec/cpu_ldst.h" +#include "exec/exec-all.h" +//#include "trace/trace-bsd_user.h" #undef DEBUG_REMAP#ifdef DEBUG_REMAP +#include <stdio.h> #endif /* DEBUG_REMAP */
osdep.hwill have includedstdio.h.
Quoted 6 lines
bsd-user/qemu.h enum BSDType { · line 49
Quoted 3 lines
bsd-user/qemu.h +3
-0+//#include "target_os_vmparam.h" +//#include "target_os_signal.h" +//#include "hostdep.h" Delete these?
Done. I'll post in v2. Thanks!
Warner
PATCH 25/49 bsd-user: define max args in terms of pages
In reply to Warner LoshFrom: Warner Losh <[email protected]>
For 32-bit platforms, pass in up to 256k of args. For 64-bit, bump that to 512k.
--- bsd-user/qemu.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
bsd-user/qemu.h +10 -4
@@ -107,11 +107,17 @@ extern const char *qemu_uname_release;extern unsigned long mmap_min_addr;/* -* MAX_ARG_PAGES defines the number of pages allocated for arguments -* and envelope for the new program. 32 should suffice, this gives -* a maximum env+arg of 128kB w/4KB pages! +* TARGET_ARG_MAX defines the number of bytes allocated for arguments +* and envelope for the new program. 256k should suffice for a reasonable +* maxiumum env+arg in 32-bit environments, bump it up to 512k for !ILP32 +* platforms. */ -#define MAX_ARG_PAGES 32 +#if TARGET_ABI_BITS >32 +#define TARGET_ARG_MAX (512 * 1024) +#else +#define TARGET_ARG_MAX (256 * 1024) +#endif +#define MAX_ARG_PAGES (TARGET_ARG_MAX / TARGET_PAGE_SIZE)/* * This structure is used to hold the arguments that are
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 25/49] bsd-user: define max args in terms of pages
Quoted 10 lines · Warner Losh
From: Warner Losh <[email protected]>
For 32-bit platforms, pass in up to 256k of args. For 64-bit, bump that to 512k.
Signed-off-by Kyle Evans <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/qemu.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
bsd-user/qemu.h extern const char *qemu_uname_release; · line 118
Quoted 3 lines
bsd-user/qemu.h +3
-0+#define TARGET_ARG_MAX (512 * 1024) +#else +#define TARGET_ARG_MAX (256 * 1024)
For the to-do list: qemu/units.h has KiB for clarity.
r~
Re: [PATCH for 6.2 25/49] bsd-user: define max args in terms of pages
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Warner Losh
From: Warner Losh <[email protected]>
For 32-bit platforms, pass in up to 256k of args. For 64-bit, bump that to 512k.
Signed-off-by Kyle Evans <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/qemu.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
Quoted 8 lines
Reviewed-by Richard Henderson <[email protected]>bsd-user/qemu.h extern const char *qemu_uname_release; · line 118
Quoted 3 lines
bsd-user/qemu.h +3
-0+#define TARGET_ARG_MAX (512 * 1024) +#else +#define TARGET_ARG_MAX (256 * 1024)For the to-do list:
qemu/units.hhas KiB for clarity.
OK. Will change. Thanks!
Warner
PATCH 26/49 bsd-user: Create target specific vmparam.h
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Target specific values for vm parameters and details.
--- bsd-user/freebsd/target_os_vmparam.h | 38 ++++++++++++++++++++++ bsd-user/i386/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ bsd-user/qemu.h | 2 +- bsd-user/x86_64/target_arch_vmparam.h | 46 +++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 bsd-user/freebsd/target_os_vmparam.h create mode 100644 bsd-user/i386/target_arch_vmparam.h create mode 100644 bsd-user/x86_64/target_arch_vmparam.h
bsd-user/freebsd/target_os_vmparam.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* FreeBSD VM parameters definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _TARGET_OS_VMPARAM_H_ +#define _TARGET_OS_VMPARAM_H_ + +#include "target_arch_vmparam.h" + +/* Compare to sys/exec.h */ +struct target_ps_strings { +abi_ulong ps_argvstr; +uint32_t ps_nargvstr; +abi_ulong ps_envstr; +uint32_t ps_nenvstr; +}; + +extern abi_ulong target_stkbas; +extern abi_ulong target_stksiz; + +#define TARGET_PS_STRINGS ((target_stkbas + target_stksiz) - \ + sizeof(struct target_ps_strings)) + +#endif /* !TARGET_OS_VMPARAM_H_ */
bsd-user/i386/target_arch_vmparam.h new file +46 -0
46 lines not on this page · raw message
bsd-user/qemu.h +1 -1
@@ -44,7 +44,7 @@ extern enum BSDType bsd_type;#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" -//#include "target_os_vmparam.h" +#include "target_os_vmparam.h" //#include "target_os_signal.h" //#include "hostdep.h" #include "exec/gdbstub.h"
bsd-user/x86_64/target_arch_vmparam.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 26/49] bsd-user: Create target specific vmparam.h
bsd-user/i386/target_arch_vmparam.h line 30
Quoted 6 lines · Warner Losh
bsd-user/i386/target_arch_vmparam.h new file +6
-0+#define TARGET_MAXTSIZ (128UL*1024*1024)/* max text size */ +#define TARGET_DFLDSIZ (128UL*1024*1024)/* initial data size limit */ +#define TARGET_MAXDSIZ (512UL*1024*1024)/* max data size */ +#define TARGET_DFLSSIZ (8UL*1024*1024)/* initial stack size limit */ +#define TARGET_MAXSSIZ (64UL*1024*1024)/* max stack size */ +#define TARGET_SGROWSIZ (128UL*1024)/* amount to grow stack */
To-do list: KiB and MiB from units.h.
bsd-user/qemu.h extern enum BSDType bsd_type; · line 49
Quoted 9 lines
+++
b/bsd-user/qemu.hbsd-user/qemu.h +1
-1@@ -44,7 +44,7 @@ extern enum BSDType bsd_type;#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h" -//#include "target_os_vmparam.h" +#include "target_os_vmparam.h" //#include "target_os_signal.h" //#include "hostdep.h"
Ah, I see. Well, perhaps just squash the addition of the include to the patch that introduces the include?
Otherwise,
r~
Warner Losh
Reviewed-by Richard HendersonRe: [PATCH for 6.2 26/49] bsd-user: Create target specific vmparam.h
Quoted 4 lines · Richard Henderson
Review
Quoted 2 lines · Warner Losh
(quoted diff) +2
-0+#define TARGET_MAXTSIZ (128UL*1024*1024) /* max text size */ +#define TARGET_DFLDSIZ (128UL*1024*1024) /* initial data size limit*/
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define TARGET_MAXDSIZ (512UL*1024*1024) /* max data size */ +#define TARGET_DFLSSIZ (8UL*1024*1024) /* initial stack size limit*/
bsd-user/i386/target_arch_vmparam.h line 30
Quoted 2 lines
bsd-user/i386/target_arch_vmparam.h new file +2
-0+#define TARGET_MAXSSIZ (64UL*1024*1024)/* max stack size */ +#define TARGET_SGROWSIZ (128UL*1024)/* amount to grow stack */ To-do list: KiB and MiB from
units.h.
Easy enough to do now and merge to our main branch
Quoted 5 lines
Quoted 5 lines
+++
b/bsd-user/qemu.hbsd-user/qemu.h +0
-0@@ -44,7 +44,7 @@ extern enum BSDType bsd_type;#include "target_arch.h" #include "syscall_defs.h" #include "target_syscall.h"
Quoted 9 lines
bsd-user/qemu.h extern enum BSDType bsd_type; · line 49
Quoted 4 lines
bsd-user/qemu.h +1
-1-//#include "target_os_vmparam.h" +#include "target_os_vmparam.h" //#include "target_os_signal.h" //#include "hostdep.h" Ah, I see. Well, perhaps just squash the addition of the include to the patch that
introduces the include?
Good idea.
Quoted 1 line
thanks!
Warner
PATCH 27/49 bsd-user: Add architecture specific signal tramp code
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Add a stubbed out version of setup_sigtramp. This is not yet used for x86, but is used for other architectures. This will be connected in future commits.
--- bsd-user/i386/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h
bsd-user/i386/target_arch_sigtramp.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Intel i386 sigcode for bsd-user +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +static inline abi_long setup_sigtramp (abi_ulong offset,unsigned sigf_uc, +unsigned sys_sigreturn) +{ + +return -TARGET_EOPNOTSUPP ; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
bsd-user/x86_64/target_arch_sigtramp.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Intel x86_64 sigcode for bsd-user +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +static inline abi_long setup_sigtramp (abi_ulong offset,unsigned sigf_uc, +unsigned sys_sigreturn) +{ + +return -TARGET_EOPNOTSUPP ; +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 27/49] bsd-user: Add architecture specific signal tramp code
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
Add a stubbed out version of
setup_sigtramp. This is not yet used for x86, but is used for other architectures. This will be connected in future commits.
Quoted 8 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/i386/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_sigtramp.h | 29 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)create mode 100644
bsd-user/i386/target_arch_sigtramp.hcreate mode 100644bsd-user/x86_64/target_arch_sigtramp.h
r~
PATCH 28/49 bsd-user: Move stack initializtion into a per-os file.
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Move all of the stack initialization into target_os_stack.h. Each BSD sets up processes a little differently.
--- bsd-user/freebsd/target_os_stack.h | 181 +++++++++++++++++++++++++++++ bsd-user/netbsd/target_os_stack.h | 56 +++++++++ bsd-user/openbsd/target_os_stack.h | 56 +++++++++ 3 files changed, 293 insertions(+) create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/target_os_stack.h
bsd-user/freebsd/target_os_stack.h new file +181 -0
@@ -0,0 +1,181 @@ +/* +* FreeBSD setup_initial_stack() implementation. +* +* Copyright (c) 2013-14 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_OS_STACK_H_ +#define _TARGET_OS_STACK_H_ + +#include <sys/param.h> +#include "target_arch_sigtramp.h" + +/* +* The inital FreeBSD stack is as follows: +* (see kern/kern_exec.c exec_copyout_strings() ) +* +* Hi Address -> char **ps_argvstr (struct ps_strings for ps, w, etc.) +* unsigned ps_nargvstr +* char **ps_envstr +* PS_STRINGS -> unsigned ps_nenvstr +* +* machine dependent sigcode (sv_sigcode of size +* sv_szsigcode) +* +* execpath (absolute image path for rtld) +* +* SSP Canary (sizeof(long) * 8) +* +* page sizes array (usually sizeof(u_long) ) +* +* "destp" -> argv, env strings (up to 262144 bytes) +*/ +static inline int setup_initial_stack (struct bsd_binprm *bprm, +abi_ulong *ret_addr,abi_ulong *stringp) +{ +int i; +abi_ulong stack_hi_addr; +size_t execpath_len, stringspace; +abi_ulong destp, argvp, envp, p; +struct target_ps_strings ps_strs; +char canary[sizeof (abi_long) *8 ]; + + stack_hi_addr = p = target_stkbas + target_stksiz; + +/* Save some space for ps_strings. */ + p -=sizeof (struct target_ps_strings ); + +#ifdef TARGET_SZSIGCODE +/* Add machine depedent sigcode. */ + p -=TARGET_SZSIGCODE ; +if (setup_sigtramp (p, (unsigned )offsetof(struct target_sigframe , sf_uc), + TARGET_FREEBSD_NR_sigreturn)) { + errno =EFAULT ; +return -1 ; + } +#endif +if (bprm->fullpath) { + execpath_len =strlen (bprm->fullpath) +1 ; + p -=roundup (execpath_len,sizeof (abi_ulong)); +if (memcpy_to_target (p, bprm->fullpath, execpath_len)) { + errno =EFAULT ; +return -1 ; + } + } +/* Add canary for SSP. */ +arc4random_buf (canary,sizeof (canary)); + p -=roundup (sizeof (canary),sizeof (abi_ulong)); +if (memcpy_to_target (p, canary,sizeof (canary))) { + errno =EFAULT ; +return -1 ; + } +/* Add page sizes array. */ + p -=sizeof (abi_ulong); +if (put_user_ual (TARGET_PAGE_SIZE , p)) { + errno =EFAULT ; +return -1 ; + } +/* +* Deviate from FreeBSD stack layout: force stack to new page here +* so that signal trampoline is not sharing the page with user stack +* frames. This is actively harmful in qemu as it marks pages with +* code it translated as read-only, which is somewhat problematic +* for user trying to use the stack as intended. +*/ + p =rounddown (p,TARGET_PAGE_SIZE ); + +/* Calculate the string space needed */ + stringspace =0 ; +for (i =0 ; i < bprm->argc; ++i) { + stringspace +=strlen (bprm->argv[i]) +1 ; + } +for (i =0 ; i < bprm->envc; ++i) { + stringspace +=strlen (bprm->envp[i]) +1 ; + } +if (stringspace >TARGET_ARG_MAX ) { + errno =ENOMEM ; +return -1 ; + } +/* Make room for the argv and envp strings */ + destp =rounddown (p - stringspace,sizeof (abi_ulong)); + p = argvp = destp - (bprm->argc + bprm->envc +2 ) *sizeof (abi_ulong); +/* Remember the strings pointer */ +if (stringp) + *stringp = destp; +/* +* Add argv strings. Note that the argv[] vectors are added by +* loader_build_argptr() +*/ +/* XXX need to make room for auxargs */ + ps_strs.ps_argvstr =tswapl (argvp); + ps_strs.ps_nargvstr =tswap32 (bprm->argc); +for (i =0 ; i < bprm->argc; ++i) { +size_t len =strlen (bprm->argv[i]) +1 ; + +if (memcpy_to_target (destp, bprm->argv[i], len)) { + errno =EFAULT ; +return -1 ; + } +if (put_user_ual (destp, argvp)) { + errno =EFAULT ; +return -1 ; + } + argvp +=sizeof (abi_ulong); + destp += len; + } +if (put_user_ual (0 , argvp)) { + errno =EFAULT ; +return -1 ; + } +/* +* Add env strings. Note that the envp[] vectors are added by +* loader_build_argptr(). +*/ + envp = argvp +sizeof (abi_ulong); + ps_strs.ps_envstr =tswapl (envp); + ps_strs.ps_nenvstr =tswap32 (bprm->envc); +for (i =0 ; i < bprm->envc; ++i) { +size_t len =strlen (bprm->envp[i]) +1 ; + +if (memcpy_to_target (destp, bprm->envp[i], len)) { + errno =EFAULT ; +return -1 ; + } +if (put_user_ual (destp, envp)) { + errno =EFAULT ; +return -1 ; + } + envp +=sizeof (abi_ulong); + destp += len; + } +if (put_user_ual (0 , envp)) { + errno =EFAULT ; +return -1 ; + } +if (memcpy_to_target (stack_hi_addr -sizeof (ps_strs), &ps_strs, +sizeof (ps_strs))) { + errno =EFAULT ; +return -1 ; + } + +if (ret_addr) { + *ret_addr = p; + } + +return 0 ; + } + +#endif /* !_TARGET_OS_STACK_H_ */
bsd-user/netbsd/target_os_stack.h new file +56 -0
56 lines not on this page · raw message
bsd-user/openbsd/target_os_stack.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 28/49] bsd-user: Move stack initializtion into a per-os file.
Quoted 14 lines · Warner Losh
bsd-user/freebsd/target_os_stack.h new file +14
-0+static inline int setup_initial_stack (struct bsd_binprm *bprm, +abi_ulong *ret_addr,abi_ulong *stringp) +{ +int i; +abi_ulong stack_hi_addr; +size_t execpath_len, stringspace; +abi_ulong destp, argvp, envp, p; +struct target_ps_strings ps_strs; +char canary[sizeof (abi_long) *8 ]; + + stack_hi_addr = p = target_stkbas + target_stksiz; + +/* Save some space for ps_strings. */ + p -=sizeof (struct target_ps_strings );
bsd-user/freebsd/target_os_stack.h line 69
Quoted 10 lines
bsd-user/freebsd/target_os_stack.h new file +10
-0+ +#ifdef TARGET_SZSIGCODE +/* Add machine depedent sigcode. */ + p -=TARGET_SZSIGCODE ; +if (setup_sigtramp (p, (unsigned )offsetof(struct target_sigframe , sf_uc), + TARGET_FREEBSD_NR_sigreturn)) { + errno =EFAULT ; +return -1 ; + } +#endif
Hmm. The x86 version you just added always returns -EOPNOTSUPP. Therefore I conclude that TARGET_SZSIGCODE is unset.
Perhaps a better interface would be
p = setup_sigtramp(p, ...);
if (p == 0) {
// fail
}then you don't need to expose TARGET_SZSIGCODE or have conditional compilation here.
Perhaps for the to-do list...
bsd-user/freebsd/target_os_stack.h line 79
Quoted 2 lines
bsd-user/freebsd/target_os_stack.h new file +2
-0+/* Add canary for SSP. */ +arc4random_buf (canary,sizeof (canary));
You should use qemu_guest_getrandom_nofail here.
bsd-user/freebsd/target_os_stack.h line 97
Quoted 7 lines
bsd-user/freebsd/target_os_stack.h new file +7
-0+/* +* Deviate from FreeBSD stack layout: force stack to new page here +* so that signal trampoline is not sharing the page with user stack +* frames. This is actively harmful in qemu as it marks pages with +* code it translated as read-only, which is somewhat problematic +* for user trying to use the stack as intended. +*/
A decent short-term solution.
I'll draw your attention to my vdso patch set for linux-user:
https://patchew.org/QEMU/[email protected]/
Modulo randomness,
r~
Re: [PATCH for 6.2 28/49] bsd-user: Move stack initializtion into a per-os file.
Quoted 38 lines · Richard Henderson
Quoted 9 lines · Warner Losh
bsd-user/freebsd/target_os_stack.h new file +9
-0+static inline int setup_initial_stack (struct bsd_binprm *bprm, +abi_ulong *ret_addr,abi_ulong *stringp) +{ +int i; +abi_ulong stack_hi_addr; +size_t execpath_len, stringspace; +abi_ulong destp, argvp, envp, p; +struct target_ps_strings ps_strs; +char canary[sizeof (abi_long) *8 ];bsd-user/freebsd/target_os_stack.h
Quoted 10 lines
bsd-user/freebsd/target_os_stack.h new file +10
-0+ + stack_hi_addr = p = target_stkbas + target_stksiz; + +/* Save some space for ps_strings. */ + p -=sizeof (struct target_ps_strings ); + +#ifdef TARGET_SZSIGCODE +/* Add machine depedent sigcode. */ + p -=TARGET_SZSIGCODE ; + if (setup_sigtramp(p, (unsigned)offsetof(struct target_sigframe,
sf_uc),bsd-user/freebsd/target_os_stack.h line 69
Quoted 5 lines
bsd-user/freebsd/target_os_stack.h new file +5
-0+ TARGET_FREEBSD_NR_sigreturn)) { + errno =EFAULT ; +return -1 ; + } +#endif Hmm. The x86 version you just added always returns
-EOPNOTSUPP. Therefore I conclude
thatTARGET_SZSIGCODEis unset.Perhaps a better interface would be
p = setup_sigtramp(p, ...); if (p == 0) { // fail }
Quoted 5 lines
then you don't need to expose
TARGET_SZSIGCODEor have conditional compilation here.Perhaps for the to-do list...
I'll add it to the todo...
Quoted 5 lines
bsd-user/freebsd/target_os_stack.h line 79
Quoted 2 lines
bsd-user/freebsd/target_os_stack.h new file +2
-0+/* Add canary for SSP. */ +arc4random_buf (canary,sizeof (canary));You should use
qemu_guest_getrandom_nofailhere.
OK.
Quoted 8 lines
bsd-user/freebsd/target_os_stack.h line 97
Quoted 7 lines
bsd-user/freebsd/target_os_stack.h new file +7
-0+/* +* Deviate from FreeBSD stack layout: force stack to new page here +* so that signal trampoline is not sharing the page with user stack +* frames. This is actively harmful in qemu as it marks pages with +* code it translated as read-only, which is somewhat problematic +* for user trying to use the stack as intended. +*/
Quoted 6 lines
A decent short-term solution.
I'll draw your attention to my vdso patch set for linux-user:
I'll look at that as well...
Warner
Quoted 6 lines
Modulo randomness,
Reviewed-by Richard Henderson <[email protected]>r~
PATCH 29/49 bsd-user: Add system independent stack, data and text limiting
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Eliminate the x86 specific stack stuff in favor of more generic control over the process size:
target_maxtsiz max text size
target_dfldsiz initial data size limit
target_maxdsiz max data size
target_dflssiz initial stack size limit
target_maxssiz max stack size target_sgrowsiz amount to grow stack
These can be set on a per-arch basis, and the stack size can be set on the command line. Adjust the stack size parameters at startup.
Sponsored by: Netflix
--- bsd-user/elfload.c | 2 +- bsd-user/main.c | 51 +++++++++++++++++++++++++++++++++------------- bsd-user/qemu.h | 7 ++++++- 3 files changed, 44 insertions(+), 16 deletions(-)
bsd-user/elfload.c +1 -1
@@ -204,7 +204,7 @@ static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm,/* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ - size = x86_stack_size; + size = target_dflssiz;if (size <MAX_ARG_PAGES *TARGET_PAGE_SIZE ) size =MAX_ARG_PAGES *TARGET_PAGE_SIZE ; error = target_mmap(0,
bsd-user/main.c +37 -14
103 lines not on this page · raw message
bsd-user/qemu.h +6 -1
@@ -223,7 +223,12 @@ void mmap_fork_end(int child);/* main.c */ extern char qemu_proc_pathname[]; -extern unsigned long x86_stack_size; +extern unsigned long target_maxtsiz; +extern unsigned long target_dfldsiz; +extern unsigned long target_maxdsiz; +extern unsigned long target_dflssiz; +extern unsigned long target_maxssiz; +extern unsigned long target_sgrowsiz;/* user access */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 29/49] bsd-user: Add system independent stack, data and text limiting
Quoted 16 lines · Warner Losh
From: Warner Losh<[email protected]>
Eliminate the x86 specific stack stuff in favor of more generic control over the process size:
target_maxtsiz max text size target_dfldsiz initial data size limit target_maxdsiz max data size target_dflssiz initial stack size limit target_maxssiz max stack size
target_sgrowsizamount to grow stack
These can be set on a per-arch basis, and the stack size can be set on the command line. Adjust the stack size parameters at startup.Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>
Quoted 6 lines
Sponsored by: Netflix
--- bsd-user/elfload.c | 2 +- bsd-user/main.c | 51 +++++++++++++++++++++++++++++++++------------- bsd-user/qemu.h | 7 ++++++- 3 files changed, 44 insertions(+), 16 deletions(-)
r~
PATCH 30/49 bsd-user: elf cleanup
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Move OS-dependent defines into target_os_elf.h. Move the architectural dependent stuff into target_arch_elf.h. Adjust elfload.c to use target_create_elf_tables instead of create_elf_tables.
Sponsored by: Netflix
--- bsd-user/elfload.c | 190 ++++--------------------------- bsd-user/freebsd/target_os_elf.h | 149 ++++++++++++++++++++++++ bsd-user/netbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/openbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/qemu.h | 1 + 5 files changed, 459 insertions(+), 167 deletions(-) create mode 100644 bsd-user/freebsd/target_os_elf.h create mode 100644 bsd-user/netbsd/target_os_elf.h create mode 100644 bsd-user/openbsd/target_os_elf.h
bsd-user/elfload.c +23 -167
@@ -23,48 +23,17 @@#include "disas/disas.h" #include "qemu/path.h" -#include "target_arch_elf.h" -#include "target_os_thread.h" - -/* this flag is uneffective under linux too, should be deleted */ -#ifndef MAP_DENYWRITE -#define MAP_DENYWRITE 0 -#endif - -/* should probably go in elf.h */ -#ifndef ELIBBAD -#define ELIBBAD 80 -#endif - -#ifndef ELF_PLATFORM -#define ELF_PLATFORM (NULL) -#endif - -#ifndef ELF_HWCAP -#define ELF_HWCAP 0 -#endif +static abi_ulong target_auxents;/* Where the AUX entries are in target */ +static size_t target_auxents_sz;/* Size of AUX entries including AT_NULL */ -#ifdef TARGET_ABI32 -#undef ELF_CLASS -#define ELF_CLASS ELFCLASS32 -#undef bswaptls -#define bswaptls (ptr) bswap32s(ptr) -#endif +#include "target_os_elf.h" +#include "target_os_stack.h" +#include "target_os_thread.h" #include "elf.h" -/* max code+data+bss space allocated to elf interpreter */ -#define INTERP_MAP_SIZE (32 * 1024 * 1024) - -/* max code+data+bss+brk space allocated to ET_DYN executables */ -#define ET_DYN_MAP_SIZE (128 * 1024 * 1024) - -/* Necessary parameters */ -#define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE -#define TARGET_ELF_PAGESTART (_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1)) -#define TARGET_ELF_PAGEOFFSET (_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1)) - -#define DLINFO_ITEMS 12 +abi_ulong target_stksiz; +abi_ulong target_stkbas;static inline void memcpy_fromfs (void *to,const void *from,unsigned long n) {
@@ -195,43 +164,36 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page,return p; } -static abi_ulong setup_arg_pages (abi_ulong p,struct bsd_binprm *bprm, -struct image_info *info) +static void setup_arg_pages (struct bsd_binprm *bprm,struct image_info *info, +abi_ulong *stackp,abi_ulong *stringp) { -abi_ulong stack_base, size, error; -int i; +abi_ulong stack_base, size; +abi_long addr;/* Create enough stack to hold everything. If we don't use * it for args, we'll use it for something else... */ size = target_dflssiz; -if (size <MAX_ARG_PAGES *TARGET_PAGE_SIZE ) - size =MAX_ARG_PAGES *TARGET_PAGE_SIZE ; - error =target_mmap (0 , + stack_base =TARGET_USRSTACK - size; + addr =target_mmap (stack_base, size + qemu_host_page_size,PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANON ,-1 ,0 ); -if (error ==-1 ) { +if (addr ==-1 ) {perror ("stk mmap" );exit (-1 ); }/* we reserve one extra page at the top of the stack as guard */ -target_mprotect (error + size, qemu_host_page_size,PROT_NONE ); +target_mprotect (addr + size, qemu_host_page_size,PROT_NONE ); - stack_base = error + size -MAX_ARG_PAGES *TARGET_PAGE_SIZE ; - p += stack_base; + target_stksiz = size; + target_stkbas = addr; -for (i =0 ; i <MAX_ARG_PAGES ; i++) { -if (bprm->page[i]) { - info->rss++; -/* FIXME - check return value of memcpy_to_target() for failure */ -memcpy_to_target (stack_base, bprm->page[i],TARGET_PAGE_SIZE ); -g_free (bprm->page[i]); - } - stack_base +=TARGET_PAGE_SIZE ; +if (setup_initial_stack (bprm, stackp, stringp) !=0 ) { +perror ("stk setup" ); +exit (-1 ); } -return p; }static void set_brk (abi_ulong start,abi_ulong end)
@@ -287,86 +249,6 @@ static void padzero(abi_ulong elf_bss, abi_ulong last_bss) } } - -static abi_ulong create_elf_tables (abi_ulong p,int argc,int envc, -struct elfhdr * exec, -abi_ulong load_addr, -abi_ulong load_bias, -abi_ulong interp_load_addr, -struct image_info *info) -{ -abi_ulong sp; -int size; -abi_ulong u_platform; -const char *k_platform; -const int n =sizeof (elf_addr_t); - - sp = p; - u_platform =0 ; - k_platform =ELF_PLATFORM ; -if (k_platform) { -size_t len =strlen (k_platform) +1 ; - sp -= (len + n -1 ) & ~(n -1 ); - u_platform = sp; -/* FIXME - check return value of memcpy_to_target() for failure */ -memcpy_to_target (sp, k_platform, len); - } -/* -* Force 16 byte _final_ alignment here for generality. -*/ - sp = sp & ~(abi_ulong )15 ; - size = (DLINFO_ITEMS +1 ) *2 ; -if (k_platform) - size +=2 ; -#ifdef DLINFO_ARCH_ITEMS - size +=DLINFO_ARCH_ITEMS *2 ; -#endif - size += envc + argc +2 ; - size +=1 ;/* argc itself */ - size *= n; -if (size &15 ) - sp -=16 - (size &15 ); - -/* This is correct because Linux defines -* elf_addr_t as Elf32_Off / Elf64_Off -*/ -#define NEW_AUX_ENT (id, val) do { \ - sp -= n; put_user_ual(val, sp); \ - sp -= n; put_user_ual(id, sp); \ - } while (0) - -NEW_AUX_ENT (AT_NULL ,0 ); - -/* There must be exactly DLINFO_ITEMS entries here. */ -NEW_AUX_ENT (AT_PHDR , (abi_ulong)(load_addr + exec->e_phoff)); -NEW_AUX_ENT (AT_PHENT , (abi_ulong)(sizeof (struct elf_phdr ))); -NEW_AUX_ENT (AT_PHNUM , (abi_ulong)(exec->e_phnum)); -NEW_AUX_ENT (AT_PAGESZ , (abi_ulong)(TARGET_PAGE_SIZE )); -NEW_AUX_ENT (AT_BASE , (abi_ulong)(interp_load_addr)); -NEW_AUX_ENT (AT_FLAGS , (abi_ulong )0 ); -NEW_AUX_ENT (AT_ENTRY , load_bias + exec->e_entry); -NEW_AUX_ENT (AT_UID , (abi_ulong )getuid ()); -NEW_AUX_ENT (AT_EUID , (abi_ulong )geteuid ()); -NEW_AUX_ENT (AT_GID , (abi_ulong )getgid ()); -NEW_AUX_ENT (AT_EGID , (abi_ulong )getegid ()); -NEW_AUX_ENT (AT_HWCAP , (abi_ulong )ELF_HWCAP ); -NEW_AUX_ENT (AT_CLKTCK , (abi_ulong )sysconf (_SC_CLK_TCK)); -if (k_platform) -NEW_AUX_ENT (AT_PLATFORM , u_platform); -#ifdef ARCH_DLINFO -/* -* ARCH_DLINFO must come last so platform specific code can enforce -* special alignment requirements on the AUXV if necessary (eg. PPC). -*/ -ARCH_DLINFO ; -#endif -#undef NEW_AUX_ENT - - sp =loader_build_argptr (envc, argc, sp, p); -return sp; -} - -static abi_ulong load_elf_interp (struct elfhdr *interp_elf_ex,int interpreter_fd,abi_ulong *interp_load_addr)
@@ -824,31 +706,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->mmap =0 ; elf_entry = (abi_ulong ) elf_ex.e_entry; -/* -* In case where user has not explicitly set the guest_base, we -* probe here that should we set it automatically. -*/ -if (!have_guest_base) { -/* -* Go through ELF program header table and find out whether -* any of the segments drop below our current mmap_min_addr and -* in that case set guest_base to corresponding address. -*/ -for (i =0 , elf_ppnt = elf_phdata; i < elf_ex.e_phnum; - i++, elf_ppnt++) { -if (elf_ppnt->p_type !=PT_LOAD ) -continue ; -if (HOST_PAGE_ALIGN (elf_ppnt->p_vaddr) < mmap_min_addr) { - guest_base =HOST_PAGE_ALIGN (mmap_min_addr); -break ; - } - } - } -/* Do this so that we can load the interpreter, if need be. We will change some of these later */ info->rss =0 ; - bprm->p =setup_arg_pages (bprm->p, bprm, info); +setup_arg_pages (bprm, info, &bprm->p, &bprm->stringp); info->start_stack = bprm->p;/* Now we do a little grungy work by mmaping the ELF image into
@@ -965,13 +826,8 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,#ifdef LOW_ELF_STACK info->start_stack = bprm->p = elf_stack -4 ;#endif - bprm->p =create_elf_tables (bprm->p, - bprm->argc, - bprm->envc, - &elf_ex, - load_addr, load_bias, - interp_load_addr, - info); + bprm->p =target_create_elf_tables (bprm->p, bprm->argc, bprm->envc, bprm->stringp, + &elf_ex, load_addr, load_bias, interp_load_addr, info); info->load_addr = reloc_func_desc; info->start_brk = info->brk = elf_brk; info->end_code = end_code;
bsd-user/freebsd/target_os_elf.h new file +149 -0
149 lines not on this page · raw message
bsd-user/netbsd/target_os_elf.h new file +143 -0
143 lines not on this page · raw message
bsd-user/openbsd/target_os_elf.h new file +143 -0
143 lines not on this page · raw message
bsd-user/qemu.h +1 -0
@@ -127,6 +127,7 @@ struct bsd_binprm {char buf[128 ];void *page[MAX_ARG_PAGES ];abi_ulong p; +abi_ulong stringp;int fd;int e_uid, e_gid;int argc, envc;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 30/49] bsd-user: elf cleanup
Quoted 20 lines · Warner Losh
From: Warner Losh<[email protected]>
Move OS-dependent defines into
target_os_elf.h. Move the architectural dependent stuff intotarget_arch_elf.h. Adjustelfload.cto usetarget_create_elf_tablesinstead ofcreate_elf_tables.Signed-off-by Warner Losh<[email protected]>Signed-off-by Stacey Son<[email protected]>Signed-off-by Kyle Evans<[email protected]>Signed-off-by Justin Hibbits<[email protected]>Signed-off-by Alexander Kabaev<[email protected]>Sponsored by: Netflix
--- bsd-user/elfload.c | 190 ++++--------------------------- bsd-user/freebsd/target_os_elf.h | 149 ++++++++++++++++++++++++ bsd-user/netbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/openbsd/target_os_elf.h | 143 +++++++++++++++++++++++ bsd-user/qemu.h | 1 + 5 files changed, 459 insertions(+), 167 deletions(-)
Quoted 3 lines
create mode 100644
bsd-user/freebsd/target_os_elf.hcreate mode 100644bsd-user/netbsd/target_os_elf.hcreate mode 100644bsd-user/openbsd/target_os_elf.h
r~
PATCH 31/49 bsd-user: Remove dead #ifdefs from elfload.c
In reply to Warner LoshFrom: Warner Losh <[email protected]>
LOW_ELF_STACK doesn't exist on FreeBSD and likely never will. Remove it. Likewise, remove an #if 0 block that's not useful
--- bsd-user/elfload.c | 20 -------------------- 1 file changed, 20 deletions(-)
bsd-user/elfload.c +0 -20
@@ -558,9 +558,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,abi_ulong elf_entry, interp_load_addr =0 ;abi_ulong start_code, end_code, start_data, end_data;abi_ulong reloc_func_desc =0 ; -#ifdef LOW_ELF_STACK -abi_ulong elf_stack = ~((abi_ulong )0UL ); -#endif load_addr =0 ; load_bias =0 ;
@@ -761,11 +758,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,exit (-1 ); } -#ifdef LOW_ELF_STACK -if (TARGET_ELF_PAGESTART (elf_ppnt->p_vaddr) < elf_stack) - elf_stack =TARGET_ELF_PAGESTART (elf_ppnt->p_vaddr); -#endif -if (!load_addr_set) { load_addr_set =1 ; load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset;
@@ -823,9 +815,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,close (bprm->fd); -#ifdef LOW_ELF_STACK - info->start_stack = bprm->p = elf_stack -4 ; -#endif bprm->p =target_create_elf_tables (bprm->p, bprm->argc, bprm->envc, bprm->stringp, &elf_ex, load_addr, load_bias, interp_load_addr, info); info->load_addr = reloc_func_desc;
@@ -842,15 +831,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,padzero (elf_bss, elf_brk); -#if 0 -printf ("(start_brk) %x\n" , info->start_brk); -printf ("(end_code) %x\n" , info->end_code); -printf ("(start_code) %x\n" , info->start_code); -printf ("(end_data) %x\n" , info->end_data); -printf ("(start_stack) %x\n" , info->start_stack); -printf ("(brk) %x\n" , info->brk); -#endif - info->entry = elf_entry;return 0 ;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 31/49] bsd-user: Remove dead #ifdefs from elfload.c
Quoted 9 lines · Warner Losh
From: Warner Losh<[email protected]>
LOW_ELF_STACKdoesn't exist on FreeBSD and likely never will. Remove it. Likewise, remove an #if 0 block that's not usefulSigned-off-by Warner Losh<[email protected]>--- bsd-user/elfload.c | 20 -------------------- 1 file changed, 20 deletions(-)
r~
PATCH 32/49 bsd-user: *BSD specific siginfo defintions
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Add FreeBSD, NetBSD and OpenBSD values for the various signal info types and defines to decode different signals to discover more information about the specific signal types.
--- bsd-user/freebsd/target_os_siginfo.h | 145 +++++++++++++++++++++++++++ bsd-user/freebsd/target_os_signal.h | 78 ++++++++++++++ bsd-user/i386/target_arch_signal.h | 94 +++++++++++++++++ bsd-user/netbsd/target_os_siginfo.h | 82 +++++++++++++++ bsd-user/netbsd/target_os_signal.h | 70 +++++++++++++ bsd-user/openbsd/target_os_siginfo.h | 82 +++++++++++++++ bsd-user/openbsd/target_os_signal.h | 70 +++++++++++++ bsd-user/qemu.h | 3 +- bsd-user/syscall_defs.h | 10 -- bsd-user/x86_64/target_arch_signal.h | 94 +++++++++++++++++ 10 files changed, 716 insertions(+), 12 deletions(-) create mode 100644 bsd-user/freebsd/target_os_siginfo.h create mode 100644 bsd-user/freebsd/target_os_signal.h create mode 100644 bsd-user/i386/target_arch_signal.h create mode 100644 bsd-user/netbsd/target_os_siginfo.h create mode 100644 bsd-user/netbsd/target_os_signal.h create mode 100644 bsd-user/openbsd/target_os_siginfo.h create mode 100644 bsd-user/openbsd/target_os_signal.h create mode 100644 bsd-user/x86_64/target_arch_signal.h
bsd-user/freebsd/target_os_siginfo.h new file +145 -0
@@ -0,0 +1,145 @@ +/* +* FreeBSD siginfo related definitions +* +* Copyright (c) 2013 Stacey D. Son +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _TARGET_OS_SIGINFO_H_ +#define _TARGET_OS_SIGINFO_H_ + +#define TARGET_NSIG 128 +#define TARGET_NSIG_BPW (sizeof(uint32_t) * 8) +#define TARGET_NSIG_WORDS (TARGET_NSIG / TARGET_NSIG_BPW) + +/* this struct defines a stack used during syscall handling */ +typedef struct target_sigaltstack { +abi_long ss_sp; +abi_ulong ss_size; +abi_long ss_flags; +}target_stack_t ; + +typedef struct { +uint32_t __bits[TARGET_NSIG_WORDS ]; +}target_sigset_t ; + +struct target_sigaction { +abi_ulong _sa_handler; +int32_t sa_flags; +target_sigset_t sa_mask; +}; + +typedef union target_sigval { +int32_t sival_int; +abi_ulong sival_ptr; +int32_t sigval_int; +abi_ulong sigval_ptr; +}target_sigval_t ; + +typedef struct target_siginfo { +int32_t si_signo;/* signal number */ +int32_t si_errno;/* errno association */ +int32_t si_code;/* signal code */ +int32_t si_pid;/* sending process */ +int32_t si_uid;/* sender's ruid */ +int32_t si_status;/* exit value */ +abi_ulong si_addr;/* faulting instruction */ +union target_sigval si_value;/* signal value */ +union { +struct { +int32_t _trapno;/* machine specific trap code */ + } _fault; + +/* POSIX.1b timers */ +struct { +int32_t _timerid; +int32_t _overrun; + } _timer; + +struct { +int32_t _mqd; + } _mesgp; + +/* SIGPOLL */ +struct { +int _band;/* POLL_IN, POLL_OUT, POLL_MSG */ + } _poll; + +struct { +abi_long __spare1__; +int32_t __spare2_[7 ]; + } __spare__; + } _reason; +}target_siginfo_t ; + +struct target_sigevent { +abi_int sigev_notify; +abi_int sigev_signo; +target_sigval_t sigev_value; +union { +abi_int _threadid; + +/* The kernel (and thus QEMU) never looks at these; +* they're only used as part of the ABI between a +* userspace program and libc. +*/ +struct { +abi_ulong _function; +abi_ulong _attribute; + } _sigev_thread; +abi_ushort _kevent_flags; +abi_long _pad[8 ]; + } _sigev_un; +}; + +#define target_si_signo si_signo +#define target_si_code si_code +#define target_si_errno si_errno +#define target_si_addr si_addr + +/* SIGILL si_codes */ +#define TARGET_ILL_ILLOPC (1)/* Illegal opcode. */ +#define TARGET_ILL_ILLOPN (2)/* Illegal operand. */ +#define TARGET_ILL_ILLADR (3)/* Illegal addressing mode. */ +#define TARGET_ILL_ILLTRP (4)/* Illegal trap. */ +#define TARGET_ILL_PRVOPC (5)/* Privileged opcode. */ +#define TARGET_ILL_PRVREG (6)/* Privileged register. */ +#define TARGET_ILL_COPROC (7)/* Coprocessor error. */ +#define TARGET_ILL_BADSTK (8)/* Internal stack error. */ + +/* SIGSEGV si_codes */ +#define TARGET_SEGV_MAPERR (1)/* address not mapped to object */ +#define TARGET_SEGV_ACCERR (2)/* invalid permissions for mapped +object */ + +/* SIGTRAP si_codes */ +#define TARGET_TRAP_BRKPT (1)/* process beakpoint */ +#define TARGET_TRAP_TRACE (2)/* process trace trap */ + +/* SIGBUS si_codes */ +#define TARGET_BUS_ADRALN (1) +#define TARGET_BUS_ADRERR (2) +#define TARGET_BUS_OBJERR (3) + +/* SIGFPE codes */ +#define TARGET_FPE_INTOVF (1)/* Integer overflow. */ +#define TARGET_FPE_INTDIV (2)/* Integer divide by zero. */ +#define TARGET_FPE_FLTDIV (3)/* Floating point divide by zero. */ +#define TARGET_FPE_FLTOVF (4)/* Floating point overflow. */ +#define TARGET_FPE_FLTUND (5)/* Floating point underflow. */ +#define TARGET_FPE_FLTRES (6)/* Floating point inexact result. */ +#define TARGET_FPE_FLTINV (7)/* Invalid floating point operation. */ +#define TARGET_FPE_FLTSUB (8)/* Subscript out of range. */ + +#endif /* !_TARGET_OS_SIGINFO_H_ */
bsd-user/freebsd/target_os_signal.h new file +78 -0
78 lines not on this page · raw message
bsd-user/i386/target_arch_signal.h new file +94 -0
94 lines not on this page · raw message
bsd-user/netbsd/target_os_siginfo.h new file +82 -0
82 lines not on this page · raw message
bsd-user/netbsd/target_os_signal.h new file +70 -0
70 lines not on this page · raw message
bsd-user/openbsd/target_os_siginfo.h new file +82 -0
82 lines not on this page · raw message
bsd-user/openbsd/target_os_signal.h new file +70 -0
70 lines not on this page · raw message
bsd-user/qemu.h +1 -2
@@ -45,8 +45,7 @@ extern enum BSDType bsd_type;#include "syscall_defs.h" #include "target_syscall.h" #include "target_os_vmparam.h" -//#include "target_os_signal.h" -//#include "hostdep.h" +#include "target_os_signal.h" #include "exec/gdbstub.h" /*
bsd-user/syscall_defs.h +0 -10
@@ -37,8 +37,6 @@* @(#)signal.h 8.2 (Berkeley) 1/21/94 */ -#define TARGET_NSIG 32/* counting 0; could be 33 (mask is 1-32) */ -#define TARGET_SIGHUP 1/* hangup */ #define TARGET_SIGINT 2/* interrupt */ #define TARGET_SIGQUIT 3/* quit */
@@ -72,14 +70,6 @@#define TARGET_SIGUSR1 30/* user defined signal 1 */ #define TARGET_SIGUSR2 31/* user defined signal 2 */ -/* -* Language spec says we must list exactly one parameter, even though we -* actually supply three. Ugh! -*/ -#define TARGET_SIG_DFL (void (*)(int))0 -#define TARGET_SIG_IGN (void (*)(int))1 -#define TARGET_SIG_ERR (void (*)(int))-1 -#define TARGET_SA_ONSTACK 0x0001/* take signal on signal stack */ #define TARGET_SA_RESTART 0x0002/* restart system on signal return */ #define TARGET_SA_RESETHAND 0x0004/* reset to SIG_DFL when taking signal */
bsd-user/x86_64/target_arch_signal.h new file +94 -0
94 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 32/49] bsd-user: *BSD specific siginfo defintions
Quoted 9 lines · Warner Losh
From: Warner Losh<[email protected]>
Add FreeBSD, NetBSD and OpenBSD values for the various signal info types and defines to decode different signals to discover more information about the specific signal types.
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>---
r~
PATCH 33/49 bsd-user: Rewrite target system call definintion glue
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Rewrite target definnitions to interface with the FreeBSD system calls. This covers basic types (time_t, iovec, umtx_time, timespec, timeval, rusage, rwusage) and basic defines (mmap, rusage). Also included are FreeBSD version-specific variations.
--- bsd-user/bsd-mman.h | 121 -------------------- bsd-user/mmap.c | 2 - bsd-user/syscall_defs.h | 247 ++++++++++++++++++++++++++-------------- 3 files changed, 162 insertions(+), 208 deletions(-) delete mode 100644 bsd-user/bsd-mman.h
bsd-user/bsd-mman.h deleted +0 -121
@@ -1,121 +0,0 @@ -/*- -* Copyright (c) 1982, 1986, 1993 -* The Regents of the University of California. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* 4. Neither the name of the University nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* -* @(#)mman.h 8.2 (Berkeley) 1/9/95 -* $FreeBSD: src/sys/sys/mman.h,v 1.42 2008/03/28 04:29:27 ps Exp $ -*/ - -#define TARGET_FREEBSD_MAP_RESERVED0080 0x0080/* previously misimplemented MAP_INHERIT */ -#define TARGET_FREEBSD_MAP_RESERVED0100 0x0100/* previously unimplemented MAP_NOEXTEND */ -#define TARGET_FREEBSD_MAP_STACK 0x0400/* region grows down, like a stack */ -#define TARGET_FREEBSD_MAP_NOSYNC 0x0800/* page to but do not sync underlying file */ - -#define TARGET_FREEBSD_MAP_FLAGMASK 0x1ff7 - -/* $NetBSD: mman.h,v 1.42 2008/11/18 22:13:49 ad Exp $ */ - -/*- -* Copyright (c) 1982, 1986, 1993 -* The Regents of the University of California. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* 3. Neither the name of the University nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* -* @(#)mman.h 8.2 (Berkeley) 1/9/95 -*/ -#define TARGET_NETBSD_MAP_INHERIT 0x0080/* region is retained after exec */ -#define TARGET_NETBSD_MAP_TRYFIXED 0x0400/* attempt hint address, even within break */ -#define TARGET_NETBSD_MAP_WIRED 0x0800/* mlock() mapping when it is established */ - -#define TARGET_NETBSD_MAP_STACK 0x2000/* allocated from memory, swap space (stack) */ - -#define TARGET_NETBSD_MAP_FLAGMASK 0x3ff7 - -/* $OpenBSD: mman.h,v 1.18 2003/07/21 22:52:19 tedu Exp $ */ -/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc Exp $ */ - -/*- -* Copyright (c) 1982, 1986, 1993 -* The Regents of the University of California. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* 1. Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* 2. Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the distribution. -* 3. Neither the name of the University nor the names of its contributors -* may be used to endorse or promote products derived from this software -* without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -* SUCH DAMAGE. -* -* @(#)mman.h 8.1 (Berkeley) 6/2/93 -*/ - -#define TARGET_OPENBSD_MAP_INHERIT 0x0080/* region is retained after exec */ -#define TARGET_OPENBSD_MAP_NOEXTEND 0x0100/* for MAP_FILE, don't change file size */ -#define TARGET_OPENBSD_MAP_TRYFIXED 0x0400/* attempt hint address, even within heap */ - -#define TARGET_OPENBSD_MAP_FLAGMASK 0x17f7 - -// XXX -#define TARGET_BSD_MAP_FLAGMASK 0x3ff7
bsd-user/mmap.c +0 -2
@@ -20,8 +20,6 @@#include "qemu.h" #include "qemu-common.h" -#include "bsd-mman.h" -#include "exec/exec-all.h" //#define DEBUG_MMAP
bsd-user/syscall_defs.h +162 -85
265 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 33/49] bsd-user: Rewrite target system call definintion glue
Quoted 7 lines · Warner Losh
From: Warner Losh <[email protected]>
Rewrite target definnitions to interface with the FreeBSD system calls. This covers basic types (
time_t, iovec,umtx_time, timespec, timeval, rusage, rwusage) and basic defines (mmap, rusage). Also included are FreeBSD version-specific variations.
Quoted 8 lines
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-mman.h | 121 -------------------- bsd-user/mmap.c | 2 - bsd-user/syscall_defs.h | 247 ++++++++++++++++++++++++++-------------- 3 files changed, 162 insertions(+), 208 deletions(-)delete mode 100644
bsd-user/bsd-mman.h
Oof. Well, I guess it's progress, but it's hard to read.
bsd-user/syscall_defs.h line 127
Quoted 7 lines
bsd-user/syscall_defs.h +7
-0+struct target_freebsd_timeval { +target_freebsd_time_t tv_sec;/* seconds */ +target_freebsd_suseconds_t tv_usec;/* and microseconds */ +#if !defined(TARGET_I386 ) &&TARGET_ABI_BITS ==32 +abi_long _pad; +#endif +} __packed;
I question the use of packed here. You do realize that removes all alignment requirements? This is probably not what you want. It's certainly not present in the real freebsd _timeval.h.
Similarly with _timespec.h.
r~
Re: [PATCH for 6.2 33/49] bsd-user: Rewrite target system call definintion glue
Quoted 19 lines · Richard Henderson
Quoted 5 lines · Warner Losh
From: Warner Losh <[email protected]>
Rewrite target definnitions to interface with the FreeBSD system calls. This covers basic types (time_t, iovec,umtx_time, timespec, timeval, rusage, rwusage) and basic defines (mmap, rusage). Also included are FreeBSD version-specific variations.Quoted 8 lines
Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/bsd-mman.h | 121 -------------------- bsd-user/mmap.c | 2 - bsd-user/syscall_defs.h | 247 ++++++++++++++++++++++++++-------------- 3 files changed, 162 insertions(+), 208 deletions(-) delete mode 100644 bsd-user/bsd-mman.h
Quoted 1 line
Oof. Well, I guess it's progress, but it's hard to read.
I too find it… tricky… Once we have it all integrated and upstream matches our fork, I’d be happy to do some cleanup in this area if you have good suggestions.
Quoted 11 lines
bsd-user/syscall_defs.h line 127
Quoted 7 lines
bsd-user/syscall_defs.h +7
-0+struct target_freebsd_timeval { +target_freebsd_time_t tv_sec;/* seconds */ +target_freebsd_suseconds_t tv_usec;/* and microseconds */ +#if !defined(TARGET_I386 ) &&TARGET_ABI_BITS ==32 +abi_long _pad; +#endif +} __packed;I question the use of packed here. You do realize that removes all alignment requirements? This is probably not what you want. It's certainly not present in the real freebsd
_timeval.h.Similarly with
_timespec.h.
Yea, these are wrong. they used to be a thing, but as you point out, __packed doesn’t do what people think it does… I’ll remove.
Warner
PATCH 34/49 bsd-user: Fix initializtion of task state
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Fix a number of mismerges in initializing the task state. Save a copy of bprm in this structure and move it earlier before starting to setup other state. Remove linux specific procfs access to find minimal vm address that likely is here through a misguided merge. Remove duplicate initialization as well.
--- bsd-user/main.c | 42 ++++-------------------------------------- bsd-user/qemu.h | 1 + 2 files changed, 5 insertions(+), 38 deletions(-)
bsd-user/main.c +4 -38
@@ -205,7 +205,7 @@ int main(int argc, char **argv)struct target_pt_regs regs1, *regs = ®s1;struct image_info info1, *info = &info1;struct bsd_binprm bprm; -TaskState ts1, *ts = &ts1; +TaskState *ts;CPUArchState *env;CPUState *cpu;int optind, rv;
@@ -407,31 +407,7 @@ int main(int argc, char **argv)*/ guest_base =HOST_PAGE_ALIGN (guest_base); -/* -* Read in mmap_min_addr kernel parameter. This value is used -* When loading the ELF image to determine whether guest_base -* is needed. -* -* When user has explicitly set the quest base, we skip this -* test. -*/ -if (!have_guest_base) { -FILE *fp; - - fp =fopen ("/proc/sys/vm/mmap_min_addr" ,"r" ); -if (fp !=NULL ) { -unsigned long tmp; -if (fscanf (fp,"%lu" , &tmp) ==1 ) { - mmap_min_addr = tmp; -qemu_log_mask (CPU_LOG_PAGE ,"host mmap_min_addr=0x%lx\n" , - mmap_min_addr); - } -fclose (fp); - } - } - -if (loader_exec (filename, argv+optind, target_environ, regs, info, - &bprm) !=0 ) { +if (loader_exec (filename, argv+optind, target_environ, regs, info, &bprm)) {printf ("Error loading %s\n" , filename);_exit (1 ); }
@@ -459,21 +435,11 @@ int main(int argc, char **argv)qemu_log ("entry 0x" TARGET_ABI_FMT_lx"\n" , info->entry); } -target_set_brk (info->brk); -syscall_init (); -signal_init (); - -/* -* Now that we've loaded the binary, GUEST_BASE is fixed. Delay -* generating the prologue until now so that the prologue can take -* the real value of GUEST_BASE into account. -*/ -tcg_prologue_init (tcg_ctx); -/* build Task State */ -memset (ts,0 ,sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts); ts->info = info; + ts->bprm = &bprm; cpu->opaque = ts;target_set_brk (info->brk);
bsd-user/qemu.h +1 -0
@@ -90,6 +90,7 @@ typedef struct TaskState {pid_t ts_tid;/* tid (or pid) of this task */ struct TaskState *next; +struct bsd_binprm *bprm;int used;/* non zero if used */ struct image_info *info;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 34/49] bsd-user: Fix initializtion of task state
Quoted 14 lines · Warner Losh
bsd-user/main.c +0
-10@@ -459,21 +435,11 @@ int main(int argc, char **argv)qemu_log ("entry 0x" TARGET_ABI_FMT_lx"\n" , info->entry); } -target_set_brk (info->brk); -syscall_init (); -signal_init (); - -/* -* Now that we've loaded the binary, GUEST_BASE is fixed. Delay -* generating the prologue until now so that the prologue can take -* the real value of GUEST_BASE into account. -*/ -tcg_prologue_init (tcg_ctx);
bsd-user/main.c int main(int argc, char **argv) · line 445
Quoted 10 lines
bsd-user/main.c +2
-2-/* build Task State */ -memset (ts,0 ,sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts); ts->info = info; + ts->bprm = &bprm; cpu->opaque = ts;target_set_brk (info->brk);
It looks like some of this damage occurs in patch 22 ("bsd-user: Move per-cpu code into target_arch_cpu.h") and could reasonably be squashed back.
Otherwise,
r~
Re: [PATCH for 6.2 34/49] bsd-user: Fix initializtion of task state
Quoted 24 lines · Richard Henderson
Quoted 23 lines · Warner Losh
bsd-user/main.c +2
-12@@ -459,21 +435,11 @@ int main(int argc, char **argv)qemu_log ("entry 0x" TARGET_ABI_FMT_lx"\n" , info->entry); } -target_set_brk (info->brk); -syscall_init (); -signal_init (); - -/* -* Now that we've loaded the binary, GUEST_BASE is fixed. Delay -* generating the prologue until now so that the prologue can take -* the real value of GUEST_BASE into account. -*/ -tcg_prologue_init (tcg_ctx); -/* build Task State */ -memset (ts,0 ,sizeof (TaskState)); + ts =g_new0 (TaskState,1 );init_task_state (ts); ts->info = info; + ts->bprm = &bprm; cpu->opaque = ts;
Quoted 9 lines
bsd-user/main.c int main(int argc, char **argv) · line 445
Quoted 1 line
bsd-user/main.c +0
-0target_set_brk (info->brk);It looks like some of this damage occurs in patch 22 ("bsd-user: Move per-cpu code into
target_arch_cpu.h") and could reasonably be squashed back.Otherwise,
Reviewed-by Richard Henderson <[email protected]>
I took the easy way and folded them together. Thanks for the tip.
Warner
PATCH 35/49 bsd-user: remove error_init
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Error reporting isn't used, so gc it until it's used.
--- bsd-user/main.c | 2 -- 1 file changed, 2 deletions(-)
bsd-user/main.c +0 -2
@@ -34,7 +34,6 @@#include "qapi/error.h" #include "qemu.h" #include "qemu/config-file.h" -#include "qemu/error-report.h" #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h"
@@ -223,7 +222,6 @@ int main(int argc, char **argv)save_proc_pathname (argv[0 ]); -error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM );
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 35/49] bsd-user: remove error_init
Quoted 5 lines · Warner Losh
From: Warner Losh <[email protected]>
Error reporting isn't used, so gc it until it's used.
Signed-off-by Warner Losh <[email protected]>
That's not true. At minimum, tcg/ uses Error during alloc_code_gen_buffer.
r~
Quoted 25 lines
--- bsd-user/main.c | 2 -- 1 file changed, 2 deletions(-)bsd-user/main.c +0
-2@@ -34,7 +34,6 @@#include "qapi/error.h" #include "qemu.h" #include "qemu/config-file.h" -#include "qemu/error-report.h" #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h" @@ -223,7 +222,6 @@ int main(int argc, char **argv)save_proc_pathname (argv[0 ]); -error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM );
Re: [PATCH for 6.2 35/49] bsd-user: remove error_init
Quoted 9 lines · Richard Henderson
Quoted 5 lines · Warner Losh
From: Warner Losh <[email protected]>
Error reporting isn't used, so gc it until it's used.
Signed-off-by Warner Losh <[email protected]>That's not true. At minimum, tcg/ uses Error during
alloc_code_gen_buffer.
I'm not sure how I overlooked that, so I'll just drop this patch. Thanks for the
good eye.
Warner
Quoted 29 lines
r~
Quoted 25 lines
--- bsd-user/main.c | 2 -- 1 file changed, 2 deletions(-)bsd-user/main.c +0
-2@@ -34,7 +34,6 @@#include "qapi/error.h" #include "qemu.h" #include "qemu/config-file.h" -#include "qemu/error-report.h" #include "qemu/path.h" #include "qemu/help_option.h" #include "qemu/module.h" @@ -223,7 +222,6 @@ int main(int argc, char **argv)save_proc_pathname (argv[0 ]); -error_init (argv[0 ]);module_call_init (MODULE_INIT_TRACE );qemu_init_cpu_list ();module_call_init (MODULE_INIT_QOM );
PATCH 36/49 bsd-user: Make cpu_model and cpu_type visible to all of main.c
In reply to Warner LoshFrom: Warner Losh <[email protected]>
cpu_model and cpu_type will be used future commits, so move them from main() scoped to file scoped.
--- bsd-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
bsd-user/main.c +2 -2
@@ -51,6 +51,8 @@int singlestep;unsigned long mmap_min_addr;uintptr_t guest_base; +static const char *cpu_model; +static const char *cpu_type;bool have_guest_base;unsigned long reserved_va;
@@ -197,8 +199,6 @@ static void save_proc_pathname(char *argv0)int main (int argc,char **argv) {const char *filename; -const char *cpu_model; -const char *cpu_type;const char *log_file =NULL ;const char *log_mask =NULL ;struct target_pt_regs regs1, *regs = ®s1;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 36/49] bsd-user: Make cpu_model and cpu_type visible to all of main.c
Quoted 9 lines · Warner Losh
From: Warner Losh<[email protected]>
cpu_modelandcpu_typewill be used future commits, so move them frommain()scoped to file scoped.Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
r~
PATCH 37/49 bsd-user: update debugging in mmap.c
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Update the debugging code for new features and different targets.
--- bsd-user/mmap.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-)
bsd-user/mmap.c +30 -19
@@ -68,8 +68,8 @@ int target_mprotect(abi_ulong start, abi_ulong len, int prot)int prot1, ret;#ifdef DEBUG_MMAP -printf ("mprotect: start=0x" TARGET_FMT_lx -" len=0x" TARGET_FMT_lx" prot=%c%c%c\n" , start, len, +printf ("mprotect: start=0x" TARGET_ABI_FMT_lx +"len=0x" TARGET_ABI_FMT_lx" prot=%c%c%c\n" , start, len, prot &PROT_READ ?'r' :'-' , prot &PROT_WRITE ?'w' :'-' , prot &PROT_EXEC ?'x' :'-' );
@@ -250,28 +250,37 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,mmap_lock ();#ifdef DEBUG_MMAP { -printf ("mmap: start=0x" TARGET_FMT_lx -" len=0x" TARGET_FMT_lx" prot=%c%c%c flags=" , +printf ("mmap: start=0x" TARGET_ABI_FMT_lx +" len=0x" TARGET_ABI_FMT_lx" prot=%c%c%c flags=" , start, len, prot &PROT_READ ?'r' :'-' , prot &PROT_WRITE ?'w' :'-' , prot &PROT_EXEC ?'x' :'-' ); +if (flags &MAP_ALIGNMENT_MASK ) +printf ("MAP_ALIGNED(%u) " , (flags &MAP_ALIGNMENT_MASK ) >>MAP_ALIGNMENT_SHIFT ); +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200035 +if (flags &MAP_GUARD ) +printf ("MAP_GUARD " ); +#endif if (flags &MAP_FIXED )printf ("MAP_FIXED " ); -if (flags &MAP_ANON ) +if (flags &MAP_ANONYMOUS )printf ("MAP_ANON " ); -switch (flags &TARGET_BSD_MAP_FLAGMASK ) { -case MAP_PRIVATE : -printf ("MAP_PRIVATE " ); -break ; -case MAP_SHARED : -printf ("MAP_SHARED " ); -break ; -default : -printf ("[MAP_FLAGMASK=0x%x] " , flags &TARGET_BSD_MAP_FLAGMASK ); -break ; - } -printf ("fd=%d offset=" TARGET_FMT_lx"\n" , fd, offset); +#ifdef MAP_EXCL +if (flags &MAP_EXCL ) +printf ("MAP_EXCL " ); +#endif +if (flags &MAP_PRIVATE ) +printf ("MAP_PRIVATE " ); +if (flags &MAP_SHARED ) +printf ("MAP_SHARED " ); +if (flags &MAP_NOCORE ) +printf ("MAP_NOCORE " ); +#ifdef MAP_STACK +if (flags &MAP_STACK ) +printf ("MAP_STACK " ); +#endif +printf ("fd=%d offset=0x%llx\n" , fd, offset); }#endif
@@ -399,7 +408,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,page_set_flags (start, start + len, prot |PAGE_VALID ); the_end:#ifdef DEBUG_MMAP -printf ("ret=0x" TARGET_FMT_lx"\n" , start); +printf ("ret=0x" TARGET_ABI_FMT_lx"\n" , start);page_dump (stdout);printf ("\n" );#endif
@@ -416,7 +425,9 @@ int target_munmap(abi_ulong start, abi_ulong len)int prot, ret;#ifdef DEBUG_MMAP -printf ("munmap: start=0x%lx len=0x%lx\n" , start, len); +printf ("munmap: start=0x" TARGET_ABI_FMT_lx" len=0x" + TARGET_ABI_FMT_lx"\n" , + start, len);#endif if (start & ~TARGET_PAGE_MASK )return -EINVAL ;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 37/49] bsd-user: update debugging in mmap.c
Quoted 11 lines · Warner Losh
From: Warner Losh<[email protected]>
Update the debugging code for new features and different targets.
Signed-off-by Mikaël Urankar<[email protected]>Signed-off-by Sean Bruno<[email protected]>Signed-off-by Kyle Evans<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/mmap.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-)
For the to-do list: convert to qemu_log_mask or tracepoints.
r~
Re: [PATCH for 6.2 37/49] bsd-user: update debugging in mmap.c
Quoted 13 lines · Richard Henderson
Quoted 11 lines · Warner Losh
From: Warner Losh<[email protected]>
Update the debugging code for new features and different targets.
Signed-off-by Mikaël Urankar<[email protected]>Signed-off-by Sean Bruno<[email protected]>Signed-off-by Kyle Evans<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/mmap.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-)
Quoted 2 lines
Thanks
Quoted 2 lines
For the to-do list: convert to
qemu_log_maskor tracepoints.
Will do. Should I create a bsd-user/TODO file with all these in it (or rather, should I
upstream the one I've already created)?
Warner
Re: [PATCH for 6.2 37/49] bsd-user: update debugging in mmap.c
Quoted 5 lines · Warner Losh
For the to-do list: convert to
qemu_log_maskor tracepoints.Will do. Should I create a bsd-user/TODO file with all these in it (or rather, should I upstream the one I've already created)?
Could do. Dunno if its easier or not, but we also have a set of Issues with the "Bite Sized" tag for small cleanups like this.
r~
PATCH 38/49 bsd-user: Update mapping to handle reserved and starting conditions
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Update the reserved base based on what platform we're on, as well as the start of the mmap range. Update routines that find va ranges to interact with the reserved ranges as well as properly align the mapping (this is especially important for targets whose page size does not match the host's). Loop where appropriate when the initial address space offered by mmap does not meet the contraints.
--- bsd-user/main.c | 23 ++- bsd-user/mmap.c | 372 ++++++++++++++++++++++++++++++++++++++++-------- bsd-user/qemu.h | 5 +- 3 files changed, 335 insertions(+), 65 deletions(-)
bsd-user/main.c +22 -1
@@ -49,12 +49,29 @@#include "target_arch_cpu.h" int singlestep; -unsigned long mmap_min_addr;uintptr_t guest_base;static const char *cpu_model;static const char *cpu_type;bool have_guest_base; +#if (TARGET_LONG_BITS ==32 ) && (HOST_LONG_BITS ==64 ) +/* +* When running 32-on-64 we should make sure we can fit all of the possible +* guest address space into a contiguous chunk of virtual host memory. +* +* This way we will never overlap with our own libraries or binaries or stack +* or anything else that QEMU maps. +*/ +# ifdef TARGET_MIPS +/* MIPS only supports 31 bits of virtual address space for user space */ +unsigned long reserved_va =0x77000000 ; +# elif defined(TARGET_PPC64 ) +unsigned long reserved_va =0xfffff000 ; +# else +unsigned long reserved_va =0xf7000000 ; +# endif +#else unsigned long reserved_va; +#endif static const char *interp_prefix =CONFIG_QEMU_INTERP_PREFIX ;const char *qemu_uname_release;
@@ -399,6 +416,10 @@ int main(int argc, char **argv) target_environ =envlist_to_environ (envlist,NULL );envlist_free (envlist); +if (reserved_va) { + mmap_next_start = reserved_va; + } +/* * Now that page sizes are configured we can do * proper page alignment for guest_base.
bsd-user/mmap.c +310 -62
460 lines not on this page · raw message
bsd-user/qemu.h +3 -2
@@ -104,7 +104,6 @@ typedef struct TaskState {void init_task_state (TaskState *ts);extern const char *qemu_uname_release; -extern unsigned long mmap_min_addr;/* * TARGET_ARG_MAX defines the number of bytes allocated for arguments
@@ -212,13 +211,15 @@ abi_long do_sigaltstack(abi_ulong uss_addr, abi_ulong uoss_addr, abi_ulong sp);/* mmap.c */ int target_mprotect (abi_ulong start,abi_ulong len,int prot);abi_long target_mmap (abi_ulong start,abi_ulong len,int prot, -int flags,int fd,abi_ulong offset); +int flags,int fd,off_t offset);int target_munmap (abi_ulong start,abi_ulong len);abi_long target_mremap (abi_ulong old_addr,abi_ulong old_size,abi_ulong new_size,unsigned long flags,abi_ulong new_addr);int target_msync (abi_ulong start,abi_ulong len,int flags);extern unsigned long last_brk; +extern abi_ulong mmap_next_start; +abi_ulong mmap_find_vma (abi_ulong start,abi_ulong size);void mmap_fork_start (void );void mmap_fork_end (int child);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 38/49] bsd-user: Update mapping to handle reserved and starting conditions
Quoted 40 lines · Warner Losh
From: Warner Losh <[email protected]>
Update the reserved base based on what platform we're on, as well as the start of the mmap range. Update routines that find va ranges to interact with the reserved ranges as well as properly align the mapping (this is especially important for targets whose page size does not match the host's). Loop where appropriate when the initial address space offered by mmap does not meet the contraints.
Signed-off-by Mikaël Urankar <[email protected]>Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/main.c | 23 ++- bsd-user/mmap.c | 372 ++++++++++++++++++++++++++++++++++++++++-------- bsd-user/qemu.h | 5 +- 3 files changed, 335 insertions(+), 65 deletions(-)bsd-user/main.c +9
-1@@ -49,12 +49,29 @@#include "target_arch_cpu.h" int singlestep; -unsigned long mmap_min_addr;uintptr_t guest_base;static const char *cpu_model;static const char *cpu_type;bool have_guest_base; +#if (TARGET_LONG_BITS ==32 ) && (HOST_LONG_BITS ==64 ) +/* +* When running 32-on-64 we should make sure we can fit all of the possible +* guest address space into a contiguous chunk of virtual host memory. +* +* This way we will never overlap with our own libraries or binaries or stack +* or anything else that QEMU maps. +*/ +# ifdef TARGET_MIPS
bsd-user/main.c line 74
Quoted 10 lines
bsd-user/main.c +9
-0+/* MIPS only supports 31 bits of virtual address space for user space */ +unsigned long reserved_va =0x77000000 ; +# elif defined(TARGET_PPC64 ) +unsigned long reserved_va =0xfffff000 ; +# else +unsigned long reserved_va =0xf7000000 ; +# endif +#else unsigned long reserved_va; +#endif
All of these 7's look to be copying an old linux-user bug. I cleaned this up in 18e80c55bb6.
Otherwise,
I would hope one day this memory management could be shared between the user-only implementations. It's complicated enough...
r~
Re: [PATCH for 6.2 38/49] bsd-user: Update mapping to handle reserved and starting conditions
Quoted 40 lines · Richard Henderson
Quoted 24 lines · Warner Losh
From: Warner Losh <[email protected]>
Update the reserved base based on what platform we're on, as well as the start of the mmap range. Update routines that find va ranges to interact with the reserved ranges as well as properly align the mapping (this is especially important for targets whose page size does not match the host's). Loop where appropriate when the initial address space offered by mmap does not meet the contraints.
Signed-off-by Mikaël Urankar <[email protected]>Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>--- bsd-user/main.c | 23 ++- bsd-user/mmap.c | 372 ++++++++++++++++++++++++++++++++++++++++-------- bsd-user/qemu.h | 5 +- 3 files changed, 335 insertions(+), 65 deletions(-)bsd-user/main.c +0
-0@@ -49,12 +49,29 @@#include "target_arch_cpu.h" bsd-user/main.c line 58
Quoted 10 lines
bsd-user/main.c +3
-1int singlestep; -unsigned long mmap_min_addr;uintptr_t guest_base;static const char *cpu_model;static const char *cpu_type;bool have_guest_base; +#if (TARGET_LONG_BITS ==32 ) && (HOST_LONG_BITS ==64 ) +/* +* When running 32-on-64 we should make sure we can fit all of the possible
bsd-user/main.c
Quoted 3 lines
bsd-user/main.c +3
-0+* guest address space into a contiguous chunk of virtual host memory. +* +* This way we will never overlap with our own libraries or binaries or stack
Quoted 17 lines
bsd-user/main.c line 74
Quoted 13 lines
bsd-user/main.c +12
-0+* or anything else that QEMU maps. +*/ +# ifdef TARGET_MIPS +/* MIPS only supports 31 bits of virtual address space for user space */ +unsigned long reserved_va =0x77000000 ; +# elif defined(TARGET_PPC64 ) +unsigned long reserved_va =0xfffff000 ; +# else +unsigned long reserved_va =0xf7000000 ; +# endif +#else unsigned long reserved_va; +#endif All of these 7's look to be copying an old linux-user bug. I cleaned this up in
18e80c55bb6.
Oh nice. I'd missed that one... a bit before I started hacking on bsd-user, but quite nice indeed.
Quoted 7 lines
Otherwise,
I would hope one day this memory management could be shared between the user-only
implementations. It's complicated enough...
Honestly, one reason I want to get "caught up" with upstream is for such a refactor. There's
so much duplication that it's hard to keep up.
Warner
PATCH 39/49 bsd-user: Need to reset CPU after creation.
In reply to Warner LoshFrom: Warner Losh <[email protected]>
--- bsd-user/main.c | 2 ++ 1 file changed, 2 insertions(+)
bsd-user/main.c +2 -0
@@ -405,8 +405,10 @@ int main(int argc, char **argv)accel_init_interfaces (ac); ac->init_machine (NULL ); } + cpu =cpu_create (cpu_type); env = cpu->env_ptr; +cpu_reset (cpu); thread_cpu = cpu;if (getenv ("QEMU_STRACE" )) {
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 39/49] bsd-user: Need to reset CPU after creation.
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 2 ++ 1 file changed, 2 insertions(+)
Slightly amusing that the line was removed in patch 1, because it was ifdefed.
r~
Re: [PATCH for 6.2 39/49] bsd-user: Need to reset CPU after creation.
Quoted 8 lines · Richard Henderson
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 2 ++ 1 file changed, 2 insertions(+)
Quoted 5 lines
Reviewed-by Richard Henderson <[email protected]>Slightly amusing that the line was removed in patch 1, because it was ifdefed.
Worth folding?
And good eye!
Warner
Re: [PATCH for 6.2 39/49] bsd-user: Need to reset CPU after creation.
Quoted 3 lines · Warner Losh
Slightly amusing that the line was removed in patch 1, because it was ifdefed.
Worth folding?
Might as well.
r~
PATCH 40/49 bsd-user: Add target_arch_reg to describe a target's register set
In reply to Warner LoshFrom: Warner Losh <[email protected]>
target_reg_t is the normal register. target_fpreg_t is the floating point registers. target_copy_regs copies the registers out of CPU context for things like core dumps.
--- bsd-user/i386/target_arch_reg.h | 82 +++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_reg.h | 92 +++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 bsd-user/i386/target_arch_reg.h create mode 100644 bsd-user/x86_64/target_arch_reg.h
bsd-user/i386/target_arch_reg.h new file +82 -0
@@ -0,0 +1,82 @@ +/* +* FreeBSD i386 register structures +* +* Copyright (c) 2015 Stacey Son +* All rights reserved. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_ARCH_REG_H_ +#define _TARGET_ARCH_REG_H_ + +/* See sys/i386/include/reg.h */ +typedef struct target_reg { +uint32_t r_fs; +uint32_t r_es; +uint32_t r_ds; +uint32_t r_edi; +uint32_t r_esi; +uint32_t r_ebp; +uint32_t r_isp; +uint32_t r_ebx; +uint32_t r_edx; +uint32_t r_ecx; +uint32_t r_eax; +uint32_t r_trapno; +uint32_t r_err; +uint32_t r_eip; +uint32_t r_cs; +uint32_t r_eflags; +uint32_t r_esp; +uint32_t r_ss; +uint32_t r_gs; +}target_reg_t ; + +typedef struct target_fpreg { +uint32_t fpr_env[7 ]; +uint8_t fpr_acc[8 ][10 ]; +uint32_t fpr_ex_sw; +uint8_t fpr_pad[64 ]; +}target_fpreg_t ; + +static inline void target_copy_regs (target_reg_t *regs,const CPUX86State *env) +{ + + regs->r_fs = env->segs[R_FS ].selector &0xffff ; + regs->r_es = env->segs[R_ES ].selector &0xffff ; + regs->r_ds = env->segs[R_DS ].selector &0xffff ; + + regs->r_edi = env->regs[R_EDI ]; + regs->r_esi = env->regs[R_ESI ]; + regs->r_ebp = env->regs[R_EBP ]; +/* regs->r_isp = env->regs[R_ISP]; XXX */ + regs->r_ebx = env->regs[R_EBX ]; + regs->r_edx = env->regs[R_EDX ]; + regs->r_ecx = env->regs[R_ECX ]; + regs->r_eax = env->regs[R_EAX ]; +/* regs->r_trapno = env->regs[R_TRAPNO]; XXX */ + regs->r_err = env->error_code;/* XXX ? */ + regs->r_eip = env->eip; + + regs->r_cs = env->segs[R_CS ].selector &0xffff ; + + regs->r_eflags = env->eflags; + regs->r_esp = env->regs[R_ESP ]; + + regs->r_ss = env->segs[R_SS ].selector &0xffff ; + regs->r_gs = env->segs[R_GS ].selector &0xffff ; +} + +#endif /* !_TARGET_ARCH_REG_H_ */
bsd-user/x86_64/target_arch_reg.h new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 40/49] bsd-user: Add target_arch_reg to describe a target's register set
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
target_reg_tis the normal register.target_fpreg_tis the floating point registers.target_copy_regscopies the registers out of CPU context for things like core dumps.
Quoted 8 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/i386/target_arch_reg.h | 82 +++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_reg.h | 92 +++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+)create mode 100644
bsd-user/i386/target_arch_reg.hcreate mode 100644bsd-user/x86_64/target_arch_reg.h
While this mirrors what linux-user does, I've wondered if this wasn't just pointless copying. If a bit of code knows enough about a target to fill in its core dump, why wouldn't it just copy the data straight from CPUArchState instead of using these intermediaries?
r~
Re: [PATCH for 6.2 40/49] bsd-user: Add target_arch_reg to describe a target's register set
Quoted 18 lines · Richard Henderson
Quoted 4 lines · Warner Losh
From: Warner Losh<[email protected]>
target_reg_tis the normal register.target_fpreg_tis the floating point registers.target_copy_regscopies the registers out of CPU context for things like core dumps.Quoted 8 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/i386/target_arch_reg.h | 82 +++++++++++++++++++++++++++ bsd-user/x86_64/target_arch_reg.h | 92 +++++++++++++++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 bsd-user/i386/target_arch_reg.h create mode 100644 bsd-user/x86_64/target_arch_reg.h
Quoted 3 lines
Reviewed-by Richard Henderson <[email protected]>While this mirrors what linux-user does, I've wondered if this wasn't just pointless copying. If a bit of code knows enough about a target to fill in its core dump, why wouldn't it just copy the data straight from CPUArchState instead of using these intermediaries?
I believe the forthcoming core dump code copies this opaque structure into the core dump….
However, this is an excellent todo item to see if there’s something that can be refined.
Warner
PATCH 41/49 bsd-user: Add target_os_user.h to capture the user/kernel structures
In reply to Warner LoshFrom: Warner Losh <[email protected]>
This file evolved over the years to capture the user/kernel interfaces, including those that changed over time.
--- bsd-user/freebsd/target_os_user.h | 429 ++++++++++++++++++++++++++++++ 1 file changed, 429 insertions(+) create mode 100644 bsd-user/freebsd/target_os_user.h
bsd-user/freebsd/target_os_user.h new file +429 -0
@@ -0,0 +1,429 @@ +/* +* sys/user.h definitions +* +* Copyright (c) 2015 Stacey D. Son (sson at FreeBSD) +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef _TARGET_OS_USER_H_ +#define _TARGET_OS_USER_H_ + +/* +* from sys/priority.h +*/ +struct target_priority { +uint8_t pri_class;/* Scheduling class. */ +uint8_t pri_level;/* Normal priority level. */ +uint8_t pri_native;/* Priority before propogation. */ +uint8_t pri_user;/* User priority based on p_cpu and p_nice. */ +}; + +/* +* sys/caprights.h +*/ +#define TARGET_CAP_RIGHTS_VERSION 0 + +typedef struct target_cap_rights { +uint64_t cr_rights[TARGET_CAP_RIGHTS_VERSION +2 ]; +}target_cap_rights_t ; + +/* +* From sys/_socketaddr_storage.h +* +*/ +#define TARGET_SS_MAXSIZE 128U +#define TARGET_SS_ALIGNSIZE (sizeof(__int64_t)) +#define TARGET_SS_PAD1SIZE (TARGET_SS_ALIGNSIZE - sizeof(unsigned char) - \ + sizeof(uint8_t)) +#define TARGET_SS_PAD2SIZE (TARGET_SS_MAXSIZE - sizeof(unsigned char) - \ + sizeof(uint8_t) - TARGET_SS_PAD1SIZE - TARGET_SS_ALIGNSIZE) + +struct target_sockaddr_storage { +unsigned char ss_len;/* address length */ +uint8_t ss_family;/* address family */ +char __ss_pad1[TARGET_SS_PAD1SIZE ]; +__int64_t __ss_align;/* force desired struct alignment */ +char __ss_pad2[TARGET_SS_PAD2SIZE ]; +}; + +/* +* from sys/user.h +*/ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +#define TARGET_KI_NSPARE_INT 2 +#elif defined(__FreeBSD_version) && __FreeBSD_version >=1100000 +#define TARGET_KI_NSPARE_INT 4 +#elif defined(__FreeBSD_version) && __FreeBSD_version >=1000000 +#define TARGET_KI_NSPARE_INT 7 +#else +#define TARGET_KI_NSPARE_INT 9 +#endif /* ! __FreeBSD_version >= 1000000 */ +#define TARGET_KI_NSPARE_LONG 12 +#define TARGET_KI_NSPARE_PTR 6 + +#define TARGET_WMESGLEN 8 +#define TARGET_LOCKNAMELEN 8 +#define TARGET_TDNAMLEN 16 +#define TARGET_COMMLEN 19 +#define TARGET_KI_EMULNAMELEN 16 +#define TARGET_KI_NGROUPS 16 +#define TARGET_LOGNAMELEN 17 +#define TARGET_LOGINCLASSLEN 17 + +#define TARGET_KF_TYPE_NONE 0 +#define TARGET_KF_TYPE_VNODE 1 +#define TARGET_KF_TYPE_SOCKET 2 +#define TARGET_KF_TYPE_PIPE 3 +#define TARGET_KF_TYPE_FIFO 4 +#define TARGET_KF_TYPE_KQUEUE 5 +#define TARGET_KF_TYPE_CRYPTO 6 +#define TARGET_KF_TYPE_MQUEUE 7 +#define TARGET_KF_TYPE_SHM 8 +#define TARGET_KF_TYPE_SEM 9 +#define TARGET_KF_TYPE_PTS 10 +#define TARGET_KF_TYPE_PROCDESC 11 +#define TARGET_KF_TYPE_DEV 12 +#define TARGET_KF_TYPE_UNKNOWN 255 + +struct target_kinfo_proc { +int32_t ki_structsize;/* size of this structure */ +int32_t ki_layout;/* reserved: layout identifier */ +abi_ulong ki_args;/* address of command arguments */ +abi_ulong ki_paddr;/* address of proc */ +abi_ulong ki_addr;/* kernel virtual addr of u-area */ +abi_ulong ki_tracep;/* pointer to trace file */ +abi_ulong ki_textvp;/* pointer to executable file */ +abi_ulong ki_fd;/* pointer to open file info */ +abi_ulong ki_vmspace;/* pointer to kernel vmspace struct */ +abi_ulong ki_wchan;/* sleep address */ +int32_t ki_pid;/* Process identifier */ +int32_t ki_ppid;/* parent process id */ +int32_t ki_pgid;/* process group id */ +int32_t ki_tpgid;/* tty process group id */ +int32_t ki_sid;/* Process session ID */ +int32_t ki_tsid;/* Terminal session ID */ +int16_t ki_jobc;/* job control counter */ +int16_t ki_spare_short1;/* unused (just here for alignment) */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +int32_t ki_tdev__freebsd11;/* controlling tty dev */ +#else +int32_t ki_tdev;/* controlling tty dev */ +#endif +target_sigset_t ki_siglist;/* Signals arrived but not delivered */ +target_sigset_t ki_sigmask;/* Current signal mask */ +target_sigset_t ki_sigignore;/* Signals being ignored */ +target_sigset_t ki_sigcatch;/* Signals being caught by user */ + +int32_t ki_uid;/* effective user id */ +int32_t ki_ruid;/* Real user id */ +int32_t ki_svuid;/* Saved effective user id */ +int32_t ki_rgid;/* Real group id */ +int32_t ki_svgid;/* Saved effective group id */ +int16_t ki_ngroups;/* number of groups */ +int16_t ki_spare_short2;/* unused (just here for alignment) */ +int32_t ki_groups[TARGET_KI_NGROUPS ];/* groups */ + +abi_long ki_size;/* virtual size */ + +abi_long ki_rssize;/* current resident set size in pages */ +abi_long ki_swrss;/* resident set size before last swap */ +abi_long ki_tsize;/* text size (pages) XXX */ +abi_long ki_dsize;/* data size (pages) XXX */ +abi_long ki_ssize;/* stack size (pages) */ + +uint16_t ki_xstat;/* Exit status for wait & stop signal */ +uint16_t ki_acflag;/* Accounting flags */ + +uint32_t ki_pctcpu;/* %cpu for process during ki_swtime */ + +uint32_t ki_estcpu;/* Time averaged value of ki_cpticks */ +uint32_t ki_slptime;/* Time since last blocked */ +uint32_t ki_swtime;/* Time swapped in or out */ +uint32_t ki_cow;/* number of copy-on-write faults */ +uint64_t ki_runtime;/* Real time in microsec */ + +struct target_freebsd_timeval ki_start;/* starting time */ +struct target_freebsd_timeval ki_childtime;/* time used by process +children */ + +abi_long ki_flag;/* P_* flags */ +abi_long ki_kiflag;/* KI_* flags (below) */ +int32_t ki_traceflag;/* Kernel trace points */ +char ki_stat;/* S* process status */ +int8_t ki_nice;/* Process "nice" value */ +char ki_lock;/* Process lock (prevent swap) count */ +char ki_rqindex;/* Run queue index */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1100000 +u_char ki_oncpu_old;/* Which cpu we are on (legacy) */ +u_char ki_lastcpu_old;/* Last cpu we were on (legacy) */ +#else +u_char ki_oncpu;/* Which cpu we are on */ +u_char ki_lastcpu;/* Last cpu we were on */ +#endif /* ! __FreeBSD_version >= 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +char ki_tdname[TARGET_TDNAMLEN +1 ];/* thread name */ +#else +char ki_ocomm[TARGET_TDNAMLEN +1 ];/* thread name */ +#endif /* ! __FreeBSD_version >= 900000 */ +char ki_wmesg[TARGET_WMESGLEN +1 ];/* wchan message */ +char ki_login[TARGET_LOGNAMELEN +1 ];/* setlogin name */ +char ki_lockname[TARGET_LOCKNAMELEN +1 ];/* lock name */ +char ki_comm[TARGET_COMMLEN +1 ];/* command name */ +char ki_emul[TARGET_KI_EMULNAMELEN +1 ];/* emulation name */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +char ki_loginclass[TARGET_LOGINCLASSLEN +1 ];/* login class */ +#endif /* ! __FreeBSD_version >= 900000 */ + +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +char ki_sparestrings[50 ];/* spare string space */ +#else +char ki_sparestrings[68 ];/* spare string space */ +#endif /* ! __FreeBSD_version >= 900000 */ +int32_t ki_spareints[TARGET_KI_NSPARE_INT ];/* spare room for growth */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint64_t ki_tdev;/* controlling tty dev */ +#endif +#if defined(__FreeBSD_version) && __FreeBSD_version >=1100000 +int32_t ki_oncpu;/* Which cpu we are on */ +int32_t ki_lastcpu;/* Last cpu we were on */ +int32_t ki_tracer;/* Pid of tracing process */ +#endif /* __FreeBSD_version >= 1100000 */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +int32_t ki_flag2;/* P2_* flags */ +int32_t ki_fibnum;/* Default FIB number */ +#endif /* ! __FreeBSD_version >= 900000 */ +uint32_t ki_cr_flags;/* Credential flags */ +int32_t ki_jid;/* Process jail ID */ +int32_t ki_numthreads;/* XXXKSE number of threads in total */ + +int32_t ki_tid;/* XXXKSE thread id */ + +struct target_priority ki_pri;/* process priority */ +struct target_freebsd_rusage ki_rusage;/* process rusage statistics */ +/* XXX - most fields in ki_rusage_ch are not (yet) filled in */ +struct target_freebsd_rusage ki_rusage_ch;/* rusage of children +processes */ + + +abi_ulong ki_pcb;/* kernel virtual addr of pcb */ +abi_ulong ki_kstack;/* kernel virtual addr of stack */ +abi_ulong ki_udata;/* User convenience pointer */ +abi_ulong ki_tdaddr;/* address of thread */ + +abi_ulong ki_spareptrs[TARGET_KI_NSPARE_PTR ];/* spare room for growth */ +abi_long ki_sparelongs[TARGET_KI_NSPARE_LONG ];/* spare room for growth */ +abi_long ki_sflag;/* PS_* flags */ +abi_long ki_tdflags;/* XXXKSE kthread flag */ +}; + +struct target_kinfo_file { +int32_t kf_structsize;/* Variable size of record. */ +int32_t kf_type;/* Descriptor type. */ +int32_t kf_fd;/* Array index. */ +int32_t kf_ref_count;/* Reference count. */ +int32_t kf_flags;/* Flags. */ +int32_t kf_pad0;/* Round to 64 bit alignment. */ +int64_t kf_offset;/* Seek location. */ +#if defined(__FreeBSD_version) && __FreeBSD_version <1200031 +int32_t kf_vnode_type;/* Vnode type. */ +int32_t kf_sock_domain;/* Socket domain. */ +int32_t kf_sock_type;/* Socket type. */ +int32_t kf_sock_protocol;/* Socket protocol. */ +struct target_sockaddr_storage kf_sa_local;/* Socket address. */ +struct target_sockaddr_storage kf_sa_peer;/* Peer address. */ +#endif +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +union { +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kf_spareint; +/* Socket domain. */ +int kf_sock_domain0; +/* Socket type. */ +int kf_sock_type0; +/* Socket protocol. */ +int kf_sock_protocol0; +/* Socket address. */ +struct sockaddr_storage kf_sa_local; +/* Peer address. */ +struct sockaddr_storage kf_sa_peer; +#endif +/* Address of so_pcb. */ +uint64_t kf_sock_pcb; +/* Address of inp_ppcb. */ +uint64_t kf_sock_inpcb; +/* Address of unp_conn. */ +uint64_t kf_sock_unpconn; +/* Send buffer state. */ +uint16_t kf_sock_snd_sb_state; +/* Receive buffer state. */ +uint16_t kf_sock_rcv_sb_state; +/* Round to 64 bit alignment. */ +uint32_t kf_sock_pad0; + } kf_sock; +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +/* Vnode type. */ +int kf_file_type; +/* Space for future use */ +int kf_spareint[3 ]; +uint64_t kf_spareint64[30 ]; +/* Vnode filesystem id. */ +uint64_t kf_file_fsid; +/* File device. */ +uint64_t kf_file_rdev; +/* Global file id. */ +uint64_t kf_file_fileid; +/* File size. */ +uint64_t kf_file_size; +/* Vnode filesystem id, FreeBSD 11 compat. */ +uint32_t kf_file_fsid_freebsd11; +/* File device, FreeBSD 11 compat. */ +uint32_t kf_file_rdev_freebsd11; +#else +/* Global file id. */ +uint64_t kf_file_fileid; +/* File size. */ +uint64_t kf_file_size; +/* Vnode filesystem id. */ +uint32_t kf_file_fsid; +/* File device. */ +uint32_t kf_file_rdev; +#endif +/* File mode. */ +uint16_t kf_file_mode; +/* Round to 64 bit alignment. */ +uint16_t kf_file_pad0; +uint32_t kf_file_pad1; + } kf_file; +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kf_spareint[4 ]; +uint64_t kf_spareint64[32 ]; +#endif +uint32_t kf_sem_value; +uint16_t kf_sem_mode; + } kf_sem; +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kf_spareint[4 ]; +uint64_t kf_spareint64[32 ]; +#endif +uint64_t kf_pipe_addr; +uint64_t kf_pipe_peer; +uint32_t kf_pipe_buffer_cnt; +/* Round to 64 bit alignment. */ +uint32_t kf_pipe_pad0[3 ]; + } kf_pipe; +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kf_spareint[4 ]; +uint64_t kf_spareint64[32 ]; +uint32_t kf_pts_dev_freebsd11; +uint32_t kf_pts_pad0; +uint64_t kf_pts_dev; +/* Round to 64 bit alignment. */ +uint32_t kf_pts_pad1[4 ]; +#else +uint32_t kf_pts_dev; +/* Round to 64 bit alignment. */ +uint32_t kf_pts_pad0[7 ]; +#endif + } kf_pts; +struct { +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kf_spareint[4 ]; +uint64_t kf_spareint64[32 ]; +#endif +int32_t kf_pid; + } kf_proc; + } kf_un; +uint16_t kf_status;/* Status flags. */ +uint16_t kf_pad1;/* Round to 32 bit alignment. */ +int32_t _kf_ispare0;/* Space for more stuff. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1000000 +target_cap_rights_t kf_cap_rights;/* Capability rights. */ +uint64_t _kf_cap_spare;/* Space for future cap_rights_t. */ +#else /* ! __FreeBSD_version >= 1000000 */ +uint64_t kf_cap_rights; +int _kf_ispare[4 ]; +#endif /* ! __FreeBSD_version >= 1000000 */ + +#else /* ! __FreeBSD_version >= 900000 */ +int _kf_ispare[16 ]; +#endif /* ! __FreeBSD_version >= 900000 */ +/* Truncated before copyout in sysctl */ +char kf_path[PATH_MAX ];/* Path to file, if any. */ +}; + +struct target_kinfo_vmentry { +int32_t kve_structsize;/* Variable size of record. */ +int32_t kve_type;/* Type of map entry. */ +uint64_t kve_start;/* Starting address. */ +uint64_t kve_end;/* Finishing address. */ +uint64_t kve_offset;/* Mapping offset in object */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +uint64_t kve_vn_fileid;/* inode number if vnode */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kve_vn_fsid_freebsd11;/* dev_t of vnode location */ +#else +uint32_t kve_vn_fsid;/* dev_t of vnode location */ +#endif +#else /* ! __FreeBSD_version >= 900000 */ +uint64_t kve_fileid;/* inode number if vnode */ +uint32_t kve_fsid;/* dev_t of vnode location */ +#endif /* ! __FreeBSD_version >= 900000 */ +int32_t kve_flags;/* Flags on map entry. */ +int32_t kve_resident;/* Number of resident pages. */ +int32_t kve_private_resident;/* Number of private pages. */ +int32_t kve_protection;/* Protection bitmask. */ +int32_t kve_ref_count;/* VM obj ref count. */ +int32_t kve_shadow_count;/* VM obj shadow count. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=900000 +int32_t kve_vn_type;/* Vnode type. */ +uint64_t kve_vn_size;/* File size. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +uint32_t kve_vn_rdev_freebsd11;/* Device id if device. */ +#else +uint32_t kve_vn_rdev;/* Device id if device. */ +#endif +uint16_t kve_vn_mode;/* File mode. */ +uint16_t kve_status;/* Status flags. */ +#if defined(__FreeBSD_version) && __FreeBSD_version >=1200031 +#if (__FreeBSD_version >=1300501 && __FreeBSD_version <1400000 ) || \ + __FreeBSD_version >=1400009 +union { +uint64_t _kve_vn_fsid;/* dev_t of vnode location */ +uint64_t _kve_obj;/* handle of anon obj */ + } kve_type_spec; +#define kve_vn_fsid kve_type_spec._kve_vn_fsid +#define kve_obj kve_type_spec._kve_obj +#else +uint64_t kve_vn_fsid;/* dev_t of vnode location */ +#endif +uint64_t kve_vn_rdev;/* Device id if device. */ +int _kve_ispare[8 ];/* Space for more stuff. */ +#else +int32_t _kve_ispare[12 ];/* Space for more stuff. */ +#endif +#else /* ! __FreeBSD_version >= 900000 */ +int _kve_pad0; +int32_t _kve_ispare[16 ];/* Space for more stuff. */ +#endif /* ! __FreeBSD_version >= 900000 */ +/* Truncated before copyout in sysctl */ +char kve_path[PATH_MAX ];/* Path to VM obj, if any. */ +}; + +#endif /* ! _TARGET_OS_USER_H_ */
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 41/49] bsd-user: Add target_os_user.h to capture the user/kernel structures
Quoted 5 lines · Warner Losh
From: Warner Losh<[email protected]>
This file evolved over the years to capture the user/kernel interfaces, including those that changed over time.
Quoted 7 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Michal Meloun<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/freebsd/target_os_user.h | 429 ++++++++++++++++++++++++++++++ 1 file changed, 429 insertions(+)create mode 100644
bsd-user/freebsd/target_os_user.h
r~
PATCH 42/49 bsd-user: add stubbed out core dump support
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Add a stubbed-out version of the bsd-user fork's core dump support. This allows elfload.c to be almost the same between what's upstream and what's in qemu-project upstream w/o the burden of reviewing the core dump support.
Sponsored by: Netflix
--- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 24 ++++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 bsd-user/elfcore.c
bsd-user/elfcore.c new file +10 -0
@@ -0,0 +1,10 @@ +/* Stubbed out version of core dump support, explicitly in public domain */ + +static int elf_core_dump (int signr,CPUArchState *env) +{ +struct elf_note en; + +bswap_note (&en); + +return 0 ; +}
bsd-user/elfload.c +22 -2
@@ -26,15 +26,19 @@static abi_ulong target_auxents;/* Where the AUX entries are in target */ static size_t target_auxents_sz;/* Size of AUX entries including AT_NULL */ +#include "target_arch_reg.h" #include "target_os_elf.h" #include "target_os_stack.h" #include "target_os_thread.h" - -#include "elf.h" +#include "target_os_user.h" abi_ulong target_stksiz;abi_ulong target_stkbas; +static int elf_core_dump (int signr,CPUArchState *env); +static int load_elf_sections (const struct elfhdr *hdr,struct elf_phdr *phdr, +int fd,abi_ulong rbase,abi_ulong *baddrp); +static inline void memcpy_fromfs (void *to,const void *from,unsigned long n) {memcpy (to, from, n);
@@ -100,15 +104,25 @@ static void bswap_sym(struct elf_sym *sym) bswap16s(&sym->st_shndx); } +static void bswap_note (struct elf_note *en) +{ +bswap32s (&en->n_namesz); +bswap32s (&en->n_descsz); +bswap32s (&en->n_type); +} +#else /* ! BSWAP_NEEDED */ static void bswap_ehdr (struct elfhdr *ehdr) { }static void bswap_phdr (struct elf_phdr *phdr,int phnum) { }static void bswap_shdr (struct elf_shdr *shdr,int shnum) { }static void bswap_sym (struct elf_sym *sym) { } +static void bswap_note (struct elf_note *en) { }#endif /* ! BSWAP_NEEDED */ +#include "elfcore.c" +/* * 'copy_elf_strings()' copies argument/envelope strings from user * memory to free pages in kernel mem. These are in a format ready
@@ -833,6 +847,12 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->entry = elf_entry; +#ifdef USE_ELF_CORE_DUMP + bprm->core_dump = &elf_core_dump; +#else + bprm->core_dump =NULL ; +#endif +return 0 ; }
bsd-user/qemu.h +6 -0
@@ -54,6 +54,7 @@ extern enum BSDType bsd_type;* kernel */ struct image_info { +abi_ulong load_bias;abi_ulong load_addr;abi_ulong start_code;abi_ulong end_code;
@@ -68,6 +69,9 @@ struct image_info {abi_ulong entry;abi_ulong code_offset;abi_ulong data_offset; +abi_ulong arg_start; +abi_ulong arg_end; +uint32_t elf_flags; };#define MAX_SIGQUEUE_SIZE 1024
@@ -134,6 +138,7 @@ struct bsd_binprm {char **envp;char *filename;/* (Given) Name of binary */ char *fullpath;/* Full path of binary */ +int (*core_dump)(int ,CPUArchState *); };void do_init_thread (struct target_pt_regs *regs,struct image_info *infop);
@@ -147,6 +152,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, struct image_info *info);int load_flt_binary (struct bsd_binprm *bprm,struct target_pt_regs *regs,struct image_info *info); +int is_target_elf_binary (int fd);abi_long memcpy_to_target (abi_ulong dest,const void *src,unsigned long len);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 42/49] bsd-user: add stubbed out core dump support
Quoted 24 lines · Warner Losh
From: Warner Losh <[email protected]>
Add a stubbed-out version of the bsd-user fork's core dump support. This allows
elfload.cto be almost the same between what's upstream and what's in qemu-project upstream w/o the burden of reviewing the core dump support.Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>Sponsored by: Netflix
--- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 24 ++++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 38 insertions(+), 2 deletions(-)create mode 100644
bsd-user/elfcore.cbsd-user/elfcore.c new file +0
-0
bsd-user/elfcore.c line 10
Quoted 10 lines
bsd-user/elfcore.c new file +10
-0@@ -0,0 +1,10 @@ +/* Stubbed out version of core dump support, explicitly in public domain */ + +static int elf_core_dump (int signr,CPUArchState *env) +{ +struct elf_note en; + +bswap_note (&en); + +return 0 ; +}
No warnings from this, e.g. uninitialized variable? If you have a chance, run this through clang-12 (mainline). It it getting much better at identifying such stuff.
Otherwise,
r~
Re: [PATCH for 6.2 42/49] bsd-user: add stubbed out core dump support
Quoted 31 lines · Richard Henderson
Quoted 26 lines · Warner Losh
From: Warner Losh <[email protected]>
Add a stubbed-out version of the bsd-user fork's core dump support. This allowselfload.cto be almost the same between what's upstream and what's in qemu-project upstream w/o the burden of reviewing the core dump support.Signed-off-by Stacey Son <[email protected]>Signed-off-by Warner Losh <[email protected]>Sponsored by: Netflix
--- bsd-user/elfcore.c | 10 ++++++++++ bsd-user/elfload.c | 24 ++++++++++++++++++++++-- bsd-user/qemu.h | 6 ++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 bsd-user/elfcore.cbsd-user/elfcore.c new file +6
-0@@ -0,0 +1,10 @@ +/* Stubbed out version of core dump support, explicitly in public domain */ + +static int elf_core_dump (int signr,CPUArchState *env) +{ +struct elf_note en; +
Quoted 8 lines
bsd-user/elfcore.c line 10
Quoted 4 lines
bsd-user/elfcore.c new file +4
-0+bswap_note (&en); + +return 0 ; +}No warnings from this, e.g. uninitialized variable? If you have a chance, run this through clang-12 (mainline). It it getting much better at identifying such stuff.
It’s easy enough to initialize en, so I’ve done that.
Warner
Quoted 5 lines
Otherwise,
Reviewed-by Richard Henderson <[email protected]>r~
PATCH 43/49 bsd-user: elfload.c style catch up patch
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Various style fixes to elfload.c that were too painful to make earlier in this series.
Sponsored by: Netflix
--- bsd-user/elfload.c | 212 ++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 107 deletions(-)
bsd-user/elfload.c +105 -107
@@ -36,8 +36,6 @@ abi_ulong target_stksiz;abi_ulong target_stkbas;static int elf_core_dump (int signr,CPUArchState *env); -static int load_elf_sections (const struct elfhdr *hdr,struct elf_phdr *phdr, -int fd,abi_ulong rbase,abi_ulong *baddrp);static inline void memcpy_fromfs (void *to,const void *from,unsigned long n) {
@@ -145,10 +143,12 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page,exit (-1 ); } tmp1 = tmp; -while (*tmp++); +while (*tmp++) { +continue ; + } len = tmp - tmp1;if (p < len) {/* this shouldn't happen - 128kB */ -return 0 ; +return 0 ; }while (len) { --p; --tmp; --len;
@@ -158,14 +158,14 @@ static abi_ulong copy_elf_strings(int argc, char **argv, void **page,if (!pag) { pag =g_try_malloc0 (TARGET_PAGE_SIZE ); page[p /TARGET_PAGE_SIZE ] = pag; -if (!pag) +if (!pag) {return 0 ; + } } }if (len ==0 || offset ==0 ) { *(pag + offset) = *tmp; - } -else { + }else {int bytes_to_copy = (len > offset) ? offset : len; tmp -= bytes_to_copy; p -= bytes_to_copy;
@@ -184,16 +184,14 @@ static void setup_arg_pages(struct bsd_binprm *bprm, struct image_info *info,abi_ulong stack_base, size;abi_long addr; -/* Create enough stack to hold everything. If we don't use -* it for args, we'll use it for something else... +/* +* Create enough stack to hold everything. If we don't use it for args, +* we'll use it for something else... */ size = target_dflssiz; stack_base =TARGET_USRSTACK - size; - addr =target_mmap (stack_base, - size + qemu_host_page_size, -PROT_READ |PROT_WRITE , -MAP_PRIVATE |MAP_ANON , --1 ,0 ); + addr =target_mmap (stack_base , size + qemu_host_page_size, +PROT_READ |PROT_WRITE ,MAP_PRIVATE |MAP_ANON ,-1 ,0 );if (addr ==-1 ) {perror ("stk mmap" );exit (-1 );
@@ -212,55 +210,60 @@ static void setup_arg_pages(struct bsd_binprm *bprm, struct image_info *info,static void set_brk (abi_ulong start,abi_ulong end) { -/* page-align the start and end addresses... */ - start =HOST_PAGE_ALIGN (start); - end =HOST_PAGE_ALIGN (end); -if (end <= start) -return ; -if (target_mmap (start, end - start, -PROT_READ |PROT_WRITE |PROT_EXEC , -MAP_FIXED |MAP_PRIVATE |MAP_ANON ,-1 ,0 ) ==-1 ) { -perror ("cannot mmap brk" ); -exit (-1 ); - } +/* page-align the start and end addresses... */ + start =HOST_PAGE_ALIGN (start); + end =HOST_PAGE_ALIGN (end); +if (end <= start) { +return ; + } +if (target_mmap (start, end - start,PROT_READ |PROT_WRITE |PROT_EXEC , +MAP_FIXED |MAP_PRIVATE |MAP_ANON ,-1 ,0 ) ==-1 ) { +perror ("cannot mmap brk" ); +exit (-1 ); + } } -/* We need to explicitly zero any fractional pages after the data -section (i.e. bss). This would contain the junk from the file that -should not be in memory. */ +/* +* We need to explicitly zero any fractional pages after the data +* section (i.e. bss). This would contain the junk from the file that +* should not be in memory. +*/ static void padzero (abi_ulong elf_bss,abi_ulong last_bss) { -abi_ulong nbyte; +abi_ulong nbyte; -if (elf_bss >= last_bss) -return ; +if (elf_bss >= last_bss) { +return ; + } -/* XXX: this is really a hack : if the real host page size is -smaller than the target page size, some pages after the end -of the file may not be mapped. A better fix would be to -patch target_mmap(), but it is more complicated as the file -size must be known */ -if (qemu_real_host_page_size < qemu_host_page_size) { -abi_ulong end_addr, end_addr1; - end_addr1 =REAL_HOST_PAGE_ALIGN (elf_bss); - end_addr =HOST_PAGE_ALIGN (elf_bss); -if (end_addr1 < end_addr) { -mmap ((void *)g2h_untagged (end_addr1), end_addr - end_addr1, -PROT_READ |PROT_WRITE |PROT_EXEC , -MAP_FIXED |MAP_PRIVATE |MAP_ANON ,-1 ,0 ); - } +/* +* XXX: this is really a hack : if the real host page size is +* smaller than the target page size, some pages after the end +* of the file may not be mapped. A better fix would be to +* patch target_mmap(), but it is more complicated as the file +* size must be known. +*/ +if (qemu_real_host_page_size < qemu_host_page_size) { +abi_ulong end_addr, end_addr1; + end_addr1 =REAL_HOST_PAGE_ALIGN (elf_bss); + end_addr =HOST_PAGE_ALIGN (elf_bss); +if (end_addr1 < end_addr) { +mmap ((void *)g2h_untagged (end_addr1), end_addr - end_addr1, +PROT_READ |PROT_WRITE |PROT_EXEC , +MAP_FIXED |MAP_PRIVATE |MAP_ANON ,-1 ,0 ); } + } - nbyte = elf_bss & (qemu_host_page_size -1 ); -if (nbyte) { - nbyte = qemu_host_page_size - nbyte; -do { -/* FIXME - what to do if put_user() fails? */ -put_user_u8 (0 , elf_bss); - elf_bss++; - }while (--nbyte); - } + nbyte = elf_bss & (qemu_host_page_size -1 ); +if (nbyte) { + nbyte = qemu_host_page_size - nbyte; +do { +/* FIXME - what to do if put_user() fails? */ +put_user_u8 (0 , elf_bss); + elf_bss++; + }while (--nbyte); + } } static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,
@@ -282,23 +285,23 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,bswap_ehdr (interp_elf_ex);/* First of all, some simple consistency checks */ -if ((interp_elf_ex->e_type !=ET_EXEC && - interp_elf_ex->e_type !=ET_DYN ) || - !elf_check_arch (interp_elf_ex->e_machine)) { +if ((interp_elf_ex->e_type !=ET_EXEC && interp_elf_ex->e_type !=ET_DYN ) || + !elf_check_arch (interp_elf_ex->e_machine)) {return ~((abi_ulong )0UL ); }/* Now read in all of the header information */ - -if (sizeof (struct elf_phdr ) * interp_elf_ex->e_phnum >TARGET_PAGE_SIZE ) +if (sizeof (struct elf_phdr ) * interp_elf_ex->e_phnum >TARGET_PAGE_SIZE ) {return ~(abi_ulong )0UL ; + } - elf_phdata = (struct elf_phdr *) -malloc (sizeof (struct elf_phdr ) * interp_elf_ex->e_phnum); + elf_phdata = (struct elf_phdr *)malloc (sizeof (struct elf_phdr ) * + interp_elf_ex->e_phnum); -if (!elf_phdata) +if (!elf_phdata) {return ~((abi_ulong )0UL ); + }/* * If the size of this structure has changed, then punt, since
@@ -311,9 +314,8 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, retval =lseek (interpreter_fd, interp_elf_ex->e_phoff,SEEK_SET );if (retval >=0 ) { - retval =read (interpreter_fd, - (char *) elf_phdata, -sizeof (struct elf_phdr ) * interp_elf_ex->e_phnum); + retval =read (interpreter_fd, (char *) elf_phdata, +sizeof (struct elf_phdr ) * interp_elf_ex->e_phnum); }if (retval <0 ) {perror ("load_elf_interp" );
@@ -324,11 +326,12 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,bswap_phdr (elf_phdata, interp_elf_ex->e_phnum);if (interp_elf_ex->e_type ==ET_DYN ) { -/* in order to avoid hardcoding the interpreter load -address in qemu, we allocate a big enough memory zone */ - error =target_mmap (0 ,INTERP_MAP_SIZE , -PROT_NONE ,MAP_PRIVATE |MAP_ANON , --1 ,0 ); +/* +* In order to avoid hardcoding the interpreter load +* address in qemu, we allocate a big enough memory zone. +*/ + error =target_mmap (0 ,INTERP_MAP_SIZE ,PROT_NONE , +MAP_PRIVATE |MAP_ANON ,-1 ,0 );if (error ==-1 ) {perror ("mmap" );exit (-1 );
@@ -432,7 +435,7 @@ static const char *lookup_symbolxx(struct syminfo *s, target_ulong orig_addr)struct elf_sym *syms = s->disas_symtab.elf64;#endif -// binary search +/* binary search */ struct elf_sym *sym; sym =bsearch (&orig_addr, syms, s->disas_num_syms,sizeof (*syms), symfind);
@@ -448,9 +451,8 @@ static int symcmp(const void *s0, const void *s1) {struct elf_sym *sym0 = (struct elf_sym *)s0;struct elf_sym *sym1 = (struct elf_sym *)s1; -return (sym0->st_value < sym1->st_value) - ?-1 - : ((sym0->st_value > sym1->st_value) ?1 :0 ); +return (sym0->st_value < sym1->st_value) ?-1 : + ((sym0->st_value > sym1->st_value) ?1 :0 ); }/* Best attempt to load symbols from this ELF object. */
@@ -464,23 +466,24 @@ static void load_symbols(struct elfhdr *hdr, int fd)lseek (fd, hdr->e_shoff,SEEK_SET );for (i =0 ; i < hdr->e_shnum; i++) { -if (read (fd, &sechdr,sizeof (sechdr)) !=sizeof (sechdr)) +if (read (fd, &sechdr,sizeof (sechdr)) !=sizeof (sechdr)) {return ; + }bswap_shdr (&sechdr,1 );if (sechdr.sh_type ==SHT_SYMTAB ) { symtab = sechdr; -lseek (fd, hdr->e_shoff - +sizeof (sechdr) * sechdr.sh_link,SEEK_SET ); -if (read (fd, &strtab,sizeof (strtab)) - !=sizeof (strtab)) +lseek (fd, hdr->e_shoff +sizeof (sechdr) * sechdr.sh_link, +SEEK_SET ); +if (read (fd, &strtab,sizeof (strtab)) !=sizeof (strtab)) {return ; + }bswap_shdr (&strtab,1 ); goto found; } }return ;/* Shouldn't happen... */ - found: +found:/* Now know where the strtab and symtab are. Snarf them. */ s =malloc (sizeof (*s)); syms =malloc (symtab.sh_size);
@@ -508,7 +511,7 @@ static void load_symbols(struct elfhdr *hdr, int fd) i =0 ;while (i < nsyms) {bswap_sym (syms + i); -// Throw away entries which we do not need. +/* Throw away entries which we do not need. */ if (syms[i].st_shndx ==SHN_UNDEF || syms[i].st_shndx >=SHN_LORESERVE ||ELF_ST_TYPE (syms[i].st_info) !=STT_FUNC ) {
@@ -521,10 +524,12 @@ static void load_symbols(struct elfhdr *hdr, int fd) i++; } -/* Attempt to free the storage associated with the local symbols -that we threw away. Whether or not this has any effect on the -memory allocation depends on the malloc implementation and how -many symbols we managed to discard. */ +/* +* Attempt to free the storage associated with the local symbols +* that we threw away. Whether or not this has any effect on the +* memory allocation depends on the malloc implementation and how +* many symbols we managed to discard. +*/ new_syms =realloc (syms, nsyms *sizeof (*syms));if (new_syms ==NULL ) {free (s);
@@ -580,19 +585,19 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,/* First of all, some simple consistency checks */ if ((elf_ex.e_type !=ET_EXEC && elf_ex.e_type !=ET_DYN ) || - (!elf_check_arch (elf_ex.e_machine))) { + (!elf_check_arch (elf_ex.e_machine))) {return -ENOEXEC ; } bprm->p =copy_elf_strings (1 , &bprm->filename, bprm->page, bprm->p); - bprm->p =copy_elf_strings (bprm->envc, bprm->envp, bprm->page,bprm->p); - bprm->p =copy_elf_strings (bprm->argc, bprm->argv, bprm->page,bprm->p); + bprm->p =copy_elf_strings (bprm->envc, bprm->envp, bprm->page, bprm->p); + bprm->p =copy_elf_strings (bprm->argc, bprm->argv, bprm->page, bprm->p);if (!bprm->p) { retval = -E2BIG ; }/* Now read in all of the header information */ - elf_phdata = (struct elf_phdr *)malloc (elf_ex.e_phentsize*elf_ex.e_phnum); + elf_phdata = (struct elf_phdr *)malloc (elf_ex.e_phentsize * elf_ex.e_phnum);if (elf_phdata ==NULL ) {return -ENOMEM ; }
@@ -611,7 +616,6 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, }bswap_phdr (elf_phdata, elf_ex.e_phnum); - elf_ppnt = elf_phdata; elf_bss =0 ;
@@ -624,23 +628,16 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, start_data =0 ; end_data =0 ; -for (i =0 ;i < elf_ex.e_phnum; i++) { +for (i =0 ; i < elf_ex.e_phnum; i++) {if (elf_ppnt->p_type ==PT_INTERP ) { -if (elf_interpreter !=NULL ) - { +if (elf_interpreter !=NULL ) {free (elf_phdata);free (elf_interpreter);close (bprm->fd);return -EINVAL ; } -/* This is the program interpreter used for -* shared libraries - for now assume that this -* is an a.out format binary -*/ - elf_interpreter = (char *)malloc (elf_ppnt->p_filesz); -if (elf_interpreter ==NULL ) {free (elf_phdata);close (bprm->fd);
@@ -660,8 +657,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, retval =open (path (elf_interpreter),O_RDONLY );if (retval >=0 ) { interpreter_fd = retval; - } -else { + }else {perror (elf_interpreter);exit (-1 );/* retval = -errno; */
@@ -675,7 +671,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } }if (retval >=0 ) { - interp_elf_ex = *((struct elfhdr *) bprm->buf);/* elf exec-header */ + interp_elf_ex = *((struct elfhdr *) bprm->buf); }if (retval <0 ) {perror ("load_elf_binary3" );
@@ -692,7 +688,7 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,/* Some simple consistency checks for the interpreter */ if (elf_interpreter) {if (interp_elf_ex.e_ident[0 ] !=0x7f || -strncmp ((char *)&interp_elf_ex.e_ident[1 ],"ELF" ,3 ) !=0 ) { +strncmp ((char *)&interp_elf_ex.e_ident[1 ],"ELF" ,3 ) !=0 ) {free (elf_interpreter);free (elf_phdata);close (bprm->fd);
@@ -700,9 +696,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, } } -/* OK, we are done with that, now set up the arg stuff, -and then start this sucker up */ - +/* +* OK, we are done with that, now set up the arg stuff, and then start this +* sucker up +*/ if (!bprm->p) {free (elf_interpreter);free (elf_phdata);
@@ -824,8 +821,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,free (elf_phdata); -if (qemu_log_enabled ()) +if (qemu_log_enabled ()) {load_symbols (&elf_ex, bprm->fd); + }close (bprm->fd);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 43/49] bsd-user: elfload.c style catch up patch
Quoted 11 lines · Warner Losh
From: Warner Losh<[email protected]>
Various style fixes to
elfload.cthat were too painful to make earlier in this series.Signed-off-by Warner Losh<[email protected]>Sponsored by: Netflix
--- bsd-user/elfload.c | 212 ++++++++++++++++++++++----------------------- 1 file changed, 105 insertions(+), 107 deletions(-)
r~
PATCH 44/49 bsd-user: Refactor load_elf_sections and is_target_elf_binary
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Factor out load_elf_sections and is_target_elf_binary out of load_elf_interp.
--- bsd-user/elfload.c | 350 +++++++++++++++++++++------------------------ 1 file changed, 164 insertions(+), 186 deletions(-)
bsd-user/elfload.c +164 -186
@@ -36,6 +36,8 @@ abi_ulong target_stksiz;abi_ulong target_stkbas;static int elf_core_dump (int signr,CPUArchState *env); +static int load_elf_sections (const struct elfhdr *hdr,struct elf_phdr *phdr, +int fd,abi_ulong rbase,abi_ulong *baddrp);static inline void memcpy_fromfs (void *to,const void *from,unsigned long n) {
@@ -271,16 +273,10 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, abi_ulong *interp_load_addr) {struct elf_phdr *elf_phdata =NULL ; -struct elf_phdr *eppnt; -abi_ulong load_addr =0 ; -int load_addr_set =0 ; +abi_ulong rbase;int retval; -abi_ulong last_bss, elf_bss; -abi_ulong error; -int i; +abi_ulong baddr, error; - elf_bss =0 ; - last_bss =0 ; error =0 ;bswap_ehdr (interp_elf_ex);
@@ -325,6 +321,7 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, }bswap_phdr (elf_phdata, interp_elf_ex->e_phnum); + rbase =0 ;if (interp_elf_ex->e_type ==ET_DYN ) {/* * In order to avoid hardcoding the interpreter load
@@ -332,86 +329,25 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,*/ error =target_mmap (0 ,INTERP_MAP_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_ANON ,-1 ,0 ); -if (error ==-1 ) { +if (rbase ==-1 ) {perror ("mmap" );exit (-1 ); } - load_addr = error; - load_addr_set =1 ; - } - - eppnt = elf_phdata; -for (i =0 ; i < interp_elf_ex->e_phnum; i++, eppnt++) -if (eppnt->p_type ==PT_LOAD ) { -int elf_type =MAP_PRIVATE |MAP_DENYWRITE ; -int elf_prot =0 ; -abi_ulong vaddr =0 ; -abi_ulong k; - -if (eppnt->p_flags &PF_R ) elf_prot =PROT_READ ; -if (eppnt->p_flags &PF_W ) elf_prot |=PROT_WRITE ; -if (eppnt->p_flags &PF_X ) elf_prot |=PROT_EXEC ; -if (interp_elf_ex->e_type ==ET_EXEC || load_addr_set) { - elf_type |=MAP_FIXED ; - vaddr = eppnt->p_vaddr; - } - error =target_mmap (load_addr +TARGET_ELF_PAGESTART (vaddr), - eppnt->p_filesz +TARGET_ELF_PAGEOFFSET (eppnt->p_vaddr), - elf_prot, - elf_type, - interpreter_fd, - eppnt->p_offset -TARGET_ELF_PAGEOFFSET (eppnt->p_vaddr)); - -if (error ==-1 ) { -/* Real error */ -close (interpreter_fd); -free (elf_phdata); -return ~((abi_ulong )0UL ); - } - -if (!load_addr_set && interp_elf_ex->e_type ==ET_DYN ) { - load_addr = error; - load_addr_set =1 ; - } - -/* -* Find the end of the file mapping for this phdr, and keep -* track of the largest address we see for this. -*/ - k = load_addr + eppnt->p_vaddr + eppnt->p_filesz; -if (k > elf_bss) elf_bss = k; + } -/* -* Do the same thing for the memory mapping - between -* elf_bss and last_bss is the bss section. -*/ - k = load_addr + eppnt->p_memsz + eppnt->p_vaddr; -if (k > last_bss) last_bss = k; - } + error =load_elf_sections (interp_elf_ex, elf_phdata, interpreter_fd, rbase, + &baddr); +if (error !=0 ) { +perror ("load_elf_sections" ); +exit (-1 ); + }/* Now use mmap to map the library into memory. */ -close (interpreter_fd); - -/* -* Now fill out the bss section. First pad the last page up -* to the page boundary, and then perform a mmap to make sure -* that there are zeromapped pages up to and including the last -* bss page. -*/ -padzero (elf_bss, last_bss); - elf_bss =TARGET_ELF_PAGESTART (elf_bss + qemu_host_page_size -1 );/* What we have mapped so far */ - -/* Map the last of the bss segment */ -if (last_bss > elf_bss) { -target_mmap (elf_bss, last_bss - elf_bss, -PROT_READ |PROT_WRITE |PROT_EXEC , -MAP_FIXED |MAP_PRIVATE |MAP_ANON ,-1 ,0 ); - }free (elf_phdata); - *interp_load_addr = load_addr; -return ((abi_ulong ) interp_elf_ex->e_entry) + load_addr; + *interp_load_addr = baddr; +return ((abi_ulong ) interp_elf_ex->e_entry) + rbase; }static int symfind (const void *s0,const void *s1)
@@ -521,6 +457,10 @@ found: }continue ; } +#if defined(TARGET_ARM ) || defined(TARGET_MIPS ) +/* The bottom address bit marks a Thumb or MIPS16 symbol. */ + syms[i].st_value &= ~(target_ulong )1 ; +#endif i++; }
@@ -560,26 +500,119 @@ found: syminfos = s; } +/* Check the elf header and see if this a target elf binary. */ +int is_target_elf_binary (int fd) +{ +uint8_t buf[128 ]; +struct elfhdr elf_ex; + +if (lseek (fd,0L ,SEEK_SET ) <0 ) { +return 0 ; + } +if (read (fd, buf,sizeof (buf)) <0 ) { +return 0 ; + } + + elf_ex = *((struct elfhdr *)buf); +bswap_ehdr (&elf_ex); + +if ((elf_ex.e_type !=ET_EXEC && elf_ex.e_type !=ET_DYN ) || + (!elf_check_arch (elf_ex.e_machine))) { +return 0 ; + }else { +return 1 ; + } +} + +static int +load_elf_sections (const struct elfhdr *hdr,struct elf_phdr *phdr,int fd, +abi_ulong rbase,abi_ulong *baddrp) +{ +struct elf_phdr *elf_ppnt; +abi_ulong baddr; +int i; +bool first; + +/* +* Now we do a little grungy work by mmaping the ELF image into +* the correct location in memory. At this point, we assume that +* the image should be loaded at fixed address, not at a variable +* address. +*/ + first = true; +for (i =0 , elf_ppnt = phdr; i < hdr->e_phnum; i++, elf_ppnt++) { +int elf_prot =0 ; +abi_ulong error; + +/* XXX Skip memsz == 0. */ +if (elf_ppnt->p_type !=PT_LOAD ) { +continue ; + } + +if (elf_ppnt->p_flags &PF_R ) { + elf_prot |=PROT_READ ; + } +if (elf_ppnt->p_flags &PF_W ) { + elf_prot |=PROT_WRITE ; + } +if (elf_ppnt->p_flags &PF_X ) { + elf_prot |=PROT_EXEC ; + } + + error =target_mmap (TARGET_ELF_PAGESTART (rbase + elf_ppnt->p_vaddr), + (elf_ppnt->p_filesz + +TARGET_ELF_PAGEOFFSET (elf_ppnt->p_vaddr)), + elf_prot, + (MAP_FIXED |MAP_PRIVATE |MAP_DENYWRITE ), + fd, + (elf_ppnt->p_offset - +TARGET_ELF_PAGEOFFSET (elf_ppnt->p_vaddr))); +if (error ==-1 ) { +perror ("mmap" ); +exit (-1 ); + }else if (elf_ppnt->p_memsz != elf_ppnt->p_filesz) { +abi_ulong start_bss, end_bss; + + start_bss = rbase + elf_ppnt->p_vaddr + elf_ppnt->p_filesz; + end_bss = rbase + elf_ppnt->p_vaddr + elf_ppnt->p_memsz; + +/* +* Calling set_brk effectively mmaps the pages that we need for the +* bss and break sections. +*/ +set_brk (start_bss, end_bss); +padzero (start_bss, end_bss); + } + +if (first) { + baddr =TARGET_ELF_PAGESTART (rbase + elf_ppnt->p_vaddr); + first = false; + } + } + +if (baddrp !=NULL ) { + *baddrp = baddr; + } +return 0 ; +} +int load_elf_binary (struct bsd_binprm *bprm,struct target_pt_regs *regs,struct image_info *info) {struct elfhdr elf_ex;struct elfhdr interp_elf_ex;int interpreter_fd =-1 ;/* avoid warning */ -abi_ulong load_addr, load_bias; -int load_addr_set =0 ; +abi_ulong load_addr;int i; -struct elf_phdr * elf_ppnt; +struct elf_phdr *elf_ppnt;struct elf_phdr *elf_phdata; -abi_ulong elf_bss, k, elf_brk; -int retval; -char * elf_interpreter; -abi_ulong elf_entry, interp_load_addr =0 ; -abi_ulong start_code, end_code, start_data, end_data; +abi_ulong elf_brk; +int error, retval; +char *elf_interpreter; +abi_ulong baddr, elf_entry, et_dyn_addr, interp_load_addr =0 ;abi_ulong reloc_func_desc =0 ; load_addr =0 ; - load_bias =0 ; elf_ex = *((struct elfhdr *) bprm->buf);/* exec-header */ bswap_ehdr (&elf_ex);
@@ -618,16 +651,10 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,bswap_phdr (elf_phdata, elf_ex.e_phnum); elf_ppnt = elf_phdata; - elf_bss =0 ; elf_brk =0 ; elf_interpreter =NULL ; - start_code = ~((abi_ulong )0UL ); - end_code =0 ; - start_data =0 ; - end_data =0 ; -for (i =0 ; i < elf_ex.e_phnum; i++) {if (elf_ppnt->p_type ==PT_INTERP ) {if (elf_interpreter !=NULL ) {
@@ -714,94 +741,45 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs, info->mmap =0 ; elf_entry = (abi_ulong ) elf_ex.e_entry; -/* Do this so that we can load the interpreter, if need be. We will -change some of these later */ +/* XXX Join this with PT_INTERP search? */ + baddr =0 ; +for (i =0 , elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { +if (elf_ppnt->p_type !=PT_LOAD ) { +continue ; + } + baddr = elf_ppnt->p_vaddr; +break ; + } + + et_dyn_addr =0 ; +if (elf_ex.e_type ==ET_DYN && baddr ==0 ) { + et_dyn_addr =ELF_ET_DYN_LOAD_ADDR ; + } + +/* +* Do this so that we can load the interpreter, if need be. We will +* change some of these later +*/ info->rss =0 ;setup_arg_pages (bprm, info, &bprm->p, &bprm->stringp); info->start_stack = bprm->p; -/* Now we do a little grungy work by mmaping the ELF image into -* the correct location in memory. At this point, we assume that -* the image should be loaded at fixed address, not at a variable -* address. -*/ + info->elf_flags = elf_ex.e_flags; + error =load_elf_sections (&elf_ex, elf_phdata, bprm->fd, et_dyn_addr, + &load_addr);for (i =0 , elf_ppnt = elf_phdata; i < elf_ex.e_phnum; i++, elf_ppnt++) { -int elf_prot =0 ; -int elf_flags =0 ; -abi_ulong error; - -if (elf_ppnt->p_type !=PT_LOAD ) +if (elf_ppnt->p_type !=PT_LOAD ) {continue ; - -if (elf_ppnt->p_flags &PF_R ) elf_prot |=PROT_READ ; -if (elf_ppnt->p_flags &PF_W ) elf_prot |=PROT_WRITE ; -if (elf_ppnt->p_flags &PF_X ) elf_prot |=PROT_EXEC ; - elf_flags =MAP_PRIVATE |MAP_DENYWRITE ; -if (elf_ex.e_type ==ET_EXEC || load_addr_set) { - elf_flags |=MAP_FIXED ; - }else if (elf_ex.e_type ==ET_DYN ) { -/* Try and get dynamic programs out of the way of the default mmap -base, as well as whatever program they might try to exec. This -is because the brk will follow the loader, and is not movable. */ -/* NOTE: for qemu, we do a big mmap to get enough space -without hardcoding any address */ - error =target_mmap (0 ,ET_DYN_MAP_SIZE , -PROT_NONE ,MAP_PRIVATE |MAP_ANON , --1 ,0 ); -if (error ==-1 ) { -perror ("mmap" ); -exit (-1 ); - } - load_bias =TARGET_ELF_PAGESTART (error - elf_ppnt->p_vaddr); } - - error =target_mmap (TARGET_ELF_PAGESTART (load_bias + elf_ppnt->p_vaddr), - (elf_ppnt->p_filesz + -TARGET_ELF_PAGEOFFSET (elf_ppnt->p_vaddr)), - elf_prot, - (MAP_FIXED |MAP_PRIVATE |MAP_DENYWRITE ), - bprm->fd, - (elf_ppnt->p_offset - -TARGET_ELF_PAGEOFFSET (elf_ppnt->p_vaddr))); -if (error ==-1 ) { -perror ("mmap" ); -exit (-1 ); - } - -if (!load_addr_set) { - load_addr_set =1 ; - load_addr = elf_ppnt->p_vaddr - elf_ppnt->p_offset; -if (elf_ex.e_type ==ET_DYN ) { - load_bias += error - -TARGET_ELF_PAGESTART (load_bias + elf_ppnt->p_vaddr); - load_addr += load_bias; - reloc_func_desc = load_bias; - } - } - k = elf_ppnt->p_vaddr; -if (k < start_code) - start_code = k; -if (start_data < k) - start_data = k; - k = elf_ppnt->p_vaddr + elf_ppnt->p_filesz; -if (k > elf_bss) - elf_bss = k; -if ((elf_ppnt->p_flags &PF_X ) && end_code < k) - end_code = k; -if (end_data < k) - end_data = k; - k = elf_ppnt->p_vaddr + elf_ppnt->p_memsz; -if (k > elf_brk) elf_brk = k; - } - - elf_entry += load_bias; - elf_bss += load_bias; - elf_brk += load_bias; - start_code += load_bias; - end_code += load_bias; - start_data += load_bias; - end_data += load_bias; +if (elf_ppnt->p_memsz > elf_ppnt->p_filesz) + elf_brk =MAX (elf_brk, et_dyn_addr + elf_ppnt->p_vaddr + + elf_ppnt->p_memsz); + } +if (error !=0 ) { +perror ("load_elf_sections" ); +exit (-1 ); + }if (elf_interpreter) { elf_entry = load_elf_interp(&interp_elf_ex, interpreter_fd,
@@ -817,6 +795,9 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,exit (-1 );return 0 ; } + }else { + interp_load_addr = et_dyn_addr; + elf_entry += interp_load_addr; }free (elf_phdata);
@@ -827,21 +808,18 @@ int load_elf_binary(struct bsd_binprm *bprm, struct target_pt_regs *regs,close (bprm->fd); - bprm->p =target_create_elf_tables (bprm->p, bprm->argc, bprm->envc, bprm->stringp, - &elf_ex, load_addr, load_bias, interp_load_addr, info); + bprm->p =target_create_elf_tables (bprm->p, + bprm->argc, + bprm->envc, + bprm->stringp, + &elf_ex, + load_addr, et_dyn_addr, + interp_load_addr, + info); info->load_addr = reloc_func_desc; info->start_brk = info->brk = elf_brk; - info->end_code = end_code; - info->start_code = start_code; - info->start_data = start_data; - info->end_data = end_data; info->start_stack = bprm->p; - -/* Calling set_brk effectively mmaps the pages that we need for the bss and break -sections */ -set_brk (elf_bss, elf_brk); - -padzero (elf_bss, elf_brk); + info->load_bias =0 ; info->entry = elf_entry;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 44/49] bsd-user: Refactor load_elf_sections and is_target_elf_binary
bsd-user/elfload.c static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex, · line 335
Quoted 9 lines · Warner Losh
bsd-user/elfload.c +1
-1@@ -332,86 +329,25 @@ static abi_ulong load_elf_interp(struct elfhdr *interp_elf_ex,*/ error =target_mmap (0 ,INTERP_MAP_SIZE ,PROT_NONE ,MAP_PRIVATE |MAP_ANON ,-1 ,0 ); -if (error ==-1 ) { +if (rbase ==-1 ) {perror ("mmap" );exit (-1 ); }
Replacement not greedy enough -- rbase is always 0.
bsd-user/elfload.c found: · line 504
Quoted 2 lines
bsd-user/elfload.c +2
-0+/* Check the elf header and see if this a target elf binary. */ +int is_target_elf_binary (int fd)
This doesn't appear to be used at all.
Which is good, because it's buggy.
Otherwise,
r~
PATCH 45/49 bsd-user: Make guest_base an unsigned long
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Make the guest_base a plan, uneigned long rather than a uintptr_t. It isn't really a pointer.
--- bsd-user/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
bsd-user/main.c +2 -2
@@ -49,9 +49,9 @@#include "target_arch_cpu.h" int singlestep; -uintptr_t guest_base;static const char *cpu_model;static const char *cpu_type; +unsigned long guest_base;bool have_guest_base;#if (TARGET_LONG_BITS ==32 ) && (HOST_LONG_BITS ==64 )/*
@@ -440,7 +440,7 @@ int main(int argc, char **argv)g_free (target_environ);if (qemu_loglevel_mask (CPU_LOG_PAGE )) { -qemu_log ("guest_base %p\n" , (void *)guest_base); +qemu_log ("guest_base 0x%lx\n" , guest_base);log_page_dump ("binary load" );qemu_log ("start_brk 0x" TARGET_ABI_FMT_lx"\n" , info->start_brk);
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 45/49] bsd-user: Make guest_base an unsigned long
Quoted 4 lines · Warner Losh
From: Warner Losh <[email protected]>
Make the
guest_basea plan, uneigned long rather than auintptr_t. It isn't really a pointer.
NACK: 5ca870b9f6c. It most certainly is a host pointer.
r~
Re: [PATCH for 6.2 45/49] bsd-user: Make guest_base an unsigned long
Quoted 8 lines · Richard Henderson
Quoted 4 lines · Warner Losh
From: Warner Losh <[email protected]>
Make the
guest_basea plan, uneigned long rather than auintptr_t. It isn't really a pointer.NACK:
5ca870b9f6c. It most certainly is a host pointer.
OK. I'll drop this one and redo in our other branch. Shouldn't be hard.
PATCH 46/49 bsd-user: move qemu_log to later in the file
In reply to Warner LoshFrom: Warner Losh <[email protected]>
--- bsd-user/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
bsd-user/main.c +9 -8
@@ -85,14 +85,6 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial data size limit */unsigned long target_maxssiz =TARGET_MAXSSIZ ;/* max stack size */ unsigned long target_sgrowsiz =TARGET_SGROWSIZ ;/* amount to grow stack */ -void gemu_log (const char *fmt, ...) -{ -va_list ap; - -va_start (ap, fmt); -vfprintf (stderr, fmt, ap); -va_end (ap); -}void fork_start (void ) {
@@ -181,6 +173,15 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =NULL ; } +void gemu_log (const char *fmt, ...) +{ +va_list ap; + +va_start (ap, fmt); +vfprintf (stderr, fmt, ap); +va_end (ap); +} +static void adjust_ssize (void ) {
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 46/49] bsd-user: move qemu_log to later in the file
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
r~
PATCH 47/49 bsd-user: Implement interlock for atomic operations
In reply to Warner LoshFrom: Warner Losh <[email protected]>
Implement the internlock in fork_start() and fork_end() to properly cope with atomic operations and to safely keep state for parent and child processes.
--- bsd-user/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
bsd-user/main.c +23 -0
@@ -85,15 +85,38 @@ unsigned long target_dflssiz = TARGET_DFLSSIZ; /* initial data size limit */unsigned long target_maxssiz =TARGET_MAXSSIZ ;/* max stack size */ unsigned long target_sgrowsiz =TARGET_SGROWSIZ ;/* amount to grow stack */ +/* Helper routines for implementing atomic operations. */ void fork_start (void ) { +start_exclusive (); +cpu_list_lock (); +mmap_fork_start (); }void fork_end (int child) {if (child) { +CPUState *cpu, *next_cpu; +/* +* Child processes created by fork() only have a single thread. +* Discard information about the parent threads. +*/ + CPU_FOREACH_SAFE(cpu, next_cpu) { +if (cpu != thread_cpu) { +QTAILQ_REMOVE_RCU (&cpus, cpu, node); + } + } +mmap_fork_end (child); +/* qemu_init_cpu_list() takes care of reinitializing the +* exclusive state, so we don't need to end_exclusive() here. +*/ +qemu_init_cpu_list ();gdbserver_fork (thread_cpu); + }else { +mmap_fork_end (child); +cpu_list_unlock (); +end_exclusive (); } }
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 47/49] bsd-user: Implement interlock for atomic operations
Quoted 11 lines · Warner Losh
From: Warner Losh<[email protected]>
Implement the internlock in
fork_start()andfork_end()to properly cope with atomic operations and to safely keep state for parent and child processes.Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
r~
PATCH 48/49 bsd-user: Implement cpu_copy() helper routine
In reply to Warner LoshFrom: Warner Losh <[email protected]>
cpu_copy shouldbe called when processes are creating new threads. It copies the current state of the CPU to a new cpu state needed for the new thread.
--- bsd-user/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
bsd-user/main.c +30 -0
@@ -196,6 +196,36 @@ void init_task_state(TaskState *ts) ts->sigqueue_table[i].next =NULL ; } +CPUArchState *cpu_copy (CPUArchState *env) +{ +CPUState *cpu =env_cpu (env); +CPUState *new_cpu =cpu_create (cpu_type); +CPUArchState *new_env = new_cpu->env_ptr; +CPUBreakpoint *bp; +CPUWatchpoint *wp; + +/* Reset non arch specific state */ +cpu_reset (new_cpu); + +memcpy (new_env, env,sizeof (CPUArchState)); + +/* +* Clone all break/watchpoints. +* Note: Once we support ptrace with hw-debug register access, make sure +* BP_CPU break/watchpoints are handled correctly on clone. +*/ +QTAILQ_INIT (&cpu->breakpoints); +QTAILQ_INIT (&cpu->watchpoints); + QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) { +cpu_breakpoint_insert (new_cpu, bp->pc, bp->flags,NULL ); + } + QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { +cpu_watchpoint_insert (new_cpu, wp->vaddr, wp->len, wp->flags,NULL ); + } + +return new_env; +} +void gemu_log (const char *fmt, ...) {va_list ap;
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 48/49] bsd-user: Implement cpu_copy() helper routine
Quoted 6 lines · Warner Losh
From: Warner Losh<[email protected]>
cpu_copyshouldbe called when processes are creating new threads. It copies the current state of the CPU to a new cpu state needed for the new thread.
Quoted 6 lines
Signed-off-by Stacey Son<[email protected]>Signed-off-by Warner Losh<[email protected]>Signed-off-by Justin Hibbits<[email protected]>--- bsd-user/main.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
r~
PATCH 49/49 bsd-user: Add '-0 argv0' option to bsd-user/main.c
In reply to Warner LoshFrom: Colin Percival <[email protected]>
Previously it was impossible to emulate a program with a file name different from its argv[0]. With this change, you can run
qemu -0 fakename realname args
which runs the program "realname" with an argv of "fakename args".
--- bsd-user/main.c | 5 +++++ 1 file changed, 5 insertions(+)
bsd-user/main.c +5 -0
@@ -284,6 +284,7 @@ int main(int argc, char **argv)char **target_environ, **wrk;envlist_t *envlist =NULL ; bsd_type =HOST_DEFAULT_BSD_TYPE ; +char * argv0 =NULL ;adjust_ssize ();
@@ -405,6 +406,8 @@ int main(int argc, char **argv) do_strace =1 ; }else if (!strcmp (r,"trace" )) {trace_opt_parse (optarg); + }else if (!strcmp (r,"0" )) { + argv0 = argv[optind++]; }else {usage (); }
@@ -428,6 +431,8 @@ int main(int argc, char **argv)usage (); } filename = argv[optind]; +if (argv0) + argv[optind] = argv0;if (!trace_init_backends ()) {exit (1 );
Signature · 1 line
2.32.0
Re: [PATCH for 6.2 49/49] bsd-user: Add '-0 argv0' option to bsd-user/main.c
Quoted 7 lines · Warner Losh
From: Colin Percival<[email protected]>
Previously it was impossible to emulate a program with a file name different from its argv[0]. With this change, you can run
qemu -0 fakename realname args
which runs the program "realname" with an argv of "fakename args".
Quoted 5 lines
Signed-off-by Colin Percival<[email protected]>Signed-off-by Warner Losh<[email protected]>--- bsd-user/main.c | 5 +++++ 1 file changed, 5 insertions(+)
r~