aboutsummaryrefslogtreecommitdiff
path: root/linux-user/qemu.h
AgeCommit message (Collapse)AuthorFilesLines
2020-07-04linux-user: Add strace support for printing arguments of ioctl()Filip Bozuta1-0/+20
This patch implements functionality for strace argument printing for ioctls. When running ioctls through qemu with "-strace", they get printed in format: "ioctl(fd_num,0x*,0x*) = ret_value" where the request code an the ioctl's third argument get printed in a hexadicemal format. This patch changes that by enabling strace to print both the request code name and the contents of the third argument. For example, when running ioctl RTC_SET_TIME with "-strace", with changes from this patch, it gets printed in this way: "ioctl(3,RTC_SET_TIME,{12,13,15,20,10,119,0,0,0}) = 0" In case of IOC_R type ioctls, the contents of the third argument get printed after the return value, and the argument inside the ioctl call gets printed as pointer in hexadecimal format. For example, when running RTC_RD_TIME with "-strace", with changes from this patch, it gets printed in this way: "ioctl(3,RTC_RD_TIME,0x40800374) = 0 ({22,9,13,11,5,120,0,0,0})" In case of IOC_RW type ioctls, the contents of the third argument get printed both inside the ioctl call and after the return value. Implementation notes: Functions "print_ioctl()" and "print_syscall_ret_ioctl()", that are defined in "strace.c", are listed in file "strace.list" as "call" and "result" value for ioctl. Structure definition "IOCTLEntry" as well as predefined values for IOC_R, IOC_W and IOC_RW were cut and pasted from file "syscall.c" to file "qemu.h" so that they can be used by these functions to print the contents of the third ioctl argument. Also, the "static" identifier for array "ioctl_entries[]" was removed and this array was declared as "extern" in "qemu.h" so that it can also be used by these functions. To decode the structure type of the ioctl third argument, function "thunk_print()" was defined in file "thunk.c" and its definition is somewhat simillar to that of function "thunk_convert()". Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200619124727.18080-3-filip.bozuta@syrmia.com> [lv: fix close-bracket] Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-06-29linux-user: Add strace support for printing arguments of fallocate()Filip Bozuta1-0/+16
This patch implements strace argument printing functionality for following syscall: *fallocate - manipulate file space int fallocate(int fd, int mode, off_t offset, off_t len) man page: https://www.man7.org/linux/man-pages/man2/fallocate.2.html Implementation notes: This syscall's second argument "mode" is composed of predefined values which represent flags that determine the type of operation that is to be performed on the file space. For that reason, a printing function "print_fallocate" was stated in file "strace.list". This printing function uses an already existing function "print_flags()" to print flags of the "mode" argument. These flags are stated inside an array "falloc_flags" that contains values of type "struct flags". These values are instantiated using an existing macro "FLAG_GENERIC()". Most of these flags are defined after kernel version 3.0 which is why they are enwrapped in an #ifdef directive. The syscall's third ant fourth argument are of type "off_t" which can cause variations between 32/64-bit architectures. To handle this variation, function "target_offset64()" was copied from file "strace.c" and used in "print_fallocate" to print "off_t" arguments for 32-bit architectures. Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200619123331.17387-7-filip.bozuta@syrmia.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-06-29linux-user: Extend strace support to enable argument printing after syscall ↵Filip Bozuta1-1/+3
execution Structure "struct syscallname" in file "strace.c" is used for "-strace" to print arguments and return values of syscalls. The last field of this structure "result" represents the calling function that prints the return values. This field was extended in this patch so that this function takes all syscalls arguments beside the return value. In this way, it enables "-strace" to print arguments of syscalls that have changed after the syscall execution. This extension will be useful as there are many syscalls that return values inside their arguments (i.e. listxattr() that returns the list of extended attributes inside the "list" argument). Implementation notes: Since there are already three existing "print_syscall_ret*" functions inside "strace.c" ("print_syscall_ret_addr()", "print_syscall_ret_adjtimex()", "print_syscall_ret_newselect()"), they were changed to have all syscall arguments beside the return value. This was done so that these functions don't cause build errors (even though syscall arguments are not used in these functions). There is code repetition in these functions for checking the return value and printing the approppriate error message (this code is also located in print_syscall_ret() at the end of "strace.c"). That is the reason why a function "syscall_print_err()" was added for this code and put inside these functions. Functions "print_newselect()" and "print_syscall_ret_newselect()" were changed to use this new implemented functionality and not store the syscall argument values in separate static variables. Signed-off-by: Filip Bozuta <Filip.Bozuta@syrmia.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200619123331.17387-2-filip.bozuta@syrmia.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-05-15linux-user: completely re-write init_guest_spaceAlex Bennée1-11/+20
First we ensure all guest space initialisation logic comes through probe_guest_base once we understand the nature of the binary we are loading. The convoluted init_guest_space routine is removed and replaced with a number of pgb_* helpers which are called depending on what requirements we have when loading the binary. We first try to do what is requested by the host. Failing that we try and satisfy the guest requested base address. If all those options fail we fall back to finding a space in the memory map using our recently written read_self_maps() helper. There are some additional complications we try and take into account when looking for holes in the address space. We try not to go directly after the system brk() space so there is space for a little growth. We also don't want to have to use negative offsets which would result in slightly less efficient code on x86 when it's unable to use the segment offset register. Less mind-binding gotos and hopefully clearer logic throughout. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Acked-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20200513175134.19619-5-alex.bennee@linaro.org>
2020-02-19linux-user: remove gemu_log from the linux-user treeJosh Kunz1-1/+0
Now that all uses have been migrated to `qemu_log' it is no longer needed. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Josh Kunz <jkz@google.com> Message-Id: <20200204025416.111409-4-jkz@google.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-02-19linux-user: Use `qemu_log' for straceJosh Kunz1-1/+0
This change switches linux-user strace logging to use the newer `qemu_log` logging subsystem rather than the older `gemu_log` (notice the "g") logger. `qemu_log` has several advantages, namely that it allows logging to a file, and provides a more unified interface for configuration of logging (via the QEMU_LOG environment variable or options). This change introduces a new log mask: `LOG_STRACE` which is used for logging of user-mode strace messages. Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Josh Kunz <jkz@google.com> Message-Id: <20200204025416.111409-3-jkz@google.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2020-01-22linux-user: Reserve space for brkRichard Henderson1-0/+1
With bad luck, we can wind up with no space at all for brk, which will generally cause the guest malloc to fail. This bad luck is easier to come by with ET_DYN (PIE) binaries, where either the stack or the interpreter (ld.so) gets placed immediately after the main executable. But there's nothing preventing this same thing from happening with ET_EXEC (normal) binaries, during probe_guest_base(). In both cases, reserve some extra space via mmap and release it back to the system after loading the interpreter and allocating the stack. The choice of 16MB is somewhat arbitrary. It's enough for libc to get going, but without being so large that 32-bit guests or 32-bit hosts are in danger of running out of virtual address space. It is expected that libc will be able to fall back to mmap arenas after the limited brk space is exhausted. Launchpad: https://bugs.launchpad.net/qemu/+bug/1749393 Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200117230245.5040-1-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2019-08-16Include qemu/queue.h slightly lessMarkus Armbruster1-1/+0
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20190812052359.30071-20-armbru@redhat.com>
2019-07-26linux-user: Make sigaltstack stacks per-threadPeter Maydell1-0/+2
The alternate signal stack set up by the sigaltstack syscall is supposed to be per-thread. We were incorrectly implementing it as process-wide. This causes problems for guest binaries that rely on this. Notably the Go runtime does, and so we were seeing crashes caused by races where two guest threads might incorrectly both execute on the same stack simultaneously. Replace the global target_sigaltstack_used with a field sigaltstack_used in the TaskState, and make all the references to the old global instead get a pointer to the TaskState and use the field. Fixes: https://bugs.launchpad.net/qemu/+bug/1696773 Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Tested-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20190725131645.19501-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2019-07-18linux-user: check valid address in access_ok()Rémi Denis-Courmont1-1/+3
Fix a crash with LTP testsuite and aarch64: tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s qemu-aarch64: .../qemu/accel/tcg/translate-all.c:2522: page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed. qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x60001554 page_check_range() should never be called with address outside the guest address space. This patch adds a guest_addr_valid() check in access_ok() to only call page_check_range() with a valid address. Fixes: f6768aa1b4c6 ("target/arm: fix AArch64 virtual address space size") Signed-off-by: Rémi Denis-Courmont <remi@remlab.net> Signed-off-by: Laurent Vivier <lvivier@redhat.com> Message-Id: <20190704084115.24713-1-lvivier@redhat.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2019-06-26linux-user/m68k: remove simulator syscall interfaceLaurent Vivier1-1/+0
This interface has been introduced in 2005 with the coldfire implementation (e6e5906b6e ColdFire target.) and looks like to do what the linux-user interface already does with the TRAP exception rather than the ILLEGAL exception. This interface has not been maintained since that. The semi-hosting interface is not removed so coldfire kernel with semi-hosting is always supported. Signed-off-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20190524162049.806-1-laurent@vivier.eu> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2019-05-24linux-user: Fix shmat emulation by honoring host SHMLBARichard Henderson1-1/+1
For those hosts with SHMLBA > getpagesize, we don't automatically select a guest address that is compatible with the host. We can achieve this by boosting the alignment of guest_base and by adding an extra alignment argument to mmap_find_vma. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20190519201953.20161-13-richard.henderson@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2019-01-22linux-user: Fix compilation with clang 3.4Thomas Huth1-5/+1
Clang version 3.4.2 does not know the -Wpragmas option yet and bails out with an error when we try to disable it in linux-user/qemu.h. Fortunately, clang has a __has_warning() macro which allows us to add an explicit check for the option that we want to ignore. With that we can check for the availability of "-Waddress-of-packed-member" properly and do not need the "-Wpragmas" at all here. Fixes: 850d5e330a9c68cc998cecc02caf8a3c8d1ee8a3 Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Thomas Huth <thuth@redhat.com>
2019-01-11avoid TABs in files that only contain a fewPaolo Bonzini1-2/+2
Most files that have TABs only contain a handful of them. Change them to spaces so that we don't confuse people. disas, standard-headers, linux-headers and libdecnumber are imported from other projects and probably should be exempted from the check. Outside those, after this patch the following files still contain both 8-space and TAB sequences at the beginning of the line. Many of them have a majority of TABs, or were initially committed with all tabs. bsd-user/i386/target_syscall.h bsd-user/x86_64/target_syscall.h crypto/aes.c hw/audio/fmopl.c hw/audio/fmopl.h hw/block/tc58128.c hw/display/cirrus_vga.c hw/display/xenfb.c hw/dma/etraxfs_dma.c hw/intc/sh_intc.c hw/misc/mst_fpga.c hw/net/pcnet.c hw/sh4/sh7750.c hw/timer/m48t59.c hw/timer/sh_timer.c include/crypto/aes.h include/disas/bfd.h include/hw/sh4/sh.h libdecnumber/decNumber.c linux-headers/asm-generic/unistd.h linux-headers/linux/kvm.h linux-user/alpha/target_syscall.h linux-user/arm/nwfpe/double_cpdo.c linux-user/arm/nwfpe/fpa11_cpdt.c linux-user/arm/nwfpe/fpa11_cprt.c linux-user/arm/nwfpe/fpa11.h linux-user/flat.h linux-user/flatload.c linux-user/i386/target_syscall.h linux-user/ppc/target_syscall.h linux-user/sparc/target_syscall.h linux-user/syscall.c linux-user/syscall_defs.h linux-user/x86_64/target_syscall.h slirp/cksum.c slirp/if.c slirp/ip.h slirp/ip_icmp.c slirp/ip_icmp.h slirp/ip_input.c slirp/ip_output.c slirp/mbuf.c slirp/misc.c slirp/sbuf.c slirp/socket.c slirp/socket.h slirp/tcp_input.c slirp/tcpip.h slirp/tcp_output.c slirp/tcp_subr.c slirp/tcp_timer.c slirp/tftp.c slirp/udp.c slirp/udp.h target/cris/cpu.h target/cris/mmu.c target/cris/op_helper.c target/sh4/helper.c target/sh4/op_helper.c target/sh4/translate.c tcg/sparc/tcg-target.inc.c tests/tcg/cris/check_addo.c tests/tcg/cris/check_moveq.c tests/tcg/cris/check_swap.c tests/tcg/multiarch/test-mmap.c ui/vnc-enc-hextile-template.h ui/vnc-enc-zywrle.h util/envlist.c util/readline.c The following have only TABs: bsd-user/i386/target_signal.h bsd-user/sparc64/target_signal.h bsd-user/sparc64/target_syscall.h bsd-user/sparc/target_signal.h bsd-user/sparc/target_syscall.h bsd-user/x86_64/target_signal.h crypto/desrfb.c hw/audio/intel-hda-defs.h hw/core/uboot_image.h hw/sh4/sh7750_regnames.c hw/sh4/sh7750_regs.h include/hw/cris/etraxfs_dma.h linux-user/alpha/termbits.h linux-user/arm/nwfpe/fpopcode.h linux-user/arm/nwfpe/fpsr.h linux-user/arm/syscall_nr.h linux-user/arm/target_signal.h linux-user/cris/target_signal.h linux-user/i386/target_signal.h linux-user/linux_loop.h linux-user/m68k/target_signal.h linux-user/microblaze/target_signal.h linux-user/mips64/target_signal.h linux-user/mips/target_signal.h linux-user/mips/target_syscall.h linux-user/mips/termbits.h linux-user/ppc/target_signal.h linux-user/sh4/target_signal.h linux-user/sh4/termbits.h linux-user/sparc64/target_syscall.h linux-user/sparc/target_signal.h linux-user/x86_64/target_signal.h linux-user/x86_64/termbits.h pc-bios/optionrom/optionrom.h slirp/mbuf.h slirp/misc.h slirp/sbuf.h slirp/tcp.h slirp/tcp_timer.h slirp/tcp_var.h target/i386/svm.h target/sparc/asi.h target/xtensa/core-dc232b/xtensa-modules.inc.c target/xtensa/core-dc233c/xtensa-modules.inc.c target/xtensa/core-de212/core-isa.h target/xtensa/core-de212/xtensa-modules.inc.c target/xtensa/core-fsf/xtensa-modules.inc.c target/xtensa/core-sample_controller/core-isa.h target/xtensa/core-sample_controller/xtensa-modules.inc.c target/xtensa/core-test_kc705_be/core-isa.h target/xtensa/core-test_kc705_be/xtensa-modules.inc.c tests/tcg/cris/check_abs.c tests/tcg/cris/check_addc.c tests/tcg/cris/check_addcm.c tests/tcg/cris/check_addoq.c tests/tcg/cris/check_bound.c tests/tcg/cris/check_ftag.c tests/tcg/cris/check_int64.c tests/tcg/cris/check_lz.c tests/tcg/cris/check_openpf5.c tests/tcg/cris/check_sigalrm.c tests/tcg/cris/crisutils.h tests/tcg/cris/sys.c tests/tcg/i386/test-i386-ssse3.c ui/vgafont.h Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-Id: <20181213223737.11793-3-pbonzini@redhat.com> Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Acked-by: Richard Henderson <richard.henderson@linaro.org> Acked-by: Eric Blake <eblake@redhat.com> Acked-by: David Gibson <david@gibson.dropbear.id.au> Reviewed-by: Stefan Markovic <smarkovic@wavecomp.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-10-30Merge remote-tracking branch ↵Peter Maydell1-1/+1
'remotes/vivier2/tags/qemu-trivial-for-3.1-pull-request' into staging QEMU trivial patches collected between June and October 2018 (Thank you to Thomas Huth) v2: fix 32bit build with updated patch (v3) from Philippe Mathieu-Daudé built in a 32bit debian sid chroot # gpg: Signature made Tue 30 Oct 2018 11:23:01 GMT # gpg: using RSA key F30C38BD3F2FBE3C # gpg: Good signature from "Laurent Vivier <lvivier@redhat.com>" # gpg: aka "Laurent Vivier <laurent@vivier.eu>" # gpg: aka "Laurent Vivier (Red Hat) <lvivier@redhat.com>" # Primary key fingerprint: CD2F 75DD C8E3 A4DC 2E4F 5173 F30C 38BD 3F2F BE3C * remotes/vivier2/tags/qemu-trivial-for-3.1-pull-request: milkymist-minimac2: Use qemu_log_mask(GUEST_ERROR) instead of error_report ppc: move at24c to its own CONFIG_ symbol hw/intc/gicv3: Remove useless parenthesis around DIV_ROUND_UP macro hw/pci-host: Remove useless parenthesis around DIV_ROUND_UP macro tests/bios-tables-test: Remove an useless cast xen: Use the PCI_DEVICE macro qobject: Catch another straggler for use of qdict_put_str() configure: Support pkg-config for zlib tests: Fix typos in comments and help message (found by codespell) cpu.h: fix a typo in comment linux-user: fix comment s/atomic_write/atomic_set/ qemu-iotests: make 218 executable scripts/qemu.py: remove trailing quotes on docstring scripts/decodetree.py: remove unused imports docs/devel/testing.rst: add missing newlines after code block qemu-iotests: fix filename containing checks tests/tcg/README: fix location for lm32 tests memory.h: fix typos in comments vga_int: remove unused function protype configs/alpha: Remove unused CONFIG_PARALLEL_ISA switch Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2018-10-29linux-user: Extend image_info struct with MIPS fp_abi and interp_fp_abi fieldsStefan Markovic1-0/+4
Add MIPS specific image_info struct fields fp_abi and interp_fp_abi to store executable and interpreter fp_abi values (based on kernel struct arch_elf_state in mips/include/asm/elf.h). Reviewed-by: Aleksandar Markovic <amarkovic@wavecomp.com> Signed-off-by: Stefan Markovic <smarkovic@wavecomp.com>
2018-10-26linux-user: fix comment s/atomic_write/atomic_set/Emilio G. Cota1-1/+1
Signed-off-by: Emilio G. Cota <cota@braap.org> Message-Id: <20180811211011.6277-1-cota@braap.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-10-18linux-user: Suppress address-of-packed-member warnings in __get/put_user_ePeter Maydell1-21/+53
Our __get_user_e() and __put_user_e() macros cause newer versions of clang to generate false-positive -Waddress-of-packed-member warnings if they are passed the address of a member of a packed struct (see https://bugs.llvm.org/show_bug.cgi?id=39113). Suppress these using the _Pragma() operator. Unfortunately _Pragma() support in gcc is broken in some gcc versions and in some usage contexts, so we limit the pragma usage here to clang. To put in the pragmas we need to convert the macros from expressions to statements, but all the callsites effectively treat them as statements already so this is OK. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20181009161814.21257-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-07-22linux-user/ppc: Implement swapcontext syscallRichard Henderson1-0/+2
This allows the tests generated by debian-powerpc-user-cross to function properly, especially tests/test-coroutine. Technically this syscall is available to both ppc32 and ppc64, but only ppc32 glibc actually uses it. Thus the ppc64 path is untested. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Tested-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20180718200648.22529-1-richard.henderson@linaro.org>
2018-07-22linux-user: fix ELF load alignment errorLaurent Vivier1-0/+1
When we try to use some targets on ppc64, it can happen the target doesn't support the host page size to align ELF load sections and fails with: ELF load command alignment not page-aligned Since commit a70daba3771 ("linux-user: Tell guest about big host page sizes") the host page size is used to align ELF sections, but this doesn't work if the alignment required by the load section is smaller than the host one. For these cases, we continue to use the TARGET_PAGE_SIZE instead of the host one. I have tested this change on ppc64, and it fixes qemu linux-user for: s390x, m68k, i386, arm, aarch64, hppa and I have tested it doesn't break the following targets: x86_64, mips64el, sh4 mips and mipsel abort, but I think for another reason. Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> [lv: fixed "info->alignment = 0"] Message-Id: <20180716195349.29959-1-laurent@vivier.eu>
2018-07-05linux-user: introduce preexit_cleanupAlex Bennée1-0/+8
To avoid repeating ourselves move our preexit clean-up code into a helper function. I figured the continuing effort to split of the syscalls made it worthwhile creating a new file for it now. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
2018-06-11linux-user: Export use is_error(), use it to avoid warningsPhilippe Mathieu-Daudé1-0/+5
This fixes: linux-user/flatload.c:740:9: warning: Loss of sign in implicit conversion if (res > (unsigned long)-4096) ^~~ Reported-by: Clang Static Analyzer Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20180604153722.24956-2-f4bug@amsat.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-06-04linux-user: move get_sp_from_cpustate() to target_cpu.hLaurent Vivier1-1/+0
Remove useless includes Fix HPPA include guard. Signed-off-by: Laurent Vivier <laurent@vivier.eu> Acked-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20180529194207.31503-9-laurent@vivier.eu>
2018-05-03linux-user: ARM-FDPIC: Add support of FDPIC for ARM.Christophe Lyon1-0/+9
Add FDPIC info into image_info structure since interpreter info is on stack and needs to be saved to be accessed later on. Co-Authored-By: Mickaël Guêné <mickael.guene@st.com> Signed-off-by: Christophe Lyon <christophe.lyon@st.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20180430080404.7323-4-christophe.lyon@st.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-05-03Remove CONFIG_USE_FDPIC.Christophe Lyon1-2/+2
We want to avoid code disabled by default, because it ends up less tested. This patch removes all instances of #ifdef CONFIG_USE_FDPIC, most of which can be safely kept. For the ones that should be conditionally executed, we define elf_is_fdpic(). Without this patch, defining CONFIG_USE_FDPIC would prevent QEMU from building precisely because elf_is_fdpic is not defined. Signed-off-by: Christophe Lyon <christophe.lyon@st.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-Id: <20180430080404.7323-2-christophe.lyon@st.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-03-09linux-user: drop unused target_msync functionMax Filippov1-1/+0
target_msync is not used, remove its declaration and implementation. Cc: Riku Voipio <riku.voipio@iki.fi> Cc: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20180228221609.11265-9-jcmvbkbc@gmail.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-03-09linux-user: Drop unicore32 codePeter Maydell1-4/+1
We dropped the unicore32-linux-user target in commit 5e2b40f7271cf9 in 2016. Nobody has made any attempt to fix the issues that caused us to drop it, so remove the associated code. (The system emulation parts of unicore32 remain.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20180308144733.25615-2-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2018-02-25linux-user: introduce functions to detect CPU typeYunQiang Su1-0/+1
Add a function to return ELF e_flags and use it to select the CPU model. Signed-off-by: YunQiang Su <syq@debian.org> [lv: split the patch and some cleanup in get_elf_eflags()] Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20180220173307.25125-3-laurent@vivier.eu>
2018-02-18linux-user: Remove THREAD macroPeter Maydell1-3/+1
Back when we used to support compiling either with or without NPTL threading library support, we used a macro THREAD which would expand either to nothing (no thread support) or to __thread (threads supported). For a long time now we have required thread support, so remove the macro and just use __thread directly as other parts of QEMU do. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-Id: <20180213132246.26844-1-peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2017-01-22linux-user: Support stack-grows-up in elfload.cRichard Henderson1-0/+3
HPPA is a (the) stack-grows-up target, and supporting that requires rearranging how we compute addresses while laying out the initial program stack. In addition, hppa32 requires 64-byte stack alignment so parameterize that as well. Signed-off-by: Richard Henderson <rth@twiddle.net>
2016-09-21linux-user: Pass si_type information to queue_signal() explicitlyPeter Maydell1-1/+2
Instead of assuming in queue_signal() that all callers are passing a siginfo structure which uses the _sifields._sigfault part of the union (and thus a si_type of QEMU_SI_FAULT), make callers pass the si_type they require in as an argument. [RV adjusted to apply] Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: report signals being taken in strace outputPeter Maydell1-0/+10
Native strace reports when the process being traced takes a signal: --- SIGSEGV {si_signo=SIGSEGV, si_code=SI_KERNEL, si_addr=0} --- Report something similar when QEMU is doing its internal strace of the guest process and is about to deliver it a signal. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-15linux-user/qemu.h: change malloc to g_malloc, free to g_freeMd Haris Iqbal1-2/+2
Signed-off-by: Md Haris Iqbal <haris.phnx@gmail.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2016-07-26exec: Reduce CONFIG_USER_ONLY ifdeffeneryIgor Mammedov1-2/+0
Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2016-07-04linux-user: Make semihosting heap/stack fields abi_ulongsPeter Maydell1-3/+3
The fields in the TaskState heap_base, heap_limit and stack_base are all guest addresses (representing the locations of the heap and stack for the guest binary), so they should be abi_ulong rather than uint32_t. (This only in practice affects ARM AArch64 since all the other semihosting implementations are 32-bit.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> Message-id: 1466783381-29506-2-git-send-email-peter.maydell@linaro.org
2016-06-26linux-user: Don't use sigfillset() on uc->uc_sigmaskPeter Maydell1-0/+5
The kernel and libc have different ideas about what a sigset_t is -- for the kernel it is only _NSIG / 8 bytes in size (usually 8 bytes), but for libc it is much larger, 128 bytes. In most situations the difference doesn't matter, because if you pass a pointer to a libc sigset_t to the kernel it just acts on the first 8 bytes of it, but for the ucontext_t* argument to a signal handler it trips us up. The kernel allocates this ucontext_t on the stack according to its idea of the sigset_t type, but the type of the ucontext_t defined by the libc headers uses the libc type, and so do the manipulator functions like sigfillset(). This means that (1) sizeof(uc->uc_sigmask) is much larger than the actual space used on the stack (2) sigfillset(&uc->uc_sigmask) will write garbage 0xff bytes off the end of the structure, which can trash data that was on the stack before the signal handler was invoked, and may result in a crash after the handler returns To avoid this, we use a memset() of the correct size to fill the signal mask rather than using the libc function. This fixes a problem where we would crash at least some of the time on an i386 host when a signal was taken. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-06-08linux-user: Make target_strerror() return 'const char *'Peter Maydell1-1/+1
Make target_strerror() return 'const char *' rather than just 'char *'; this will allow us to return constant strings from it for some special cases. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Laurent Vivier <laurent@vivier.eu>
2016-06-07linux-user: Queue synchronous signals separatelyTimothy E Baldwin1-0/+1
If a synchronous signal and an asynchronous signal arrive near simultaneously, and the signal number of the asynchronous signal is lower than that of the synchronous signal the the handler for the asynchronous would be called first, and then the handler for the synchronous signal would be called within or after the first handler with an incorrect context. This is fixed by queuing synchronous signals separately. Note that this does risk delaying a asynchronous signal until the synchronous signal handler returns rather than handling the signal on another thread, but this seems unlikely to cause problems for real guest programs and is unavoidable unless we could guarantee to roll back and reexecute whatever guest instruction caused the synchronous signal (which would be a bit odd if we've already logged its execution, for instance, and would require careful analysis of all guest CPUs to check it was possible in all cases). Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk> Message-id: 1441497448-32489-24-git-send-email-T.E.Baldwin99@members.leeds.ac.uk [PMM: added a comment] Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-06-07linux-user: Remove real-time signal queuingTimothy E Baldwin1-10/+1
As host signals are now blocked whenever guest signals are blocked, the queue of realtime signals is now in Linux. The QEMU queue is now redundant and can be removed. (We already did not queue non-RT signals, and none of the calls to queue_signal() except the one in host_signal_handler() pass an RT signal number.) Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk> Message-id: 1441497448-32489-23-git-send-email-T.E.Baldwin99@members.leeds.ac.uk Reviewed-by: Peter Maydell <peter.maydell@linaro.org> [PMM: minor commit message tweak] Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-06-07linux-user: Fix race between multiple signalsPeter Maydell1-2/+48
If multiple host signals are received in quick succession they would be queued in TaskState then delivered to the guest in spite of signals being supposed to be blocked by the guest signal handler's sa_mask. Fix this by decoupling the guest signal mask from the host signal mask, so we can have protected sections where all host signals are blocked. In particular we block signals from when host_signal_handler() queues a signal from the guest until process_pending_signals() has unqueued it. We also block signals while we are manipulating the guest signal mask in emulation of sigprocmask and similar syscalls. Blocking host signals also ensures the correct behaviour with respect to multiple threads and the overrun count of timer related signals. Alas blocking and queuing in qemu is still needed because of virtual processor exceptions, SIGSEGV and SIGBUS. Blocking signals inside process_pending_signals() protects against concurrency problems that would otherwise happen if host_signal_handler() ran and accessed the signal data structures while process_pending_signals() was manipulating them. Since we now track the guest signal mask separately from that of the host, the sigsuspend system calls must track the signal mask passed to them, because when we process signals as we leave the sigsuspend the guest signal mask in force is that passed to sigsuspend. Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk> Message-id: 1441497448-32489-19-git-send-email-T.E.Baldwin99@members.leeds.ac.uk [PMM: make signal_pending a simple flag rather than a word with two flag bits; ensure we don't call block_signals() twice in sigreturn codepaths; document and assert() the guarantee that using do_sigprocmask() to get the current mask never fails; use the qemu atomics.h functions rather than raw volatile variable access; add extra commentary and documentation; block SIGSEGV/SIGBUS in block_signals() and in process_pending_signals() because they can't occur synchronously here; check the right do_sigprocmask() call for errors in ssetmask syscall; expand commit message; fixed sigsuspend() hanging] Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-05-27linux-user: Provide safe_syscall for fixing races between signals and syscallsTimothy E Baldwin1-1/+126
If a signal is delivered immediately before a blocking system call the handler will only be called after the system call returns, which may be a long time later or never. This is fixed by using a function (safe_syscall) that checks if a guest signal is pending prior to making a system call, and if so does not call the system call and returns -TARGET_ERESTARTSYS. If a signal is received between the check and the system call host_signal_handler() rewinds execution to before the check. This rewinding has the effect of closing the race window so that safe_syscall will reliably either (a) go into the host syscall with no unprocessed guest signals pending or or (b) return -TARGET_ERESTARTSYS so that the caller can deal with the signals. Implementing this requires a per-host-architecture assembly language fragment. This will also resolve the mishandling of the SA_RESTART flag where we would restart a host system call and not call the guest signal handler until the syscall finally completed -- syscall restarting now always happens at the guest syscall level so the guest signal handler will run. (The host syscall will never be restarted because if the host kernel rewinds the PC to point at the syscall insn for a restart then our host_signal_handler() will see this and arrange the guest PC rewind.) This commit contains the infrastructure for implementing safe_syscall and the assembly language fragment for x86-64, but does not change any syscalls to use it. Signed-off-by: Timothy Edward Baldwin <T.E.Baldwin99@members.leeds.ac.uk> Message-id: 1441497448-32489-14-git-send-email-T.E.Baldwin99@members.leeds.ac.uk [PMM: * Avoid having an architecture if-ladder in configure by putting linux-user/host/$(ARCH) on the include path and including safe-syscall.inc.S from it * Avoid ifdef ladder in signal.c by creating new hostdep.h to hold host-architecture-specific things * Added copyright/license header to safe-syscall.inc.S * Rewrote commit message * Added comments to safe-syscall.inc.S * Changed calling convention of safe_syscall() to match syscall() (returns -1 and host error in errno on failure) * Added a long comment in qemu.h about how to use safe_syscall() to implement guest syscalls. ] RV: squashed Peters "fixup! linux-user: compile on non-x86-64 hosts" patch Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-05-19cpu: move exec-all.h inclusion out of cpu.hPaolo Bonzini1-0/+1
exec-all.h contains TCG-specific definitions. It is not needed outside TCG-specific files such as translate.c, exec.c or *helper.c. One generic function had snuck into include/exec/exec-all.h; move it to include/qom/cpu.h. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-23build: [linux-user] Rename "syscall.h" to "target_syscall.h" in target ↵Lluís Vilanova1-1/+1
directories This fixes double-definitions in linux-user builds when using the UST tracing backend (which indirectly includes the system's "syscall.h"). Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-02-23all: Clean up includesPeter Maydell1-3/+0
Clean up includes so that osdep.h is included first and headers which it implies are not included manually. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Eric Blake <eblake@redhat.com>
2015-09-28linux-user: remove MAX_ARG_PAGES limitStefan Brüns1-7/+0
Instead of creating a temporary copy for the whole environment and the arguments, directly copy everything to the target stack. For this to work, we have to change the order of stack creation and copying the arguments. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2015-09-28linux-user: remove unused image_info membersStefan Brüns1-2/+0
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2015-09-09exec: make mmap_lock/mmap_unlock globally availablePaolo Bonzini1-2/+0
There is some iffy lock hierarchy going on in translate-all.c. To fix it, we need to take the mmap_lock in cpu-exec.c. Make the functions globally available. Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-06-17linux-user: fix gcc-4.9 compiler error on __{get,put]}_userRiku Voipio1-6/+6
gcc-4.9 finds unused operand: linux-user/syscall.c: In function ‘host_to_target_stat64’: linux-user/qemu.h:301:19: error: right-hand operand of comma expression has no effect [-Werror=unused-value] ((hptr), (x)), 0) Just removing the rh operand is no good, it will error in later: linux-user/main.c: In function ‘arm_kernel_cmpxchg64_helper’: linux-user/qemu.h:330:15: error: void value not ignored as it ought to be __ret = __put_user((x), __hptr); \ Thus, remove setting __ret from __get_user and __put_user, as and set the right hand operand to (void)0 to make it clear that these return never nothing. This commit depends on the signal.c cleanup, to ensure bisectable version history. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Cc: Richard Henderson <rth@twiddle.net>
2014-06-05softmmu: introduce cpu_ldst.hPaolo Bonzini1-0/+1
This will collect all load and store helpers soon. For now it is just a replacement for softmmu_exec.h, which this patch stops including directly, but we also include it where this will be necessary in order to simplify the next patch. Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2014-03-17linux-user: Don't allow guest to block SIGSEGVPeter Maydell1-0/+1
Don't allow the linux-user guest to block SIGSEGV -- QEMU needs this signal to detect accesses to pages which it has marked read-only because it has cached translated code from them. We implement this by making the do_sigprocmask() wrapper suppress SIGSEGV when doing the host process signal mask manipulation; instead we store the current state of SIGSEGV in the TaskState struct. If we get a SIGSEGV for the guest when the guest has blocked the signal, we treat it as if the default SEGV handler was in place, as the kernel does for forced SIGSEGV delivery. This patch is based on an idea by Alex Barcelo, but rather than simply lying to the guest about the SIGSEGV state we track it. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reported-by: Alex Barcelo <abarcelo@ac.upc.edu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>