summaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
AgeCommit message (Collapse)AuthorFilesLines
2014-11-11linux-user: Fix up timer id handlingAlexander Graf1-17/+37
When creating a timer handle, we give the timer id a special magic offset of 0xcafe0000. However, we never mask that offset out of the timer id before we start using it to dereference our timer array. So we always end up aborting timer operations because the timer id is out of bounds. This was not an issue before my patch e52a99f756e ("linux-user: Simplify timerid checks on g_posix_timers range") because before we would blindly mask anything above the first 16 bits. This patch simplifies the code around timer id creation by introducing a proper target_timer_id typedef that is s32, just like Linux has it. It also changes the magic offset to a value that makes all timer ids be positive. Reported-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Tom Musta <tommusta@gmail.com> Tested-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-10-06linux-user: don't include timerfd if not neededRiku Voipio1-1/+3
Without this, builds on older systems fail with: qemu/linux-user/syscall.c:61:25: warning: sys/timerfd.h: No such file or directory v2: fix the usual case where CONFIG_TIMERFD is enabled.. Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-10-06linux-user: Simplify timerid checks on g_posix_timers rangeAlexander Graf1-13/+17
We check whether the passed in timer id is negative on all calls that involve g_posix_timers. However, these checks are bogus. First off we limit the timer_id to 16 bits which is not what Linux does. Then we check whether it's negative which it can't be because we masked it. We can safely remove the masking. For the negativity check we can just treat the timerid as unsigned and only check for upper boundaries. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-10-06linux-user: Convert blkpg to use a special subop handlerAlexander Graf1-0/+53
The blkpg ioctl can take different payloads depending on the opcode in its payload structure. Create a new special ioctl handler that can only deal with partition style ones for now. This patch fixes running parted for me. Signed-off-by: Alexander Graf <agraf@suse.de> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-24linux-user: fix file descriptor leakszhanghailiang1-0/+1
Handle variable "fd_orig" going out of scope leaks the handle. Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Reviewed-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-08-22linux-user: check return value of malloc()zhanghailiang1-0/+4
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com> Acked-by: Riku Voipio <riku.voipio@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: writev Partial WritesTom Musta1-2/+14
Although not technically not required by POSIX, the writev system call will typically write out its buffers individually. That is, if the first buffer is written successfully, but the second buffer pointer is invalid, then the first chuck will be written and its size is returned. Signed-off-by: Tom Musta <tommusta@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Support target-to-host translation of mlockall argumentTom Musta1-1/+16
The argument to the mlockall system call is not necessarily the same on all platforms and thus may require translation prior to passing to the host. For example, PowerPC 64 bit platforms define values for MCL_CURRENT (0x2000) and MCL_FUTURE (0x4000) which are different from Intel platforms (0x1 and 0x2, respectively) Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: clock_nanosleep errno Handling on PPCTom Musta1-0/+8
The clock_nanosleep syscall is unusual in that it returns positive numbers in error handling situations, versus returning -1 and setting errno, or returning a negative errno value. On POWER, the kernel will set the SO bit of CR0 to indicate failure in a syscall. QEMU has generic handling to do this for syscalls with standard return values. Add special case code for clock_nanosleep to handle CR0 properly. Signed-off-by: Tom Musta <tommusta@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Detect fault in sched_rr_get_intervalTom Musta1-1/+1
Properly detect a fault when attempting to store into an invalid struct timespec pointer. Signed-off-by: Tom Musta <tommusta@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Handle NULL sched_param argument to sched_*Tom Musta1-0/+10
The sched_getparam, sched_setparam and sched_setscheduler system calls take a pointer argument to a sched_param structure. When this pointer is null, errno should be set to EINVAL. Signed-off-by: Tom Musta <tommusta@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Detect Negative Message Sizes in msgsnd System CallTom Musta1-1/+5
The msgsnd system call takes an argument that describes the message size (msgsz) and is of type size_t. The system call should set errno to EINVAL in the event that a negative message size is passed. Signed-off-by: Tom Musta <tommusta@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-08-22linux-user: Conditionally Pass Attribute Pointer to mq_open()Tom Musta1-3/+7
The mq_open system call takes an optional struct mq_attr pointer argument in the fourth position. This pointer is used when O_CREAT is specified in the flags (second) argument. It may be NULL, in which case the queue is created with implementation defined attributes. Change the code to properly handle the case when NULL is passed in the arg4 position. Signed-off-by: Tom Musta <tommusta@gmail.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
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 Voipio1-0/+11
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 Voipio1-0/+45
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: 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-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 Tjernlund1-0/+7
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-06-29linux-user: support the KDSIGACCEPT ioctlPaul Burton1-0/+7
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 Burton1-1/+28
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: 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 Burton1-0/+3
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-18target-mips: implement UserLocal RegisterPetar Jovanovic1-1/+1
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-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-05-05linux-user: fix getrusage and wait4 failures with invalid rusage structPetar Jovanovic1-3/+8
Implementations of system calls getrusage and wait4 have not previously handled correctly cases when incorrect address of struct rusage is passed. This change makes sure return values are correctly set for these cases. Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: move uname functions to uname.cRiku Voipio1-102/+0
Make syscall.c slightly smaller by moving uname-related functions to uname.c. Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: rename cpu-uname -> unameRiku Voipio1-1/+1
To move more uname related functions out of syscall.c, rename cpu-uname.{c,h} to uname.{c.h} Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: avoid using glibc internals in _syscall5 and in definition of ↵Natanael Copa1-1/+1
target_sigevent struct Use the public sigset_t instead of the glibc specific internal __sigset_t in _syscall. Calculate the sigevent pad size is calculated in similar way as kernel does it instead of using glibc internal field _pad. This is needed for building with musl libc. Signed-off-by: Natanael Copa <ncopa@alpinelinux.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2014-05-02linux-user: Handle arches with llseek instead of _llseekJames Hogan1-0/+5
Recently merged kernel ports (such as OpenRISC and Meta) have an llseek system call instead of _llseek. This is handled for the host architecture by defining __NR__llseek as __NR_llseek, but not for the target architecture. Handle it in the same way for these architectures, defining TARGET_NR__llseek as TARGET_NR_llseek. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Riku Voipio <riku.voipio@iki.fi> Cc: Jia Liu <proljc@gmail.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: Add support for SCM_CREDENTIALS.Huw Davies1-0/+11
Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: Move if-elses to a switch statement.Huw Davies1-18/+33
This makes adding more message types cleaner. Signed-off-by: Huw Davies <huw@codeweavers.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-05-02linux-user: Add /proc/self/exe open forwardingMaxim Ostapenko1-0/+5
QEMU already supports /proc/self/{maps,stat,auxv} so addition of /proc/self/exe is rather trivial. Fixes https://bugs.launchpad.net/qemu/+bug/1299190 Signed-off-by: Maxim Ostapenko <m.ostapenko@partner.samsung.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-04-01linux-user: pass correct host flags to accept4()Petar Jovanovic1-2/+5
Flags NONBLOCK and CLOEXEC can have different values on the host and the guest, so set correct host values before calling accept4(). This fixes several issues with accept4 system call and user-mode of QEMU. Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2014-03-19linux-user: Fix build if headers don't define _LINUX_CAPABILITY_VERSION_1Peter Maydell1-1/+1
Older kernel headers don't define _LINUX_CAPABILITY_VERSION_1. Switch to using the older _LINUX_CAPABILITY_VERSION; newer headers still define this for source compatibility. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com> Reviewed-by: Laurent Desnogues <laurent.desnogues@gmail.com> Acked-by: Riku Voipio <riku.voipio@iki.fi>