summaryrefslogtreecommitdiff
path: root/linux-user
AgeCommit message (Collapse)AuthorFilesLines
2014-08-22linux-user: Make ipc syscall's third argument an abi_longTom Musta1-4/+4
For those target ABIs that use the ipc system call (e.g. POWER), the third argument is used in the shmat path as a pointer. It therefore must be declared as an abi_long (versus int) so that the address bits are not lost in truncation. In fact, all arguments to do_ipc should be declared as abit_long. In fact, it makes more sense for all of the arguments to be declaried as abi_long (except call). Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Properly Handle semun Structure In Cross-Endian SituationsTom Musta1-2/+11
The semun union used in the semctl system call contains both an int (val) and pointers. In cross-endian situations on 64 bit targets, the value passed to semctl is an 8 byte (abi_long) value and thus does not have the 4-byte val field in the correct location. In order to rectify this, the other half of the union must be accessed. This is achieved in code by performing a byte swap on the entire 8 byte union, followed by a 4-byte swap of the first half. Also, eliminate an extraneous (dead) line of code that sets target_su.val in the IPC_SET/IPC_GET case. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Dereference Pointer Argument to ipc/semctl Sys CallTom Musta1-2/+8
When the ipc system call is used to wrap a semctl system call, the ptr argument to ipc needs to be dereferenced prior to passing it to the semctl handler. This is because the fourth argument to semctl is a union and not a pointer to a union. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: PPC64 semid_ds Doesnt Include _unused1 and _unused2Tom Musta1-0/+4
The 64 bit PowerPC platforms eliminate the _unused1 and _unused2 elements of the semid_ds structure from <sys/sem.h>. So eliminate these from the target_semid_ds structure. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: add setns and unshareRiku Voipio2-0/+14
Add support for the setns and unshare syscalls, trivially passed through to the host. Based on patches by Paul Burton, added configure check. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: support ioprio_{get, set} syscallsPaul Burton1-0/+18
Add support for the ioprio_get & ioprio_set syscalls, allowing their use by target programs. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: support timerfd_{create, gettime, settime} syscallsRiku Voipio2-0/+54
Adds support for the timerfd_create, timerfd_gettime & timerfd_settime syscalls, allowing use of timerfds by target programs. v2: By Riku - added configure check for timerfd and ifdefs for benefit of old distributions like RHEL5. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: fix readlink handling with magic exe symlinkMike Frysinger1-2/+13
The current code always returns the length of the path when it should be returning the number of bytes it wrote to the output string. Further, readlink is not supposed to append a NUL byte, but the current snprintf logic will always do just that. Even further, if you pass in a length of 0, you're suppoesd to get back an error (EINVAL), but the current logic just returns 0. Further still, if there was an error reading the symlink, we should not go ahead and try to read the target buffer as it is garbage. Simple test for the first two issues: $ cat test.c int main() { char buf[50]; size_t len; for (len = 0; len < 10; ++len) { memset(buf, '!', sizeof(buf)); ssize_t ret = readlink("/proc/self/exe", buf, len); buf[20] = '\0'; printf("readlink(/proc/self/exe, {%s}, %zu) = %zi\n", buf, len, ret); } return 0; } Now compare the output of the native: $ gcc test.c -o /tmp/x $ /tmp/x $ strace /tmp/x With what qemu does: $ armv7a-cros-linux-gnueabi-gcc test.c -o /tmp/x -static $ qemu-arm /tmp/x $ qemu-arm -strace /tmp/x Signed-off-by: Mike Frysinger <vapier@chromium.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Fix conversion of sigevent argument to timer_createPeter Maydell1-8/+30
There were a number of bugs in the conversion of the sigevent argument to timer_create from target to host format: * signal number not converted from target to host * thread ID not copied across * sigev_value not copied across * we never unlocked the struct when we were done Between them, these problems meant that SIGEV_THREAD_ID timers (and the glibc-implemented SIGEV_THREAD timers which depend on them) didn't work. Fix these problems and clean up the code a little by pulling the struct conversion out into its own function, in line with how we convert various other structs. This allows the test program in bug LP:1042388 to run. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Fix syscall instruction usermode emulation on X86_64Jincheng Miao1-1/+0
Currently syscall instruction is buggy on user mode X86_64, the EIP is updated after do_syscall(), that is too late for clone(). Because clone() will create a thread at the env->EIP (the address of syscall insn), and then child thread enters do_syscall() again, that is not expected. Sometimes it is tragic. User mode syscall insn emulation is not used MSR, so the action should be same to INT 0x80. INT 0x80 will update EIP in do_interrupt(), ditto for syscall() for consistency. Signed-off-by: Jincheng Miao <jmiao@redhat.com> Reviewed-by: Richard Henderson <rth@twiddle.net> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: redirect openat callsRiku Voipio1-14/+9
While Mikhail fixed /proc/self/maps, it was noticed openat calls are not redirected currently. Some archs don't have open at all, so openat needs to be redirected. Fix this by consolidating open/openat code to do_openat - open is implemented using openat(AT_FDCWD, ... ), which according to open(2) man page is identical. Since all targets now have openat, remove the ifdef around sys_openat and openat: case in do_syscall. Cc: Mikhail Ilin <m.ilin@samsung.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: /proc/self/maps contentMikhail Ilyin1-15/+10
Build /proc/self/maps doing a match against guest memory translation table. Output only that map records which are valid for guest memory layout. Signed-off-by: Mikhail Ilyin <m.ilin@samsung.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-15linux-user: use TARGET_SA_ONSTACK in get_sigframeRiku Voipio1-3/+4
As reported by Laurent, which should use TARGET_SA_ONSTACK on arm, microblaze and openrisc targets like we do on all others. Practical matter is minimal as for almost all archs SA_ONSTACK is 0x08000000: http://lxr.free-electrons.com/ident?i=SA_ONSTACK Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-15alloca one extra byte socketsJoakim Tjernlund1-3/+3
target_to_host_sockaddr() may increase the lenth with 1 byte for AF_UNIX sockets so allocate 1 extra byte. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-15linux-user: handle AF_PACKET sockaddrs in target_to_host_sockaddrJoakim Tjernlund2-0/+17
Implement conversion of the AF_PACKET sockaddr subtype in target_to_host_sockaddr. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-15qemu-user: Impl. setsockopt(SO_BINDTODEVICE)Joakim Tjernlund1-0/+19
Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-15SIOCGIFINDEX: fix typoJoakim Tjernlund1-1/+1
Wrong type was used in ioctl definition. Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund@transmode.se> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-07-08target-ppc: Change default cpu for ppc64le-linux-userRichard Henderson1-4/+4
The default, 970fx, doesn't support MSR_LE. So even though we set LE in ppc_cpu_reset, it gets cleared again in hreg_store_msr. Error out if a user-selected cpu model doesn't support LE. Signed-off-by: Richard Henderson <rth@twiddle.net> [agraf: switch to POWER7 as default for BE and LE] Signed-off-by: Alexander Graf <agraf@suse.de>
2014-06-29Merge remote-tracking branch 'remotes/riku/linux-user-for-upstream' into stagingPeter Maydell5-27/+207
* remotes/riku/linux-user-for-upstream: linux-user: support the SIOCGIFINDEX ioctl linux-user: support the KDSIGACCEPT ioctl linux-user: allow NULL tv argument for settimeofday linux-user: respect timezone for settimeofday linux-user: fix struct target_epoll_event layout for MIPS linux-user: support strace of epoll_create1 linux-user: allow NULL arguments to mount linux-user: support SO_PASSSEC setsockopt option linux-user: support SO_{SND, RCV}BUFFORCE setsockopt options linux-user: support SO_ACCEPTCONN getsockopt option linux-user: translate the result of getsockopt SO_TYPE linux-user: added fake open() for /proc/self/cmdline Add support for MAP_NORESERVE mmap flag. Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2014-06-29linux-user: support the SIOCGIFINDEX ioctlPaul Burton2-0/+2
Add a definition of the SIOCGIFINDEX ioctl, allowing its use by target programs. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: support the KDSIGACCEPT ioctlPaul Burton3-0/+9
Add a definition of the KDSIGACCEPT ioctl & allow its use by target programs. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: allow NULL tv argument for settimeofdayPaul Burton1-4/+8
The tv argument to the settimeofday syscall is allowed to be NULL, if the program only wishes to provide the timezone. QEMU previously returned -EFAULT when tv was NULL. Instead, execute the syscall & provide NULL to the kernel as the target program expected. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: respect timezone for settimeofdayPaul Burton2-1/+33
The settimeofday syscall accepts a tz argument indicating the desired timezone to the kernel. QEMU previously ignored any argument provided by the target program & always passed NULL to the kernel. Instead, translate the argument & pass along the data userland provided. Although this argument is described by the settimeofday man page as obsolete, it is used by systemd as of version 213. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: fix struct target_epoll_event layout for MIPSPaul Burton1-1/+1
MIPS requires the pad field to 64b-align the data field just as ARM does. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: support strace of epoll_create1Paul Burton1-0/+3
Add the epoll_create1 syscall to strace.list in order to display that syscall when it occurs, rather than a message about the syscall being unknown despite QEMU already implementing support for it. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: allow NULL arguments to mountPaul Burton1-22/+53
Calls to the mount syscall can legitimately provide NULL as the value for the source of filesystemtype arguments, which QEMU would previously reject & return -EFAULT to the target program. An example of this is remounting an already mounted filesystem with different properties. Instead of rejecting such syscalls with -EFAULT, pass NULL along to the kernel as the target program expects. Additionally this patch fixes a potential memory leak when DEBUG_REMAP is enabled and lock_user_string fails on the target or filesystemtype arguments but a prior argument was non-NULL and already locked. Since the patch already touched most lines of the TARGET_NR_mount case, it fixes the indentation & coding style for good measure. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: support SO_PASSSEC setsockopt optionPaul Burton2-0/+8
Translate the SO_PASSSEC option to setsockopt to the host value & perform the syscall as expected, allowing use of the option by target programs. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: support SO_{SND, RCV}BUFFORCE setsockopt optionsPaul Burton1-0/+6
Translate the SO_SNDBUFFORCE & SO_RCVBUFFORCE options to setsockopt to the host values & perform the syscall as expected, allowing use of those options by target programs. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: support SO_ACCEPTCONN getsockopt optionPaul Burton1-0/+3
Translate the SO_ACCEPTCONN option to the host value & execute the syscall as expected. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: translate the result of getsockopt SO_TYPEPaul Burton1-0/+34
QEMU previously passed the result of the host syscall directly to the target program. This is a problem if the host & target have different representations of socket types, as is the case when running a MIPS target program on an x86 host. Introduce a host_to_target_sock_type helper function mirroring the existing target_to_host_sock_type, and call it to translate the value provided by getsockopt when called for the SO_TYPE option. Signed-off-by: Paul Burton <paul@archlinuxmips.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29linux-user: added fake open() for /proc/self/cmdlineWim Vander Schelden1-0/+46
Signed-off-by: Wim Vander Schelden <wim@fixnum.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-29Add support for MAP_NORESERVE mmap flag.Christophe Lyon1-0/+2
mmap_flags_tbl contains a list of mmap flags, and how to map them to the target. This patch adds MAP_NORESERVE, which was missing to the list. Signed-off-by: Christophe Lyon <christophe.lyon@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-27linux-user: Support HWCAP2 in PowerPCTom Musta1-0/+31
Set bits in the AT_HWCAP2 entry of the AUXV. Specifically, detect and set bits for bctar, ISEL and ISA 2.07. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
2014-06-27linux-user: Identify Addition Hardware Capabilities for PowerPCTom Musta1-0/+8
Add VSX, DFP and ISA 2.06 to the bits identified in the AT_HWCAP entry of the AUXV. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
2014-06-27linux-user: Correct AUXV Cache Line Sizes for PowerPCTom Musta1-2/+3
Set the AT_ICACHEBSIZE and AT_DCACHEBSIZE entries of the AUXV to match the CPU model's cache line sizes. This fixes memory clobbering problems on more recent Book 3s implementations; memset(p, 0, N) will use the dcbz instruction when N is sufficiently large and many of the newer server CPUs have cache lines sizes of 128 bytes. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
2014-06-24Add support for the arm breakpoint syscallHunter Laux2-0/+5
OABI arm used a software interrupt(0xef9f0001) for breakpoints. Since 2005 gdb has used the break instruction(0xe7f001f0) for EABI. Apparently Steel Bank Common Lisp still uses the swi instruction. This is the kernel implementation: http://lxr.free-electrons.com/source/arch/arm/kernel/traps.c#L598 Signed-off-by: Hunter Laux <hunterlaux@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-06-23tcg-ppc: Merge cache-utils into the backendRichard Henderson1-3/+0
As a "utility", it only supported ppc, and in a way that other tcg backends provided directly in tcg-target.h. Removing this disparity is easier now that the two ppc backends are merged. Tested-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Richard Henderson <rth@twiddle.net>
2014-06-23qemu/osdep: Remove the need for qemu_init_auxvalRichard Henderson1-1/+0
Instead of getting backup auxv data from the env pointer given to main, read it from /proc/self/auxv. We can do this at any time, so we're not tied to any ordering wrt a call to qemu_init_auxval from main. Tested-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Richard Henderson <rth@twiddle.net>
2014-06-18target-mips: implement UserLocal RegisterPetar Jovanovic2-2/+2
From MIPS documentation (Volume III): UserLocal Register (CP0 Register 4, Select 2) Compliance Level: Recommended. The UserLocal register is a read-write register that is not interpreted by the hardware and conditionally readable via the RDHWR instruction. This register only exists if the Config3-ULRI register field is set. Privileged software may write this register with arbitrary information and make it accessible to unprivileged software via register 29 (ULR) of the RDHWR instruction. To do so, bit 29 of the HWREna register must be set to a 1 to enable unprivileged access to the register. Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com> Reviewed-by: Andreas Färber <afaerber@suse.de> Reviewed-by: Aurelien Jarno <aurelien@aurel32.net> Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2014-06-17User mode support for Linux ELF files with no section headerCraig Heffner1-1/+0
In user mode Linux, Qemu currently refuses to load ELF files that do not contain section headers (ehdr->e_shentsize == 0). Since section headers are not required in order to load an ELF file, simply removing the e_shentsize check in elf_check_ehdr() allows ELF binaries with no section headers to be run properly in user mode: Signed-off-by: Craig Heffner <cheffner@tacnetsol.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-17linux-user: Return correct errno for unsupported netlink socketEd Swierk1-1/+1
This fixes "Cannot open audit interface - aborting." when the EAFNOSUPPORT errno differs between the target and host architectures (e.g. mips target and x86_64 host). Signed-off-by: Ed Swierk <eswierk@skyportsystems.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-17linux-user: Don't overrun guest buffer in sched_getaffinityPeter Maydell1-0/+16
If the guest's "long" type is smaller than the host's, then our sched_getaffinity wrapper needs to round the buffer size up to a multiple of the host sizeof(long). This means that when we copy the data back from the host buffer to the guest's buffer there might be more than we can fit. Rather than overflowing the guest's buffer, handle this case by returning EINVAL or ignoring the unused extra space, as appropriate. Note that only guests using the syscall interface directly might run into this bug -- the glibc wrappers around it will always use a buffer whose size is a multiple of 8 regardless of guest architecture. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-06-17linux-user/uname: Return correct uname string for x86_64Peter Maydell1-3/+1
We were returning the incorrect uname string (with a hyphen, not an underscore) for x86_64. Fix this by removing the x86_64 special case, since the default "just use UNAME_MACHINE" behaviour suffices. This leaves cpu_to_uname_machine() special cases for only those architectures which need to vary the string based on runtime CPU features. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
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-17signal/ppc/do_setcontext remove __get_user return checkRiku Voipio1-2/+1
The last remaining check for return value of __get_user. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Cc: Alexander Graf <agraf@suse.de>
2014-06-17signal/sparc64_set_context: remove __get_user checksRiku Voipio1-9/+3
Remove checks of __get_user and the err variable used to control flow with it. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2014-06-17signal/ppc/{save,restore}_user_regs remove __put/get error checksRiku Voipio1-85/+41
As __get_user and __put_user do not return errors, remove the if checks from around them. This allows making the save/restore functions void. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Cc: Alexander Graf <agraf@suse.de>
2014-06-17signal/all/setup_frame remove __put_user checksRiku Voipio1-72/+25
Remove "if(__put_user" checks and their related error paths for all architecture's setup_frame, setup_rt_frame and similar. Remove the unlock_user_struct when the only way to end up there is from failed lock_user_struct. Remove err variable if there are no users for it in the function anymore. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2014-06-17signal/all/do_sigreturn - remove __get_user checksRiku Voipio1-41/+18
Remove "if(__get_user" checks and their related error paths for all architecture's do_sigreturn. Remove the unlock_user_struct when the only way to end up there is from failed lock_user_struct. v3: remove unneccesary sigsegv label as suggested by Peter Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2014-06-17signal/all/do_sigaltstack remove __get_user value checkRiku Voipio1-4/+5
Access is already checked in the lock_user_struct call before. Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>