Re: [Qemu-devel] QEMU build broken
On May 9, 2014, at 4:55 AM, Peter Maydell peter.mayd...@linaro.org wrote: On 9 May 2014 09:57, Riku Voipio riku.voi...@linaro.org wrote: On 8 May 2014 17:54, Peter Maydell peter.mayd...@linaro.org wrote: Ah, bsd-user. Do you actually use it, or is it just in the default compile that you're running? One year since last bsd-user specific patch, I take we need a new maintainer for bsd-user? Perhaps so. Stacey Son submitted a set of patches to it back in January, but they were a very large series which needed some restructuring to get through code review and I don't think there's been a respin of those. Personally I would like to see it either (a) actively maintained upstream or (b) just removed from the tree; the current situation doesn't seem very useful. There is some interest from FreeBSD folks to use qemu bsd-user mode in package cross building. In fact, support was added recently to poudriere to used qemu to cross build packages for armv6 and mips64 (see https://fossil.etoilebsd.net/poudriere/tktview/eb7afa654cec95e107905c64b78fb030abc1437b for example). Sean Bruno added the missing bits to make mips32 work correctly. Juergen Lock (nox@) has also contributed a lot of bug fixes and maintains the FreeBSD port. As for restructuring the (25,000+ lines of) patches Sean has agreed to help with that given that I am busy with some other things at the moment. Regards, -stacey.
Re: [Qemu-devel] [PATCH v3 00/19] bsd-user: Add system call and mips/arm support.
On Jan 27, 2014, at 1:15 PM, Peter Maydell peter.mayd...@linaro.org wrote: On 17 December 2013 11:52, Stacey Son s...@freebsd.org wrote: [v3] - Rebases to commit f46e720a82ccdf1a521cf459448f3f96ed895d43 (HEAD). - Changes 'HOST_API_DIR' to 'HOST_VARIANT_DIR' for the BSD variant. - Fixes boundry condition bug in mmap() system call handler. - Fixes floating point support for MIPS64. - Fixes execve() syscall handler so shell scripts are properly exec'ed. - Fixes uninitialized data bug for extended attribute syscall handlers. - Fixes minor typos in ACL syscall structures. This patch series adds a significant number of system calls and mips/arm support for bsd-user. In its current state it can emulate most FreeBSD mips/mips64 and arm target binaries on a x86 host in a simple chroot environment. (see https://wiki.freebsd.org/QemuUserModeHowTo for the details.) I've been hoping somebody who uses FreeBSD would review these, but since nobody has I'm going to take a look at them. However, I've noticed that none of the patches in this series have Signed-off-by: lines (oddly, since v2 and v1 certainly did). We can't apply them at all without those, so you'll need to fix that in your next respin. I must have neglected to include the signed off option that last time I generated a patch set. I'll generate a new patch set (v4) here in the next day or so. FYI, Anthony Liguori mentioned that he might be able to help with these patches as well. Thanks, -stacey.
Re: [Qemu-devel] [PATCH v3 19/19] bsd-user: fix linking conflicts with FreeBSD libcrypto
On Jan 27, 2014, at 2:07 PM, Peter Maydell peter.mayd...@linaro.org wrote: On 17 December 2013 11:52, Stacey Son s...@freebsd.org wrote: FreeBSD has it's own AES_set_decrypt_key, etc. in libcrypto. This change fixes these conflicts and allows statically linking BSD user mode qemu. --- include/qemu/aes.h |9 + 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/include/qemu/aes.h b/include/qemu/aes.h index e79c707..6d253a3 100644 --- a/include/qemu/aes.h +++ b/include/qemu/aes.h @@ -10,6 +10,15 @@ struct aes_key_st { }; typedef struct aes_key_st AES_KEY; +/* FreeBSD has it's own AES_set_decrypt_key in -lcrypto, avoid conflicts. */ +#ifdef __FreeBSD__ +#define AES_set_encrypt_key QEMU_AES_set_encrypt_key +#define AES_set_decrypt_key QEMU_AES_set_decrypt_key +#define AES_encrypt QEMU_AES_encrypt +#define AES_decrypt QEMU_AES_decrypt +#define AES_cbc_encrypt QEMU_AES_cbc_encrypt +#endif You never answered Paolo's question about this patch, I think: What is the error? Do the functions have different signatures or semantics between QEMU and FreeBSD? If we need to resolve a clash, maybe we should just rename the QEMU versions. Paolo? I must have missed Paolo's question. The linker error (during a static build of qemu bsd-user)... /usr/lib/libcrypto.a(aes-x86_64.o): In function `asm_AES_cbc_encrypt': (.text+0xfa0): multiple definition of `AES_cbc_encrypt' libqemuutil.a(aes.o):/home/sson/src/qemu/util/aes.c:1263: first defined here /usr/lib/libcrypto.a(aes-x86_64.o): In function `asm_AES_decrypt': (.text+0x9f0): multiple definition of `AES_decrypt' libqemuutil.a(aes.o):/home/sson/src/qemu/util/aes.c:1072: first defined here /usr/lib/libcrypto.a(aes-x86_64.o): In function `asm_AES_encrypt': (.text+0x460): multiple definition of `AES_encrypt' -stacey.
[Qemu-devel] [PATCH v3 05/19] bsd-user: move arch/OS dependent code out of syscall.c
This change moves the system call handler for sysctl(2) and sysarch(2) from syscall.c to the OS and arch dependent directories. This eliminates many of the #ifdef's in syscall.c. These system call handlers are now located in the host os and target arch directories. --- bsd-user/Makefile.objs |2 +- bsd-user/arm/target_arch_sigtramp.h | 33 bsd-user/bsdload.c | 170 +- bsd-user/elfload.c |9 +- bsd-user/freebsd/os-sys.c | 284 +++ bsd-user/freebsd/target_os_stack.h | 157 + bsd-user/i386/target_arch_sigtramp.h| 11 ++ bsd-user/mips/target_arch_sigtramp.h| 23 +++ bsd-user/mips64/target_arch_sigtramp.h | 23 +++ bsd-user/netbsd/os-sys.c| 46 + bsd-user/netbsd/target_os_stack.h | 33 bsd-user/openbsd/os-sys.c | 46 + bsd-user/openbsd/target_os_stack.h | 33 bsd-user/qemu.h | 30 +++- bsd-user/sparc/target_arch_sigtramp.h | 11 ++ bsd-user/sparc64/target_arch_sigtramp.h | 11 ++ bsd-user/syscall.c | 210 +++ bsd-user/x86_64/target_arch_sigtramp.h | 11 ++ 18 files changed, 900 insertions(+), 243 deletions(-) create mode 100644 bsd-user/arm/target_arch_sigtramp.h create mode 100644 bsd-user/freebsd/os-sys.c create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/mips/target_arch_sigtramp.h create mode 100644 bsd-user/mips64/target_arch_sigtramp.h create mode 100644 bsd-user/netbsd/os-sys.c create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/os-sys.c create mode 100644 bsd-user/openbsd/target_os_stack.h create mode 100644 bsd-user/sparc/target_arch_sigtramp.h create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 41e8dce..a4dca8e 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,2 +1,2 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o $(TARGET_ABI_DIR)/target_arch_cpu.o + uaccess.o $(HOST_VARIANT_DIR)/os-sys.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/arm/target_arch_sigtramp.h b/bsd-user/arm/target_arch_sigtramp.h new file mode 100644 index 000..98dc313 --- /dev/null +++ b/bsd-user/arm/target_arch_sigtramp.h @@ -0,0 +1,33 @@ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, +unsigned sys_sigreturn) +{ +int i; +uint32_t sys_exit = TARGET_FREEBSD_NR_exit; +/* + * The code has to load r7 manually rather than using + * ldr r7, =SYS_return to make sure the size of the + * code is correct. + */ +uint32_t sigtramp_code[] = { +/* 1 */ 0xE1AD, /* mov r0, sp */ +/* 2 */ 0xE59F700C, /* ldr r7, [pc, #12] */ +/* 3 */ 0xEF00 + sys_sigreturn, /* swi (SYS_sigreturn) */ +/* 4 */ 0xE59F7008, /* ldr r7, [pc, #8] */ +/* 5 */ 0xEF00 + sys_exit, /* swi (SYS_exit)*/ +/* 6 */ 0xEAFA, /* b . -16 */ +/* 7 */ sys_sigreturn, +/* 8 */ sys_exit +}; + +for (i = 0; i 8; i++) { +tswap32s(sigtramp_code[i]); +} + +return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 2abc713..45fdcf8 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -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 sys/types.h #include sys/stat.h @@ -26,38 +41,22 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src, return 0; } -static int in_group_p(gid_t g) -{ -/* return TRUE if we're in the specified group, FALSE otherwise */ -int ngroup; -int i; -gid_t grouplist[TARGET_NGROUPS]; - -
[Qemu-devel] [PATCH v3 00/19] bsd-user: Add system call and mips/arm support.
[v3] - Rebases to commit f46e720a82ccdf1a521cf459448f3f96ed895d43 (HEAD). - Changes 'HOST_API_DIR' to 'HOST_VARIANT_DIR' for the BSD variant. - Fixes boundry condition bug in mmap() system call handler. - Fixes floating point support for MIPS64. - Fixes execve() syscall handler so shell scripts are properly exec'ed. - Fixes uninitialized data bug for extended attribute syscall handlers. - Fixes minor typos in ACL syscall structures. [v2] - Rebases to 1.7.0-rc0. (Requires, however, Andreas Tobler's patch to build: see http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg0.html) - Fixes deadlock in the _umtx_op() system call handler. - Fixes race condition in mmap() system call handler. - Makes qemu-mips (o32) usable. - A small code clean up to the ARM cpu_loop(). - Fixes comment in arm-bsd-user.mak to match filename. - Fixes symbol conflicts with FreeBSD's libcrypto for static link. [v1] This patch series adds a significant number of system calls and mips/arm support for bsd-user. In its current state it can emulate most FreeBSD mips/mips64 and arm target binaries on a x86 host in a simple chroot environment. (see https://wiki.freebsd.org/QemuUserModeHowTo for the details.) Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. I would like to recognize Olivier Houchard for a lot of the arm dependent code and Juergen Lock, the maintainer of the FreeBSD Qemu port, for their contributions. Note that these patches are also available at: http://people.freebsd.org/~sson/qemu/qemu-bsd-user/ and on github in the 'bsd-user' branch of the following repository: https://github.com/staceyson/qemu-bsd-user Best Regards, Stacey D. Son --- Stacey Son (19): bsd-user: refresh freebsd system call numbers bsd-user: add HOST_VARIANT_DIR for various *BSD dependent code bsd-user: move strace OS/arch dependent code to host/arch dirs bsd-user: move arch/OS dependent code out of main.c bsd-user: move arch/OS dependent code out of syscall.c bsd-user: add support for freebsd time related system calls bsd-user: add support for freebsd signal related system calls bsd-user: move arch/OS dependent code out of elfload.c bsd-user: add support for freebsd process related system calls bsd-user: add support for file system related system calls bsd-user: add support for stat, dir, and fcntl related syscalls bsd-user: add support for memory management related syscalls bsd-user: add support for socket related system calls bsd-user: add support for thread related system calls bsd-user: add support for the ioctl system call bsd-user: add support for extattr and ACL related syscalls bsd-user: add support for miscellaneous system calls bsd-user: add arm, mips and mips64 options to configure target-list bsd-user: fix linking conflicts with FreeBSD libcrypto Makefile.target |5 +- bsd-user/Makefile.objs |6 +- bsd-user/arm/syscall.h | 36 + bsd-user/arm/target_arch.h | 10 + bsd-user/arm/target_arch_cpu.c | 27 + bsd-user/arm/target_arch_cpu.h | 375 ++ bsd-user/arm/target_arch_elf.h | 54 + bsd-user/arm/target_arch_signal.h | 257 + bsd-user/arm/target_arch_sigtramp.h | 33 + bsd-user/arm/target_arch_sysarch.h | 78 ++ bsd-user/arm/target_arch_thread.h | 67 ++ bsd-user/arm/target_arch_vmparam.h | 48 + bsd-user/bsd-file.h | ++ bsd-user/bsd-ioctl.c| 448 bsd-user/bsd-ioctl.h| 27 + bsd-user/bsd-mem.c | 122 ++ bsd-user/bsd-mem.h | 393 +++ bsd-user/bsd-misc.c | 209 bsd-user/bsd-misc.h | 339 ++ bsd-user/bsd-proc.c | 160 +++ bsd-user/bsd-proc.h | 434 +++ bsd-user/bsd-signal.h | 232 bsd-user/bsd-socket.c | 108 ++ bsd-user/bsd-socket.h | 266 + bsd-user/bsdload.c | 170 ++- bsd-user/elfload.c | 956 - bsd-user/errno_defs.h | 13 +- bsd-user/freebsd/host_os.h | 46 + bsd-user/freebsd/os-extattr.c | 118 ++ bsd-user/freebsd/os-extattr.h | 654 +++ bsd-user/freebsd/os-ioctl-cmds.h| 47 + bsd-user/freebsd/os-ioctl-filio.h | 45 + bsd-user/freebsd/os-ioctl-ioccom.h | 54 + bsd-user/freebsd/os-ioctl-ttycom.h | 257
[Qemu-devel] [PATCH v3 18/19] bsd-user: add arm, mips and mips64 options to configure target-list
This change adds arm-bsd-user, mips-bsd-user, mips64-bsd-user, mips64el-bsd-user, and mipsel-bsd-user as --target-list options to configure. --- default-configs/arm-bsd-user.mak |3 +++ default-configs/mips-bsd-user.mak |1 + default-configs/mips64-bsd-user.mak |1 + default-configs/mips64el-bsd-user.mak |1 + default-configs/mipsel-bsd-user.mak |1 + 5 files changed, 7 insertions(+), 0 deletions(-) create mode 100644 default-configs/arm-bsd-user.mak create mode 100644 default-configs/mips-bsd-user.mak create mode 100644 default-configs/mips64-bsd-user.mak create mode 100644 default-configs/mips64el-bsd-user.mak create mode 100644 default-configs/mipsel-bsd-user.mak diff --git a/default-configs/arm-bsd-user.mak b/default-configs/arm-bsd-user.mak new file mode 100644 index 000..869e6fb --- /dev/null +++ b/default-configs/arm-bsd-user.mak @@ -0,0 +1,3 @@ +# Default configuration for arm-bsd-user + +CONFIG_GDBSTUB_XML=y diff --git a/default-configs/mips-bsd-user.mak b/default-configs/mips-bsd-user.mak new file mode 100644 index 000..3fb129a --- /dev/null +++ b/default-configs/mips-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips-bsd-user diff --git a/default-configs/mips64-bsd-user.mak b/default-configs/mips64-bsd-user.mak new file mode 100644 index 000..d4e72a6 --- /dev/null +++ b/default-configs/mips64-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64-bsd-user diff --git a/default-configs/mips64el-bsd-user.mak b/default-configs/mips64el-bsd-user.mak new file mode 100644 index 000..b879228 --- /dev/null +++ b/default-configs/mips64el-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64el-bsd-user diff --git a/default-configs/mipsel-bsd-user.mak b/default-configs/mipsel-bsd-user.mak new file mode 100644 index 000..312b9d5 --- /dev/null +++ b/default-configs/mipsel-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mipsel-bsd-user -- 1.7.8
[Qemu-devel] [PATCH v3 19/19] bsd-user: fix linking conflicts with FreeBSD libcrypto
FreeBSD has it's own AES_set_decrypt_key, etc. in libcrypto. This change fixes these conflicts and allows statically linking BSD user mode qemu. --- include/qemu/aes.h |9 + 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/include/qemu/aes.h b/include/qemu/aes.h index e79c707..6d253a3 100644 --- a/include/qemu/aes.h +++ b/include/qemu/aes.h @@ -10,6 +10,15 @@ struct aes_key_st { }; typedef struct aes_key_st AES_KEY; +/* FreeBSD has it's own AES_set_decrypt_key in -lcrypto, avoid conflicts. */ +#ifdef __FreeBSD__ +#define AES_set_encrypt_key QEMU_AES_set_encrypt_key +#define AES_set_decrypt_key QEMU_AES_set_decrypt_key +#define AES_encrypt QEMU_AES_encrypt +#define AES_decrypt QEMU_AES_decrypt +#define AES_cbc_encrypt QEMU_AES_cbc_encrypt +#endif + int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); int AES_set_decrypt_key(const unsigned char *userKey, const int bits, -- 1.7.8
[Qemu-devel] [PATCH v3 11/19] bsd-user: add support for stat, dir, and fcntl related syscalls
This change adds support or stubs for stat, directory, and file control related system calls including stat(2), lstat(2), fstat(2), fstatat(2), nstat(), nfstat(), nlstat(), getfh(2), lgetfh(2), fhopen(2), fhstat(2), fhstatfs(2), statfs(2), fstatfs(2), getfsstat(2), getdents(2), getdirentries(2), and fcntl(2). --- bsd-user/Makefile.objs |1 + bsd-user/freebsd/os-stat.c | 234 +++ bsd-user/freebsd/os-stat.h | 437 bsd-user/freebsd/qemu-os.h |8 + bsd-user/netbsd/os-stat.c |1 + bsd-user/netbsd/os-stat.h |1 + bsd-user/openbsd/os-stat.c |1 + bsd-user/openbsd/os-stat.h | 176 ++ bsd-user/syscall.c | 76 9 files changed, 935 insertions(+), 0 deletions(-) create mode 100644 bsd-user/freebsd/os-stat.c create mode 100644 bsd-user/freebsd/os-stat.h create mode 100644 bsd-user/netbsd/os-stat.c create mode 100644 bsd-user/netbsd/os-stat.h create mode 100644 bsd-user/openbsd/os-stat.c create mode 100644 bsd-user/openbsd/os-stat.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index fac11bb..caf95ed 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-proc.o \ $(HOST_VARIANT_DIR)/os-proc.o \ + $(HOST_VARIANT_DIR)/os-stat.o \ $(HOST_VARIANT_DIR)/os-sys.o \ $(HOST_VARIANT_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-stat.c b/bsd-user/freebsd/os-stat.c new file mode 100644 index 000..50885d1 --- /dev/null +++ b/bsd-user/freebsd/os-stat.c @@ -0,0 +1,234 @@ +/* + * FreeBSD stat related conversion routines + * + * 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 sys/types.h +#include sys/stat.h +#include sys/mount.h + +#include qemu.h +#include qemu-os.h + +/* + * stat conversion + */ +abi_long h2t_freebsd_stat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_stat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +__put_user(host_st-st_atim.tv_nsec, target_st-st_atim.tv_nsec); +__put_user(host_st-st_mtim.tv_sec, target_st-st_mtim.tv_sec); +__put_user(host_st-st_mtim.tv_nsec, target_st-st_mtim.tv_nsec); +__put_user(host_st-st_ctim.tv_sec, target_st-st_ctim.tv_sec); +__put_user(host_st-st_ctim.tv_nsec, target_st-st_ctim.tv_nsec); +__put_user(host_st-st_size, target_st-st_size); +__put_user(host_st-st_blocks, target_st-st_blocks); +__put_user(host_st-st_blksize, target_st-st_blksize); +__put_user(host_st-st_flags, target_st-st_flags); +__put_user(host_st-st_gen, target_st-st_gen); +/* st_lspare not used */ +__put_user(host_st-st_birthtim.tv_sec, target_st-st_birthtim.tv_sec); +__put_user(host_st-st_birthtim.tv_nsec, target_st-st_birthtim.tv_nsec); +unlock_user_struct(target_st, target_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_nstat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_nstat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +
[Qemu-devel] [PATCH v3 13/19] bsd-user: add support for socket related system calls
This change adds support or stubs for socket related system calls including accept(2), bind(2), connect(2), getpeername(2), getsockname(2), getsockopt(2), setsockopt(2), listen(2), recvfrom(2), recvmsg(2), sendmsg(2), sendto(2), socket(2), socketpair(2), shutdown(2), setfib(2), sctp_peeloff(2), sctp_generic_sendmsg(2), sctp_generic_recvmsg(2), sendfile(2), and freebsd4_sendfile(2). --- bsd-user/Makefile.objs |4 +- bsd-user/bsd-socket.c| 108 + bsd-user/bsd-socket.h| 266 bsd-user/freebsd/os-socket.c | 149 bsd-user/freebsd/os-socket.h | 548 ++ bsd-user/freebsd/qemu-os.h |6 + bsd-user/netbsd/os-socket.c |1 + bsd-user/netbsd/os-socket.h | 98 bsd-user/openbsd/os-socket.c |1 + bsd-user/openbsd/os-socket.h | 98 bsd-user/qemu-bsd.h |8 + bsd-user/syscall.c | 93 +++ 12 files changed, 1378 insertions(+), 2 deletions(-) create mode 100644 bsd-user/bsd-socket.c create mode 100644 bsd-user/bsd-socket.h create mode 100644 bsd-user/freebsd/os-socket.c create mode 100644 bsd-user/freebsd/os-socket.h create mode 100644 bsd-user/netbsd/os-socket.c create mode 100644 bsd-user/netbsd/os-socket.h create mode 100644 bsd-user/openbsd/os-socket.c create mode 100644 bsd-user/openbsd/os-socket.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 77709cd..635d879 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-mem.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o bsd-socket.o \ $(HOST_VARIANT_DIR)/os-proc.o \ - $(HOST_VARIANT_DIR)/os-stat.o \ + $(HOST_VARIANT_DIR)/os-socket.o $(HOST_VARIANT_DIR)/os-stat.o \ $(HOST_VARIANT_DIR)/os-sys.o \ $(HOST_VARIANT_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 000..c1a3b49 --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,108 @@ +/* + * BSD socket system call related helpers + * + * 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 sys/types.h +#include sys/socket.h +#include sys/un.h +#include netinet/in.h + +#include qemu.h +#include qemu-bsd.h + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, +socklen_t len) +{ +const socklen_t unix_maxlen = sizeof(struct sockaddr_un); +sa_family_t sa_family; +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} + +sa_family = target_saddr-sa_family; + +/* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * strlen(x-sun_path) while it should be strlen(...) + 1. We will + * fix that here if needed. + */ +if (target_saddr-sa_family == AF_UNIX) { +if (len unix_maxlen len 0) { +char *cp = (char *)target_saddr; + +if (cp[len-1] !cp[len]) { +len++; +} +} +if (len unix_maxlen) { +len = unix_maxlen; +} +} + +memcpy(addr, target_saddr, len); +addr-sa_family = sa_family;/* type uint8_t */ +addr-sa_len = target_saddr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, 0); + +return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr, +socklen_t len) +{ +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} +memcpy(target_saddr, addr, len); +target_saddr-sa_family = addr-sa_family; /* type uint8_t */ +target_saddr-sa_len = addr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, len); + +return 0; +} + +abi_long
[Qemu-devel] [PATCH v3 12/19] bsd-user: add support for memory management related syscalls
This change adds support or stubs for memory management related system calls including mmap(2), munmap(2), mprotect(2), msync(2), mlock(2), munlock(2), mlockall(2), munlockall(2), madvise(2), minherit(2), mincore(2), shm_open(2), shm_unlink(2), shmget(2), shmctl(2), shmat(2), shmdt(2), vadvise(), sbrk(), sstk(), and freebsd6_mmap(). --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-mem.c | 122 +++ bsd-user/bsd-mem.h | 393 bsd-user/mmap.c| 178 -- bsd-user/qemu-bsd.h| 10 ++ bsd-user/qemu.h|3 +- bsd-user/syscall.c | 174 +- 7 files changed, 700 insertions(+), 182 deletions(-) create mode 100644 bsd-user/bsd-mem.c create mode 100644 bsd-user/bsd-mem.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index caf95ed..77709cd 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,5 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o \ $(HOST_VARIANT_DIR)/os-proc.o \ $(HOST_VARIANT_DIR)/os-stat.o \ $(HOST_VARIANT_DIR)/os-sys.o \ diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c new file mode 100644 index 000..bfe03aa --- /dev/null +++ b/bsd-user/bsd-mem.c @@ -0,0 +1,122 @@ +/* + * memory management system conversion routines + * + * 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 sys/ipc.h +#include sys/shm.h + +#include qemu.h +#include qemu-bsd.h + +struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; + +abi_ulong bsd_target_brk; +abi_ulong bsd_target_original_brk; + +void target_set_brk(abi_ulong new_brk) +{ + +bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk); +} + +abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, +abi_ulong target_addr) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_ip-cuid, target_ip-cuid); +__get_user(host_ip-cgid, target_ip-cgid); +__get_user(host_ip-uid, target_ip-uid); +__get_user(host_ip-gid, target_ip-gid); +__get_user(host_ip-mode, target_ip-mode); +__get_user(host_ip-seq, target_ip-seq); +__get_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 0); + +return 0; +} + +abi_long host_to_target_ipc_perm(abi_ulong target_addr, +struct ipc_perm *host_ip) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(host_ip-cuid, target_ip-cuid); +__put_user(host_ip-cgid, target_ip-cgid); +__put_user(host_ip-uid, target_ip-uid); +__put_user(host_ip-gid, target_ip-gid); +__put_user(host_ip-mode, target_ip-mode); +__put_user(host_ip-seq, target_ip-seq); +__put_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 1); + +return 0; +} + +abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, +abi_ulong target_addr) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { +return -TARGET_EFAULT; +} +if (target_to_host_ipc_perm((host_sd-shm_perm), target_addr)) { +return -TARGET_EFAULT; +} +__get_user(host_sd-shm_segsz, target_sd-shm_segsz); +__get_user(host_sd-shm_lpid, target_sd-shm_lpid); +__get_user(host_sd-shm_cpid, target_sd-shm_cpid); +__get_user(host_sd-shm_nattch, target_sd-shm_nattch); +__get_user(host_sd-shm_atime, target_sd-shm_atime); +__get_user(host_sd-shm_dtime, target_sd-shm_dtime); +__get_user(host_sd-shm_ctime, target_sd-shm_ctime); +unlock_user_struct(target_sd, target_addr, 0); + +return 0; +} + +abi_long host_to_target_shmid_ds(abi_ulong target_addr, +struct shmid_ds *host_sd) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { +return -TARGET_EFAULT; +} +if (host_to_target_ipc_perm(target_addr, (host_sd-shm_perm))) { +
[Qemu-devel] [PATCH v3 10/19] bsd-user: add support for file system related system calls
This change adds support or stubs for file system (except stat) related system calls including read(2), pread(2), readv(2), write(2), pwrite(2), writev(2), pwritev(2), open(2), openat(2), close(2), closefrom(2), revoke(2), access(2), eaccess(2), faccessat(2), chdir(2), fchdir(2), rename(2), renameat(2), link(2), linkat(2), unlink(2), unlinkat(2), mkdir(2), mkdirat(2), rmdir(2), __getcwd(), dup(2), dup2(2), truncate(2), ftruncate(2), acct(2), sync(2), mount(2), nmount(2), symlink(2), symlinkat(2), readlink(2), readlinkat(2), chmod(2), fchmod(2), lchmod(2), fchmodat(2), mknod(2), mknodat(2), chown(2), fchown(2), lchown(2), fchownat(2), chflags(2), lchflags(2), fchflags(2), chroot(2), flock(2), mkfifo(2), mkfifoat(2), pathconf(2), lpathconf(2), fpathconf(2), undelete(2), poll(2), lseek(2), pipe(2), swapon(2), swapoff(2), the undocumented openbsd_poll() and freebsd6_*() system calls. --- bsd-user/bsd-file.h | +++ bsd-user/qemu.h | 36 ++ bsd-user/syscall.c | 391 ++ 3 files changed, 1454 insertions(+), 84 deletions(-) create mode 100644 bsd-user/bsd-file.h diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h new file mode 100644 index 000..fc279a8 --- /dev/null +++ b/bsd-user/bsd-file.h @@ -0,0 +1, @@ +/* + * file related system call shims 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 __BSD_FILE_H_ +#define __BSD_FILE_H_ + +#include sys/types.h +#include sys/mount.h +#include sys/uio.h +#include fcntl.h +#include poll.h +#include stdio.h +#include stdlib.h +#include unistd.h + +#define target_to_host_bitmask(x, tbl) (x) + +#define LOCK_PATH(p, arg) do { \ +(p) = lock_user_string(arg); \ +if ((p) == NULL) { \ +return -TARGET_EFAULT; \ +} \ +} while (0) + +#define UNLOCK_PATH(p, arg) unlock_user((p), (arg), 0) + +struct target_pollfd { +int32_t fd; /* file descriptor */ +int16_t events; /* requested events */ +int16_t revents;/* returned events */ +}; + +static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr, +int count, int copy); +static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr, +int count, int copy); +extern int __getcwd(char *path, size_t len); + +/* read(2) */ +static inline abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(read(arg1, p, arg3)); +unlock_user(p, arg2, ret); + +return ret; +} + +/* pread(2) */ +static inline abi_long do_bsd_pread(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +if (regpairs_aligned(cpu_env) != 0) { +arg4 = arg5; +arg5 = arg6; +} +ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5))); +unlock_user(p, arg2, ret); + +return ret; +} + +/* readv(2) */ +static inline abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +int count = arg3; +struct iovec *vec; + +vec = alloca(count * sizeof(struct iovec)); +if (vec == NULL) { +return -TARGET_ENOMEM; +} +if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) 0) { +return -TARGET_EFAULT; +} +ret = get_errno(readv(arg1, vec, count)); +unlock_iovec(vec, arg2, count, 1); + +return ret; +} + +/* write(2) */ +static inline abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_READ, arg2, arg3, 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(write(arg1, p, arg3)); +unlock_user(p, arg2, 0); + +return ret; +} + +/* pwrite(2) */ +static inline abi_long do_bsd_pwrite(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ +abi_long ret; +void *p; + +
[Qemu-devel] [PATCH v3 16/19] bsd-user: add support for extattr and ACL related syscalls
This change add support for extended attribute and Access Control List (ACL) related system calls including extattrctl(), extattr_set_file(2), extattr_delete_file(2), extattr_set_fd(2), extattr_get_fd(2), extattr_delete_fd(2), extattr_get_link(2), extattr_set_link(2), extattr_delete_link(2), extattr_list_fd(2), extattr_list_file(2), extattr_list_link(2), __acl_aclcheck_fd(), __acl_aclcheck_file(), __acl_aclcheck_link(), __acl_delete_fd(), __acl_delete_file(), __acl_delete_link(), __acl_get_fd(), __acl_get_file(), __acl_get_link(), __acl_get_fd(), __acl_set_file(), and __acl_set_link(). --- bsd-user/Makefile.objs|2 +- bsd-user/freebsd/os-extattr.c | 118 bsd-user/freebsd/os-extattr.h | 654 + bsd-user/freebsd/qemu-os.h|6 + bsd-user/netbsd/os-extattr.h | 247 bsd-user/openbsd/os-extattr.h | 247 bsd-user/syscall.c| 104 +++ 7 files changed, 1377 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-extattr.c create mode 100644 bsd-user/freebsd/os-extattr.h create mode 100644 bsd-user/netbsd/os-extattr.h create mode 100644 bsd-user/openbsd/os-extattr.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index a6dba89..d2e005b 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-ioctl.o bsd-mem.o bsd-proc.o bsd-socket.o \ - $(HOST_VARIANT_DIR)/os-proc.o \ + $(HOST_VARIANT_DIR)/os-extattr.o $(HOST_VARIANT_DIR)/os-proc.o \ $(HOST_VARIANT_DIR)/os-socket.o $(HOST_VARIANT_DIR)/os-stat.o \ $(HOST_VARIANT_DIR)/os-sys.o $(HOST_VARIANT_DIR)/os-thread.o \ $(HOST_VARIANT_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 000..95e7b24 --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,118 @@ +/* + * FreeBSD extend attributes and ACL conversions + * + * 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 sys/types.h +#ifndef _ACL_PRIVATE +#define _ACL_PRIVATE +#endif +#include sys/acl.h + +#include qemu.h +#include qemu-os.h + +/* + * FreeBSD ACL conversion. + */ +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_READ, target_acl, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__get_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__get_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__get_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__get_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +unlock_user_struct(target_acl, target_addr, 0); +return 0; +} + +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_WRITE, target_acl, target_addr, 0)) { +return -TARGET_EFAULT; +} + +__put_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__put_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__put_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__put_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__put_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__put_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__put_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +
[Qemu-devel] [PATCH v3 02/19] bsd-user: add HOST_VARIANT_DIR for various *BSD dependent code
This change adds HOST_VARIANT_DIR so the various BSD OS dependent code can be seperated into its own directories rather than using #ifdef's. This may also allow an BSD variant OS to host another BSD variant's executible as a target. --- Makefile.target |3 ++- configure | 11 +++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Makefile.target b/Makefile.target index af6ac7e..1306b24 100644 --- a/Makefile.target +++ b/Makefile.target @@ -99,7 +99,8 @@ endif #CONFIG_LINUX_USER ifdef CONFIG_BSD_USER -QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) +QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \ +-I$(SRC_PATH)/bsd-user/$(HOST_VARIANT_DIR) obj-y += bsd-user/ obj-y += gdbstub.o user-exec.o diff --git a/configure b/configure index edfea95..4e834cf 100755 --- a/configure +++ b/configure @@ -465,6 +465,9 @@ fi # OS specific +# host *BSD for user mode +HOST_VARIANT_DIR= + case $targetos in CYGWIN*) mingw32=yes @@ -490,12 +493,14 @@ FreeBSD) # needed for kinfo_getvmmap(3) in libutil.h LIBS=-lutil $LIBS netmap= # enable netmap autodetect + HOST_VARIANT_DIR=freebsd ;; DragonFly) bsd=yes make=${MAKE-gmake} audio_drv_list=oss audio_possible_drivers=oss sdl esd pa + HOST_VARIANT_DIR=dragonfly ;; NetBSD) bsd=yes @@ -503,12 +508,14 @@ NetBSD) audio_drv_list=oss audio_possible_drivers=oss sdl esd oss_lib=-lossaudio + HOST_VARIANT_DIR=netbsd ;; OpenBSD) bsd=yes make=${MAKE-gmake} audio_drv_list=sdl audio_possible_drivers=sdl esd + HOST_VARIANT_DIR=openbsd ;; Darwin) bsd=yes @@ -527,6 +534,7 @@ Darwin) # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS=-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS + HOST_VARIANT_DIR=darwin ;; SunOS) solaris=yes @@ -4538,6 +4546,9 @@ if [ $TARGET_ABI_DIR = ]; then TARGET_ABI_DIR=$TARGET_ARCH fi echo TARGET_ABI_DIR=$TARGET_ABI_DIR $config_target_mak +if [ $HOST_VARIANT_DIR != ]; then +echo HOST_VARIANT_DIR=$HOST_VARIANT_DIR $config_target_mak +fi case $target_name in i386|x86_64) if test $xen = yes -a $target_softmmu = yes ; then -- 1.7.8
[Qemu-devel] [PATCH v3 01/19] bsd-user: refresh freebsd system call numbers
Update FreeBSD system call numbers in freebsd/syscall_nr.h. Reviewed-by: Ed Maste ema...@freebsd.org --- bsd-user/freebsd/syscall_nr.h | 813 ++--- 1 files changed, 445 insertions(+), 368 deletions(-) diff --git a/bsd-user/freebsd/syscall_nr.h b/bsd-user/freebsd/syscall_nr.h index 36336ab..d849024 100644 --- a/bsd-user/freebsd/syscall_nr.h +++ b/bsd-user/freebsd/syscall_nr.h @@ -1,373 +1,450 @@ /* * System call numbers. * - * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $ - * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson + * created from FreeBSD: releng/9.1/sys/kern/syscalls.master 229723 + * 2012-01-06 19:29:16Z jhb */ -#define TARGET_FREEBSD_NR_syscall 0 -#define TARGET_FREEBSD_NR_exit1 -#define TARGET_FREEBSD_NR_fork2 -#define TARGET_FREEBSD_NR_read3 -#define TARGET_FREEBSD_NR_write 4 -#define TARGET_FREEBSD_NR_open5 -#define TARGET_FREEBSD_NR_close 6 -#define TARGET_FREEBSD_NR_wait4 7 -#define TARGET_FREEBSD_NR_link9 -#define TARGET_FREEBSD_NR_unlink 10 -#define TARGET_FREEBSD_NR_chdir 12 -#define TARGET_FREEBSD_NR_fchdir 13 -#define TARGET_FREEBSD_NR_mknod 14 -#define TARGET_FREEBSD_NR_chmod 15 -#define TARGET_FREEBSD_NR_chown 16 -#define TARGET_FREEBSD_NR_break 17 -#define TARGET_FREEBSD_NR_freebsd4_getfsstat 18 -#define TARGET_FREEBSD_NR_getpid 20 -#define TARGET_FREEBSD_NR_mount 21 -#define TARGET_FREEBSD_NR_unmount 22 -#define TARGET_FREEBSD_NR_setuid 23 -#define TARGET_FREEBSD_NR_getuid 24 -#define TARGET_FREEBSD_NR_geteuid 25 -#define TARGET_FREEBSD_NR_ptrace 26 -#define TARGET_FREEBSD_NR_recvmsg 27 -#define TARGET_FREEBSD_NR_sendmsg 28 -#define TARGET_FREEBSD_NR_recvfrom29 -#define TARGET_FREEBSD_NR_accept 30 -#define TARGET_FREEBSD_NR_getpeername 31 -#define TARGET_FREEBSD_NR_getsockname 32 -#define TARGET_FREEBSD_NR_access 33 -#define TARGET_FREEBSD_NR_chflags 34 -#define TARGET_FREEBSD_NR_fchflags35 -#define TARGET_FREEBSD_NR_sync36 -#define TARGET_FREEBSD_NR_kill37 -#define TARGET_FREEBSD_NR_getppid 39 -#define TARGET_FREEBSD_NR_dup 41 -#define TARGET_FREEBSD_NR_pipe42 -#define TARGET_FREEBSD_NR_getegid 43 -#define TARGET_FREEBSD_NR_profil 44 -#define TARGET_FREEBSD_NR_ktrace 45 -#define TARGET_FREEBSD_NR_getgid 47 -#define TARGET_FREEBSD_NR_getlogin49 -#define TARGET_FREEBSD_NR_setlogin50 -#define TARGET_FREEBSD_NR_acct51 -#define TARGET_FREEBSD_NR_sigaltstack 53 -#define TARGET_FREEBSD_NR_ioctl 54 -#define TARGET_FREEBSD_NR_reboot 55 -#define TARGET_FREEBSD_NR_revoke 56 -#define TARGET_FREEBSD_NR_symlink 57 -#define TARGET_FREEBSD_NR_readlink58 -#define TARGET_FREEBSD_NR_execve 59 -#define TARGET_FREEBSD_NR_umask 60 -#define TARGET_FREEBSD_NR_chroot 61 -#define TARGET_FREEBSD_NR_msync 65 -#define TARGET_FREEBSD_NR_vfork 66 -#define TARGET_FREEBSD_NR_sbrk69 -#define TARGET_FREEBSD_NR_sstk70 -#define TARGET_FREEBSD_NR_vadvise 72 -#define TARGET_FREEBSD_NR_munmap 73 -#define TARGET_FREEBSD_NR_mprotect74 -#define TARGET_FREEBSD_NR_madvise 75 -#define TARGET_FREEBSD_NR_mincore 78 -#define TARGET_FREEBSD_NR_getgroups 79 -#define TARGET_FREEBSD_NR_setgroups 80 -#define TARGET_FREEBSD_NR_getpgrp 81 -#define TARGET_FREEBSD_NR_setpgid 82 -#define TARGET_FREEBSD_NR_setitimer 83 -#define TARGET_FREEBSD_NR_swapon 85 -#define TARGET_FREEBSD_NR_getitimer 86 -#define TARGET_FREEBSD_NR_getdtablesize 89 -#define TARGET_FREEBSD_NR_dup290 -#define TARGET_FREEBSD_NR_fcntl 92 -#define TARGET_FREEBSD_NR_select 93 -#define TARGET_FREEBSD_NR_fsync 95 -#define TARGET_FREEBSD_NR_setpriority 96 -#define TARGET_FREEBSD_NR_socket 97 -#define TARGET_FREEBSD_NR_connect 98 -#define TARGET_FREEBSD_NR_getpriority 100 -#define TARGET_FREEBSD_NR_bind104 -#define TARGET_FREEBSD_NR_setsockopt 105 -#define TARGET_FREEBSD_NR_listen 106 -#define TARGET_FREEBSD_NR_gettimeofday116 -#define TARGET_FREEBSD_NR_getrusage 117 -#define TARGET_FREEBSD_NR_getsockopt 118 -#define TARGET_FREEBSD_NR_readv 120 -#define TARGET_FREEBSD_NR_writev 121 -#define TARGET_FREEBSD_NR_settimeofday122 -#define TARGET_FREEBSD_NR_fchown 123 -#define TARGET_FREEBSD_NR_fchmod 124 -#define TARGET_FREEBSD_NR_setreuid126 -#define TARGET_FREEBSD_NR_setregid127 -#define TARGET_FREEBSD_NR_rename 128 -#define TARGET_FREEBSD_NR_flock 131 -#define TARGET_FREEBSD_NR_mkfifo 132 -#define TARGET_FREEBSD_NR_sendto 133 -#define TARGET_FREEBSD_NR_shutdown134 -#define TARGET_FREEBSD_NR_socketpair 135 -#define TARGET_FREEBSD_NR_mkdir 136 -#define TARGET_FREEBSD_NR_rmdir 137 -#define
[Qemu-devel] [PATCH v3 03/19] bsd-user: move strace OS/arch dependent code to host/arch dirs
This change moves host OS and arch dependent code for the sysarch system call related to the -strace functionality into the appropriate host OS and target arch directories. --- bsd-user/arm/syscall.h | 36 +++ bsd-user/arm/target_arch_sysarch.h | 78 ++ bsd-user/freebsd/os-strace.h | 29 + bsd-user/freebsd/strace.list | 76 +-- bsd-user/i386/syscall.h| 23 bsd-user/i386/target_arch_sysarch.h| 78 ++ bsd-user/mips/syscall.h| 52 ++ bsd-user/mips/target_arch_sysarch.h| 69 + bsd-user/mips64/syscall.h | 53 ++ bsd-user/mips64/target_arch_sysarch.h | 69 + bsd-user/netbsd/os-strace.h|1 + bsd-user/openbsd/os-strace.h |1 + bsd-user/qemu.h| 26 + bsd-user/sparc/syscall.h | 29 +- bsd-user/sparc/target_arch_sysarch.h | 52 ++ bsd-user/sparc64/syscall.h | 28 +- bsd-user/sparc64/target_arch_sysarch.h | 52 ++ bsd-user/strace.c | 175 +-- bsd-user/x86_64/syscall.h | 26 +- bsd-user/x86_64/target_arch_sysarch.h | 76 ++ 20 files changed, 962 insertions(+), 67 deletions(-) create mode 100644 bsd-user/arm/syscall.h create mode 100644 bsd-user/arm/target_arch_sysarch.h create mode 100644 bsd-user/freebsd/os-strace.h create mode 100644 bsd-user/i386/target_arch_sysarch.h create mode 100644 bsd-user/mips/syscall.h create mode 100644 bsd-user/mips/target_arch_sysarch.h create mode 100644 bsd-user/mips64/syscall.h create mode 100644 bsd-user/mips64/target_arch_sysarch.h create mode 100644 bsd-user/netbsd/os-strace.h create mode 100644 bsd-user/openbsd/os-strace.h create mode 100644 bsd-user/sparc/target_arch_sysarch.h create mode 100644 bsd-user/sparc64/target_arch_sysarch.h create mode 100644 bsd-user/x86_64/target_arch_sysarch.h diff --git a/bsd-user/arm/syscall.h b/bsd-user/arm/syscall.h new file mode 100644 index 000..bc3d6e6 --- /dev/null +++ b/bsd-user/arm/syscall.h @@ -0,0 +1,36 @@ +#ifndef __ARCH_SYSCALL_H_ +#define __ARCH_SYSCALL_H_ + +struct target_pt_regs { +abi_long uregs[17]; +}; + +#define ARM_cpsruregs[16] +#define ARM_pc uregs[15] +#define ARM_lr uregs[14] +#define ARM_sp uregs[13] +#define ARM_ip uregs[12] +#define ARM_fp uregs[11] +#define ARM_r10 uregs[10] +#define ARM_r9 uregs[9] +#define ARM_r8 uregs[8] +#define ARM_r7 uregs[7] +#define ARM_r6 uregs[6] +#define ARM_r5 uregs[5] +#define ARM_r4 uregs[4] +#define ARM_r3 uregs[3] +#define ARM_r2 uregs[2] +#define ARM_r1 uregs[1] +#define ARM_r0 uregs[0] + +#define ARM_SYSCALL_BASE0 /* XXX: FreeBSD only */ + +#define TARGET_FREEBSD_ARM_SYNC_ICACHE 0 +#define TARGET_FREEBSD_ARM_DRAIN_WRITEBUF 1 +#define TARGET_FREEBSD_ARM_SET_TP 2 +#define TARGET_FREEBSD_ARM_GET_TP 3 + +#define TARGET_HW_MACHINE arm +#define TARGET_HW_MACHINE_ARCH armv6 + +#endif /* !__ARCH_SYSCALL_H_ */ diff --git a/bsd-user/arm/target_arch_sysarch.h b/bsd-user/arm/target_arch_sysarch.h new file mode 100644 index 000..96d617a --- /dev/null +++ b/bsd-user/arm/target_arch_sysarch.h @@ -0,0 +1,78 @@ +/* + * arm sysarch() system call emulation + * + * 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 __ARCH_SYSARCH_H_ +#define __ARCH_SYSARCH_H_ + +#include syscall.h +#include target_arch.h + +static inline abi_long do_freebsd_arch_sysarch(CPUARMState *env, int op, +abi_ulong parms) +{ +int ret = 0; + +switch (op) { +case TARGET_FREEBSD_ARM_SYNC_ICACHE: +case TARGET_FREEBSD_ARM_DRAIN_WRITEBUF: +break; + +case TARGET_FREEBSD_ARM_SET_TP: +target_cpu_set_tls(env, parms); +break; + +case TARGET_FREEBSD_ARM_GET_TP: +ret = target_cpu_get_tls(env); +break; + +default: +ret = -TARGET_EINVAL; +break; +} +return ret; +} + +static inline void do_freebsd_arch_print_sysarch( +const struct syscallname *name, abi_long arg1, abi_long arg2, +abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
Re: [Qemu-devel] [PATCH v2 00/19] bsd-user: Add system call and mips/arm support.
On Dec 12, 2013, at 1:57 PM, Ed Maste ema...@freebsd.org wrote: On 27 November 2013 06:29, Paolo Bonzini pbonz...@redhat.com wrote: Il 26/11/2013 22:01, Ed Maste ha scritto: Ping. This is a large change in an area that hasn't had a lot of activity of late; what are the next steps here? We're now in hard freeze, so the next step is to wait for 1.8 to be released. I reviewed the parts out of bsd-user, and had only one question. Ok, 1.7's now out, and we'll sort out the HOST_ABI vs. HOST_VARIANT question. What's our next step after that? FYI, I have some addition bug fixes that I will be adding in a new patch set (v3) and will be rebasing to HEAD. Also, I'll make the change from HOST_ABI_DIR to HOST_VARIANT_DIR. The idea is if someone wanted to run, say, OpenBSD targets on a FreeBSD host it would use the code in the bsd-user/freebsd directory to do that. The code would need to support emulation for OpenBSD system calls that are not already natively supported by FreeBSD. Best Regards, -stacey.
[Qemu-devel] [PATCH v2 02/19] bsd-user: add HOST_ABI_DIR for the various *BSD dependent code.
This change adds HOST_ABI_DIR (similar to TARGET_ABI_DIR) so the various BSD OS dependent code can be seperated into its own directories rather than using #ifdef's. Signed-off-by: Stacey Son s...@freebsd.org --- Makefile.target |3 ++- configure | 11 +++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Makefile.target b/Makefile.target index af6ac7e..82ae8cb 100644 --- a/Makefile.target +++ b/Makefile.target @@ -99,7 +99,8 @@ endif #CONFIG_LINUX_USER ifdef CONFIG_BSD_USER -QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) +QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \ +-I$(SRC_PATH)/bsd-user/$(HOST_ABI_DIR) obj-y += bsd-user/ obj-y += gdbstub.o user-exec.o diff --git a/configure b/configure index 91372f9..14571c6 100755 --- a/configure +++ b/configure @@ -449,6 +449,9 @@ fi # OS specific +# host *BSD for user mode +HOST_ABI_DIR= + case $targetos in CYGWIN*) mingw32=yes @@ -473,12 +476,14 @@ FreeBSD) audio_possible_drivers=oss sdl esd pa # needed for kinfo_getvmmap(3) in libutil.h LIBS=-lutil $LIBS + HOST_ABI_DIR=freebsd ;; DragonFly) bsd=yes make=${MAKE-gmake} audio_drv_list=oss audio_possible_drivers=oss sdl esd pa + HOST_ABI_DIR=dragonfly ;; NetBSD) bsd=yes @@ -486,12 +491,14 @@ NetBSD) audio_drv_list=oss audio_possible_drivers=oss sdl esd oss_lib=-lossaudio + HOST_ABI_DIR=netbsd ;; OpenBSD) bsd=yes make=${MAKE-gmake} audio_drv_list=sdl audio_possible_drivers=sdl esd + HOST_ABI_DIR=openbsd ;; Darwin) bsd=yes @@ -510,6 +517,7 @@ Darwin) # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS=-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS + HOST_ABI_DIR=darwin ;; SunOS) solaris=yes @@ -4471,6 +4479,9 @@ if [ $TARGET_ABI_DIR = ]; then TARGET_ABI_DIR=$TARGET_ARCH fi echo TARGET_ABI_DIR=$TARGET_ABI_DIR $config_target_mak +if [ $HOST_ABI_DIR != ]; then +echo HOST_ABI_DIR=$HOST_ABI_DIR $config_target_mak +fi case $target_name in i386|x86_64) if test $xen = yes -a $target_softmmu = yes ; then -- 1.7.8
[Qemu-devel] [PATCH v2 10/19] bsd-user: add support for file system related system calls
This change adds support or stubs for file system (except stat) related system calls including read(2), pread(2), readv(2), write(2), pwrite(2), writev(2), pwritev(2), open(2), openat(2), close(2), closefrom(2), revoke(2), access(2), eaccess(2), faccessat(2), chdir(2), fchdir(2), rename(2), renameat(2), link(2), linkat(2), unlink(2), unlinkat(2), mkdir(2), mkdirat(2), rmdir(2), __getcwd(), dup(2), dup2(2), truncate(2), ftruncate(2), acct(2), sync(2), mount(2), nmount(2), symlink(2), symlinkat(2), readlink(2), readlinkat(2), chmod(2), fchmod(2), lchmod(2), fchmodat(2), mknod(2), mknodat(2), chown(2), fchown(2), lchown(2), fchownat(2), chflags(2), lchflags(2), fchflags(2), chroot(2), flock(2), mkfifo(2), mkfifoat(2), pathconf(2), lpathconf(2), fpathconf(2), undelete(2), poll(2), lseek(2), pipe(2), swapon(2), swapoff(2), and the undocumented openbsd_poll() and freebsd6_*() system calls. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsd-file.h | +++ bsd-user/qemu.h | 36 ++ bsd-user/syscall.c | 391 ++ 3 files changed, 1454 insertions(+), 84 deletions(-) create mode 100644 bsd-user/bsd-file.h diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h new file mode 100644 index 000..fc279a8 --- /dev/null +++ b/bsd-user/bsd-file.h @@ -0,0 +1, @@ +/* + * file related system call shims 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 __BSD_FILE_H_ +#define __BSD_FILE_H_ + +#include sys/types.h +#include sys/mount.h +#include sys/uio.h +#include fcntl.h +#include poll.h +#include stdio.h +#include stdlib.h +#include unistd.h + +#define target_to_host_bitmask(x, tbl) (x) + +#define LOCK_PATH(p, arg) do { \ +(p) = lock_user_string(arg); \ +if ((p) == NULL) { \ +return -TARGET_EFAULT; \ +} \ +} while (0) + +#define UNLOCK_PATH(p, arg) unlock_user((p), (arg), 0) + +struct target_pollfd { +int32_t fd; /* file descriptor */ +int16_t events; /* requested events */ +int16_t revents;/* returned events */ +}; + +static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr, +int count, int copy); +static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr, +int count, int copy); +extern int __getcwd(char *path, size_t len); + +/* read(2) */ +static inline abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(read(arg1, p, arg3)); +unlock_user(p, arg2, ret); + +return ret; +} + +/* pread(2) */ +static inline abi_long do_bsd_pread(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +if (regpairs_aligned(cpu_env) != 0) { +arg4 = arg5; +arg5 = arg6; +} +ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5))); +unlock_user(p, arg2, ret); + +return ret; +} + +/* readv(2) */ +static inline abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +int count = arg3; +struct iovec *vec; + +vec = alloca(count * sizeof(struct iovec)); +if (vec == NULL) { +return -TARGET_ENOMEM; +} +if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) 0) { +return -TARGET_EFAULT; +} +ret = get_errno(readv(arg1, vec, count)); +unlock_iovec(vec, arg2, count, 1); + +return ret; +} + +/* write(2) */ +static inline abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_READ, arg2, arg3, 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(write(arg1, p, arg3)); +unlock_user(p, arg2, 0); + +return ret; +} + +/* pwrite(2) */ +static inline abi_long do_bsd_pwrite(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5
[Qemu-devel] [PATCH v2 00/19] bsd-user: Add system call and mips/arm support.
[v2] - Rebases to 1.7.0-rc0. (Requires, however, Andreas Tobler's patch to build: see http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg0.html) - Fixes deadlock in the _umtx_op() system call handler. - Fixes race condition in mmap() system call handler. - Makes qemu-mips (o32) usable. - A small code clean up to the ARM cpu_loop(). - Fixes comment in arm-bsd-user.mak to match filename. - Fixes symbol conflicts with FreeBSD's libcrypto for static link. [v1] This patch series adds a significant number of system calls and mips/arm support for bsd-user. In its current state it can emulate most FreeBSD mips/mips64 and arm target binaries on a x86 host in a simple chroot environment. (see https://wiki.freebsd.org/QemuUserModeHowTo for the details.) Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. I would like to recognize Olivier Houchard for a lot of the arm dependent code and Juergen Lock, the maintainer of the FreeBSD Qemu port, for their contributions. Best Regards, Stacey D. Son --- Stacey Son (19): bsd-user: refresh freebsd system call numbers bsd-user: add HOST_ABI_DIR for the various *BSD dependent code. bsd-user: move OS/arch dependent code for strace into separate directories bsd-user: move target arch and host OS dependent code out of main.c bsd-user: move target arch and host OS dependent code out of syscall.c bsd-user: add support for freebsd time related system calls bsd-user: add support for freebsd signal related system calls bsd-user: move target arch and host OS dependent code out of elfload.c bsd-user: add support for freebsd process related system calls bsd-user: add support for file system related system calls bsd-user: add support for stat, directory, and file control related system calls bsd-user: add support for memory management related system calls bsd-user: add support for socket related system calls bsd-user: add support for thread related system calls bsd-user: add support for the ioctl system call bsd-user: add support for extended attribute and ACL related syscalls bsd-user: add support for miscellaneous system calls bsd-user: add arm, mips and mips64 options to configure target-list bsd-user: fix linking conflicts with FreeBSD libcrypto Makefile.target |5 +- bsd-user/Makefile.objs |6 +- bsd-user/arm/syscall.h | 36 + bsd-user/arm/target_arch.h | 10 + bsd-user/arm/target_arch_cpu.c | 27 + bsd-user/arm/target_arch_cpu.h | 375 ++ bsd-user/arm/target_arch_elf.h | 54 + bsd-user/arm/target_arch_signal.h | 257 + bsd-user/arm/target_arch_sigtramp.h | 33 + bsd-user/arm/target_arch_sysarch.h | 78 ++ bsd-user/arm/target_arch_thread.h | 67 ++ bsd-user/arm/target_arch_vmparam.h | 51 + bsd-user/bsd-file.h | ++ bsd-user/bsd-ioctl.c| 448 bsd-user/bsd-ioctl.h| 27 + bsd-user/bsd-mem.c | 122 ++ bsd-user/bsd-mem.h | 393 +++ bsd-user/bsd-misc.c | 209 bsd-user/bsd-misc.h | 339 ++ bsd-user/bsd-proc.c | 160 +++ bsd-user/bsd-proc.h | 434 +++ bsd-user/bsd-signal.h | 232 bsd-user/bsd-socket.c | 108 ++ bsd-user/bsd-socket.h | 266 + bsd-user/bsdload.c | 170 ++- bsd-user/elfload.c | 956 - bsd-user/errno_defs.h | 13 +- bsd-user/freebsd/host_os.h | 46 + bsd-user/freebsd/os-extattr.c | 119 ++ bsd-user/freebsd/os-extattr.h | 644 +++ bsd-user/freebsd/os-ioctl-cmds.h| 47 + bsd-user/freebsd/os-ioctl-filio.h | 45 + bsd-user/freebsd/os-ioctl-ioccom.h | 54 + bsd-user/freebsd/os-ioctl-ttycom.h | 257 + bsd-user/freebsd/os-ioctl-types.h |7 + bsd-user/freebsd/os-misc.h | 442 bsd-user/freebsd/os-proc.c | 234 bsd-user/freebsd/os-proc.h | 428 +++ bsd-user/freebsd/os-signal.h| 43 + bsd-user/freebsd/os-socket.c| 149 +++ bsd-user/freebsd/os-socket.h| 548 + bsd-user/freebsd/os-stat.c | 234 bsd-user/freebsd/os-stat.h | 437 +++ bsd-user/freebsd/os-strace.h| 29 + bsd-user
[Qemu-devel] [PATCH v2 11/19] bsd-user: add support for stat, directory, and file control related system calls
This change adds support or stubs for stat, directory, and file control related system calls including stat(2), lstat(2), fstat(2), fstatat(2), nstat(), nfstat(), nlstat(), getfh(2), lgetfh(2), fhopen(2), fhstat(2), fhstatfs(2), statfs(2), fstatfs(2), getfsstat(2), getdents(2), getdirentries(2), and fcntl(2). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |1 + bsd-user/freebsd/os-stat.c | 234 +++ bsd-user/freebsd/os-stat.h | 437 bsd-user/freebsd/qemu-os.h |8 + bsd-user/netbsd/os-stat.c |1 + bsd-user/netbsd/os-stat.h |1 + bsd-user/openbsd/os-stat.c |1 + bsd-user/openbsd/os-stat.h | 176 ++ bsd-user/syscall.c | 76 9 files changed, 935 insertions(+), 0 deletions(-) create mode 100644 bsd-user/freebsd/os-stat.c create mode 100644 bsd-user/freebsd/os-stat.h create mode 100644 bsd-user/netbsd/os-stat.c create mode 100644 bsd-user/netbsd/os-stat.h create mode 100644 bsd-user/openbsd/os-stat.c create mode 100644 bsd-user/openbsd/os-stat.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 6a2fc37..ee70866 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-proc.o \ $(HOST_ABI_DIR)/os-proc.o \ + $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-stat.c b/bsd-user/freebsd/os-stat.c new file mode 100644 index 000..50885d1 --- /dev/null +++ b/bsd-user/freebsd/os-stat.c @@ -0,0 +1,234 @@ +/* + * FreeBSD stat related conversion routines + * + * 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 sys/types.h +#include sys/stat.h +#include sys/mount.h + +#include qemu.h +#include qemu-os.h + +/* + * stat conversion + */ +abi_long h2t_freebsd_stat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_stat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +__put_user(host_st-st_atim.tv_nsec, target_st-st_atim.tv_nsec); +__put_user(host_st-st_mtim.tv_sec, target_st-st_mtim.tv_sec); +__put_user(host_st-st_mtim.tv_nsec, target_st-st_mtim.tv_nsec); +__put_user(host_st-st_ctim.tv_sec, target_st-st_ctim.tv_sec); +__put_user(host_st-st_ctim.tv_nsec, target_st-st_ctim.tv_nsec); +__put_user(host_st-st_size, target_st-st_size); +__put_user(host_st-st_blocks, target_st-st_blocks); +__put_user(host_st-st_blksize, target_st-st_blksize); +__put_user(host_st-st_flags, target_st-st_flags); +__put_user(host_st-st_gen, target_st-st_gen); +/* st_lspare not used */ +__put_user(host_st-st_birthtim.tv_sec, target_st-st_birthtim.tv_sec); +__put_user(host_st-st_birthtim.tv_nsec, target_st-st_birthtim.tv_nsec); +unlock_user_struct(target_st, target_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_nstat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_nstat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st
[Qemu-devel] [PATCH v2 01/19] bsd-user: refresh freebsd system call numbers
Update FreeBSD system call numbers in freebsd/syscall_nr.h. Reviewed-by: Ed Maste ema...@freebsd.org Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/freebsd/syscall_nr.h | 813 ++--- 1 files changed, 445 insertions(+), 368 deletions(-) diff --git a/bsd-user/freebsd/syscall_nr.h b/bsd-user/freebsd/syscall_nr.h index 36336ab..d849024 100644 --- a/bsd-user/freebsd/syscall_nr.h +++ b/bsd-user/freebsd/syscall_nr.h @@ -1,373 +1,450 @@ /* * System call numbers. * - * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $ - * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson + * created from FreeBSD: releng/9.1/sys/kern/syscalls.master 229723 + * 2012-01-06 19:29:16Z jhb */ -#define TARGET_FREEBSD_NR_syscall 0 -#define TARGET_FREEBSD_NR_exit1 -#define TARGET_FREEBSD_NR_fork2 -#define TARGET_FREEBSD_NR_read3 -#define TARGET_FREEBSD_NR_write 4 -#define TARGET_FREEBSD_NR_open5 -#define TARGET_FREEBSD_NR_close 6 -#define TARGET_FREEBSD_NR_wait4 7 -#define TARGET_FREEBSD_NR_link9 -#define TARGET_FREEBSD_NR_unlink 10 -#define TARGET_FREEBSD_NR_chdir 12 -#define TARGET_FREEBSD_NR_fchdir 13 -#define TARGET_FREEBSD_NR_mknod 14 -#define TARGET_FREEBSD_NR_chmod 15 -#define TARGET_FREEBSD_NR_chown 16 -#define TARGET_FREEBSD_NR_break 17 -#define TARGET_FREEBSD_NR_freebsd4_getfsstat 18 -#define TARGET_FREEBSD_NR_getpid 20 -#define TARGET_FREEBSD_NR_mount 21 -#define TARGET_FREEBSD_NR_unmount 22 -#define TARGET_FREEBSD_NR_setuid 23 -#define TARGET_FREEBSD_NR_getuid 24 -#define TARGET_FREEBSD_NR_geteuid 25 -#define TARGET_FREEBSD_NR_ptrace 26 -#define TARGET_FREEBSD_NR_recvmsg 27 -#define TARGET_FREEBSD_NR_sendmsg 28 -#define TARGET_FREEBSD_NR_recvfrom29 -#define TARGET_FREEBSD_NR_accept 30 -#define TARGET_FREEBSD_NR_getpeername 31 -#define TARGET_FREEBSD_NR_getsockname 32 -#define TARGET_FREEBSD_NR_access 33 -#define TARGET_FREEBSD_NR_chflags 34 -#define TARGET_FREEBSD_NR_fchflags35 -#define TARGET_FREEBSD_NR_sync36 -#define TARGET_FREEBSD_NR_kill37 -#define TARGET_FREEBSD_NR_getppid 39 -#define TARGET_FREEBSD_NR_dup 41 -#define TARGET_FREEBSD_NR_pipe42 -#define TARGET_FREEBSD_NR_getegid 43 -#define TARGET_FREEBSD_NR_profil 44 -#define TARGET_FREEBSD_NR_ktrace 45 -#define TARGET_FREEBSD_NR_getgid 47 -#define TARGET_FREEBSD_NR_getlogin49 -#define TARGET_FREEBSD_NR_setlogin50 -#define TARGET_FREEBSD_NR_acct51 -#define TARGET_FREEBSD_NR_sigaltstack 53 -#define TARGET_FREEBSD_NR_ioctl 54 -#define TARGET_FREEBSD_NR_reboot 55 -#define TARGET_FREEBSD_NR_revoke 56 -#define TARGET_FREEBSD_NR_symlink 57 -#define TARGET_FREEBSD_NR_readlink58 -#define TARGET_FREEBSD_NR_execve 59 -#define TARGET_FREEBSD_NR_umask 60 -#define TARGET_FREEBSD_NR_chroot 61 -#define TARGET_FREEBSD_NR_msync 65 -#define TARGET_FREEBSD_NR_vfork 66 -#define TARGET_FREEBSD_NR_sbrk69 -#define TARGET_FREEBSD_NR_sstk70 -#define TARGET_FREEBSD_NR_vadvise 72 -#define TARGET_FREEBSD_NR_munmap 73 -#define TARGET_FREEBSD_NR_mprotect74 -#define TARGET_FREEBSD_NR_madvise 75 -#define TARGET_FREEBSD_NR_mincore 78 -#define TARGET_FREEBSD_NR_getgroups 79 -#define TARGET_FREEBSD_NR_setgroups 80 -#define TARGET_FREEBSD_NR_getpgrp 81 -#define TARGET_FREEBSD_NR_setpgid 82 -#define TARGET_FREEBSD_NR_setitimer 83 -#define TARGET_FREEBSD_NR_swapon 85 -#define TARGET_FREEBSD_NR_getitimer 86 -#define TARGET_FREEBSD_NR_getdtablesize 89 -#define TARGET_FREEBSD_NR_dup290 -#define TARGET_FREEBSD_NR_fcntl 92 -#define TARGET_FREEBSD_NR_select 93 -#define TARGET_FREEBSD_NR_fsync 95 -#define TARGET_FREEBSD_NR_setpriority 96 -#define TARGET_FREEBSD_NR_socket 97 -#define TARGET_FREEBSD_NR_connect 98 -#define TARGET_FREEBSD_NR_getpriority 100 -#define TARGET_FREEBSD_NR_bind104 -#define TARGET_FREEBSD_NR_setsockopt 105 -#define TARGET_FREEBSD_NR_listen 106 -#define TARGET_FREEBSD_NR_gettimeofday116 -#define TARGET_FREEBSD_NR_getrusage 117 -#define TARGET_FREEBSD_NR_getsockopt 118 -#define TARGET_FREEBSD_NR_readv 120 -#define TARGET_FREEBSD_NR_writev 121 -#define TARGET_FREEBSD_NR_settimeofday122 -#define TARGET_FREEBSD_NR_fchown 123 -#define TARGET_FREEBSD_NR_fchmod 124 -#define TARGET_FREEBSD_NR_setreuid126 -#define TARGET_FREEBSD_NR_setregid127 -#define TARGET_FREEBSD_NR_rename 128 -#define TARGET_FREEBSD_NR_flock 131 -#define TARGET_FREEBSD_NR_mkfifo 132 -#define TARGET_FREEBSD_NR_sendto 133 -#define TARGET_FREEBSD_NR_shutdown134 -#define TARGET_FREEBSD_NR_socketpair 135 -#define TARGET_FREEBSD_NR_mkdir 136 -#define
[Qemu-devel] [PATCH v2 13/19] bsd-user: add support for socket related system calls
This change adds support or stubs for socket related system calls including accept(2), bind(2), connect(2), getpeername(2), getsockname(2), getsockopt(2), setsockopt(2), listen(2), recvfrom(2), recvmsg(2), sendmsg(2), sendto(2), socket(2), socketpair(2), shutdown(2), setfib(2), sctp_peeloff(2), sctp_generic_sendmsg(2), sctp_generic_recvmsg(2), sendfile(2), and freebsd4_sendfile(2). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |4 +- bsd-user/bsd-socket.c| 108 + bsd-user/bsd-socket.h| 266 bsd-user/freebsd/os-socket.c | 149 bsd-user/freebsd/os-socket.h | 548 ++ bsd-user/freebsd/qemu-os.h |6 + bsd-user/netbsd/os-socket.c |1 + bsd-user/netbsd/os-socket.h | 98 bsd-user/openbsd/os-socket.c |1 + bsd-user/openbsd/os-socket.h | 98 bsd-user/qemu-bsd.h |8 + bsd-user/syscall.c | 93 +++ 12 files changed, 1378 insertions(+), 2 deletions(-) create mode 100644 bsd-user/bsd-socket.c create mode 100644 bsd-user/bsd-socket.h create mode 100644 bsd-user/freebsd/os-socket.c create mode 100644 bsd-user/freebsd/os-socket.h create mode 100644 bsd-user/netbsd/os-socket.c create mode 100644 bsd-user/netbsd/os-socket.h create mode 100644 bsd-user/openbsd/os-socket.c create mode 100644 bsd-user/openbsd/os-socket.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 1a33a6d..9869837 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-mem.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o bsd-socket.o \ $(HOST_ABI_DIR)/os-proc.o \ - $(HOST_ABI_DIR)/os-stat.o \ + $(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 000..c1a3b49 --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,108 @@ +/* + * BSD socket system call related helpers + * + * 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 sys/types.h +#include sys/socket.h +#include sys/un.h +#include netinet/in.h + +#include qemu.h +#include qemu-bsd.h + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, +socklen_t len) +{ +const socklen_t unix_maxlen = sizeof(struct sockaddr_un); +sa_family_t sa_family; +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} + +sa_family = target_saddr-sa_family; + +/* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * strlen(x-sun_path) while it should be strlen(...) + 1. We will + * fix that here if needed. + */ +if (target_saddr-sa_family == AF_UNIX) { +if (len unix_maxlen len 0) { +char *cp = (char *)target_saddr; + +if (cp[len-1] !cp[len]) { +len++; +} +} +if (len unix_maxlen) { +len = unix_maxlen; +} +} + +memcpy(addr, target_saddr, len); +addr-sa_family = sa_family;/* type uint8_t */ +addr-sa_len = target_saddr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, 0); + +return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr, +socklen_t len) +{ +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} +memcpy(target_saddr, addr, len); +target_saddr-sa_family = addr-sa_family; /* type uint8_t */ +target_saddr-sa_len = addr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, len); + +return 0
[Qemu-devel] [PATCH v2 03/19] bsd-user: move OS/arch dependent code for strace into separate directories
This change moves host OS and arch dependent code for the sysarch system call related to the -strace functionality into the appropriate HOST_ABI_DIR and TARGET_ABI_DIR directories. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/arm/syscall.h | 36 +++ bsd-user/arm/target_arch_sysarch.h | 78 ++ bsd-user/freebsd/os-strace.h | 29 + bsd-user/freebsd/strace.list | 76 +-- bsd-user/i386/syscall.h| 23 bsd-user/i386/target_arch_sysarch.h| 78 ++ bsd-user/mips/syscall.h| 52 ++ bsd-user/mips/target_arch_sysarch.h| 69 + bsd-user/mips64/syscall.h | 53 ++ bsd-user/mips64/target_arch_sysarch.h | 69 + bsd-user/netbsd/os-strace.h|1 + bsd-user/openbsd/os-strace.h |1 + bsd-user/qemu.h| 26 + bsd-user/sparc/syscall.h | 29 +- bsd-user/sparc/target_arch_sysarch.h | 52 ++ bsd-user/sparc64/syscall.h | 28 +- bsd-user/sparc64/target_arch_sysarch.h | 52 ++ bsd-user/strace.c | 175 +-- bsd-user/x86_64/syscall.h | 26 +- bsd-user/x86_64/target_arch_sysarch.h | 76 ++ 20 files changed, 962 insertions(+), 67 deletions(-) create mode 100644 bsd-user/arm/syscall.h create mode 100644 bsd-user/arm/target_arch_sysarch.h create mode 100644 bsd-user/freebsd/os-strace.h create mode 100644 bsd-user/i386/target_arch_sysarch.h create mode 100644 bsd-user/mips/syscall.h create mode 100644 bsd-user/mips/target_arch_sysarch.h create mode 100644 bsd-user/mips64/syscall.h create mode 100644 bsd-user/mips64/target_arch_sysarch.h create mode 100644 bsd-user/netbsd/os-strace.h create mode 100644 bsd-user/openbsd/os-strace.h create mode 100644 bsd-user/sparc/target_arch_sysarch.h create mode 100644 bsd-user/sparc64/target_arch_sysarch.h create mode 100644 bsd-user/x86_64/target_arch_sysarch.h diff --git a/bsd-user/arm/syscall.h b/bsd-user/arm/syscall.h new file mode 100644 index 000..bc3d6e6 --- /dev/null +++ b/bsd-user/arm/syscall.h @@ -0,0 +1,36 @@ +#ifndef __ARCH_SYSCALL_H_ +#define __ARCH_SYSCALL_H_ + +struct target_pt_regs { +abi_long uregs[17]; +}; + +#define ARM_cpsruregs[16] +#define ARM_pc uregs[15] +#define ARM_lr uregs[14] +#define ARM_sp uregs[13] +#define ARM_ip uregs[12] +#define ARM_fp uregs[11] +#define ARM_r10 uregs[10] +#define ARM_r9 uregs[9] +#define ARM_r8 uregs[8] +#define ARM_r7 uregs[7] +#define ARM_r6 uregs[6] +#define ARM_r5 uregs[5] +#define ARM_r4 uregs[4] +#define ARM_r3 uregs[3] +#define ARM_r2 uregs[2] +#define ARM_r1 uregs[1] +#define ARM_r0 uregs[0] + +#define ARM_SYSCALL_BASE0 /* XXX: FreeBSD only */ + +#define TARGET_FREEBSD_ARM_SYNC_ICACHE 0 +#define TARGET_FREEBSD_ARM_DRAIN_WRITEBUF 1 +#define TARGET_FREEBSD_ARM_SET_TP 2 +#define TARGET_FREEBSD_ARM_GET_TP 3 + +#define TARGET_HW_MACHINE arm +#define TARGET_HW_MACHINE_ARCH armv6 + +#endif /* !__ARCH_SYSCALL_H_ */ diff --git a/bsd-user/arm/target_arch_sysarch.h b/bsd-user/arm/target_arch_sysarch.h new file mode 100644 index 000..96d617a --- /dev/null +++ b/bsd-user/arm/target_arch_sysarch.h @@ -0,0 +1,78 @@ +/* + * arm sysarch() system call emulation + * + * 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 __ARCH_SYSARCH_H_ +#define __ARCH_SYSARCH_H_ + +#include syscall.h +#include target_arch.h + +static inline abi_long do_freebsd_arch_sysarch(CPUARMState *env, int op, +abi_ulong parms) +{ +int ret = 0; + +switch (op) { +case TARGET_FREEBSD_ARM_SYNC_ICACHE: +case TARGET_FREEBSD_ARM_DRAIN_WRITEBUF: +break; + +case TARGET_FREEBSD_ARM_SET_TP: +target_cpu_set_tls(env, parms); +break; + +case TARGET_FREEBSD_ARM_GET_TP: +ret = target_cpu_get_tls(env); +break; + +default: +ret = -TARGET_EINVAL; +break; +} +return ret; +} + +static inline void do_freebsd_arch_print_sysarch( +const struct syscallname *name, abi_long arg1, abi_long arg2, +abi_long
[Qemu-devel] [PATCH v2 16/19] bsd-user: add support for extended attribute and ACL related syscalls
This change add support for extended attribute and Access Control List (ACL) related system calls including extattrctl(), extattr_set_file(2), extattr_delete_file(2), extattr_set_fd(2), extattr_get_fd(2), extattr_delete_fd(2), extattr_get_link(2), extattr_set_link(2), extattr_delete_link(2), extattr_list_fd(2), extattr_list_file(2), extattr_list_link(2), __acl_aclcheck_fd(), __acl_aclcheck_file(), __acl_aclcheck_link(), __acl_delete_fd(), __acl_delete_file(), __acl_delete_link(), __acl_get_fd(), __acl_get_file(), __acl_get_link(), __acl_get_fd(), __acl_set_file(), and __acl_set_link(). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs|2 +- bsd-user/freebsd/os-extattr.c | 119 bsd-user/freebsd/os-extattr.h | 644 + bsd-user/freebsd/qemu-os.h|6 + bsd-user/netbsd/os-extattr.h | 247 bsd-user/openbsd/os-extattr.h | 247 bsd-user/syscall.c| 104 +++ 7 files changed, 1368 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-extattr.c create mode 100644 bsd-user/freebsd/os-extattr.h create mode 100644 bsd-user/netbsd/os-extattr.h create mode 100644 bsd-user/openbsd/os-extattr.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 242e6f4..b9eaf2d 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-ioctl.o bsd-mem.o bsd-proc.o bsd-socket.o \ - $(HOST_ABI_DIR)/os-proc.o \ + $(HOST_ABI_DIR)/os-extattr.o $(HOST_ABI_DIR)/os-proc.o \ $(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o $(HOST_ABI_DIR)/os-thread.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 000..7a10047 --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,119 @@ +/* + * FreeBSD extend attributes and ACL conversions + * + * 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 sys/types.h +#ifndef _ACL_PRIVATE +#define _ACL_PRIVATE +#endif +#include sys/acl.h + +#include qemu.h +#include qemu-os.h + +/* + * FreeBSD ACL conversion. + */ +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_READ, target_acl, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__get_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__get_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__get_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__get_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +unlock_user_struct(target_acl, target_addr, 0); +return 0; +} + +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_WRITE, target_acl, target_addr, 0)) { +return -TARGET_EFAULT; +} + +__put_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__put_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__put_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__put_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__put_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags
[Qemu-devel] [PATCH v2 05/19] bsd-user: move target arch and host OS dependent code out of syscall.c
This change moves the system call handler for sysctl(2) and sysarch(2) from syscall.c to the OS and arch dependent directories. This eliminates many of the #ifdef's in syscall.c. These system call handlers are now located in the host os and target arch directories. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/arm/target_arch_sigtramp.h | 33 bsd-user/bsdload.c | 170 ++-- bsd-user/elfload.c |9 +- bsd-user/freebsd/os-sys.c | 268 +++ bsd-user/freebsd/target_os_stack.h | 157 ++ bsd-user/i386/target_arch_sigtramp.h| 11 ++ bsd-user/mips/target_arch_sigtramp.h| 23 +++ bsd-user/mips64/target_arch_sigtramp.h | 23 +++ bsd-user/netbsd/os-sys.c| 46 ++ bsd-user/netbsd/target_os_stack.h | 33 bsd-user/openbsd/os-sys.c | 46 ++ bsd-user/openbsd/target_os_stack.h | 33 bsd-user/qemu.h | 30 +++- bsd-user/sparc/target_arch_sigtramp.h | 11 ++ bsd-user/sparc64/target_arch_sigtramp.h | 11 ++ bsd-user/syscall.c | 210 +++- bsd-user/x86_64/target_arch_sigtramp.h | 11 ++ 18 files changed, 884 insertions(+), 243 deletions(-) create mode 100644 bsd-user/arm/target_arch_sigtramp.h create mode 100644 bsd-user/freebsd/os-sys.c create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/mips/target_arch_sigtramp.h create mode 100644 bsd-user/mips64/target_arch_sigtramp.h create mode 100644 bsd-user/netbsd/os-sys.c create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/os-sys.c create mode 100644 bsd-user/openbsd/target_os_stack.h create mode 100644 bsd-user/sparc/target_arch_sigtramp.h create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 41e8dce..b5ed89e 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,2 +1,2 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o $(TARGET_ABI_DIR)/target_arch_cpu.o + uaccess.o $(HOST_ABI_DIR)/os-sys.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/arm/target_arch_sigtramp.h b/bsd-user/arm/target_arch_sigtramp.h new file mode 100644 index 000..98dc313 --- /dev/null +++ b/bsd-user/arm/target_arch_sigtramp.h @@ -0,0 +1,33 @@ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, +unsigned sys_sigreturn) +{ +int i; +uint32_t sys_exit = TARGET_FREEBSD_NR_exit; +/* + * The code has to load r7 manually rather than using + * ldr r7, =SYS_return to make sure the size of the + * code is correct. + */ +uint32_t sigtramp_code[] = { +/* 1 */ 0xE1AD, /* mov r0, sp */ +/* 2 */ 0xE59F700C, /* ldr r7, [pc, #12] */ +/* 3 */ 0xEF00 + sys_sigreturn, /* swi (SYS_sigreturn) */ +/* 4 */ 0xE59F7008, /* ldr r7, [pc, #8] */ +/* 5 */ 0xEF00 + sys_exit, /* swi (SYS_exit)*/ +/* 6 */ 0xEAFA, /* b . -16 */ +/* 7 */ sys_sigreturn, +/* 8 */ sys_exit +}; + +for (i = 0; i 8; i++) { +tswap32s(sigtramp_code[i]); +} + +return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 2abc713..45fdcf8 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -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 sys/types.h #include sys/stat.h @@ -26,38 +41,22 @@ abi_long memcpy_to_target(abi_ulong dest, const void *src, return 0; } -static int in_group_p(gid_t g) -{ -/* return TRUE if we're in the specified group, FALSE otherwise */ -int ngroup; -int i
[Qemu-devel] [PATCH v2 19/19] bsd-user: fix linking conflicts with FreeBSD libcrypto
FreeBSD has it's own AES_set_decrypt_key, etc. in libcrypto. This change fixes these conflicts and allows statically linking BSD user mode qemu. Signed-off-by: Stacey Son s...@freebsd.org --- include/qemu/aes.h |9 + 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/include/qemu/aes.h b/include/qemu/aes.h index e79c707..6d253a3 100644 --- a/include/qemu/aes.h +++ b/include/qemu/aes.h @@ -10,6 +10,15 @@ struct aes_key_st { }; typedef struct aes_key_st AES_KEY; +/* FreeBSD has it's own AES_set_decrypt_key in -lcrypto, avoid conflicts. */ +#ifdef __FreeBSD__ +#define AES_set_encrypt_key QEMU_AES_set_encrypt_key +#define AES_set_decrypt_key QEMU_AES_set_decrypt_key +#define AES_encrypt QEMU_AES_encrypt +#define AES_decrypt QEMU_AES_decrypt +#define AES_cbc_encrypt QEMU_AES_cbc_encrypt +#endif + int AES_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); int AES_set_decrypt_key(const unsigned char *userKey, const int bits, -- 1.7.8
[Qemu-devel] [PATCH v2 12/19] bsd-user: add support for memory management related system calls
This change adds support or stubs for memory management related system calls including mmap(2), munmap(2), mprotect(2), msync(2), mlock(2), munlock(2), mlockall(2), munlockall(2), madvise(2), minherit(2), mincore(2), shm_open(2), shm_unlink(2), shmget(2), shmctl(2), shmat(2), shmdt(2), vadvise(), sbrk(), sstk(), and freebsd6_mmap(). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-mem.c | 122 bsd-user/bsd-mem.h | 393 ++ bsd-user/mmap.c| 493 ++-- bsd-user/qemu-bsd.h| 10 + bsd-user/qemu.h|3 +- bsd-user/syscall.c | 174 ++--- 7 files changed, 942 insertions(+), 255 deletions(-) create mode 100644 bsd-user/bsd-mem.c create mode 100644 bsd-user/bsd-mem.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index ee70866..1a33a6d 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,5 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o \ $(HOST_ABI_DIR)/os-proc.o \ $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c new file mode 100644 index 000..bfe03aa --- /dev/null +++ b/bsd-user/bsd-mem.c @@ -0,0 +1,122 @@ +/* + * memory management system conversion routines + * + * 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 sys/ipc.h +#include sys/shm.h + +#include qemu.h +#include qemu-bsd.h + +struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; + +abi_ulong bsd_target_brk; +abi_ulong bsd_target_original_brk; + +void target_set_brk(abi_ulong new_brk) +{ + +bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk); +} + +abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, +abi_ulong target_addr) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_ip-cuid, target_ip-cuid); +__get_user(host_ip-cgid, target_ip-cgid); +__get_user(host_ip-uid, target_ip-uid); +__get_user(host_ip-gid, target_ip-gid); +__get_user(host_ip-mode, target_ip-mode); +__get_user(host_ip-seq, target_ip-seq); +__get_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 0); + +return 0; +} + +abi_long host_to_target_ipc_perm(abi_ulong target_addr, +struct ipc_perm *host_ip) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(host_ip-cuid, target_ip-cuid); +__put_user(host_ip-cgid, target_ip-cgid); +__put_user(host_ip-uid, target_ip-uid); +__put_user(host_ip-gid, target_ip-gid); +__put_user(host_ip-mode, target_ip-mode); +__put_user(host_ip-seq, target_ip-seq); +__put_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 1); + +return 0; +} + +abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, +abi_ulong target_addr) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { +return -TARGET_EFAULT; +} +if (target_to_host_ipc_perm((host_sd-shm_perm), target_addr)) { +return -TARGET_EFAULT; +} +__get_user(host_sd-shm_segsz, target_sd-shm_segsz); +__get_user(host_sd-shm_lpid, target_sd-shm_lpid); +__get_user(host_sd-shm_cpid, target_sd-shm_cpid); +__get_user(host_sd-shm_nattch, target_sd-shm_nattch); +__get_user(host_sd-shm_atime, target_sd-shm_atime); +__get_user(host_sd-shm_dtime, target_sd-shm_dtime); +__get_user(host_sd-shm_ctime, target_sd-shm_ctime); +unlock_user_struct(target_sd, target_addr, 0); + +return 0; +} + +abi_long host_to_target_shmid_ds(abi_ulong target_addr, +struct shmid_ds *host_sd) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { +return -TARGET_EFAULT; +} +if (host_to_target_ipc_perm
[Qemu-devel] [PATCH v2 18/19] bsd-user: add arm, mips and mips64 options to configure target-list
This change adds arm-bsd-user, mips-bsd-user, mips64-bsd-user, mips64el-bsd-user, and mipsel-bsd-user as --target-list options to configure. Signed-off-by: Stacey Son s...@freebsd.org --- default-configs/arm-bsd-user.mak |3 +++ default-configs/mips-bsd-user.mak |1 + default-configs/mips64-bsd-user.mak |1 + default-configs/mips64el-bsd-user.mak |1 + default-configs/mipsel-bsd-user.mak |1 + 5 files changed, 7 insertions(+), 0 deletions(-) create mode 100644 default-configs/arm-bsd-user.mak create mode 100644 default-configs/mips-bsd-user.mak create mode 100644 default-configs/mips64-bsd-user.mak create mode 100644 default-configs/mips64el-bsd-user.mak create mode 100644 default-configs/mipsel-bsd-user.mak diff --git a/default-configs/arm-bsd-user.mak b/default-configs/arm-bsd-user.mak new file mode 100644 index 000..869e6fb --- /dev/null +++ b/default-configs/arm-bsd-user.mak @@ -0,0 +1,3 @@ +# Default configuration for arm-bsd-user + +CONFIG_GDBSTUB_XML=y diff --git a/default-configs/mips-bsd-user.mak b/default-configs/mips-bsd-user.mak new file mode 100644 index 000..3fb129a --- /dev/null +++ b/default-configs/mips-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips-bsd-user diff --git a/default-configs/mips64-bsd-user.mak b/default-configs/mips64-bsd-user.mak new file mode 100644 index 000..d4e72a6 --- /dev/null +++ b/default-configs/mips64-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64-bsd-user diff --git a/default-configs/mips64el-bsd-user.mak b/default-configs/mips64el-bsd-user.mak new file mode 100644 index 000..b879228 --- /dev/null +++ b/default-configs/mips64el-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64el-bsd-user diff --git a/default-configs/mipsel-bsd-user.mak b/default-configs/mipsel-bsd-user.mak new file mode 100644 index 000..312b9d5 --- /dev/null +++ b/default-configs/mipsel-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mipsel-bsd-user -- 1.7.8
Re: [Qemu-devel] [PATCH 04/18] bsd-user: move target arch and host OSdependent code out of main.cc
On Oct 16, 2013, at 11:32 AM, Peter Maydell peter.mayd...@linaro.org wrote: On 16 October 2013 16:46, Stacey Son s...@freebsd.org wrote: The arm code came from another source as noted in the cover letter. It could use a lot more work. Possibly better to leave it out of this initial patch set and submit it separately later then? I cleaned up the arm cpu_loop() a bit. You can view the replacement patch it at: http://people.freebsd.org/~sson/qemu/qemu-1.6.1/0004-bsd-user-move-target-arch-and-host-OS-dependent-code.patch Of course, it is still missing support for things like handling undefined instruction (co-proc) exceptions via EmulateAll() but I am hoping someone will pick that up. It is current state, however, it can be used to cross build a good amount of FreeBSD/arm ports. I am hoping one of the BSD/arm guys will find it useful and start contributing. :) -stacey.
[Qemu-devel] [PATCH 00/18] bsd-user: Add system call and mips/arm support.
This patch series adds a significant number of system calls and mips/arm support for bsd-user. In its current state it can emulate most FreeBSD mips/mips64 and arm target binaries on a x86 host in a simple chroot environment. (see https://wiki.freebsd.org/QemuUserModeHowTo for the details.) Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. I would like to recognize Olivier Houchard for a lot of the arm dependent code and Juergen Lock, the maintainer of the FreeBSD Qemu port, for their contributions. Best Regards, Stacey D. Son --- Stacey Son (18): bsd-user: refresh freebsd system call numbers bsd-user: add HOST_ABI_DIR for the various *BSD dependent code. bsd-user: move OS/arch dependent code for strace into separate directories bsd-user: move target arch and host OS dependent code out of main.c bsd-user: move target arch and host OS dependent code out of syscall.c bsd-user: add support for freebsd time related system calls bsd-user: add support for freebsd signal related system calls bsd-user: move target arch and host OS dependent code out of elfload.c bsd-user: add support for freebsd process related system calls bsd-user: add support for file system related system calls bsd-user: add support for stat, directory, and file control related system calls bsd-user: add support for memory management related system calls bsd-user: add support for socket related system calls bsd-user: add support for thread related system calls bsd-user: add support for the ioctl system call bsd-user: add support for extended attribute and ACL related syscalls bsd-user: add support for miscellaneous system calls bsd-user: add arm, mips and mips64 options to configure target-list Makefile.target |5 +- bsd-user/Makefile.objs |6 +- bsd-user/arm/syscall.h | 36 + bsd-user/arm/target_arch.h | 10 + bsd-user/arm/target_arch_cpu.c | 27 + bsd-user/arm/target_arch_cpu.h | 435 +++ bsd-user/arm/target_arch_elf.h | 54 + bsd-user/arm/target_arch_signal.h | 257 + bsd-user/arm/target_arch_sigtramp.h | 33 + bsd-user/arm/target_arch_sysarch.h | 81 ++ bsd-user/arm/target_arch_thread.h | 62 + bsd-user/arm/target_arch_vmparam.h | 49 + bsd-user/bsd-file.h | ++ bsd-user/bsd-ioctl.c| 448 bsd-user/bsd-ioctl.h| 27 + bsd-user/bsd-mem.c | 122 ++ bsd-user/bsd-mem.h | 393 +++ bsd-user/bsd-misc.c | 209 bsd-user/bsd-misc.h | 339 ++ bsd-user/bsd-proc.c | 160 +++ bsd-user/bsd-proc.h | 434 +++ bsd-user/bsd-signal.h | 232 bsd-user/bsd-socket.c | 108 ++ bsd-user/bsd-socket.h | 266 + bsd-user/bsdload.c | 147 ++- bsd-user/elfload.c | 947 +++- bsd-user/errno_defs.h | 13 +- bsd-user/freebsd/host_os.h | 46 + bsd-user/freebsd/os-extattr.c | 119 ++ bsd-user/freebsd/os-extattr.h | 644 +++ bsd-user/freebsd/os-ioctl-cmds.h| 47 + bsd-user/freebsd/os-ioctl-filio.h | 45 + bsd-user/freebsd/os-ioctl-ioccom.h | 54 + bsd-user/freebsd/os-ioctl-ttycom.h | 257 + bsd-user/freebsd/os-ioctl-types.h |7 + bsd-user/freebsd/os-misc.h | 442 bsd-user/freebsd/os-proc.c | 234 bsd-user/freebsd/os-proc.h | 428 +++ bsd-user/freebsd/os-signal.h| 43 + bsd-user/freebsd/os-socket.c| 149 +++ bsd-user/freebsd/os-socket.h| 548 + bsd-user/freebsd/os-stat.c | 234 bsd-user/freebsd/os-stat.h | 437 +++ bsd-user/freebsd/os-strace.h| 29 + bsd-user/freebsd/os-sys.c | 268 + bsd-user/freebsd/os-thread.c| 936 +++ bsd-user/freebsd/os-thread.h| 510 + bsd-user/freebsd/os-time.c | 205 bsd-user/freebsd/os-time.h | 643 +++ bsd-user/freebsd/qemu-os.h | 79 ++ bsd-user/freebsd/strace.list| 76 ++- bsd-user/freebsd/syscall_nr.h | 813 -- bsd-user/freebsd/target_os_elf.h| 145 +++ bsd-user/freebsd/target_os_siginfo.h| 100
[Qemu-devel] [PATCH 01/18] bsd-user: refresh freebsd system call numbers
Update FreeBSD system call numbers in freebsd/syscall_nr.h. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/freebsd/syscall_nr.h | 813 ++--- 1 files changed, 445 insertions(+), 368 deletions(-) diff --git a/bsd-user/freebsd/syscall_nr.h b/bsd-user/freebsd/syscall_nr.h index 36336ab..d849024 100644 --- a/bsd-user/freebsd/syscall_nr.h +++ b/bsd-user/freebsd/syscall_nr.h @@ -1,373 +1,450 @@ /* * System call numbers. * - * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $ - * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson + * created from FreeBSD: releng/9.1/sys/kern/syscalls.master 229723 + * 2012-01-06 19:29:16Z jhb */ -#define TARGET_FREEBSD_NR_syscall 0 -#define TARGET_FREEBSD_NR_exit1 -#define TARGET_FREEBSD_NR_fork2 -#define TARGET_FREEBSD_NR_read3 -#define TARGET_FREEBSD_NR_write 4 -#define TARGET_FREEBSD_NR_open5 -#define TARGET_FREEBSD_NR_close 6 -#define TARGET_FREEBSD_NR_wait4 7 -#define TARGET_FREEBSD_NR_link9 -#define TARGET_FREEBSD_NR_unlink 10 -#define TARGET_FREEBSD_NR_chdir 12 -#define TARGET_FREEBSD_NR_fchdir 13 -#define TARGET_FREEBSD_NR_mknod 14 -#define TARGET_FREEBSD_NR_chmod 15 -#define TARGET_FREEBSD_NR_chown 16 -#define TARGET_FREEBSD_NR_break 17 -#define TARGET_FREEBSD_NR_freebsd4_getfsstat 18 -#define TARGET_FREEBSD_NR_getpid 20 -#define TARGET_FREEBSD_NR_mount 21 -#define TARGET_FREEBSD_NR_unmount 22 -#define TARGET_FREEBSD_NR_setuid 23 -#define TARGET_FREEBSD_NR_getuid 24 -#define TARGET_FREEBSD_NR_geteuid 25 -#define TARGET_FREEBSD_NR_ptrace 26 -#define TARGET_FREEBSD_NR_recvmsg 27 -#define TARGET_FREEBSD_NR_sendmsg 28 -#define TARGET_FREEBSD_NR_recvfrom29 -#define TARGET_FREEBSD_NR_accept 30 -#define TARGET_FREEBSD_NR_getpeername 31 -#define TARGET_FREEBSD_NR_getsockname 32 -#define TARGET_FREEBSD_NR_access 33 -#define TARGET_FREEBSD_NR_chflags 34 -#define TARGET_FREEBSD_NR_fchflags35 -#define TARGET_FREEBSD_NR_sync36 -#define TARGET_FREEBSD_NR_kill37 -#define TARGET_FREEBSD_NR_getppid 39 -#define TARGET_FREEBSD_NR_dup 41 -#define TARGET_FREEBSD_NR_pipe42 -#define TARGET_FREEBSD_NR_getegid 43 -#define TARGET_FREEBSD_NR_profil 44 -#define TARGET_FREEBSD_NR_ktrace 45 -#define TARGET_FREEBSD_NR_getgid 47 -#define TARGET_FREEBSD_NR_getlogin49 -#define TARGET_FREEBSD_NR_setlogin50 -#define TARGET_FREEBSD_NR_acct51 -#define TARGET_FREEBSD_NR_sigaltstack 53 -#define TARGET_FREEBSD_NR_ioctl 54 -#define TARGET_FREEBSD_NR_reboot 55 -#define TARGET_FREEBSD_NR_revoke 56 -#define TARGET_FREEBSD_NR_symlink 57 -#define TARGET_FREEBSD_NR_readlink58 -#define TARGET_FREEBSD_NR_execve 59 -#define TARGET_FREEBSD_NR_umask 60 -#define TARGET_FREEBSD_NR_chroot 61 -#define TARGET_FREEBSD_NR_msync 65 -#define TARGET_FREEBSD_NR_vfork 66 -#define TARGET_FREEBSD_NR_sbrk69 -#define TARGET_FREEBSD_NR_sstk70 -#define TARGET_FREEBSD_NR_vadvise 72 -#define TARGET_FREEBSD_NR_munmap 73 -#define TARGET_FREEBSD_NR_mprotect74 -#define TARGET_FREEBSD_NR_madvise 75 -#define TARGET_FREEBSD_NR_mincore 78 -#define TARGET_FREEBSD_NR_getgroups 79 -#define TARGET_FREEBSD_NR_setgroups 80 -#define TARGET_FREEBSD_NR_getpgrp 81 -#define TARGET_FREEBSD_NR_setpgid 82 -#define TARGET_FREEBSD_NR_setitimer 83 -#define TARGET_FREEBSD_NR_swapon 85 -#define TARGET_FREEBSD_NR_getitimer 86 -#define TARGET_FREEBSD_NR_getdtablesize 89 -#define TARGET_FREEBSD_NR_dup290 -#define TARGET_FREEBSD_NR_fcntl 92 -#define TARGET_FREEBSD_NR_select 93 -#define TARGET_FREEBSD_NR_fsync 95 -#define TARGET_FREEBSD_NR_setpriority 96 -#define TARGET_FREEBSD_NR_socket 97 -#define TARGET_FREEBSD_NR_connect 98 -#define TARGET_FREEBSD_NR_getpriority 100 -#define TARGET_FREEBSD_NR_bind104 -#define TARGET_FREEBSD_NR_setsockopt 105 -#define TARGET_FREEBSD_NR_listen 106 -#define TARGET_FREEBSD_NR_gettimeofday116 -#define TARGET_FREEBSD_NR_getrusage 117 -#define TARGET_FREEBSD_NR_getsockopt 118 -#define TARGET_FREEBSD_NR_readv 120 -#define TARGET_FREEBSD_NR_writev 121 -#define TARGET_FREEBSD_NR_settimeofday122 -#define TARGET_FREEBSD_NR_fchown 123 -#define TARGET_FREEBSD_NR_fchmod 124 -#define TARGET_FREEBSD_NR_setreuid126 -#define TARGET_FREEBSD_NR_setregid127 -#define TARGET_FREEBSD_NR_rename 128 -#define TARGET_FREEBSD_NR_flock 131 -#define TARGET_FREEBSD_NR_mkfifo 132 -#define TARGET_FREEBSD_NR_sendto 133 -#define TARGET_FREEBSD_NR_shutdown134 -#define TARGET_FREEBSD_NR_socketpair 135 -#define TARGET_FREEBSD_NR_mkdir 136 -#define TARGET_FREEBSD_NR_rmdir 137 -#define
[Qemu-devel] [PATCH 03/18] bsd-user: move OS/arch dependent code for strace into separate directories
This change moves host OS and arch dependent code for the sysarch system call related to the -strace functionality into the appropriate HOST_ABI_DIR and TARGET_ABI_DIR directories. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/arm/syscall.h | 36 +++ bsd-user/arm/target_arch_sysarch.h | 81 +++ bsd-user/freebsd/os-strace.h | 29 + bsd-user/freebsd/strace.list | 76 +-- bsd-user/i386/syscall.h| 23 bsd-user/i386/target_arch_sysarch.h| 78 ++ bsd-user/mips/syscall.h| 52 ++ bsd-user/mips/target_arch_sysarch.h| 69 + bsd-user/mips64/syscall.h | 53 ++ bsd-user/mips64/target_arch_sysarch.h | 69 + bsd-user/netbsd/os-strace.h|1 + bsd-user/openbsd/os-strace.h |1 + bsd-user/qemu.h| 26 + bsd-user/sparc/syscall.h | 29 +- bsd-user/sparc/target_arch_sysarch.h | 52 ++ bsd-user/sparc64/syscall.h | 28 +- bsd-user/sparc64/target_arch_sysarch.h | 52 ++ bsd-user/strace.c | 175 +-- bsd-user/x86_64/syscall.h | 26 +- bsd-user/x86_64/target_arch_sysarch.h | 76 ++ 20 files changed, 965 insertions(+), 67 deletions(-) create mode 100644 bsd-user/arm/syscall.h create mode 100644 bsd-user/arm/target_arch_sysarch.h create mode 100644 bsd-user/freebsd/os-strace.h create mode 100644 bsd-user/i386/target_arch_sysarch.h create mode 100644 bsd-user/mips/syscall.h create mode 100644 bsd-user/mips/target_arch_sysarch.h create mode 100644 bsd-user/mips64/syscall.h create mode 100644 bsd-user/mips64/target_arch_sysarch.h create mode 100644 bsd-user/netbsd/os-strace.h create mode 100644 bsd-user/openbsd/os-strace.h create mode 100644 bsd-user/sparc/target_arch_sysarch.h create mode 100644 bsd-user/sparc64/target_arch_sysarch.h create mode 100644 bsd-user/x86_64/target_arch_sysarch.h diff --git a/bsd-user/arm/syscall.h b/bsd-user/arm/syscall.h new file mode 100644 index 000..bc3d6e6 --- /dev/null +++ b/bsd-user/arm/syscall.h @@ -0,0 +1,36 @@ +#ifndef __ARCH_SYSCALL_H_ +#define __ARCH_SYSCALL_H_ + +struct target_pt_regs { +abi_long uregs[17]; +}; + +#define ARM_cpsruregs[16] +#define ARM_pc uregs[15] +#define ARM_lr uregs[14] +#define ARM_sp uregs[13] +#define ARM_ip uregs[12] +#define ARM_fp uregs[11] +#define ARM_r10 uregs[10] +#define ARM_r9 uregs[9] +#define ARM_r8 uregs[8] +#define ARM_r7 uregs[7] +#define ARM_r6 uregs[6] +#define ARM_r5 uregs[5] +#define ARM_r4 uregs[4] +#define ARM_r3 uregs[3] +#define ARM_r2 uregs[2] +#define ARM_r1 uregs[1] +#define ARM_r0 uregs[0] + +#define ARM_SYSCALL_BASE0 /* XXX: FreeBSD only */ + +#define TARGET_FREEBSD_ARM_SYNC_ICACHE 0 +#define TARGET_FREEBSD_ARM_DRAIN_WRITEBUF 1 +#define TARGET_FREEBSD_ARM_SET_TP 2 +#define TARGET_FREEBSD_ARM_GET_TP 3 + +#define TARGET_HW_MACHINE arm +#define TARGET_HW_MACHINE_ARCH armv6 + +#endif /* !__ARCH_SYSCALL_H_ */ diff --git a/bsd-user/arm/target_arch_sysarch.h b/bsd-user/arm/target_arch_sysarch.h new file mode 100644 index 000..0baa54a --- /dev/null +++ b/bsd-user/arm/target_arch_sysarch.h @@ -0,0 +1,81 @@ +/* + * arm sysarch() system call emulation + * + * 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 __ARCH_SYSARCH_H_ +#define __ARCH_SYSARCH_H_ + +#include syscall.h +#include target_arch.h + +static inline abi_long do_freebsd_arch_sysarch(CPUARMState *env, int op, +abi_ulong parms) +{ +int ret = 0; + +switch (op) { +case TARGET_FREEBSD_ARM_SYNC_ICACHE: +case TARGET_FREEBSD_ARM_DRAIN_WRITEBUF: +break; + +case TARGET_FREEBSD_ARM_SET_TP: +target_cpu_set_tls(env, parms); +break; + +case TARGET_FREEBSD_ARM_GET_TP: +/* XXX Need a cpu_get_tls() */ +if (put_user(target_cpu_get_tls(env), parms, abi_ulong)) { +ret = -TARGET_EFAULT; +} +break; + +default: +ret = -TARGET_EINVAL; +break; +} +return ret; +} + +static inline void
[Qemu-devel] [PATCH 05/18] bsd-user: move target arch and host OS dependent code out of syscall.c
This change moves the system call handler for sysctl(2) and sysarch(2) from syscall.c to the OS and arch dependent directories. This eliminates many of the #ifdef's in syscall.c. These system call handlers are now located in the host os and target arch directories. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/arm/target_arch_sigtramp.h | 33 bsd-user/bsdload.c | 147 ++--- bsd-user/elfload.c |9 +- bsd-user/freebsd/os-sys.c | 268 +++ bsd-user/freebsd/target_os_stack.h | 157 ++ bsd-user/i386/target_arch_sigtramp.h| 11 ++ bsd-user/main.c |6 +- bsd-user/mips/target_arch_sigtramp.h| 23 +++ bsd-user/mips64/target_arch_sigtramp.h | 23 +++ bsd-user/netbsd/os-sys.c| 46 ++ bsd-user/netbsd/target_os_stack.h | 33 bsd-user/openbsd/os-sys.c | 46 ++ bsd-user/openbsd/target_os_stack.h | 33 bsd-user/qemu.h | 30 +++- bsd-user/sparc/target_arch_sigtramp.h | 11 ++ bsd-user/sparc64/target_arch_sigtramp.h | 11 ++ bsd-user/syscall.c | 210 +++- bsd-user/x86_64/target_arch_sigtramp.h | 11 ++ 19 files changed, 889 insertions(+), 221 deletions(-) create mode 100644 bsd-user/arm/target_arch_sigtramp.h create mode 100644 bsd-user/freebsd/os-sys.c create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/mips/target_arch_sigtramp.h create mode 100644 bsd-user/mips64/target_arch_sigtramp.h create mode 100644 bsd-user/netbsd/os-sys.c create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/os-sys.c create mode 100644 bsd-user/openbsd/target_os_stack.h create mode 100644 bsd-user/sparc/target_arch_sigtramp.h create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 41e8dce..b5ed89e 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,2 +1,2 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o $(TARGET_ABI_DIR)/target_arch_cpu.o + uaccess.o $(HOST_ABI_DIR)/os-sys.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/arm/target_arch_sigtramp.h b/bsd-user/arm/target_arch_sigtramp.h new file mode 100644 index 000..98dc313 --- /dev/null +++ b/bsd-user/arm/target_arch_sigtramp.h @@ -0,0 +1,33 @@ + +#ifndef _TARGET_ARCH_SIGTRAMP_H_ +#define _TARGET_ARCH_SIGTRAMP_H_ + +/* Compare to arm/arm/locore.S ENTRY_NP(sigcode) */ +static inline abi_long setup_sigtramp(abi_ulong offset, unsigned sigf_uc, +unsigned sys_sigreturn) +{ +int i; +uint32_t sys_exit = TARGET_FREEBSD_NR_exit; +/* + * The code has to load r7 manually rather than using + * ldr r7, =SYS_return to make sure the size of the + * code is correct. + */ +uint32_t sigtramp_code[] = { +/* 1 */ 0xE1AD, /* mov r0, sp */ +/* 2 */ 0xE59F700C, /* ldr r7, [pc, #12] */ +/* 3 */ 0xEF00 + sys_sigreturn, /* swi (SYS_sigreturn) */ +/* 4 */ 0xE59F7008, /* ldr r7, [pc, #8] */ +/* 5 */ 0xEF00 + sys_exit, /* swi (SYS_exit)*/ +/* 6 */ 0xEAFA, /* b . -16 */ +/* 7 */ sys_sigreturn, +/* 8 */ sys_exit +}; + +for (i = 0; i 8; i++) { +tswap32s(sigtramp_code[i]); +} + +return memcpy_to_target(offset, sigtramp_code, TARGET_SZSIGCODE); +} +#endif /* _TARGET_ARCH_SIGTRAMP_H_ */ diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 2abc713..4d5a008 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -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 sys/types.h #include sys/stat.h @@ -34,7 +49,7 @@ static int in_group_p(gid_t g) gid_t grouplist[TARGET_NGROUPS]; ngroup = getgroups(TARGET_NGROUPS, grouplist); -for(i = 0; i ngroup; i++) { +for (i = 0; i ngroup; i
[Qemu-devel] [PATCH 02/18] bsd-user: add HOST_ABI_DIR for the various *BSD dependent code.
This change adds HOST_ABI_DIR (similar to TARGET_ABI_DIR) so the various BSD OS dependent code can be seperated into its own directories rather than using #ifdef's. Signed-off-by: Stacey Son s...@freebsd.org --- Makefile.target |3 ++- configure | 11 +++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/Makefile.target b/Makefile.target index 9a49852..7da81dc 100644 --- a/Makefile.target +++ b/Makefile.target @@ -103,7 +103,8 @@ endif #CONFIG_LINUX_USER ifdef CONFIG_BSD_USER -QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) +QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \ +-I$(SRC_PATH)/bsd-user/$(HOST_ABI_DIR) obj-y += bsd-user/ obj-y += gdbstub.o user-exec.o diff --git a/configure b/configure index 23dbaaf..fb81859 100755 --- a/configure +++ b/configure @@ -449,6 +449,9 @@ fi # OS specific +# host *BSD for user mode +HOST_ABI_DIR= + case $targetos in CYGWIN*) mingw32=yes @@ -473,12 +476,14 @@ FreeBSD) audio_possible_drivers=oss sdl esd pa # needed for kinfo_getvmmap(3) in libutil.h LIBS=-lutil $LIBS + HOST_ABI_DIR=freebsd ;; DragonFly) bsd=yes make=${MAKE-gmake} audio_drv_list=oss audio_possible_drivers=oss sdl esd pa + HOST_ABI_DIR=dragonfly ;; NetBSD) bsd=yes @@ -486,12 +491,14 @@ NetBSD) audio_drv_list=oss audio_possible_drivers=oss sdl esd oss_lib=-lossaudio + HOST_ABI_DIR=netbsd ;; OpenBSD) bsd=yes make=${MAKE-gmake} audio_drv_list=sdl audio_possible_drivers=sdl esd + HOST_ABI_DIR=openbsd ;; Darwin) bsd=yes @@ -510,6 +517,7 @@ Darwin) # Disable attempts to use ObjectiveC features in os/object.h since they # won't work when we're compiling with gcc as a C compiler. QEMU_CFLAGS=-DOS_OBJECT_USE_OBJC=0 $QEMU_CFLAGS + HOST_ABI_DIR=darwin ;; SunOS) solaris=yes @@ -4475,6 +4483,9 @@ if [ $TARGET_ABI_DIR = ]; then TARGET_ABI_DIR=$TARGET_ARCH fi echo TARGET_ABI_DIR=$TARGET_ABI_DIR $config_target_mak +if [ $HOST_ABI_DIR != ]; then +echo HOST_ABI_DIR=$HOST_ABI_DIR $config_target_mak +fi case $target_name in i386|x86_64) if test $xen = yes -a $target_softmmu = yes ; then -- 1.7.8
[Qemu-devel] [PATCH 10/18] bsd-user: add support for file system related system calls
This change adds support or stubs for file system (except stat) related system calls including read(2), pread(2), readv(2), write(2), pwrite(2), writev(2), pwritev(2), open(2), openat(2), close(2), closefrom(2), revoke(2), access(2), eaccess(2), faccessat(2), chdir(2), fchdir(2), rename(2), renameat(2), link(2), linkat(2), unlink(2), unlinkat(2), mkdir(2), mkdirat(2), rmdir(2), __getcwd(), dup(2), dup2(2), truncate(2), ftruncate(2), acct(2), sync(2), mount(2), nmount(2), symlink(2), symlinkat(2), readlink(2), readlinkat(2), chmod(2), fchmod(2), lchmod(2), fchmodat(2), mknod(2), mknodat(2), chown(2), fchown(2), lchown(2), fchownat(2), chflags(2), lchflags(2), fchflags(2), chroot(2), flock(2), mkfifo(2), mkfifoat(2), pathconf(2), lpathconf(2), fpathconf(2), undelete(2), poll(2), lseek(2), pipe(2), swapon(2), swapoff(2), and the undocumented openbsd_poll() and freebsd6_*() system calls. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsd-file.h | +++ bsd-user/qemu.h | 36 ++ bsd-user/syscall.c | 391 ++ 3 files changed, 1454 insertions(+), 84 deletions(-) create mode 100644 bsd-user/bsd-file.h diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h new file mode 100644 index 000..fc279a8 --- /dev/null +++ b/bsd-user/bsd-file.h @@ -0,0 +1, @@ +/* + * file related system call shims 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 __BSD_FILE_H_ +#define __BSD_FILE_H_ + +#include sys/types.h +#include sys/mount.h +#include sys/uio.h +#include fcntl.h +#include poll.h +#include stdio.h +#include stdlib.h +#include unistd.h + +#define target_to_host_bitmask(x, tbl) (x) + +#define LOCK_PATH(p, arg) do { \ +(p) = lock_user_string(arg); \ +if ((p) == NULL) { \ +return -TARGET_EFAULT; \ +} \ +} while (0) + +#define UNLOCK_PATH(p, arg) unlock_user((p), (arg), 0) + +struct target_pollfd { +int32_t fd; /* file descriptor */ +int16_t events; /* requested events */ +int16_t revents;/* returned events */ +}; + +static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr, +int count, int copy); +static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr, +int count, int copy); +extern int __getcwd(char *path, size_t len); + +/* read(2) */ +static inline abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(read(arg1, p, arg3)); +unlock_user(p, arg2, ret); + +return ret; +} + +/* pread(2) */ +static inline abi_long do_bsd_pread(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +if (regpairs_aligned(cpu_env) != 0) { +arg4 = arg5; +arg5 = arg6; +} +ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5))); +unlock_user(p, arg2, ret); + +return ret; +} + +/* readv(2) */ +static inline abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +int count = arg3; +struct iovec *vec; + +vec = alloca(count * sizeof(struct iovec)); +if (vec == NULL) { +return -TARGET_ENOMEM; +} +if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) 0) { +return -TARGET_EFAULT; +} +ret = get_errno(readv(arg1, vec, count)); +unlock_iovec(vec, arg2, count, 1); + +return ret; +} + +/* write(2) */ +static inline abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_READ, arg2, arg3, 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(write(arg1, p, arg3)); +unlock_user(p, arg2, 0); + +return ret; +} + +/* pwrite(2) */ +static inline abi_long do_bsd_pwrite(void *cpu_env, abi_long arg1, +abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5
[Qemu-devel] [PATCH 11/18] bsd-user: add support for stat, directory, and file control related system calls
This change adds support or stubs for stat, directory, and file control related system calls including stat(2), lstat(2), fstat(2), fstatat(2), nstat(), nfstat(), nlstat(), getfh(2), lgetfh(2), fhopen(2), fhstat(2), fhstatfs(2), statfs(2), fstatfs(2), getfsstat(2), getdents(2), getdirentries(2), and fcntl(2). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |1 + bsd-user/freebsd/os-stat.c | 234 +++ bsd-user/freebsd/os-stat.h | 437 bsd-user/freebsd/qemu-os.h |8 + bsd-user/netbsd/os-stat.c |1 + bsd-user/netbsd/os-stat.h |1 + bsd-user/openbsd/os-stat.c |1 + bsd-user/openbsd/os-stat.h | 176 ++ bsd-user/syscall.c | 76 9 files changed, 935 insertions(+), 0 deletions(-) create mode 100644 bsd-user/freebsd/os-stat.c create mode 100644 bsd-user/freebsd/os-stat.h create mode 100644 bsd-user/netbsd/os-stat.c create mode 100644 bsd-user/netbsd/os-stat.h create mode 100644 bsd-user/openbsd/os-stat.c create mode 100644 bsd-user/openbsd/os-stat.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 6a2fc37..ee70866 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-proc.o \ $(HOST_ABI_DIR)/os-proc.o \ + $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-stat.c b/bsd-user/freebsd/os-stat.c new file mode 100644 index 000..50885d1 --- /dev/null +++ b/bsd-user/freebsd/os-stat.c @@ -0,0 +1,234 @@ +/* + * FreeBSD stat related conversion routines + * + * 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 sys/types.h +#include sys/stat.h +#include sys/mount.h + +#include qemu.h +#include qemu-os.h + +/* + * stat conversion + */ +abi_long h2t_freebsd_stat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_stat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +__put_user(host_st-st_atim.tv_nsec, target_st-st_atim.tv_nsec); +__put_user(host_st-st_mtim.tv_sec, target_st-st_mtim.tv_sec); +__put_user(host_st-st_mtim.tv_nsec, target_st-st_mtim.tv_nsec); +__put_user(host_st-st_ctim.tv_sec, target_st-st_ctim.tv_sec); +__put_user(host_st-st_ctim.tv_nsec, target_st-st_ctim.tv_nsec); +__put_user(host_st-st_size, target_st-st_size); +__put_user(host_st-st_blocks, target_st-st_blocks); +__put_user(host_st-st_blksize, target_st-st_blksize); +__put_user(host_st-st_flags, target_st-st_flags); +__put_user(host_st-st_gen, target_st-st_gen); +/* st_lspare not used */ +__put_user(host_st-st_birthtim.tv_sec, target_st-st_birthtim.tv_sec); +__put_user(host_st-st_birthtim.tv_nsec, target_st-st_birthtim.tv_nsec); +unlock_user_struct(target_st, target_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_nstat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_nstat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st
[Qemu-devel] [PATCH 12/18] bsd-user: add support for memory management related system calls
This change adds support or stubs for memory management related system calls including mmap(2), munmap(2), mprotect(2), msync(2), mlock(2), munlock(2), mlockall(2), munlockall(2), madvise(2), minherit(2), mincore(2), shm_open(2), shm_unlink(2), shmget(2), shmctl(2), shmat(2), shmdt(2), vadvise(), sbrk(), sstk(), and freebsd6_mmap(). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-mem.c | 122 +++ bsd-user/bsd-mem.h | 393 bsd-user/mmap.c| 160 +--- bsd-user/qemu-bsd.h| 10 ++ bsd-user/qemu.h|3 +- bsd-user/syscall.c | 174 +- 7 files changed, 670 insertions(+), 194 deletions(-) create mode 100644 bsd-user/bsd-mem.c create mode 100644 bsd-user/bsd-mem.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index ee70866..1a33a6d 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,5 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o \ $(HOST_ABI_DIR)/os-proc.o \ $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c new file mode 100644 index 000..bfe03aa --- /dev/null +++ b/bsd-user/bsd-mem.c @@ -0,0 +1,122 @@ +/* + * memory management system conversion routines + * + * 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 sys/ipc.h +#include sys/shm.h + +#include qemu.h +#include qemu-bsd.h + +struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; + +abi_ulong bsd_target_brk; +abi_ulong bsd_target_original_brk; + +void target_set_brk(abi_ulong new_brk) +{ + +bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk); +} + +abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, +abi_ulong target_addr) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_ip-cuid, target_ip-cuid); +__get_user(host_ip-cgid, target_ip-cgid); +__get_user(host_ip-uid, target_ip-uid); +__get_user(host_ip-gid, target_ip-gid); +__get_user(host_ip-mode, target_ip-mode); +__get_user(host_ip-seq, target_ip-seq); +__get_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 0); + +return 0; +} + +abi_long host_to_target_ipc_perm(abi_ulong target_addr, +struct ipc_perm *host_ip) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(host_ip-cuid, target_ip-cuid); +__put_user(host_ip-cgid, target_ip-cgid); +__put_user(host_ip-uid, target_ip-uid); +__put_user(host_ip-gid, target_ip-gid); +__put_user(host_ip-mode, target_ip-mode); +__put_user(host_ip-seq, target_ip-seq); +__put_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 1); + +return 0; +} + +abi_long target_to_host_shmid_ds(struct shmid_ds *host_sd, +abi_ulong target_addr) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_READ, target_sd, target_addr, 1)) { +return -TARGET_EFAULT; +} +if (target_to_host_ipc_perm((host_sd-shm_perm), target_addr)) { +return -TARGET_EFAULT; +} +__get_user(host_sd-shm_segsz, target_sd-shm_segsz); +__get_user(host_sd-shm_lpid, target_sd-shm_lpid); +__get_user(host_sd-shm_cpid, target_sd-shm_cpid); +__get_user(host_sd-shm_nattch, target_sd-shm_nattch); +__get_user(host_sd-shm_atime, target_sd-shm_atime); +__get_user(host_sd-shm_dtime, target_sd-shm_dtime); +__get_user(host_sd-shm_ctime, target_sd-shm_ctime); +unlock_user_struct(target_sd, target_addr, 0); + +return 0; +} + +abi_long host_to_target_shmid_ds(abi_ulong target_addr, +struct shmid_ds *host_sd) +{ +struct target_shmid_ds *target_sd; + +if (!lock_user_struct(VERIFY_WRITE, target_sd, target_addr, 0)) { +return -TARGET_EFAULT; +} +if (host_to_target_ipc_perm(target_addr
[Qemu-devel] [PATCH 13/18] bsd-user: add support for socket related system calls
This change adds support or stubs for socket related system calls including accept(2), bind(2), connect(2), getpeername(2), getsockname(2), getsockopt(2), setsockopt(2), listen(2), recvfrom(2), recvmsg(2), sendmsg(2), sendto(2), socket(2), socketpair(2), shutdown(2), setfib(2), sctp_peeloff(2), sctp_generic_sendmsg(2), sctp_generic_recvmsg(2), sendfile(2), and freebsd4_sendfile(2). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |4 +- bsd-user/bsd-socket.c| 108 + bsd-user/bsd-socket.h| 266 bsd-user/freebsd/os-socket.c | 149 bsd-user/freebsd/os-socket.h | 548 ++ bsd-user/freebsd/qemu-os.h |6 + bsd-user/netbsd/os-socket.c |1 + bsd-user/netbsd/os-socket.h | 98 bsd-user/openbsd/os-socket.c |1 + bsd-user/openbsd/os-socket.h | 98 bsd-user/qemu-bsd.h |8 + bsd-user/syscall.c | 93 +++ 12 files changed, 1378 insertions(+), 2 deletions(-) create mode 100644 bsd-user/bsd-socket.c create mode 100644 bsd-user/bsd-socket.h create mode 100644 bsd-user/freebsd/os-socket.c create mode 100644 bsd-user/freebsd/os-socket.h create mode 100644 bsd-user/netbsd/os-socket.c create mode 100644 bsd-user/netbsd/os-socket.h create mode 100644 bsd-user/openbsd/os-socket.c create mode 100644 bsd-user/openbsd/os-socket.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 1a33a6d..9869837 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-mem.o bsd-proc.o \ + uaccess.o bsd-mem.o bsd-proc.o bsd-socket.o \ $(HOST_ABI_DIR)/os-proc.o \ - $(HOST_ABI_DIR)/os-stat.o \ + $(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 000..c1a3b49 --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,108 @@ +/* + * BSD socket system call related helpers + * + * 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 sys/types.h +#include sys/socket.h +#include sys/un.h +#include netinet/in.h + +#include qemu.h +#include qemu-bsd.h + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, +socklen_t len) +{ +const socklen_t unix_maxlen = sizeof(struct sockaddr_un); +sa_family_t sa_family; +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} + +sa_family = target_saddr-sa_family; + +/* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * strlen(x-sun_path) while it should be strlen(...) + 1. We will + * fix that here if needed. + */ +if (target_saddr-sa_family == AF_UNIX) { +if (len unix_maxlen len 0) { +char *cp = (char *)target_saddr; + +if (cp[len-1] !cp[len]) { +len++; +} +} +if (len unix_maxlen) { +len = unix_maxlen; +} +} + +memcpy(addr, target_saddr, len); +addr-sa_family = sa_family;/* type uint8_t */ +addr-sa_len = target_saddr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, 0); + +return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr, +socklen_t len) +{ +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} +memcpy(target_saddr, addr, len); +target_saddr-sa_family = addr-sa_family; /* type uint8_t */ +target_saddr-sa_len = addr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, len); + +return 0
[Qemu-devel] [PATCH 18/18] bsd-user: add arm, mips and mips64 options to configure target-list
This change adds arm-bsd-user, mips-bsd-user, mips64-bsd-user, mips64el-bsd-user, and mipsel-bsd-user as --target-list options to configure. Signed-off-by: Stacey Son s...@freebsd.org --- default-configs/arm-bsd-user.mak |3 +++ default-configs/mips-bsd-user.mak |1 + default-configs/mips64-bsd-user.mak |1 + default-configs/mips64el-bsd-user.mak |1 + default-configs/mipsel-bsd-user.mak |1 + 5 files changed, 7 insertions(+), 0 deletions(-) create mode 100644 default-configs/arm-bsd-user.mak create mode 100644 default-configs/mips-bsd-user.mak create mode 100644 default-configs/mips64-bsd-user.mak create mode 100644 default-configs/mips64el-bsd-user.mak create mode 100644 default-configs/mipsel-bsd-user.mak diff --git a/default-configs/arm-bsd-user.mak b/default-configs/arm-bsd-user.mak new file mode 100644 index 000..46d4aa2 --- /dev/null +++ b/default-configs/arm-bsd-user.mak @@ -0,0 +1,3 @@ +# Default configuration for arm-linux-user + +CONFIG_GDBSTUB_XML=y diff --git a/default-configs/mips-bsd-user.mak b/default-configs/mips-bsd-user.mak new file mode 100644 index 000..3fb129a --- /dev/null +++ b/default-configs/mips-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips-bsd-user diff --git a/default-configs/mips64-bsd-user.mak b/default-configs/mips64-bsd-user.mak new file mode 100644 index 000..d4e72a6 --- /dev/null +++ b/default-configs/mips64-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64-bsd-user diff --git a/default-configs/mips64el-bsd-user.mak b/default-configs/mips64el-bsd-user.mak new file mode 100644 index 000..b879228 --- /dev/null +++ b/default-configs/mips64el-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mips64el-bsd-user diff --git a/default-configs/mipsel-bsd-user.mak b/default-configs/mipsel-bsd-user.mak new file mode 100644 index 000..312b9d5 --- /dev/null +++ b/default-configs/mipsel-bsd-user.mak @@ -0,0 +1 @@ +# Default configuration for mipsel-bsd-user -- 1.7.8
[Qemu-devel] [PATCH 16/18] bsd-user: add support for extended attribute and ACL related syscalls
This change add support for extended attribute and Access Control List (ACL) related system calls including extattrctl(), extattr_set_file(2), extattr_delete_file(2), extattr_set_fd(2), extattr_get_fd(2), extattr_delete_fd(2), extattr_get_link(2), extattr_set_link(2), extattr_delete_link(2), extattr_list_fd(2), extattr_list_file(2), extattr_list_link(2), __acl_aclcheck_fd(), __acl_aclcheck_file(), __acl_aclcheck_link(), __acl_delete_fd(), __acl_delete_file(), __acl_delete_link(), __acl_get_fd(), __acl_get_file(), __acl_get_link(), __acl_get_fd(), __acl_set_file(), and __acl_set_link(). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs|2 +- bsd-user/freebsd/os-extattr.c | 119 bsd-user/freebsd/os-extattr.h | 644 + bsd-user/freebsd/qemu-os.h|6 + bsd-user/netbsd/os-extattr.h | 247 bsd-user/openbsd/os-extattr.h | 247 bsd-user/syscall.c| 104 +++ 7 files changed, 1368 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-extattr.c create mode 100644 bsd-user/freebsd/os-extattr.h create mode 100644 bsd-user/netbsd/os-extattr.h create mode 100644 bsd-user/openbsd/os-extattr.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 242e6f4..b9eaf2d 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,6 +1,6 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-ioctl.o bsd-mem.o bsd-proc.o bsd-socket.o \ - $(HOST_ABI_DIR)/os-proc.o \ + $(HOST_ABI_DIR)/os-extattr.o $(HOST_ABI_DIR)/os-proc.o \ $(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \ $(HOST_ABI_DIR)/os-sys.o $(HOST_ABI_DIR)/os-thread.o \ $(HOST_ABI_DIR)/os-time.o $(TARGET_ABI_DIR)/target_arch_cpu.o diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 000..7a10047 --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,119 @@ +/* + * FreeBSD extend attributes and ACL conversions + * + * 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 sys/types.h +#ifndef _ACL_PRIVATE +#define _ACL_PRIVATE +#endif +#include sys/acl.h + +#include qemu.h +#include qemu-os.h + +/* + * FreeBSD ACL conversion. + */ +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_READ, target_acl, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__get_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__get_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__get_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__get_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +unlock_user_struct(target_acl, target_addr, 0); +return 0; +} + +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_WRITE, target_acl, target_addr, 0)) { +return -TARGET_EFAULT; +} + +__put_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__put_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__put_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__put_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__put_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags
Re: [Qemu-devel] [PATCH 00/18] bsd-user: Add system call and mips/armsupport..
On Oct 16, 2013, at 10:27 AM, Alex Bennée alex.ben...@linaro.org wrote: s...@freebsd.org writes: This patch series adds a significant number of system calls and mips/arm support for bsd-user. In its current state it can emulate most FreeBSD mips/mips64 and arm target binaries on a x86 host in a simple chroot environment. (see https://wiki.freebsd.org/QemuUserModeHowTo for the details.) Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. snip What has been the approach to test and verification of the shims? Is there a BSD equivalent to the LTP or some other POSIX test suite to exercise all these shim calls? I did write a lot unit tests which I didn't submit (yet) but my main test was cross building things like perl 5.14 and running its rather large test suite. I also cross built over 8,000 packages for FreeBSD/MIPS64 using Poudrière and qemu-mips64 (see http://people.freebsd.org/~bapt/pres/modern-package-management.pdf for more information). Regards, -stacey.
Re: [Qemu-devel] [PATCH 04/18] bsd-user: move target arch and host OSdependent code out of main.cc
The arm code came from another source as noted in the cover letter. It could use a lot more work. -stacey. On Oct 16, 2013, at 10:38 AM, Alex Bennée alex.ben...@linaro.org wrote: s...@freebsd.org writes: This change moves the cpu initialization and main loop code from main.c to the OS and arch dependent directories. This eliminates many of the #ifdef's in main.c. The cpu initialization and loop code is now located in the arch directory along with target arch support code. Signed-off-by: Stacey Son s...@freebsd.org snip +#if 0 +TaskState *ts = env-opaque; +uint32_t opcode; +int rc; + +/* we handle the FPU emulation here, as Linux */ +/* we get the opcode */ +/* FIXME - what to do if get_user() fails? */ +get_user_u32(opcode, env-regs[15]); + +rc = EmulateAll(opcode, ts-fpa, env); +if (rc == 0) { /* illegal instruction */ +info.si_signo = SIGILL; +info.si_errno = 0; +info.si_code = TARGET_ILL_ILLOPN; +info._sifields._sigfault._addr = env-regs[15]; +queue_signal(env, info.si_signo, info); + +} else if (rc 0) { /* FP exception */ +int arm_fpe = 0; + +/* translate softfloat flags to FPSR flags */ +if (-rc float_flag_invalid) { +arm_fpe |= BIT_IOC; +} +if (-rc float_flag_divbyzero) { +arm_fpe |= BIT_DZC; +} +if (-rc float_flag_overflow) { +arm_fpe |= BIT_OFC; +} +if (-rc float_flag_underflow) { +arm_fpe |= BIT_UFC; +} +if (-rc float_flag_inexact) { +arm_fpe |= BIT_IXC; +} + +FPSR fpsr = ts-fpa.fpsr; +/* printf(fpsr 0x%x, arm_fpe 0x%x\n,fpsr,arm_fpe); */ + +if (fpsr (arm_fpe 16)) { /* exception enabled? */ +info.si_signo = SIGFPE; +info.si_errno = 0; + +/* ordered by priority, least first */ +if (arm_fpe BIT_IXC) { +info.si_code = TARGET_FPE_FLTRES; +} +if (arm_fpe BIT_UFC) { +info.si_code = TARGET_FPE_FLTUND; +} +if (arm_fpe BIT_OFC) { +info.si_code = TARGET_FPE_FLTOVF; +} +if (arm_fpe BIT_DZC) { +info.si_code = TARGET_FPE_FLTDIV; +} +if (arm_fpe BIT_IOC) { +info.si_code = TARGET_FPE_FLTINV; +} +info._sifields._sigfault._addr = env-regs[15]; +queue_signal(env, info.si_signo, info); +} else { +env-regs[15] += 4; +} + +/* accumulate unenabled exceptions */ +if ((!(fpsr BIT_IXE)) (arm_fpe BIT_IXC)) { +fpsr |= BIT_IXC; +} +if ((!(fpsr BIT_UFE)) (arm_fpe BIT_UFC)) { +fpsr |= BIT_UFC; +} +if ((!(fpsr BIT_OFE)) (arm_fpe BIT_OFC)) { +fpsr |= BIT_OFC; +} +if ((!(fpsr BIT_DZE)) (arm_fpe BIT_DZC)) { +fpsr |= BIT_DZC; +} +if ((!(fpsr BIT_IOE)) (arm_fpe BIT_IOC)) { +fpsr |= BIT_IOC; +} +ts-fpa.fpsr = fpsr; +} else { /* everything OK */ +/* increment PC */ +env-regs[15] += 4; +} +} +#endif I'm fairly sure that should either be deleted or re-instated. We have SCMs for a reason ;-) +break; +case EXCP_SWI: +case EXCP_BKPT: +{ +env-eabi = 1; +/* system call */ +if (trapnr == EXCP_BKPT) { +if (env-thumb) { +/* FIXME - what to do if get_user() fails? */ +#ifdef FREEBSD_ARM_OABI +get_user_u16(insn, env-regs[15]); +n = insn 0xff; +#else +n = env-regs[7]; +#endif +env-regs[15] += 2
Re: [Qemu-devel] [PATCH 18/18] bsd-user: add arm, mips and mips64 options to configure target-listt
On Oct 16, 2013, at 10:22 AM, Alex Bennée alex.ben...@linaro.org wrote: s...@freebsd.org writes: This change adds arm-bsd-user, mips-bsd-user, mips64-bsd-user, mips64el-bsd-user, and mipsel-bsd-user as --target-list options to configure. Signed-off-by: Stacey Son s...@freebsd.org --- snip new file mode 100644 index 000..46d4aa2 --- /dev/null +++ b/default-configs/arm-bsd-user.mak @@ -0,0 +1,3 @@ +# Default configuration for arm-linux-user Comment wrong Yes, indeed. Now we know the source of this file. I fixed that in the patch set at http://people.freebsd.org/~sson/qemu/qemu-1.6.1/ snip -stacey.
[Qemu-devel] [PATCH 00/23] bsd-user: FreeBSD support for mips/mips64 and arm
Hi all, This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example). To build this code it requires Ed Maste's configure/linker patches for using an alternate .text segment on FreeBSD. ie. https://github.com/emaste/qemu/commit/2fdae0f4172175dddbd19283a4607eae2a46587d and the suggested change by Richard Henderson https://github.com/emaste/qemu/commit/ede607ad998bac1d44f2e3a79d5f5fb5e70c9f46 Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. I recognize and give credit to Olivier Houchard (arm dependent and other bsd-user code), Juergen Lock (FreeBSD qemu port owner), and Ed Maste (linker configuration). Also, to Andreas Tobler (initial PPC dependent code). I am sure I forgot someone and apoligize in advance. Once this patch set has been has been reviewed and approved I can submit it as a pull request if desired. Best Regards, Stacey D. Son --- Stacey Son (23): bsd-user: initial code clean up bsd-user: add initial support for mips/mips64 bsd-user: additional seperation of OS and architecture dependent code bsd-user: add bsd signal emulation bsd-user: add bsd_binprm to TaskState for core dumping emulation bsd-user: fix thread initialization and ELF addresses for mips/mips64 bsd-user: find target executable in path when absolute path not given bsd-user: initialize stack with signal trampolin code and canary bsd-user: refresh FreeBSD's system call numbers bsd-user: add shims for memory management related syscalls bsd-user: add shims for file related system calls bsd-user: add shims for time related system calls. bsd-user: add shims for signal related system calls bsd-user: add shims for process related system calls bsd-user: add shims for socket related system calls bsd-user: add shims for stat and file handle related syscalls bsd-user: add shims for thread related system calls bsd-user: add shim for the ioctl system call bsd-user: add shims for sysarch() and sysctl() system calls bsd-user: add shims for extended attributes system calls bsd-user: add miscellaneous system call shims bsd-user: add more strace formating bsd-user: add arm cpu support Makefile.target |5 +- bsd-user/Makefile.objs |9 +- bsd-user/arm/syscall.h | 36 + bsd-user/arm/target_arch.h | 13 + bsd-user/arm/target_arch_cpu.h | 405 +++ bsd-user/arm/target_arch_signal.h | 255 bsd-user/arm/target_arch_sigtramp.h | 33 + bsd-user/arm/target_arch_sysarch.h | 80 ++ bsd-user/arm/target_arch_thread.h | 40 + bsd-user/arm/target_arch_vmparam.h | 49 + bsd-user/bsd-file.h | 1095 ++ bsd-user/bsd-mem.c | 122 ++ bsd-user/bsd-mem.h | 387 +++ bsd-user/bsd-misc.c | 209 bsd-user/bsd-misc.h | 339 ++ bsd-user/bsd-mman.h | 121 -- bsd-user/bsd-proc.c | 160 +++ bsd-user/bsd-proc.h | 434 +++ bsd-user/bsd-signal.h | 232 bsd-user/bsd-socket.c | 108 ++ bsd-user/bsd-socket.h | 266 + bsd-user/bsdload.c | 139 ++- bsd-user/elfload.c | 387 --- bsd-user/errno_defs.h | 13 +- bsd-user/freebsd/host_os.h | 46 + bsd-user/freebsd/ioctl-cmds.h | 47 + bsd-user/freebsd/ioctl-filio.h | 45 + bsd-user/freebsd/ioctl-ioccom.h | 54 + bsd-user/freebsd/ioctl-ttycom.h | 257 bsd-user/freebsd/ioctl-types.h |7 + bsd-user/freebsd/os-extattr.c | 119 ++ bsd-user/freebsd/os-extattr.h | 644 +++ bsd-user/freebsd/os-misc.h | 442 +++ bsd-user/freebsd/os-proc.c | 234 bsd-user/freebsd/os-proc.h | 427 +++ bsd-user/freebsd/os-signal.h| 43 + bsd-user/freebsd/os-socket.c| 149 +++ bsd-user/freebsd/os-socket.h| 548 + bsd-user/freebsd/os-stat.c | 234 bsd-user/freebsd/os-stat.h | 437 +++ bsd-user/freebsd/os-strace.h| 29 + bsd-user/freebsd/os-sys.c
[Qemu-devel] [PATCH 08/23] bsd-user: initialize stack with signal trampolin code and canary
Put full path for target executable, signal trampolin code, and stack canary on the stack in addition to just simply coping argv and env values. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/elfload.c | 32 +++- bsd-user/freebsd/target_os_stack.h | 124 +++ bsd-user/i386/target_arch_sigtramp.h| 11 +++ bsd-user/mips/target_arch_signal.h |2 +- bsd-user/mips/target_arch_sigtramp.h| 23 ++ bsd-user/mips64/target_arch_sigtramp.h | 23 ++ bsd-user/netbsd/target_os_stack.h | 31 bsd-user/openbsd/target_os_stack.h | 31 bsd-user/sparc/target_arch_sigtramp.h | 11 +++ bsd-user/sparc64/target_arch_sigtramp.h | 11 +++ bsd-user/x86_64/target_arch_sigtramp.h | 11 +++ 11 files changed, 289 insertions(+), 21 deletions(-) create mode 100644 bsd-user/freebsd/target_os_stack.h create mode 100644 bsd-user/i386/target_arch_sigtramp.h create mode 100644 bsd-user/mips/target_arch_sigtramp.h create mode 100644 bsd-user/mips64/target_arch_sigtramp.h create mode 100644 bsd-user/netbsd/target_os_stack.h create mode 100644 bsd-user/openbsd/target_os_stack.h create mode 100644 bsd-user/sparc/target_arch_sigtramp.h create mode 100644 bsd-user/sparc64/target_arch_sigtramp.h create mode 100644 bsd-user/x86_64/target_arch_sigtramp.h diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 8c8ed6a..0cd5fc4 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -27,6 +27,7 @@ #include qemu.h #include disas/disas.h +#include target_os_stack.h #ifdef _ARCH_PPC64 #undef ARCH_DLINFO @@ -712,38 +713,29 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page, static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm, struct image_info *info) { -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; stack_base = TARGET_USRSTACK - size; -error = target_mmap(0, -size + qemu_host_page_size, -PROT_READ | PROT_WRITE, -MAP_PRIVATE | MAP_ANON, --1, 0); -if (error == -1) { +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); } /* we reserve one extra page at the top of the stack as guard */ -target_mprotect(error + size, qemu_host_page_size, PROT_NONE); - -stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE; -p += stack_base; +target_mprotect(addr + size, qemu_host_page_size, PROT_NONE); -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; +p = setup_initial_stack(p, bprm, stack_base, size, addr); +if (p == 0) { +perror(stk setup); +exit(-1); } + return p; } diff --git a/bsd-user/freebsd/target_os_stack.h b/bsd-user/freebsd/target_os_stack.h new file mode 100644 index 000..f69 --- /dev/null +++ b/bsd-user/freebsd/target_os_stack.h @@ -0,0 +1,124 @@ +#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 abi_ulong setup_initial_stack(abi_ulong p, +struct bsd_binprm *bprm, abi_ulong stack_base, abi_ulong size, +abi_ulong addr) +{ +int i; +abi_ulong stack_hi_addr; +size_t execpath_len; +abi_ulong destp, argvp, envp; +struct target_ps_strings ps_strs; +char canary[sizeof(abi_long) * 8]; + +stack_hi_addr = p = addr + size; + +/* Save some space for ps_strings. */ +p -= sizeof(struct target_ps_strings); + +#ifdef TARGET_SZSIGCODE +/* Add machine depedent sigcode. */ +p -= TARGET_SZSIGCODE
[Qemu-devel] [PATCH 11/23] bsd-user: add shims for file related system calls
This changes adds support for file and file system related system calls that are largely BSD OS independent. Also includes some more clean up of syscall.c. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsd-file.h| 1095 bsd-user/i386/target_arch_vmparam.h|5 + bsd-user/mips/target_arch_vmparam.h|5 + bsd-user/mips64/target_arch_vmparam.h |5 + bsd-user/qemu.h| 36 + bsd-user/sparc/target_arch_vmparam.h |5 + bsd-user/sparc64/target_arch_vmparam.h |5 + bsd-user/syscall.c | 384 +--- bsd-user/x86_64/target_arch_vmparam.h |5 + 9 files changed, 1467 insertions(+), 78 deletions(-) create mode 100644 bsd-user/bsd-file.h diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h new file mode 100644 index 000..f2c0fc7 --- /dev/null +++ b/bsd-user/bsd-file.h @@ -0,0 +1,1095 @@ +/* + * file related system call shims 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 __BSD_FILE_H_ +#define __BSD_FILE_H_ + +#include sys/types.h +#include sys/mount.h +#include sys/uio.h +#include fcntl.h +#include poll.h +#include stdio.h +#include stdlib.h +#include unistd.h + +#define target_to_host_bitmask(x, tbl) (x) + +#define LOCK_PATH(p, arg) do { \ +(p) = lock_user_string(arg); \ +if ((p) == NULL) { \ +return -TARGET_EFAULT; \ +} \ +} while (0) + +#define UNLOCK_PATH(p, arg) unlock_user((p), (arg), 0) + +struct target_pollfd { +int32_t fd; /* file descriptor */ +int16_t events; /* requested events */ +int16_t revents;/* returned events */ +}; + +static abi_long lock_iovec(int type, struct iovec *vec, abi_ulong target_addr, +int count, int copy); +static abi_long unlock_iovec(struct iovec *vec, abi_ulong target_addr, +int count, int copy); +extern int __getcwd(char *path, size_t len); + +/* read(2) */ +static inline abi_long do_bsd_read(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(read(arg1, p, arg3)); +unlock_user(p, arg2, ret); + +return ret; +} + +/* pread(2) */ +static inline abi_long do_bsd_pread(abi_long arg1, abi_long arg2, abi_long arg3, +abi_long arg4, abi_long arg5) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_WRITE, arg2, arg3, 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(pread(arg1, p, arg3, target_offset64(arg4, arg5))); +unlock_user(p, arg2, ret); + +return ret; +} + +/* readv(2) */ +static inline abi_long do_bsd_readv(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +int count = arg3; +struct iovec *vec; + +vec = alloca(count * sizeof(struct iovec)); +if (vec == NULL) { +return -TARGET_ENOMEM; +} +if (lock_iovec(VERIFY_WRITE, vec, arg2, count, 0) 0) { +return -TARGET_EFAULT; +} +ret = get_errno(readv(arg1, vec, count)); +unlock_iovec(vec, arg2, count, 1); + +return ret; +} + +/* write(2) */ +static inline abi_long do_bsd_write(abi_long arg1, abi_long arg2, abi_long arg3) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_READ, arg2, arg3, 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(write(arg1, p, arg3)); +unlock_user(p, arg2, 0); + +return ret; +} + +/* pwrite(2) */ +static inline abi_long do_bsd_pwrite(abi_long arg1, abi_long arg2, +abi_long arg3, abi_long arg4, abi_long arg5) +{ +abi_long ret; +void *p; + +p = lock_user(VERIFY_READ, arg2, arg3, 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +ret = get_errno(pwrite(arg1, p, arg3, target_offset64(arg4, arg5))); +unlock_user(p, arg2, 0); + +return ret; +} + +/* writev(2) */ +static inline abi_long do_bsd_writev(abi_long arg1, abi_long arg2, +abi_long arg3) +{ +abi_long ret; +int count = arg3; +struct iovec *vec; + +vec = alloca(count * sizeof(struct iovec)); +if (vec == NULL) { +return
[Qemu-devel] [PATCH 02/23] bsd-user: add initial support for mips/mips64
Add the main cpu loop, cpu_loop(), for mips and mips64 architecture. Set the cpu model. Add some stubs for future code. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/errno_defs.h |5 + bsd-user/main.c | 189 + bsd-user/mips/syscall.h | 42 +++ bsd-user/mips/target_signal.h | 38 +++ bsd-user/mips64/syscall.h | 42 +++ bsd-user/mips64/target_signal.h | 38 +++ bsd-user/syscall.c|8 ++ default-configs/mips-bsd-user.mak |1 + default-configs/mips64-bsd-user.mak |1 + default-configs/mips64el-bsd-user.mak |1 + default-configs/mipsel-bsd-user.mak |1 + target-mips/mips-defs.h | 13 ++- 12 files changed, 377 insertions(+), 2 deletions(-) create mode 100644 bsd-user/mips/syscall.h create mode 100644 bsd-user/mips/target_signal.h create mode 100644 bsd-user/mips64/syscall.h create mode 100644 bsd-user/mips64/target_signal.h create mode 100644 default-configs/mips-bsd-user.mak create mode 100644 default-configs/mips64-bsd-user.mak create mode 100644 default-configs/mips64el-bsd-user.mak create mode 100644 default-configs/mipsel-bsd-user.mak diff --git a/bsd-user/errno_defs.h b/bsd-user/errno_defs.h index fcf95d3..f01181d 100644 --- a/bsd-user/errno_defs.h +++ b/bsd-user/errno_defs.h @@ -148,4 +148,9 @@ #define TARGET_ENOMSG 90 /* No message of desired type */ #define TARGET_ELAST90 /* Must be equal largest errno */ +/* Internal errors: */ +#define TARGET_EJUSTRETURN 254 /* Just return without + modifing regs */ +#define TARGET_ERESTART 255 /* Restart syscall */ + #endif /* ! _ERRNO_DEFS_H_ */ diff --git a/bsd-user/main.c b/bsd-user/main.c index 572aa14..e64a3ba 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -2,6 +2,7 @@ * qemu user main * * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2013 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 @@ -23,6 +24,7 @@ #include errno.h #include unistd.h #include machine/trap.h +#include sys/syscall.h #include sys/types.h #include sys/mman.h @@ -387,6 +389,172 @@ void cpu_loop(CPUX86State *env) } #endif +#if defined(TARGET_MIPS) + +/* Compare to sys/mips/mips/trap.c */ + +void cpu_loop(CPUMIPSState *env) +{ +#if 0 /* not yet */ +target_siginfo_t info; +#endif +int trapnr; +abi_long ret; +unsigned int syscall_num; + +for (;;) { +cpu_exec_start(env); +trapnr = cpu_mips_exec(env); +cpu_exec_end(env); +switch (trapnr) { +case EXCP_SYSCALL: /* syscall exception */ +syscall_num = env-active_tc.gpr[2]; /* v0 */ +env-active_tc.PC += TARGET_INSN_SIZE; +if (syscall_num = SYS_MAXSYSCALL) { +ret = -TARGET_ENOSYS; +} else { +if (SYS_syscall == syscall_num || +SYS___syscall == syscall_num) { +#if defined(TARGET_MIPS64) +ret = do_freebsd_syscall(env, +env-active_tc.gpr[4],/* syscall #*/ +env-active_tc.gpr[5], /* arg0 */ +env-active_tc.gpr[6], /* arg1 */ +env-active_tc.gpr[7], /* arg2 */ +env-active_tc.gpr[8], /* arg3 */ +env-active_tc.gpr[9], /* arg4 */ +env-active_tc.gpr[10],/* arg5 */ +env-active_tc.gpr[11],/* arg6 */ +0 /* no arg 7 */); +} else { +ret = do_freebsd_syscall(env, +syscall_num, +env-active_tc.gpr[4], +env-active_tc.gpr[5], +env-active_tc.gpr[6], +env-active_tc.gpr[7], +env-active_tc.gpr[8], +env-active_tc.gpr[9], +env-active_tc.gpr[10], +env-active_tc.gpr[11] +); + +#else /* ! TARGET_MIPS64 */ +/* indirect syscall */ +ret = do_freebsd_syscall(env, +env-active_tc.gpr[4],/* syscall #*/ +env-active_tc.gpr[5], /* a1/arg0 */ +env-active_tc.gpr[6], /* a2/arg1 */ +env-active_tc.gpr[7], /* a3/arg2 */ +env-active_tc.gpr[12],/* t4/arg3 */ +env-active_tc.gpr[13],/* t5/arg4 */ +env-active_tc.gpr[14],/* t6/arg5 */ +env-active_tc.gpr[15],/* t7/arg6 */ +0 /* no arg7
[Qemu-devel] [PATCH 12/23] bsd-user: add shims for time related system calls.
This change adds support for time related system calls that are largely FreeBSD dependent because time_t is inconsistly defined for the various *BSD's. On FreeBSD time_t is mostly defined as a 64-bit value. On some architectures like PPC32 it is defined as a 32-bit value, however. On NetBSD it is always defined as an int64_t. On OpenBSD it is defined as an int. This change also defines system call shim stubs for NetBSD/OpenBSD in case some whats to add code to emulate FreeBSD binaries on one of the other *BSD's. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/freebsd/os-time.c | 205 +++ bsd-user/freebsd/os-time.h | 602 bsd-user/freebsd/qemu-os.h | 41 +++ bsd-user/netbsd/os-time.c |1 + bsd-user/netbsd/os-time.h | 179 + bsd-user/netbsd/qemu-os.h |1 + bsd-user/openbsd/os-time.c |1 + bsd-user/openbsd/os-time.h | 179 + bsd-user/openbsd/qemu-os.h |1 + bsd-user/syscall.c | 96 +++ bsd-user/syscall_defs.h| 76 ++ 12 files changed, 1383 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-time.c create mode 100644 bsd-user/freebsd/os-time.h create mode 100644 bsd-user/freebsd/qemu-os.h create mode 100644 bsd-user/netbsd/os-time.c create mode 100644 bsd-user/netbsd/os-time.h create mode 100644 bsd-user/netbsd/qemu-os.h create mode 100644 bsd-user/openbsd/os-time.c create mode 100644 bsd-user/openbsd/os-time.h create mode 100644 bsd-user/openbsd/qemu-os.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index d0cea36..4c6acb0 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,2 +1,2 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-mem.o + uaccess.o bsd-mem.o $(TARGET_OS)/os-time.o diff --git a/bsd-user/freebsd/os-time.c b/bsd-user/freebsd/os-time.c new file mode 100644 index 000..7ac4397 --- /dev/null +++ b/bsd-user/freebsd/os-time.c @@ -0,0 +1,205 @@ +/* + * FreeBSD time related system call helpers + * + * 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 time.h +#include sys/timex.h +#include sys/select.h + +#include qemu.h +#include qemu-os.h + +/* + * FreeBSD time conversion functions + */ +abi_long t2h_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr) +{ +struct target_freebsd_timeval *target_tv; + +if (!lock_user_struct(VERIFY_READ, target_tv, target_tv_addr, 0)) { +return -TARGET_EFAULT; +} +__get_user(tv-tv_sec, target_tv-tv_sec); +__get_user(tv-tv_usec, target_tv-tv_usec); +unlock_user_struct(target_tv, target_tv_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_timeval(struct timeval *tv, abi_ulong target_tv_addr) +{ +struct target_freebsd_timeval *target_tv; + +if (!lock_user_struct(VERIFY_WRITE, target_tv, target_tv_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(tv-tv_sec, target_tv-tv_sec); +__put_user(tv-tv_usec, target_tv-tv_usec); +unlock_user_struct(target_tv, target_tv_addr, 1); + +return 0; +} + +abi_long t2h_freebsd_timespec(struct timespec *ts, abi_ulong target_ts_addr) +{ +struct target_freebsd_timespec *target_ts; + +if (!lock_user_struct(VERIFY_READ, target_ts, target_ts_addr, 0)) { +return -TARGET_EFAULT; +} +__get_user(ts-tv_sec, target_ts-tv_sec); +__get_user(ts-tv_nsec, target_ts-tv_nsec); +unlock_user_struct(target_ts, target_ts_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_timespec(abi_ulong target_ts_addr, struct timespec *ts) +{ +struct target_freebsd_timespec *target_ts; + +if (!lock_user_struct(VERIFY_WRITE, target_ts, target_ts_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(ts-tv_sec, target_ts-tv_sec); +__put_user(ts-tv_nsec, target_ts-tv_nsec); +unlock_user_struct(target_ts, target_ts_addr, 1); + +return 0; +} + +abi_long t2h_freebsd_timex(struct timex *host_tx, abi_ulong target_tx_addr) +{ +struct target_freebsd_timex *target_tx; + +if (!lock_user_struct(VERIFY_READ, target_tx, target_tx_addr, 0)) { +return -TARGET_EFAULT; +} +__get_user(host_tx-modes, target_tx-modes); +__get_user(host_tx-offset, target_tx
[Qemu-devel] [PATCH 10/23] bsd-user: add shims for memory management related syscalls
This change adds support for bsd memory management system calls including mmap(2), munmap(2), mprotect(2), msync(2), etc. Also, it adds shared memory management system calls. In addition, cleans up syscall.c a bit and fixes checkpatch.pl warnings and errors. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-errno.h| 41 + bsd-user/bsd-mem.c | 122 +++ bsd-user/bsd-mem.h | 387 +++ bsd-user/bsd-mman.h | 121 --- bsd-user/mmap.c | 84 +++ bsd-user/qemu-bsd.h | 34 bsd-user/qemu.h |1 + bsd-user/syscall.c | 185 +-- bsd-user/syscall_defs.h | 71 + 10 files changed, 782 insertions(+), 266 deletions(-) create mode 100644 bsd-user/bsd-errno.h create mode 100644 bsd-user/bsd-mem.c create mode 100644 bsd-user/bsd-mem.h delete mode 100644 bsd-user/bsd-mman.h create mode 100644 bsd-user/qemu-bsd.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 5e77f57..d0cea36 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,2 +1,2 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ - uaccess.o + uaccess.o bsd-mem.o diff --git a/bsd-user/bsd-errno.h b/bsd-user/bsd-errno.h new file mode 100644 index 000..721bfc0 --- /dev/null +++ b/bsd-user/bsd-errno.h @@ -0,0 +1,41 @@ +/* + * errno translation + * + * Copyright (c) 2003 - 2008 Fabrice Bellard + * 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 __BSD_ERRNO_H_ +#define __BSD_ERRNO_H_ + +static inline abi_long get_errno(abi_long ret) +{ + +if (ret == -1) { +/* XXX need to translate host - target errnos here */ +return -(errno); +} else { +return ret; +} +} + +static inline int is_error(abi_long ret) +{ + +return (abi_ulong)ret = (abi_ulong)(-4096); +} + +#endif /* !__BSD_ERRNO_H_ */ diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c new file mode 100644 index 000..bfe03aa --- /dev/null +++ b/bsd-user/bsd-mem.c @@ -0,0 +1,122 @@ +/* + * memory management system conversion routines + * + * 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 sys/ipc.h +#include sys/shm.h + +#include qemu.h +#include qemu-bsd.h + +struct bsd_shm_regions bsd_shm_regions[N_BSD_SHM_REGIONS]; + +abi_ulong bsd_target_brk; +abi_ulong bsd_target_original_brk; + +void target_set_brk(abi_ulong new_brk) +{ + +bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk); +} + +abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, +abi_ulong target_addr) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_ip-cuid, target_ip-cuid); +__get_user(host_ip-cgid, target_ip-cgid); +__get_user(host_ip-uid, target_ip-uid); +__get_user(host_ip-gid, target_ip-gid); +__get_user(host_ip-mode, target_ip-mode); +__get_user(host_ip-seq, target_ip-seq); +__get_user(host_ip-key, target_ip-key); +unlock_user_struct(target_ip, target_addr, 0); + +return 0; +} + +abi_long host_to_target_ipc_perm(abi_ulong target_addr, +struct ipc_perm *host_ip) +{ +struct target_ipc_perm *target_ip; + +if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(host_ip-cuid, target_ip-cuid); +__put_user(host_ip-cgid, target_ip-cgid); +__put_user(host_ip-uid, target_ip-uid); +__put_user(host_ip-gid, target_ip-gid
[Qemu-devel] [PATCH 01/23] bsd-user: initial code clean up
Add license headers, #ifndef's for header files, and fix various style problem as reported by checkpatch.pl. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsd-mman.h |2 +- bsd-user/bsdload.c | 21 ++- bsd-user/elfload.c | 122 ++ bsd-user/errno_defs.h|8 ++- bsd-user/freebsd/strace.list | 18 ++ bsd-user/freebsd/syscall_nr.h| 21 ++- bsd-user/i386/syscall.h | 21 +++ bsd-user/i386/target_signal.h| 17 + bsd-user/main.c | 24 bsd-user/mmap.c | 24 bsd-user/netbsd/strace.list | 18 ++ bsd-user/netbsd/syscall_nr.h | 24 +++- bsd-user/openbsd/strace.list | 18 ++ bsd-user/openbsd/syscall_nr.h| 24 +++- bsd-user/qemu.h | 20 ++- bsd-user/sparc/syscall.h | 22 +++ bsd-user/sparc64/syscall.h | 21 +++ bsd-user/sparc64/target_signal.h | 23 ++- bsd-user/strace.c| 17 + bsd-user/syscall.c | 14 ++-- bsd-user/syscall_defs.h |6 +- bsd-user/uaccess.c | 20 ++- bsd-user/x86_64/syscall.h| 22 +++ bsd-user/x86_64/target_signal.h | 23 ++- 24 files changed, 442 insertions(+), 108 deletions(-) diff --git a/bsd-user/bsd-mman.h b/bsd-user/bsd-mman.h index 910e8c1..2193ce7 100644 --- a/bsd-user/bsd-mman.h +++ b/bsd-user/bsd-mman.h @@ -1,4 +1,4 @@ -/*- +/*-- * Copyright (c) 1982, 1986, 1993 * The Regents of the University of California. All rights reserved. * diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 2abc713..637a217 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -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 sys/types.h #include sys/stat.h @@ -34,7 +49,7 @@ static int in_group_p(gid_t g) gid_t grouplist[TARGET_NGROUPS]; ngroup = getgroups(TARGET_NGROUPS, grouplist); -for(i = 0; i ngroup; i++) { +for (i = 0; i ngroup; i++) { if(grouplist[i] == g) { return 1; } @@ -46,7 +61,7 @@ static int count(char ** vec) { int i; -for(i = 0; *vec; i++) { +for (i = 0; *vec; i++) { vec++; } diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 5e20510..007bcb1 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -1,4 +1,20 @@ -/* This is the Linux kernel elf-loading code, ported into user space */ +/* + * ELF loading code + * + * + * 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 stdio.h #include sys/types.h @@ -918,54 +934,57 @@ static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex, } eppnt = elf_phdata; -for(i=0; iinterp_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
[Qemu-devel] [PATCH 09/23] bsd-user: refresh FreeBSD's system call numbers
Update freebsd/syscall_nr.h with FreeBSD's latest system call numbers from -current (FreeBSD 10). Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/freebsd/syscall_nr.h | 834 ++--- 1 files changed, 446 insertions(+), 388 deletions(-) diff --git a/bsd-user/freebsd/syscall_nr.h b/bsd-user/freebsd/syscall_nr.h index 057f46c..d849024 100644 --- a/bsd-user/freebsd/syscall_nr.h +++ b/bsd-user/freebsd/syscall_nr.h @@ -1,392 +1,450 @@ /* - * FreeBSD System call numbers. + * System call numbers. * - * 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/. - */ - -/* - * $FreeBSD: src/sys/sys/syscall.h,v 1.224 2008/08/24 21:23:08 rwatson Exp $ - * created from FreeBSD: head/sys/kern/syscalls.master 182123 2008-08-24 21:20:35Z rwatson + * created from FreeBSD: releng/9.1/sys/kern/syscalls.master 229723 + * 2012-01-06 19:29:16Z jhb */ -#ifndef _FREEBSD_SYSCALL_NR_H_ -#define _FREEBSD_SYSCALL_NR_H_ - -#define TARGET_FREEBSD_NR_syscall 0 -#define TARGET_FREEBSD_NR_exit1 -#define TARGET_FREEBSD_NR_fork2 -#define TARGET_FREEBSD_NR_read3 -#define TARGET_FREEBSD_NR_write 4 -#define TARGET_FREEBSD_NR_open5 -#define TARGET_FREEBSD_NR_close 6 -#define TARGET_FREEBSD_NR_wait4 7 -#define TARGET_FREEBSD_NR_link9 -#define TARGET_FREEBSD_NR_unlink 10 -#define TARGET_FREEBSD_NR_chdir 12 -#define TARGET_FREEBSD_NR_fchdir 13 -#define TARGET_FREEBSD_NR_mknod 14 -#define TARGET_FREEBSD_NR_chmod 15 -#define TARGET_FREEBSD_NR_chown 16 -#define TARGET_FREEBSD_NR_break 17 -#define TARGET_FREEBSD_NR_freebsd4_getfsstat 18 -#define TARGET_FREEBSD_NR_getpid 20 -#define TARGET_FREEBSD_NR_mount 21 -#define TARGET_FREEBSD_NR_unmount 22 -#define TARGET_FREEBSD_NR_setuid 23 -#define TARGET_FREEBSD_NR_getuid 24 -#define TARGET_FREEBSD_NR_geteuid 25 -#define TARGET_FREEBSD_NR_ptrace 26 -#define TARGET_FREEBSD_NR_recvmsg 27 -#define TARGET_FREEBSD_NR_sendmsg 28 -#define TARGET_FREEBSD_NR_recvfrom29 -#define TARGET_FREEBSD_NR_accept 30 -#define TARGET_FREEBSD_NR_getpeername 31 -#define TARGET_FREEBSD_NR_getsockname 32 -#define TARGET_FREEBSD_NR_access 33 -#define TARGET_FREEBSD_NR_chflags 34 -#define TARGET_FREEBSD_NR_fchflags35 -#define TARGET_FREEBSD_NR_sync36 -#define TARGET_FREEBSD_NR_kill37 -#define TARGET_FREEBSD_NR_getppid 39 -#define TARGET_FREEBSD_NR_dup 41 -#define TARGET_FREEBSD_NR_pipe42 -#define TARGET_FREEBSD_NR_getegid 43 -#define TARGET_FREEBSD_NR_profil 44 -#define TARGET_FREEBSD_NR_ktrace 45 -#define TARGET_FREEBSD_NR_getgid 47 -#define TARGET_FREEBSD_NR_getlogin49 -#define TARGET_FREEBSD_NR_setlogin50 -#define TARGET_FREEBSD_NR_acct51 -#define TARGET_FREEBSD_NR_sigaltstack 53 -#define TARGET_FREEBSD_NR_ioctl 54 -#define TARGET_FREEBSD_NR_reboot 55 -#define TARGET_FREEBSD_NR_revoke 56 -#define TARGET_FREEBSD_NR_symlink 57 -#define TARGET_FREEBSD_NR_readlink58 -#define TARGET_FREEBSD_NR_execve 59 -#define TARGET_FREEBSD_NR_umask 60 -#define TARGET_FREEBSD_NR_chroot 61 -#define TARGET_FREEBSD_NR_msync 65 -#define TARGET_FREEBSD_NR_vfork 66 -#define TARGET_FREEBSD_NR_sbrk69 -#define TARGET_FREEBSD_NR_sstk70 -#define TARGET_FREEBSD_NR_vadvise 72 -#define TARGET_FREEBSD_NR_munmap 73 -#define TARGET_FREEBSD_NR_mprotect74 -#define TARGET_FREEBSD_NR_madvise 75 -#define TARGET_FREEBSD_NR_mincore 78 -#define TARGET_FREEBSD_NR_getgroups 79 -#define TARGET_FREEBSD_NR_setgroups 80 -#define TARGET_FREEBSD_NR_getpgrp 81 -#define TARGET_FREEBSD_NR_setpgid 82 -#define TARGET_FREEBSD_NR_setitimer 83 -#define TARGET_FREEBSD_NR_swapon 85 -#define TARGET_FREEBSD_NR_getitimer 86 -#define TARGET_FREEBSD_NR_getdtablesize 89 -#define TARGET_FREEBSD_NR_dup290 -#define TARGET_FREEBSD_NR_fcntl 92 -#define TARGET_FREEBSD_NR_select 93 -#define TARGET_FREEBSD_NR_fsync 95 -#define TARGET_FREEBSD_NR_setpriority 96 -#define TARGET_FREEBSD_NR_socket 97 -#define TARGET_FREEBSD_NR_connect 98 -#define TARGET_FREEBSD_NR_getpriority 100 -#define TARGET_FREEBSD_NR_bind104 -#define TARGET_FREEBSD_NR_setsockopt 105 -#define TARGET_FREEBSD_NR_listen
[Qemu-devel] [PATCH 22/23] bsd-user: add more strace formating
This change add more strace formating for popular system calls. It also separates out *BSD and architecture dependent code. In addition, it changes TARGET_OS in configure (and in the associated makefiles) to what it should really be: HOST_OS. Signed-off-by: Stacey Son s...@freebsd.org --- Makefile.target|4 +- bsd-user/Makefile.objs | 10 +- bsd-user/freebsd/os-strace.h | 29 ++ bsd-user/freebsd/strace.list | 58 ++-- bsd-user/i386/target_arch_sysarch.h| 11 ++- bsd-user/mips/target_arch_sysarch.h| 21 - bsd-user/mips64/target_arch_sysarch.h | 19 bsd-user/netbsd/os-strace.h|1 + bsd-user/openbsd/os-strace.h |1 + bsd-user/qemu.h| 10 ++ bsd-user/sparc/target_arch_sysarch.h | 11 ++- bsd-user/sparc64/target_arch_sysarch.h | 11 ++- bsd-user/strace.c | 158 bsd-user/x86_64/target_arch_sysarch.h | 11 ++- configure | 18 ++-- 15 files changed, 290 insertions(+), 83 deletions(-) create mode 100644 bsd-user/freebsd/os-strace.h create mode 100644 bsd-user/netbsd/os-strace.h create mode 100644 bsd-user/openbsd/os-strace.h diff --git a/Makefile.target b/Makefile.target index e67e2bd..ef52ee4 100644 --- a/Makefile.target +++ b/Makefile.target @@ -103,8 +103,8 @@ endif #CONFIG_LINUX_USER ifdef CONFIG_BSD_USER -QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH) \ --I$(SRC_PATH)/bsd-user/$(TARGET_OS) +QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \ +-I$(SRC_PATH)/bsd-user/$(HOST_ABI_DIR) obj-y += bsd-user/ obj-y += gdbstub.o thunk.o user-exec.o diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 5308e29..06a3026 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,5 +1,7 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \ - uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ - $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \ - $(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \ - $(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o bsd-misc.o + uaccess.o bsd-mem.o bsd-misc.o bsd-proc.o bsd-socket.o \ + $(HOST_ABI_DIR)/os-extattr.o $(HOST_ABI_DIR)/os-proc.o \ + $(HOST_ABI_DIR)/os-socket.o $(HOST_ABI_DIR)/os-stat.o \ + $(HOST_ABI_DIR)/os-sys.o $(HOST_ABI_DIR)/os-thread.o \ + $(HOST_ABI_DIR)/os-time.o + diff --git a/bsd-user/freebsd/os-strace.h b/bsd-user/freebsd/os-strace.h new file mode 100644 index 000..a222f09 --- /dev/null +++ b/bsd-user/freebsd/os-strace.h @@ -0,0 +1,29 @@ +/* + * FreeBSD dependent strace print functions + * + * 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 target_arch_sysarch.h/* architecture dependent functions */ + + +static inline void do_os_print_sysarch(const struct syscallname *name, +abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, +abi_long arg5, abi_long arg6) +{ +/* This is arch dependent */ +do_freebsd_arch_print_sysarch(name, arg1, arg2, arg3, arg4, arg5, arg6); +} diff --git a/bsd-user/freebsd/strace.list b/bsd-user/freebsd/strace.list index 3e793cb..ae2a4a3 100644 --- a/bsd-user/freebsd/strace.list +++ b/bsd-user/freebsd/strace.list @@ -16,10 +16,23 @@ * along with this program; if not, see http://www.gnu.org/licenses/. */ +{ TARGET_FREEBSD_NR___acl_aclcheck_fd, __acl_get_fd, %s(%d, %d, %#x), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_aclcheck_file, __acl_get_file, %s(\%s\, %d, %#x), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_aclcheck_link, __acl_get_link, %s(\%s\, %d, %#x), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_delete_fd, __acl_delete_fd, %s(%d, %d), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_delete_file, __acl_delete_file, %s(\%s\, %d), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_delete_link, __acl_delete_link, %s(\%s\, %d), NULL, NULL }, +{ TARGET_FREEBSD_NR___acl_get_fd, __acl_get_fd, %s(\%s\, %d, %#x), NULL, NULL
[Qemu-devel] [PATCH 16/23] bsd-user: add shims for stat and file handle related syscalls
This change adds support for status, file handle, and fcntl related system calls including stat(), statfs(), fhstatfs(), fcntl() and the many variants. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |3 +- bsd-user/freebsd/os-stat.c | 234 +++ bsd-user/freebsd/os-stat.h | 437 bsd-user/freebsd/qemu-os.h | 10 + bsd-user/netbsd/os-stat.c |1 + bsd-user/netbsd/os-stat.h | 176 ++ bsd-user/openbsd/os-stat.c |1 + bsd-user/openbsd/os-stat.h | 176 ++ bsd-user/syscall.c | 76 bsd-user/syscall_defs.h| 155 10 files changed, 1268 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-stat.c create mode 100644 bsd-user/freebsd/os-stat.h create mode 100644 bsd-user/netbsd/os-stat.c create mode 100644 bsd-user/netbsd/os-stat.h create mode 100644 bsd-user/openbsd/os-stat.c create mode 100644 bsd-user/openbsd/os-stat.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 01f315e..cc7a82b 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,3 +1,4 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ - $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o + $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \ + $(TARGET_OS)/os-stat.o diff --git a/bsd-user/freebsd/os-stat.c b/bsd-user/freebsd/os-stat.c new file mode 100644 index 000..50885d1 --- /dev/null +++ b/bsd-user/freebsd/os-stat.c @@ -0,0 +1,234 @@ +/* + * FreeBSD stat related conversion routines + * + * 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 sys/types.h +#include sys/stat.h +#include sys/mount.h + +#include qemu.h +#include qemu-os.h + +/* + * stat conversion + */ +abi_long h2t_freebsd_stat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_stat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +__put_user(host_st-st_atim.tv_nsec, target_st-st_atim.tv_nsec); +__put_user(host_st-st_mtim.tv_sec, target_st-st_mtim.tv_sec); +__put_user(host_st-st_mtim.tv_nsec, target_st-st_mtim.tv_nsec); +__put_user(host_st-st_ctim.tv_sec, target_st-st_ctim.tv_sec); +__put_user(host_st-st_ctim.tv_nsec, target_st-st_ctim.tv_nsec); +__put_user(host_st-st_size, target_st-st_size); +__put_user(host_st-st_blocks, target_st-st_blocks); +__put_user(host_st-st_blksize, target_st-st_blksize); +__put_user(host_st-st_flags, target_st-st_flags); +__put_user(host_st-st_gen, target_st-st_gen); +/* st_lspare not used */ +__put_user(host_st-st_birthtim.tv_sec, target_st-st_birthtim.tv_sec); +__put_user(host_st-st_birthtim.tv_nsec, target_st-st_birthtim.tv_nsec); +unlock_user_struct(target_st, target_addr, 1); + +return 0; +} + +abi_long h2t_freebsd_nstat(abi_ulong target_addr, struct stat *host_st) +{ +struct target_freebsd_nstat *target_st; + +if (!lock_user_struct(VERIFY_WRITE, target_st, target_addr, 0)) { +return -TARGET_EFAULT; +} +memset(target_st, 0, sizeof(*target_st)); +__put_user(host_st-st_dev, target_st-st_dev); +__put_user(host_st-st_ino, target_st-st_ino); +__put_user(host_st-st_mode, target_st-st_mode); +__put_user(host_st-st_nlink, target_st-st_nlink); +__put_user(host_st-st_uid, target_st-st_uid); +__put_user(host_st-st_gid, target_st-st_gid); +__put_user(host_st-st_rdev, target_st-st_rdev); +__put_user(host_st-st_atim.tv_sec, target_st-st_atim.tv_sec); +__put_user(host_st-st_atim.tv_nsec, target_st-st_atim.tv_nsec
[Qemu-devel] [PATCH 20/23] bsd-user: add shims for extended attributes system calls
This change adds support for the extended attribute and access control list system calls. While NetBSD has the same extended attribute system calls it is unclear if OpenBSD does. Therefore, this calls were added as FreeBSD-only. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs|2 +- bsd-user/freebsd/os-extattr.c | 119 bsd-user/freebsd/os-extattr.h | 644 + bsd-user/freebsd/qemu-os.h|7 + bsd-user/netbsd/os-extattr.h | 247 bsd-user/openbsd/os-extattr.h | 247 bsd-user/syscall.c| 105 +++ bsd-user/syscall_defs.h | 27 ++ 8 files changed, 1397 insertions(+), 1 deletions(-) create mode 100644 bsd-user/freebsd/os-extattr.c create mode 100644 bsd-user/freebsd/os-extattr.h create mode 100644 bsd-user/netbsd/os-extattr.h create mode 100644 bsd-user/openbsd/os-extattr.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index e392760..3dddc00 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -2,4 +2,4 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \ $(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \ - $(TARGET_OS)/os-thread.o + $(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o diff --git a/bsd-user/freebsd/os-extattr.c b/bsd-user/freebsd/os-extattr.c new file mode 100644 index 000..7a10047 --- /dev/null +++ b/bsd-user/freebsd/os-extattr.c @@ -0,0 +1,119 @@ +/* + * FreeBSD extend attributes and ACL conversions + * + * 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 sys/types.h +#ifndef _ACL_PRIVATE +#define _ACL_PRIVATE +#endif +#include sys/acl.h + +#include qemu.h +#include qemu-os.h + +/* + * FreeBSD ACL conversion. + */ +abi_long t2h_freebsd_acl(struct acl *host_acl, abi_ulong target_addr) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_READ, target_acl, target_addr, 1)) { +return -TARGET_EFAULT; +} +__get_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__get_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__get_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__get_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__get_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +unlock_user_struct(target_acl, target_addr, 0); +return 0; +} + +abi_long h2t_freebsd_acl(abi_ulong target_addr, struct acl *host_acl) +{ +uint32_t i; +struct target_freebsd_acl *target_acl; + +if (!lock_user_struct(VERIFY_WRITE, target_acl, target_addr, 0)) { +return -TARGET_EFAULT; +} + +__put_user(host_acl-acl_maxcnt, target_acl-acl_maxcnt); +__put_user(host_acl-acl_cnt, target_acl-acl_cnt); + +for (i = 0; i host_acl-acl_maxcnt; i++) { +__put_user(host_acl-acl_entry[i].ae_tag, +target_acl-acl_entry[i].ae_tag); +__put_user(host_acl-acl_entry[i].ae_id, +target_acl-acl_entry[i].ae_id); +__put_user(host_acl-acl_entry[i].ae_perm, +target_acl-acl_entry[i].ae_perm); +__get_user(host_acl-acl_entry[i].ae_entry_type, +target_acl-acl_entry[i].ae_entry_type); +__get_user(host_acl-acl_entry[i].ae_flags, +target_acl-acl_entry[i].ae_flags); +} + +unlock_user_struct(target_acl, target_addr, 1); +return 0; +} + +abi_long t2h_freebsd_acl_type(acl_type_t *host_type, abi_long target_type) +{ +acl_type_t type = tswap32(target_type); + +switch (type) { +case TARGET_FREEBSD_ACL_TYPE_ACCESS_OLD: +*host_type = ACL_TYPE_ACCESS_OLD; +break; + +case TARGET_FREEBSD_ACL_TYPE_DEFAULT_OLD: +*host_type
[Qemu-devel] [PATCH 15/23] bsd-user: add shims for socket related system calls
This change adds support for socket related system calls including socket, bind, accept, getsockopt, setsocketopt, etc. Like the other changes to add shims for system calls some are FreeBSD dependent. These shims are defined in freebsd/os-socket.h. Stubs to emulate these on other *BSDs are included in *bsd/os-socket.h. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-socket.c| 108 + bsd-user/bsd-socket.h| 266 bsd-user/freebsd/os-socket.c | 149 bsd-user/freebsd/os-socket.h | 548 ++ bsd-user/freebsd/qemu-os.h | 14 + bsd-user/netbsd/os-socket.c |1 + bsd-user/netbsd/os-socket.h | 98 bsd-user/openbsd/os-socket.c |1 + bsd-user/openbsd/os-socket.h | 98 bsd-user/qemu-bsd.h | 11 + bsd-user/syscall.c | 98 - bsd-user/syscall_defs.h | 134 ++ 13 files changed, 1524 insertions(+), 4 deletions(-) create mode 100644 bsd-user/bsd-socket.c create mode 100644 bsd-user/bsd-socket.h create mode 100644 bsd-user/freebsd/os-socket.c create mode 100644 bsd-user/freebsd/os-socket.h create mode 100644 bsd-user/netbsd/os-socket.c create mode 100644 bsd-user/netbsd/os-socket.h create mode 100644 bsd-user/openbsd/os-socket.c create mode 100644 bsd-user/openbsd/os-socket.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index d21ddfa..01f315e 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,3 +1,3 @@ obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ - $(TARGET_OS)/os-proc.o + $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o diff --git a/bsd-user/bsd-socket.c b/bsd-user/bsd-socket.c new file mode 100644 index 000..c1a3b49 --- /dev/null +++ b/bsd-user/bsd-socket.c @@ -0,0 +1,108 @@ +/* + * BSD socket system call related helpers + * + * 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 sys/types.h +#include sys/socket.h +#include sys/un.h +#include netinet/in.h + +#include qemu.h +#include qemu-bsd.h + +/* + * socket conversion + */ +abi_long target_to_host_sockaddr(struct sockaddr *addr, abi_ulong target_addr, +socklen_t len) +{ +const socklen_t unix_maxlen = sizeof(struct sockaddr_un); +sa_family_t sa_family; +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} + +sa_family = target_saddr-sa_family; + +/* + * Oops. The caller might send a incomplete sun_path; sun_path + * must be terminated by \0 (see the manual page), but unfortunately + * it is quite common to specify sockaddr_un length as + * strlen(x-sun_path) while it should be strlen(...) + 1. We will + * fix that here if needed. + */ +if (target_saddr-sa_family == AF_UNIX) { +if (len unix_maxlen len 0) { +char *cp = (char *)target_saddr; + +if (cp[len-1] !cp[len]) { +len++; +} +} +if (len unix_maxlen) { +len = unix_maxlen; +} +} + +memcpy(addr, target_saddr, len); +addr-sa_family = sa_family;/* type uint8_t */ +addr-sa_len = target_saddr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, 0); + +return 0; +} + +abi_long host_to_target_sockaddr(abi_ulong target_addr, struct sockaddr *addr, +socklen_t len) +{ +struct target_sockaddr *target_saddr; + +target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); +if (target_saddr == 0) { +return -TARGET_EFAULT; +} +memcpy(target_saddr, addr, len); +target_saddr-sa_family = addr-sa_family; /* type uint8_t */ +target_saddr-sa_len = addr-sa_len;/* type uint8_t */ +unlock_user(target_saddr, target_addr, len); + +return 0; +} + +abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn, abi_ulong target_addr, +socklen_t len) +{ +struct target_ip_mreqn *target_smreqn; + +target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1
[Qemu-devel] [PATCH 04/23] bsd-user: add bsd signal emulation
Add bsd-user signal emulation code, fix name space confict with sigqueue, add arch dependent code for mips/mips64, and OS dependent definitions for FreeBSD. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/freebsd/target_os_signal.h |9 + bsd-user/i386/target_arch_signal.h| 39 ++ bsd-user/i386/target_arch_vmparam.h |2 - bsd-user/mips/target_arch_signal.h| 160 ++ bsd-user/mips/target_arch_vmparam.h |6 +- bsd-user/mips64/target_arch_signal.h | 159 ++ bsd-user/qemu.h | 33 +- bsd-user/signal.c | 922 + bsd-user/sparc/target_arch_signal.h | 39 ++ bsd-user/sparc64/target_arch_signal.h | 39 ++ bsd-user/x86_64/target_arch_signal.h | 39 ++ 11 files changed, 1429 insertions(+), 18 deletions(-) diff --git a/bsd-user/freebsd/target_os_signal.h b/bsd-user/freebsd/target_os_signal.h index 3421a4e..d7004c8 100644 --- a/bsd-user/freebsd/target_os_signal.h +++ b/bsd-user/freebsd/target_os_signal.h @@ -52,6 +52,15 @@ #define TARGET_SIG_IGN ((abi_long)1) /* ignore signal */ #define TARGET_SIG_ERR ((abi_long)-1) /* error return from signal */ +#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 */ +#define TARGET_SA_NODEFER 0x0010 /* don't mask the signal we're delivering */ +#define TARGET_SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid 1) */ +#define TARGET_SA_USERTRAMP 0x0100 /* do not bounce off kernel's sigtramp */ +#define TARGET_SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */ +#define TARGET_SA_SIGINFO 0x0040 /* generate siginfo_t */ + /* * Flags for sigprocmask: */ diff --git a/bsd-user/i386/target_arch_signal.h b/bsd-user/i386/target_arch_signal.h index ebd83f6..2e89529 100644 --- a/bsd-user/i386/target_arch_signal.h +++ b/bsd-user/i386/target_arch_signal.h @@ -20,4 +20,43 @@ #include cpu.h +/* Size of the signal trampolin code placed on the stack. */ +/* #define TARGET_SZSIGCODE(0) */ /* XXX to be added. */ + +/* compare to x86/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (512 * 4) /* min sig stack size */ +#define TARGET_SIGSTKSZ (MINSIGSTKSZ + 32768) /* recommended size */ + +struct target_sigcontext { +/* to be added */ +}; + +typedef struct target_mcontext { +} target_mcontext_t; + +typedef struct target_ucontext { +target_sigset_t uc_sigmask; +target_mcontext_t uc_mcontext; +abi_ulong uc_link; +target_stack_tuc_stack; +int32_t uc_flags; +int32_t __spare__[4]; +} target_ucontext_t; + +struct target_sigframe { +abi_ulong sf_signum; +abi_ulong sf_siginfo;/* code or pointer to sf_si */ +abi_ulong sf_ucontext; /* points to sf_uc */ +abi_ulong sf_addr; /* undocumented 4th arg */ +target_ucontext_t sf_uc; /* = *sf_uncontext */ +target_siginfo_tsf_si; /* = *sf_siginfo (SA_SIGINFO case)*/ +uint32_t__spare__[2]; +}; + +static inline abi_long set_mcontext(CPUX86State *regs, +target_mcontext_t *mcp, int srflag) +{ +return -TARGET_EOPNOTSUPP; +} + #endif /* TARGET_ARCH_SIGNAL_H */ diff --git a/bsd-user/i386/target_arch_vmparam.h b/bsd-user/i386/target_arch_vmparam.h index 6687adb..6d3cf4f 100644 --- a/bsd-user/i386/target_arch_vmparam.h +++ b/bsd-user/i386/target_arch_vmparam.h @@ -13,8 +13,6 @@ #define TARGET_USRSTACK (0xbfc0) -#define TARGET_PS_STRINGS (TARGET_USRSTACK - sizeof(struct target_ps_strings)) - static inline abi_ulong get_sp_from_cpustate(CPUX86State *state) { return state-regs[R_ESP]; diff --git a/bsd-user/mips/target_arch_signal.h b/bsd-user/mips/target_arch_signal.h index 256c135..cc7e750 100644 --- a/bsd-user/mips/target_arch_signal.h +++ b/bsd-user/mips/target_arch_signal.h @@ -22,6 +22,23 @@ #define TARGET_INSN_SIZE4 /* mips instruction size */ +/* Size of the signal trampolin code placed on the stack. */ +#define TARGET_SZSIGCODE((abi_ulong)(4 * TARGET_INSN_SIZE)) + +/* compare to mips/include/_limits.h */ +#define TARGET_MINSIGSTKSZ (512 * 4) /* min sig stack size */ +#define TARGET_SIGSTKSZ (TARGET_MINSIGSTKSZ + 32768) /* recommended size */ + +/* compare to sys/mips/include/asm.h */ +#define TARGET_SZREG8 +#define TARGET_CALLFRAME_SIZ(TARGET_SZREG * 4) + +/* mips/mips/pm_machdep.c */ +#define TARGET_UCONTEXT_MAGIC 0xACEDBADE +#define TARGET_MC_GET_CLEAR_RET 0x0001 +#define TARGET_MC_ADD_MAGIC 0x0002 +#define TARGET_MC_SET_ONSTACK 0x0004 + struct target_sigcontext { target_sigset_t sc_mask;/* signal mask to retstore */ int32_t sc_onstack; /* sigstack state to restore */ @@ -65,4 +82,147 @@ struct target_sigframe { uint32_t__spare__[2
[Qemu-devel] [PATCH 19/23] bsd-user: add shims for sysarch() and sysctl() system calls
This change adds support for sysarch() and sysctl() system call emulation. sysarch() is both architecture and OS dependent. Therefore this change adds a handler for each architecture. sysctl() has a lot special cases that have to each decoded and handled individually. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |3 +- bsd-user/freebsd/os-sys.c | 268 bsd-user/i386/syscall.h|2 + bsd-user/i386/target_arch_sysarch.h| 69 bsd-user/mips/syscall.h| 12 ++- bsd-user/mips/target_arch_sysarch.h| 50 ++ bsd-user/mips64/syscall.h | 11 ++ bsd-user/mips64/target_arch_sysarch.h | 50 ++ bsd-user/netbsd/os-sys.c | 46 ++ bsd-user/openbsd/os-sys.c | 46 ++ bsd-user/qemu.h|5 + bsd-user/sparc/syscall.h |7 +- bsd-user/sparc/target_arch_sysarch.h | 43 + bsd-user/sparc64/syscall.h |7 +- bsd-user/sparc64/target_arch_sysarch.h | 43 + bsd-user/syscall.c | 209 +++-- bsd-user/x86_64/syscall.h |4 +- bsd-user/x86_64/target_arch_sysarch.h | 67 18 files changed, 747 insertions(+), 195 deletions(-) create mode 100644 bsd-user/freebsd/os-sys.c create mode 100644 bsd-user/i386/target_arch_sysarch.h create mode 100644 bsd-user/mips/target_arch_sysarch.h create mode 100644 bsd-user/mips64/target_arch_sysarch.h create mode 100644 bsd-user/netbsd/os-sys.c create mode 100644 bsd-user/openbsd/os-sys.c create mode 100644 bsd-user/sparc/target_arch_sysarch.h create mode 100644 bsd-user/sparc64/target_arch_sysarch.h create mode 100644 bsd-user/x86_64/target_arch_sysarch.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index fbb3e56..e392760 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -1,4 +1,5 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \ - $(TARGET_OS)/os-stat.o $(TARGET_OS)/os-thread.o + $(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \ + $(TARGET_OS)/os-thread.o diff --git a/bsd-user/freebsd/os-sys.c b/bsd-user/freebsd/os-sys.c new file mode 100644 index 000..86b2826 --- /dev/null +++ b/bsd-user/freebsd/os-sys.c @@ -0,0 +1,268 @@ +/* + * FreeBSD sysctl() and sysarch() system call emulation + * + * 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 sys/types.h +#include sys/param.h +#include sys/sysctl.h +#include string.h + +#include qemu.h + +#include target_arch_sysarch.h +#include target_os_vmparam.h + +/* + * XXX this uses the undocumented oidfmt interface to find the kind of + * a requested sysctl, see /sys/kern/kern_sysctl.c:sysctl_sysctl_oidfmt() + * (compare to src/sbin/sysctl/sysctl.c) + */ +static int +oidfmt(int *oid, int len, char *fmt, uint32_t *kind) +{ +int qoid[CTL_MAXNAME+2]; +uint8_t buf[BUFSIZ]; +int i; +size_t j; + +qoid[0] = 0; +qoid[1] = 4; +memcpy(qoid + 2, oid, len * sizeof(int)); + +j = sizeof(buf); +i = sysctl(qoid, len + 2, buf, j, 0, 0); +if (i) { +return i; +} + +if (kind) { +*kind = *(uint32_t *)buf; +} + +if (fmt) { +strcpy(fmt, (char *)(buf + sizeof(uint32_t))); +} +return 0; +} + +/* + * try and convert sysctl return data for the target. + * XXX doesn't handle CTLTYPE_OPAQUE and CTLTYPE_STRUCT. + */ +static int sysctl_oldcvt(void *holdp, size_t holdlen, uint32_t kind) +{ +switch (kind CTLTYPE) { +case CTLTYPE_INT: +case CTLTYPE_UINT: +*(uint32_t *)holdp = tswap32(*(uint32_t *)holdp); +break; + +#ifdef TARGET_ABI32 +case CTLTYPE_LONG: +case CTLTYPE_ULONG: +*(uint32_t *)holdp = tswap32(*(long *)holdp); +break; +#else +case CTLTYPE_LONG: +*(uint64_t *)holdp = tswap64(*(long *)holdp); +case CTLTYPE_ULONG: +*(uint64_t *)holdp = tswap64(*(unsigned long *)holdp); +break; +#endif +#if !defined(__FreeBSD_version
[Qemu-devel] [PATCH 07/23] bsd-user: find target executable in path when absolute path not given
If the target executable's path is not absolute then this code will search the PATH to find it. Save the fullpath to put on to the stack for the runtime linker. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsdload.c | 84 +-- bsd-user/qemu.h|3 +- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index cc4f534..c768855 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -169,19 +169,95 @@ abi_ulong loader_build_argptr(int envc, int argc, abi_ulong sp, return sp; } +static int 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 1; +} + +return 0; +} + +static int find_in_path(char *path, const char *filename, char *retpath, +size_t rpsize) +{ +const char *d; +int found; + +if (strchr(filename, '/') != NULL) { +if (is_there(filename)) { +if (!realpath(filename, retpath)) { +return -1; +} +return 0; +} else { +return -1; +} +} + +found = 0; +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)) { +found = 1; +break; +} +} +return found; +} + 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; +char *p, *path = NULL, fullpath[PATH_MAX]; +const char *execname = NULL; +int retval, i; -bprm-p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int); +bprm-p = TARGET_PAGE_SIZE * MAX_ARG_PAGES; /* -sizeof(unsigned int); */ for (i=0 ; iMAX_ARG_PAGES ; i++) /* clear page-table */ bprm-page[i] = NULL; -retval = open(filename, O_RDONLY); + +/* Find target executable in path, if not already an absolute path. */ +p = getenv(PATH); +if (p != NULL) { +path = g_strdup(p); +if (path == NULL) { +fprintf(stderr, Out of memory\n); +return -1; +} +execname = realpath(filename, NULL); +if (execname == NULL) { +execname = filename; +} +if (!find_in_path(path, execname, fullpath, sizeof(fullpath))) { +retval = open(fullpath, O_RDONLY); +bprm-fullpath = g_strdup(fullpath); +} else { +retval = open(execname, O_RDONLY); +bprm-fullpath = NULL; +} +if (execname) { +free((void *)execname); +} +free(path); +} else { +retval = open(filename, O_RDONLY); +bprm-fullpath = NULL; +} if (retval 0) return retval; + bprm-fd = retval; bprm-filename = (char *)filename; bprm-argc = count(argv); diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index a36e9d2..1e2abd5 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -128,7 +128,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 */ int (*core_dump)(int, const CPUArchState *); }; -- 1.7.8
[Qemu-devel] [PATCH 05/23] bsd-user: add bsd_binprm to TaskState for core dumping emulation
Add the bsd_binprm (formerly linux_binprm) structure to TaskState so it can be used to support core dumping emulation support in the future. Also, make freebsd the default bsd_type, if compiled on a FreeBSD system. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsdload.c | 36 ++-- bsd-user/elfload.c |6 +++--- bsd-user/main.c| 19 ++- bsd-user/qemu.h| 22 +- bsd-user/signal.c |6 -- 5 files changed, 52 insertions(+), 37 deletions(-) diff --git a/bsd-user/bsdload.c b/bsd-user/bsdload.c index 637a217..cc4f534 100644 --- a/bsd-user/bsdload.c +++ b/bsd-user/bsdload.c @@ -68,7 +68,7 @@ static int count(char ** vec) return(i); } -static int prepare_binprm(struct linux_binprm *bprm) +static int prepare_binprm(struct bsd_binprm *bprm) { struct stat st; int mode; @@ -170,33 +170,33 @@ 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 linux_binprm bprm; int retval; int i; -bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int); +bprm-p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int); for (i=0 ; iMAX_ARG_PAGES ; i++) /* clear page-table */ -bprm.page[i] = NULL; +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; +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); +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; @@ -211,7 +211,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 ; iMAX_ARG_PAGES ; i++) { -g_free(bprm.page[i]); +g_free(bprm-page[i]); } return(retval); } diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 035bcea..0f6c3db 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -679,7 +679,7 @@ static abi_ulong copy_elf_strings(int argc,char ** argv, void **page, return p; } -static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm, +static abi_ulong setup_arg_pages(abi_ulong p, struct bsd_binprm *bprm, struct image_info *info) { abi_ulong stack_base, size, error; @@ -1164,8 +1164,8 @@ static void load_symbols(struct elfhdr *hdr, int fd) syminfos = s; } -int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, -struct image_info * info) +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; diff --git a/bsd-user/main.c b/bsd-user/main.c index 2eb4a1b..0442dbe 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -884,6 +884,15 @@ static void usage(void) THREAD CPUArchState *thread_env; +void stop_all_tasks(void) +{ +/* + * We trust when using NPTL (pthreads) start_exclusive() handles thread + * stopping correctly. + */ +start_exclusive(); +} + /* Assumes contents are already zeroed. */ void init_task_state(TaskState *ts) { @@ -905,6 +914,7 @@ int main(int argc, char **argv) const char *log_mask = NULL; struct target_pt_regs regs1, *regs = regs1; struct image_info info1, *info = info1; +struct bsd_binprm bprm; TaskState ts1, *ts = ts1; CPUArchState *env; int optind; @@ -912,7 +922,11 @@ int main(int argc, char **argv) int gdbstub_port = 0; char **target_environ, **wrk; envlist_t *envlist = NULL; +#ifdef __FreeBSD__ +bsd_type = target_freebsd; +#else bsd_type = target_openbsd; +#endif if (argc = 1) usage(); @@ -1054,6 +1068,8 @@ int main(int argc, char **argv) /* Zero out regs */ memset(regs, 0, sizeof(struct target_pt_regs)); +memset(bprm, 0, sizeof(bprm
[Qemu-devel] [PATCH 06/23] bsd-user: fix thread initialization and ELF addresses for mips/mips64
Initialize all the registers correctly for mips/mips64 in init_thread(), use the correct ELF_START_MMAP for mips64, use the correct run-time linker, and clean up the code by eliminating some #if's. Also, fix all the checkpatch.pl warnings and errors. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/elfload.c | 185 +--- 1 files changed, 103 insertions(+), 82 deletions(-) diff --git a/bsd-user/elfload.c b/bsd-user/elfload.c index 0f6c3db..8c8ed6a 100644 --- a/bsd-user/elfload.c +++ b/bsd-user/elfload.c @@ -45,10 +45,11 @@ * These occupy the top three bytes. */ enum { -ADDR_NO_RANDOMIZE = 0x004, /* disable randomization of VA space */ -FDPIC_FUNCPTRS =0x008, /* userspace function ptrs point to descriptors - * (signal handling) - */ +ADDR_NO_RANDOMIZE = 0x004, /* disable randomization of VA + space */ +FDPIC_FUNCPTRS =0x008, /* userspace function ptrs + point to descriptors + (signal handling) */ MMAP_PAGE_ZERO =0x010, ADDR_COMPAT_LAYOUT =0x020, READ_IMPLIES_EXEC = 0x040, @@ -163,7 +164,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #define ELF_DATAELFDATA2LSB #define ELF_ARCHEM_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; @@ -198,7 +200,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #endif #define ELF_ARCHEM_ARM -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) { abi_long stack = infop-start_stack; memset(regs, 0, sizeof(*regs)); @@ -255,7 +258,8 @@ enum #define STACK_BIAS 2047 -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) { #ifndef TARGET_ABI32 regs-tstate = 0; @@ -287,7 +291,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #define ELF_DATAELFDATA2MSB #define ELF_ARCHEM_SPARC -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-psr = 0; regs-pc = infop-entry; @@ -355,7 +360,8 @@ do { \ NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);\ } while (0) -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) { abi_ulong pos = infop-start_stack; abi_ulong tmp; @@ -391,13 +397,13 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info * #ifdef TARGET_MIPS -#define ELF_START_MMAP 0x8000 - #define elf_check_arch(x) ( (x) == EM_MIPS ) #ifdef TARGET_MIPS64 +#define ELF_START_MMAP 0x2ab000ULL #define ELF_CLASS ELFCLASS64 #else +#define ELF_START_MMAP 0x8000 #define ELF_CLASS ELFCLASS32 #endif #ifdef TARGET_WORDS_BIGENDIAN @@ -407,11 +413,14 @@ static inline void init_thread(struct target_pt_regs *_regs, struct image_info * #endif #define ELF_ARCHEM_MIPS -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-cp0_status = 2 CP0St_KSU; -regs-cp0_epc = infop-entry; -regs-regs[29] = infop-start_stack; +regs-regs[25] = regs-cp0_epc = infop-entry ~3; /* t9/pc = entry */ +regs-regs[4] = regs-regs[29] = infop-start_stack; /* a0/sp = stack */ +regs-regs[5] = regs-regs[6] = 0; /* a1/a2 = 0 */ +regs-regs[7] = TARGET_PS_STRINGS; /* a3 = ps_strings */ } #define USE_ELF_CORE_DUMP @@ -429,7 +438,8 @@ static inline void init_thread(struct target_pt_regs *regs, struct image_info *i #define ELF_DATA ELFDATA2LSB #define ELF_ARCH EM_SH -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) { /* Check other registers X */ regs-pc
[Qemu-devel] [PATCH 13/23] bsd-user: add shims for signal related system calls
This change adds support for signal related system calls including sigaction(2), sigprocmask(2), sigpending(2), sigsuspend(2), and so on. The older, obsolete, system calls such as sigvec(2), sigblock(2), sigsetmask(2), and sigstack(2) are not supported. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/bsd-signal.h| 232 ++ bsd-user/freebsd/os-signal.h | 43 bsd-user/netbsd/os-signal.h | 34 ++ bsd-user/openbsd/os-signal.h | 34 ++ bsd-user/syscall.c | 57 ++ 5 files changed, 400 insertions(+), 0 deletions(-) create mode 100644 bsd-user/bsd-signal.h create mode 100644 bsd-user/freebsd/os-signal.h create mode 100644 bsd-user/netbsd/os-signal.h create mode 100644 bsd-user/openbsd/os-signal.h diff --git a/bsd-user/bsd-signal.h b/bsd-user/bsd-signal.h new file mode 100644 index 000..48a8b56 --- /dev/null +++ b/bsd-user/bsd-signal.h @@ -0,0 +1,232 @@ +/* + * signal related system call shims + * + * 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 __BSD_SIGNAL_H_ +#define __BSD_SIGNAL_H_ + +/* sigaction(2) */ +static inline abi_long do_bsd_sigaction(abi_long arg1, abi_long arg2, +abi_long arg3) +{ +abi_long ret; +struct target_sigaction *old_act, act, oact, *pact; + +if (arg2) { +if (!lock_user_struct(VERIFY_READ, old_act, arg2, 1)) { +return -TARGET_EFAULT; +} +act._sa_handler = old_act-_sa_handler; +act.sa_flags = old_act-sa_flags; +memcpy(act.sa_mask, old_act-sa_mask, sizeof(target_sigset_t)); +unlock_user_struct(old_act, arg2, 0); +pact = act; +} else { +pact = NULL; +} +ret = get_errno(do_sigaction(arg1, pact, oact)); +if (!is_error(ret) arg3) { +if (!lock_user_struct(VERIFY_WRITE, old_act, arg3, 0)) { +return -TARGET_EFAULT; +} +old_act-_sa_handler = oact._sa_handler; +old_act-sa_flags = oact.sa_flags; +memcpy(old_act-sa_mask, oact.sa_mask, sizeof(target_sigset_t)); +unlock_user_struct(old_act, arg3, 1); +} +return ret; +} + + +/* sigprocmask(2) */ +static inline abi_long do_bsd_sigprocmask(abi_long arg1, abi_ulong arg2, +abi_ulong arg3) +{ +abi_long ret; +void *p; +sigset_t set, oldset, *set_ptr; +int how; + +if (arg2) { +switch (arg1) { +case TARGET_SIG_BLOCK: +how = SIG_BLOCK; +break; + +case TARGET_SIG_UNBLOCK: +how = SIG_UNBLOCK; +break; + +case TARGET_SIG_SETMASK: +how = SIG_SETMASK; +break; + +default: +return -TARGET_EFAULT; +} +p = lock_user(VERIFY_READ, arg2, sizeof(target_sigset_t), 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +target_to_host_sigset(set, p); +unlock_user(p, arg2, 0); +set_ptr = set; +} else { +how = 0; +set_ptr = NULL; +} +ret = get_errno(sigprocmask(how, set_ptr, oldset)); +if (!is_error(ret) arg3) { +p = lock_user(VERIFY_WRITE, arg3, sizeof(target_sigset_t), 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +host_to_target_sigset(p, oldset); +unlock_user(p, arg3, sizeof(target_sigset_t)); +} +return ret; +} + +/* sigpending(2) */ +static inline abi_long do_bsd_sigpending(abi_long arg1) +{ +abi_long ret; +void *p; +sigset_t set; + +ret = get_errno(sigpending(set)); +if (!is_error(ret)) { +p = lock_user(VERIFY_WRITE, arg1, sizeof(target_sigset_t), 0); +if (p == NULL) { +return -TARGET_EFAULT; +} +host_to_target_sigset(p, set); +unlock_user(p, arg1, sizeof(target_sigset_t)); +} +return ret; +} + +/* sigsuspend(2) */ +static inline abi_long do_bsd_sigsuspend(abi_long arg1, abi_long arg2) +{ +void *p; +sigset_t set; + +p = lock_user(VERIFY_READ, arg1, sizeof(target_sigset_t), 1); +if (p == NULL) { +return -TARGET_EFAULT; +} +target_to_host_sigset(set, p); +unlock_user(p, arg1, 0); + +return get_errno(sigsuspend(set)); +} + +/* sigreturn(2) */ +static inline abi_long do_bsd_sigreturn(void *cpu_env, abi_long
[Qemu-devel] [PATCH 21/23] bsd-user: add miscellaneous system call shims
This change add System V semaphores/messages, uuid, FreeBSD cpu scheduling/affinity management, and other miscellaneous system call shims. A lot of these other system call shims are stubs for maybe future work. Signed-off-by: Stacey Son s...@freebsd.org --- bsd-user/Makefile.objs |2 +- bsd-user/bsd-misc.c| 209 + bsd-user/bsd-misc.h| 339 + bsd-user/freebsd/os-misc.h | 442 bsd-user/qemu-bsd.h| 21 ++ bsd-user/syscall.c | 224 ++ bsd-user/syscall_defs.h| 81 7 files changed, 1317 insertions(+), 1 deletions(-) create mode 100644 bsd-user/bsd-misc.c create mode 100644 bsd-user/bsd-misc.h create mode 100644 bsd-user/freebsd/os-misc.h diff --git a/bsd-user/Makefile.objs b/bsd-user/Makefile.objs index 3dddc00..5308e29 100644 --- a/bsd-user/Makefile.objs +++ b/bsd-user/Makefile.objs @@ -2,4 +2,4 @@ obj-y = main.o bsdload.o elfload.o ioctl.o mmap.o signal.o strace.o syscall.o \ uaccess.o bsd-mem.o bsd-proc.o $(TARGET_OS)/os-time.o \ $(TARGET_OS)/os-proc.o bsd-socket.o $(TARGET_OS)/os-socket.o \ $(TARGET_OS)/os-stat.o $(TARGET_OS)/os-sys.o \ - $(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o + $(TARGET_OS)/os-thread.o $(TARGET_OS)/os-extattr.o bsd-misc.o diff --git a/bsd-user/bsd-misc.c b/bsd-user/bsd-misc.c new file mode 100644 index 000..bc85473 --- /dev/null +++ b/bsd-user/bsd-misc.c @@ -0,0 +1,209 @@ +/* + * BSD misc system call conversions routines + * + * 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 sys/types.h +#include sys/ipc.h +#include sys/msg.h +#include sys/sem.h +#include sys/uuid.h + +#include qemu.h +#include qemu-bsd.h + +/* + * BSD uuidgen(2) struct uuid conversion + */ +abi_long host_to_target_uuid(abi_ulong target_addr, struct uuid *host_uuid) +{ +struct target_uuid *target_uuid; + +if (!lock_user_struct(VERIFY_WRITE, target_uuid, target_addr, 0)) { +return -TARGET_EFAULT; +} +__put_user(host_uuid-time_low, target_uuid-time_low); +__put_user(host_uuid-time_mid, target_uuid-time_mid); +__put_user(host_uuid-time_hi_and_version, +target_uuid-time_hi_and_version); +host_uuid-clock_seq_hi_and_reserved = +target_uuid-clock_seq_hi_and_reserved; +host_uuid-clock_seq_low = target_uuid-clock_seq_low; +memcpy(host_uuid-node, target_uuid-node, TARGET_UUID_NODE_LEN); +unlock_user_struct(target_uuid, target_addr, 1); +return 0; +} + +abi_long target_to_host_semarray(int semid, unsigned short **host_array, +abi_ulong target_addr) +{ +abi_long ret; +int nsems, i; +unsigned short *array; +union semun semun; +struct semid_ds semid_ds; + +semun.buf = semid_ds; +ret = semctl(semid, 0, IPC_STAT, semun); +if (ret == -1) { +return get_errno(ret); +} +nsems = semid_ds.sem_nsems; +*host_array = (unsigned short *)malloc(nsems * sizeof(unsigned short)); +array = lock_user(VERIFY_READ, target_addr, +nsems*sizeof(unsigned short), 1); +if (array == NULL) { +free(*host_array); +return -TARGET_EFAULT; +} +for (i = 0; i nsems; i++) { +(*host_array)[i] = array[i]; +} +unlock_user(array, target_addr, 0); + +return 0; +} + +abi_long host_to_target_semarray(int semid, abi_ulong target_addr, +unsigned short **host_array) +{ +abi_long ret; +int nsems, i; +unsigned short *array; +union semun semun; +struct semid_ds semid_ds; + +semun.buf = semid_ds; + +ret = semctl(semid, 0, IPC_STAT, semun); +if (ret == -1) { +free(*host_array); +return get_errno(ret); +} + +nsems = semid_ds.sem_nsems; +array = (unsigned short *)lock_user(VERIFY_WRITE, target_addr, +nsems*sizeof(unsigned short), 0); +if (array == NULL) { +free(*host_array); +return -TARGET_EFAULT; +} +for (i = 0; i nsems; i++) { +array[i] = (*host_array)[i]; +} +free(*host_array); +unlock_user(array, target_addr, 1); +return 0; +} + +abi_long target_to_host_semid_ds(struct semid_ds *host_sd, +abi_ulong
Re: [Qemu-devel] [PATCH 00/23] bsd-user: FreeBSD support for mips/mips64 and arm
On Jun 24, 2013, at 12:49 PM, Peter Maydell wrote: On 24 June 2013 03:03, Stacey Son s...@freebsd.org wrote: This patch series add BSD user mode support for FreeBSD. In addition, it adds the necessary architecture dependent code for the mips, mips64, and arm targets. In its current state it can emulate most mips/mips64 and arm target binaries on a x86 host in a simple chroot environment (see https://wiki.freebsd.org/QemuUserModeHowTo for example). Besides adding a lot of shims and other support code this change restructures the code significantly to reduce the amount of C preprocessor conditionals for the various target and host arch/OS's. In general, the target cpu depedent code has been moved into into the various arch directories and the host OS dependent code (ie. FreeBSD, NetBSD, OpenBSD) has been moved into the OS directories as much as possible. 178 files changed, 23181 insertions(+), 2192 deletions(-) This is an awful lot of code to ask people to review. Your patchset here is doing a lot of things: * restructuring to put cpu dependent code into subdirs * adding ARM support * adding MIPS support * adding support for lots of extra system calls and it's also doing them all jumbled up together, and includes individual patches which do more than one thing at once. Sorry about that. Yes, this patch set is adding a lot of code. It has been maintained as a huge set patches in the FreeBSD qemu-devel port for some time but I finally cleaned it up and checkpatch.pl it all. I'm not the bsd-user maintainer, but my suggestion would be that you'll find it much easier to get your code submitted if you try to get these various new features added one at a time rather than all at once. Such as one system call shim at a time? That would be a lot of emails to this list. :) The patch set does break down the individual features into individual patches such as groups of system call shims. Of course, those patches are indeed still quite large. I do apologize for that. PS: for future bsd-user patch submissions you should cc Blue Swirl blauwir...@gmail.com who is the bsd-user maintainer (see the MAINTAINERS file). Done. Thanks, -stacey.
Re: [Qemu-devel] [PATCH 00/23] bsd-user: FreeBSD support for mips/mips64 and arm
On Jun 24, 2013, at 12:55 PM, Anthony Liguori wrote: There is no humanly way 23k LOC can be reviewed in a single series. Yes, indeed, it is a lot of code. Has this been maintained out of tree for some time? Yes, it has been a large, ugly patch set in the FreeBSD qemu-devel port for some time. Is it largely copy/paste from linux-user? A good amount of the initial code came from linux-user but then diverged when the code was restructured to put cpu and *BSD dependent code into its own subdirs which I believe was the original thought on how the code was to be structured. Regards, -stacey.
Re: [Qemu-devel] [PATCH 02/23] bsd-user: add initial support for mips/mips64
On Jun 24, 2013, at 12:15 PM, Peter Maydell wrote: +#if defined(TARGET_MIPS) + +/* Compare to sys/mips/mips/trap.c */ + +void cpu_loop(CPUMIPSState *env) I suspect you'd do better in the long term to restructure to pull cpu_loop out into a per-architecture source file and avoid the ifdefs. (This is something I'd like to do to the linux-user/ code, which is currently even more ifdef-ridden than bsd-user/.) Yes, the cpu_loop()'s and the cpu initialization code is actually separated out in the arm arch patch for all the arch's. --- a/target-mips/mips-defs.h +++ b/target-mips/mips-defs.h @@ -10,8 +10,17 @@ #if defined(TARGET_MIPS64) #define TARGET_LONG_BITS 64 -#define TARGET_PHYS_ADDR_SPACE_BITS 36 -#define TARGET_VIRT_ADDR_SPACE_BITS 42 +# if defined(CONFIG_BSD) defined(CONFIG_USER_ONLY) +#define TARGET_PHYS_ADDR_SPACE_BITS 59 +#ifdef TARGET_ABI32 +# define TARGET_VIRT_ADDR_SPACE_BITS 32 +#else +# define TARGET_VIRT_ADDR_SPACE_BITS 62 +#endif +# else +#define TARGET_PHYS_ADDR_SPACE_BITS 36 +#define TARGET_VIRT_ADDR_SPACE_BITS 42 +# endif #else #define TARGET_LONG_BITS 32 #define TARGET_PHYS_ADDR_SPACE_BITS 36 This looks a little fishy -- could you give some rationale? Why does only BSD need to do this? Why do you need to change the TARGET_PHYS_ADDR_SPACE_BITS for a -user target? Where do the numbers come from? If I remember correctly these: +# if defined(CONFIG_BSD) defined(CONFIG_USER_ONLY) +#define TARGET_PHYS_ADDR_SPACE_BITS 59 +#ifdef TARGET_ABI32 +# define TARGET_VIRT_ADDR_SPACE_BITS 32 +#else +# define TARGET_VIRT_ADDR_SPACE_BITS 62 +#endif come from the See Mips Run book. The reason they were changed for the bsd-user is FreeBSD puts the text segment in something like 0x1200 (plus or minus a zero) and the stack at 0x80 (- minus a page or two) for mips64 which didn't work as defined originally. -stacey.
Re: [Qemu-devel] [PATCH 03/23] bsd-user: additional seperation of OS and architecture dependent code
On Jun 24, 2013, at 12:24 PM, Peter Maydell wrote: On 24 June 2013 03:03, Stacey Son s...@freebsd.org wrote: diff --git a/configure b/configure index ad32f87..749eba8 100755 --- a/configure +++ b/configure @@ -432,6 +432,7 @@ if test -z $ARCH; then fi # OS specific +TARGET_OS= case $targetos in CYGWIN*) @@ -457,6 +458,7 @@ FreeBSD) audio_possible_drivers=oss sdl esd pa # needed for kinfo_getvmmap(3) in libutil.h LIBS=-lutil $LIBS + TARGET_OS=freebsd ;; DragonFly) bsd=yes @@ -470,12 +472,14 @@ NetBSD) audio_drv_list=oss audio_possible_drivers=oss sdl esd oss_lib=-lossaudio + TARGET_OS=netbsd ;; OpenBSD) bsd=yes make=${MAKE-gmake} audio_drv_list=sdl audio_possible_drivers=sdl esd + TARGET_OS=openbsd ;; Darwin) bsd=yes @@ -4267,6 +4271,9 @@ upper() { target_arch_name=`upper $TARGET_ARCH` echo TARGET_$target_arch_name=y $config_target_mak +if [ $TARGET_OS != ]; then +echo TARGET_OS=$TARGET_OS $config_target_mak +fi echo TARGET_NAME=$target_name $config_target_mak echo TARGET_BASE_ARCH=$TARGET_BASE_ARCH $config_target_mak if [ $TARGET_ABI_DIR = ]; then This looks kind of fishy. What do you need this for that you can't do just by checking for relevant preprocessor defines like __OpenBSD__ directly in the bsd-user code? Note that the OS dependent directories are freebsd, netbsd, and openbsd. This is used in the Makefiles to use the correct OS dependent (which eliminates much of the #if defined(__OpenBSD__) in the code files themselves). Regards, -stacey.
Re: [Qemu-devel] [PATCH 17/23] bsd-user: add shims for thread related system calls
On Jun 24, 2013, at 12:37 PM, Peter Maydell wrote: On 24 June 2013 03:03, Stacey Son s...@freebsd.org wrote: diff --git a/configure b/configure index ba90975..812ea3f 100755 --- a/configure +++ b/configure @@ -1438,6 +1438,15 @@ fi if test $nptl != no ; then cat $TMPC EOF +#ifdef __FreeBSD__ +#include sys/thr.h +int main(void) { +#if !defined(THR_SUSPENDED) +#error bork +#endif + return 0; +} +#else #include sched.h #include linux/futex.h int main(void) { @@ -1446,6 +1455,7 @@ int main(void) { #endif return 0; } +#endif EOF if compile_object ; then @@ -4202,6 +4212,7 @@ case $target_name in TARGET_ARCH=mips64 TARGET_BASE_ARCH=mips echo TARGET_ABI_MIPSN64=y $config_target_mak +target_nptl=yes ;; moxie) ;; I think this is the wrong way to do this. target_nptl should be a linux-user specific define (and we really ought to try to get rid of it altogether there at some point). For bsd-user, the ideal would be if you could just support guest threads always, ie no #defines or configure checks needed. If you do need a configure check, then it should be its own, totally separate from CONFIG_NPTL. In any case, definitely do not make the Linux mistake of having do we support threads? be target specific if you can avoid it. (You might not be able to avoid it, though -- not sure :-( ) Yes, my plan is to get rid of the NPTL flag at some point for bsd-user once the FreeBSD thread emulation code proves to be stable. (Yes, I was lazy and didn't create a new thread flag for FreeBSD in configure.) It seems to fairly stable now but it is nice to turn off thread emulation now and then to eliminate the possibility of threads being a problem. I suspect that we can just turn threads up for good and be all right, however. (I suspect these other MIPS targets should actually have target_nptl set as your patch fragment does, but that should be done as a linux-user bugfix patch, not buried in the bsd-user support patchset.) diff --git a/include/qemu/tls.h b/include/qemu/tls.h index b92ea9d..ae7d79d 100644 --- a/include/qemu/tls.h +++ b/include/qemu/tls.h @@ -38,7 +38,7 @@ * TODO: proper implementations via Win32 .tls sections and * POSIX pthread_getspecific. */ -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #define DECLARE_TLS(type, x) extern DEFINE_TLS(type, x) #define DEFINE_TLS(type, x) __thread __typeof__(type) tls__##x #define tls_var(x) tls__##x This should be its own patch (especially as it affects the system emulation code on FreeBSD hosts). Yes, that is a good point. I separate into its own patch so it can be reviewed and tested individually. -stacey.
Re: [Qemu-devel] [PATCH 00/23] bsd-user: FreeBSD support for mips/mips64 and arm
On Jun 24, 2013, at 3:07 PM, Anthony Liguori wrote: Stacey Son s...@freebsd.org writes: On Jun 24, 2013, at 12:55 PM, Anthony Liguori wrote: There is no humanly way 23k LOC can be reviewed in a single series. Yes, indeed, it is a lot of code. Has this been maintained out of tree for some time? Yes, it has been a large, ugly patch set in the FreeBSD qemu-devel port for some time. Okay, I assume there were many collaborators then? You may want to consider collecting some additional Signed-off-bys then from the original authors. I don't like the idea merging a very large patch series without preserving authorship info. No, not a lot of collaborators and most of the code comes from me. The exceptions are: (1) A lot of the arm dependent code comes from Olivier Houchard. He also added some some system call shims. I noted this in the cover letter but, yes, I should add signed-off-bys and you pointed out. (2) Some of the system call shims comes from the linux-user code. (3) I have some initial ppc dependent from Andreas Tobler. Of course, none of that code is included (yet). (4) Juergen Lock, who maintains the FreeBSD port, has given me build patches for older (and supported) FreeBSD versions. Is it largely copy/paste from linux-user? A good amount of the initial code came from linux-user but then diverged when the code was restructured to put cpu and *BSD dependent code into its own subdirs which I believe was the original thought on how the code was to be structured. I think Peter made some suggestions about how to split things up... Yes, Peter has made some good suggestions and I'll work on splitting things up a bit more. Thanks, -stacey.
Re: [Qemu-devel] [PATCH 22/23] bsd-user: add more strace formating
On Jun 24, 2013, at 12:41 PM, Peter Maydell wrote: On 24 June 2013 03:03, Stacey Son s...@freebsd.org wrote: This change add more strace formating for popular system calls. It also separates out *BSD and architecture dependent code. In addition, it changes TARGET_OS in configure (and in the associated makefiles) to what it should really be: HOST_OS. You introduced TARGET_OS in the first place. Please don't put code in in one patch and then change it in a later one; rearrange your patchset to avoid this. This patch is also doing too many things at once. +if [ $HOST_ABI_DIR != ]; then +echo HOST_ABI_DIR=$HOST_ABI_DIR $config_target_mak +fi Host specific definitions in the target config? Doesn't look right. You're right. I originally used TARGET_OS but later decided that it was not the target but really the host os that was being defined. Then after rebasing I noticed that there was a change defining TARGET_ABI_DIR so I changed HOST_OS to HOST_ABI_DIR to be consistent with that change. I really need to may this change back when TARGET_OS is first introduced. -stacey.