summaryrefslogtreecommitdiff
path: root/linux-user/syscall.c
AgeCommit message (Collapse)AuthorFilesLines
2017-02-27syscall: fixed mincore(2) not failing with ENOMEMFranklin \"Snaipe\" Mathieu1-3/+8
The current implementation of the mincore(2) syscall sets errno to EFAULT when the region identified by the first two parameters is invalid. This goes against the man page specification, where mincore(2) should only fail with EFAULT when the third parameter is an invalid address; and fail with ENOMEM when the checked region does not point to mapped memory. Signed-off-by: Franklin "Snaipe" Mathieu <snaipe@diacritic.io> Cc: Riku Voipio <riku.voipio@linaro.org> Cc: Aurelien Jarno <aurelien@aurel32.net> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20170217085800.28873-2-snaipe@diacritic.io> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2017-02-27linux-user: Add sockopts for IPv6 ping and IPv6 tracerouteHelge Deller1-1/+131
Add the neccessary sockopts for ping and traceroute on IPv6. This fixes the following qemu warnings with IPv6: Unsupported ancillary data: 0/2 Unsupported ancillary data: 0/11 Unsupported ancillary data: 41/25 Unsupported setsockopt level=0 optname=12 Unsupported setsockopt level=41 optname=16 Unsupported setsockopt level=41 optname=25 Unsupported setsockopt level=41 optname=50 Unsupported setsockopt level=41 optname=51 Unsupported setsockopt level=41 optname=8 Unsupported setsockopt level=58 optname=1 Tested with hppa-linux-user (big-endian) on x86_64 (little-endian). Signed-off-by: Helge Deller <deller@gmx.de> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20170218223130.GA25278@ls3530.fritz.box> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2017-02-27linux-user: fix fork()Laurent Vivier1-2/+3
Since commit 5ea2fc8 ("linux-user: Sanity check clone flags"), trying to run fork() fails with old distro on some architectures. This is the case with HP-PA and Debian 5 (Lenny). It fails on: if ((flags & CSIGNAL) != TARGET_SIGCHLD) { return -TARGET_EINVAL; } because flags is 17, whereas on HP-PA, SIGCHLD is 18. 17 is the SIGCHLD value of my host (x86_64). It appears that for TARGET_NR_fork and TARGET_NR_vfork, QEMU calls do_fork() with SIGCHLD instead of TARGET_SIGCHLD. Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20170216173707.16209-1-laurent@vivier.eu>
2017-02-16linux-user: fix settime old value locationMarc-André Lureau1-2/+6
old_value is the 4th argument of timer_settime(), not the 2nd. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Pranith Kumar <bobby.prani@gmail.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <20170119151533.29328-1-bobby.prani@gmail.com> Signed-off-by: Laurent Vivier <laurent@vivier.eu>
2017-02-14linux-user: manage two new IFLA host message typesLaurent Vivier1-0/+2
Add QEMU_IFLA_GSO_MAX_SEGS and QEMU_IFLA_GSO_MAX_SIZE in host_to_target_data_link_rtattr(). These two messages are sent by the host kernel when we use "sudo". Found with qemu-m68k and Debian etch-m68k (sudo 1.6.8p12-4) and host kernel 4.7.6-200.fc24.x86_64 Signed-off-by: Laurent Vivier <laurent@vivier.eu> Message-Id: <1477530049-15676-1-git-send-email-laurent@vivier.eu>
2017-02-14linux-user: Fix mq_openLena Djokic1-3/+8
If fourth argument is NULL it should be passed without using lock_user function which would, in that case, return EFAULT, and system call supports passing NULL as fourth argument. Signed-off-by: Lena Djokic <Lena.Djokic@rt-rk.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2017-02-14linux-user: Fix readaheadLena Djokic1-1/+1
Calculation of 64-bit offset was not correct for all cases. Signed-off-by: Lena Djokic <Lena.Djokic@rt-rk.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2017-02-14linux-user: Fix inotify_init1 supportLena Djokic1-1/+2
This commit adds necessary conversion of argument passed to inotify_init1. inotify_init1 flags can be IN_NONBLOCK and IN_CLOEXEC which rely on O_NONBLOCK and O_CLOEXEC and those can have different values on different platforms. Signed-off-by: Lena Djokic <Lena.Djokic@rt-rk.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2017-02-06linux-user: fix "apt-get update" on linux-user hppaLaurent Vivier1-1/+0
apt-get was hanging on linux-user hppa. strace has shown the netlink data stream was not correctly byte swapped. It appears the fd translator function is unregistered just after it has been registered, so the translator function is not called. This patch removes the fd_trans_unregister() after the do_socket() in the TARGET_NR_socket case. This fd_trans_unregister() was added by commit e36800c linux-user: add signalfd/signalfd4 syscalls when do_socket() was not registering any fd translator. And as now it is, we must remove this fd_trans_unregister() to keep them. Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Message-Id: <20170126080449.28255-3-laurent@vivier.eu> Signed-off-by: Richard Henderson <rth@twiddle.net>
2017-01-22linux-user: Handle ERFKILL and EHWPOISONRichard Henderson1-0/+6
With definitions for generic, alpha and mips taken from 4.9-rc2. Signed-off-by: Richard Henderson <rth@twiddle.net>
2017-01-22linux-user: Handle TIOCSTART and TIOCSTOPHelge Deller1-0/+6
Some architectures (ppc, alpha, sparc, parisc, sh and xtensa) define the BSD TIOCSTART and TIOCSTOP ioctls in their kernel headers to provide compatibility to other operating systems. Those ioctls are not implemented in Linux, nevertheless, bash will use this ioctl if it's available on those architectures. To avoid false warnings, add code to simply ignore those ioctls. Signed-off-by: Helge Deller <deller@gmx.de> Message-Id: <20161206152403.GA6651@ls3530> Signed-off-by: Richard Henderson <rth@twiddle.net>
2016-10-26linux-user: enable parallel code generation on cloneAlex Bennée1-0/+8
The variable parallel_cpus controls the generation of thread aware atomic code. We only need to set it once we clone our first thread. At this point any existing translations need to be thrown away. Reviewed-by: Emilio G. Cota <cota@braap.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Signed-off-by: Richard Henderson <rth@twiddle.net>
2016-10-21linux-user: added support for pwritev() system call.Dejan Jovicevic1-0/+15
This system call performs the same task as the writev() system call, with the exception of having the fourth argument, offset, which specifes the file offset at which the input operation is to be performed. Because of this, the pwritev() implementation is based on the writev() implementation in linux-user mode. But, since pwritev() is implemented in the kernel as a 5-argument syscall, 5 arguments are needed to be handled as input and passed to the host syscall. The pos_l and pos_h argument of the safe_pwritev() are of type unsigned long, which can be of different sizes on different platforms. The input arguments are converted to the appropriate host size when passed to safe_pwritev(). Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: added support for preadv() system call.Dejan Jovicevic1-0/+15
This system call performs the same task as the readv() system call, with the exception of having the fourth argument, offset, which specifes the file offset at which the input operation is to be performed. Because of this, the preadv() implementation is based on the readv() implementation in linux-user mode. But, since preadv() is implemented in the kernel as a 5-argument syscall, 5 arguments are needed to be handled as input and passed to the host syscall. The pos_l and pos_h argument of the safe_preadv() are of type unsigned long, which can be of different sizes on different platforms. The input arguments are converted to the appropriate host size when passed to safe_preadv(). Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Add support for syncfs() syscallAleksandar Markovic1-0/+5
This patch implements Qemu user mode syncfs() syscall support. Syscall syncfs() syncs the filesystem containing file determined by the open file descriptor passed as the argument to syncfs(). The implementation consists of a straightforward invocation of host's syncfs(). Configure and strace support is included as well. Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Add support for clock_adjtime() syscallAleksandar Markovic1-0/+18
This patch implements Qemu user mode clock_adjtime() syscall support. The implementation is based on invocation of host's clock_adjtime(). Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@imgtec.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Don't use alloca() for epoll_wait's epoll event arrayPeter Maydell1-4/+13
The epoll event array which epoll_wait() allocates has a size determined by the guest which could potentially be quite large. Use g_try_new() rather than alloca() so that we can fail more cleanly if the guest hands us an oversize value. (ENOMEM is not a documented return value for epoll_wait() but in practice some kernel configurations can return it -- see for instance sys_oabi_epoll_wait() on ARM.) This rearrangement includes fixing a bug where we were incorrectly passing a negative length to unlock_user() in the error-exit codepath. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: add RTA_PRIORITY in netlinkLaurent Vivier1-0/+1
Used by fedora21 on ppc64 in the network initialization Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: add kcmp() syscallLaurent Vivier1-0/+10
Signed-off-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Fix syslog() syscall supportAleksandar Markovic1-6/+44
There are currently several problems related to syslog() support. For example, if the second argument "bufp" of target syslog() syscall is NULL, the current implementation always returns error code EFAULT. However, NULL is a perfectly valid value for the second argument for many use cases of this syscall. This is, for example, visible from this excerpt of man page for syslog(2): > EINVAL Bad arguments (e.g., bad type; or for type 2, 3, or 4, buf is > NULL, or len is less than zero; or for type 8, the level is > outside the range 1 to 8). Moreover, the argument "bufp" is ignored for all cases of values of the first argument, except 2, 3 and 4. This means that for such cases (the first argument is not 2, 3 or 4), there is no need to pass "buf" between host and target, and it can be set to NULL while calling host's syslog(), without loss of emulation accuracy. Note also that if "bufp" is NULL and the first argument is 2, 3 or 4, the correct returned error code is EINVAL, not EFAULT. All these details are reflected in this patch. "#ifdef TARGET_NR_syslog" is also proprerly inserted when needed. Support for Qemu's "-strace" switch for syslog() syscall is included too. LTP tests syslog11 and syslog12 pass with this patch (while fail without it), on any platform. Changes to original patch by Riku Voipio: fixed error paths in TARGET_SYSLOG_ACTION_READ_ALL to match http://lxr.free-electrons.com/source/kernel/printk/printk.c?v=4.7#L1335 Should fix also the build error in: https://lists.gnu.org/archive/html/qemu-devel/2016-10/msg03721.html Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Fix socketcall() syscall supportAleksandar Markovic1-57/+62
Since not all Linux host platforms support socketcall() (most notably Intel), do_socketcall() function in Qemu's syscalls.c is implemented to mirror the corespondant implementation of socketcall() in Linux kernel, and to utilise individual socket operations that are supported on all Linux platforms. (see kernel source file net/socket.c, definition of socketcall). However, error codes produced by Qemu implementation are wrong for the cases of invalid values of the first argument. Also, naming of constants is not consistent with kernel one, and not consistant with Qemu convention of prefixing such constants with "TARGET_". This patch in that light brings do_socketcall() closer to its kernel counterpart, and in that way fixes the errors and yields more consisrtent Qemu code. There were also three missing cases (among 20) for strace support for socketcall(). The array that contains pointers for appropriate printing functions is updated with 3 elements, however pointers to functions are left NULL, and its implementation is left for future. Also, this patch fixes failure of LTP test socketcall02, if executed on some Qemu emulated sywstems (uer mode). Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Fix msgrcv() and msgsnd() syscalls supportAleksandar Markovic1-0/+3
If syscalls msgrcv() and msgsnd() fail, they return E2BIG, EACCES, EAGAIN, EFAULT, EIDRM, EINTR, EINVAL, ENOMEM, or ENOMSG. By examining negative scenarios of these syscalls for Mips, it was established that ENOMSG does not have the same value accross all platforms, but it is nevertheless not included for conversion in the correspondant conversion table defined in linux-user/syscall.c. This is certainly a bug, since it leads to the incorrect emulation of msgrcv() and msgsnd() for scenarios involving ENOMSG. This patch fixes this by extending the conversion table to include ENOMSG. Also, LTP test msgrcv04 will be fixed for some platforms. Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Fix mq_open() syscall supportAleksandar Markovic1-7/+9
Conversion of file creation flags (O_CREAT, ...) from target to host was missing. Also, this patch implements better error handling. Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-21linux-user: Add support for adjtimex() syscallAleksandar Markovic1-1/+86
This patch implements Qemu user mode adjtimex() syscall support. Syscall adjtimex() reads and optionally sets parameters for a clock adjustment algorithm used in network synchonization or similar scenarios. Its declaration is: int adjtimex(struct timex *buf); The correspondent source code in the Linux kernel is at kernel/time.c, line 206. The Qemu implementation is based on invocation of host's adjtimex(), and its key part is in the "TARGET_NR_adjtimex" case segment of the the main switch statement of the function do_syscall(), in linux-user/syscalls.c. All necessary conversions of the data structures from target to host and from host to target are covered. Two new functions, target_to_host_timex() and host_to_target_timex(), are provided for the purpose of such conversions. For that purpose, the support for related structure "timex" had tp be added to the file linux-user/syscall_defs.h, based on its definition in Linux kernel. Also, the relevant support for "-strace" Qemu option is included in files linux-user/strace.c and linux-user/strace.list. This patch also fixes failures of LTP tests adjtimex01 and adjtimex02, if executed in Qemu user mode. Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@imgtec.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-10-10Merge remote-tracking branch 'remotes/mjt/tags/trivial-patches-fetch' into ↵Peter Maydell1-1/+1
staging trivial patches for 2016-10-08 # gpg: Signature made Sat 08 Oct 2016 09:56:38 BST # gpg: using RSA key 0x701B4F6B1A693E59 # gpg: Good signature from "Michael Tokarev <mjt@tls.msk.ru>" # gpg: aka "Michael Tokarev <mjt@corpit.ru>" # gpg: aka "Michael Tokarev <mjt@debian.org>" # Primary key fingerprint: 6EE1 95D1 886E 8FFB 810D 4324 457C E0A0 8044 65C5 # Subkey fingerprint: 7B73 BAD6 8BE7 A2C2 8931 4B22 701B 4F6B 1A69 3E59 * remotes/mjt/tags/trivial-patches-fetch: (26 commits) net/filter-mirror: Fix mirror initial check typo virtio: rename the bar index field name in VirtIOPCIProxy linux-user: include <poll.h> instead of <sys/poll.h> char: fix missing return in error path for chardev TLS init CODING_STYLE: Fix a typo ("have" vs. "has") bitmap: refine and move BITMAP_{FIRST/LAST}_WORD_MASK build-sys: fix find-in-path m68k: change default system clock for m5208evb exec: remove unused compacted argument usb: ehci: fix memory leak in ehci_process_itd qapi: make the json schema files more regular. maint: Add module_block.h to .gitignore MAINTAINERS: Some updates related to the SH4 machines MAINTAINERS: Add some more MIPS related files MAINTAINERS: Add usermode related config files MAINTAINERS: Add some more pattern to recognize all win32 related files MAINTAINERS: Add some more rocker related files MAINTAINERS: Add header files to CRIS section MAINTAINERS: Add some more files to the virtio section MAINTAINERS: Add some SPARC machine related files ... # Conflicts: # MAINTAINERS
2016-10-08linux-user: include <poll.h> instead of <sys/poll.h>Felix Janda1-1/+1
This removes the last usage of <sys/poll.h> in the code base. Signed-off-by: Felix Janda <felix.janda@posteo.de> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2016-10-04linux-user/syscall: extend lock around cpu-listAlex Bennée1-1/+6
There is a potential race if several threads exit at once. To serialise the exits extend the lock above the initial checking of the CPU list. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20160930213106.20186-11-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-09-23linux-user: Add missing TARGET_EDQUOT error code for MipsAleksandar Markovic1-0/+1
EDQUOT is defined for Mips platform in Linux kernel in such a way that it has different value than on most other platforms. However, correspondent TARGET_EDQUOT for Mips is missing in Qemu code. Moreover, TARGET_EDQUOT is missing from the table for conversion of error codes from host to target. This patch fixes these problems. Without this patch, syscalls add_key(), keyctl(), link(), mkdir(), mknod(), open(), rename(), request_key(), setxattr(), symlink(), and write() will not be able to return the right error code in some scenarios on Mips platform. (Some of these syscalls are not yet supported in Qemu, but once they are supported, they will need correct EDQUOT handling.) Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Acked-by: Riku Voipio <riku.voipio@linaro.org> Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-09-23linux-user: Fix certain argument alignment cases for Mips64Aleksandar Markovic1-1/+1
The function that is changed in this patch is supposed to indicate that there was certain argument rearrangement related to 64-bit arguments on 32-bit platforms. The background on such rearrangements can be found, for example, in the man page for syscall(2). However, for 64-bit Mips architectures there is no such rearrangement, and this patch reflects it. Signed-off-by: Aleksandar Rikalo <aleksandar.rikalo@imgtec.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@imgtec.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Reviewed-by: Leon Alrae <leon.alrae@imgtec.com> Acked-by: Riku Voipio <riku.voipio@linaro.org> Signed-off-by: Leon Alrae <leon.alrae@imgtec.com>
2016-09-22linux-user: fix TARGET_NR_selectLaurent Vivier1-17/+31
TARGET_NR_select can have three different implementations: 1- to always return -ENOSYS microblaze, ppc, ppc64 -> TARGET_WANT_NI_OLD_SELECT 2- to take parameters from a structure pointed by arg1 (kernel sys_old_select) i386, arm, m68k -> TARGET_WANT_OLD_SYS_SELECT 3- to take parameters from arg[1-5] (kernel sys_select) x86_64, alpha, s390x, cris, sparc, sparc64 Some (new) architectures don't define NR_select, 4- but only NR__newselect with sys_select: mips, mips64, sh 5- don't define NR__newselect, and use pselect6 syscall: aarch64, openrisc, tilegx, unicore32 Reported-by: Timothy Pearson <tpearson@raptorengineering.com> Reported-by: Allan Wirth <awirth@akamai.com> Suggested-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Laurent Vivier <laurent@vivier.eu> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Sanity check clone flagsPeter Maydell1-3/+63
We currently make no checks on the flags passed to the clone syscall, which means we will not fail clone attempts which ask for features that we can't implement. Add sanity checking of the flags to clone (which we were already doing in the "this is a fork" path, but not for the "this is a new thread" path), tidy up the checking in the fork path to match it, and check that the fork case isn't trying to specify a custom termination signal. This is helpful in causing some LTP test cases to fail cleanly rather than behaving bizarrely when we let the clone succeed but didn't provide the semantics requested by the flags. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Remove unnecessary nptl_flags variable from do_fork()Peter Maydell1-9/+7
The 'nptl_flags' variable in do_fork() is set to a copy of 'flags', and then the CLONE_NPTL_FLAGS are cleared out of 'flags'. However the only effect of this is that the later check on "if (flags & CLONE_PARENT_SETTID)" is never true. Since we will already have done the setting of parent_tidptr in clone_func() in the child thread, we don't need to do it again. Delete the dead if() and the clearing of CLONE_NPTL_FLAGS from 'flags', and then use 'flags' where we were previously using 'nptl_flags', so we can delete the unnecessary variable. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Pass si_type information to queue_signal() explicitlyPeter Maydell1-2/+4
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: Use correct target SHMLBA in shmat()Peter Maydell1-6/+39
The shmat() handling needs to do target-specific handling of the attach address for shmat(): * if the SHM_RND flag is passed, the address is rounded down to a SHMLBA boundary * if SHM_RND is not passed, then the call is failed EINVAL if the address is not a multiple of SHMLBA Since SHMLBA is target-specific, we need to do this checking and rounding in QEMU and can't leave it up to the host syscall. Allow targets to define TARGET_FORCE_SHMLBA and provide a target_shmlba() function if appropriate, and update do_shmat() to honour them. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Fix incorrect use of host errno in do_ioctl_dm()Peter Maydell1-1/+1
do_ioctl_dm() should return target errno values, not host ones; correct an accidental use of a host errno in an error path. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Check lock_user() return value for NULLPeter Maydell1-0/+9
lock_user() can return NULL, which typically means the syscall should fail with EFAULT. Add checks in various places where Coverity spotted that we were missing them. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Range check the nfds argument to ppoll syscallPeter Maydell1-0/+5
Do an initial range check on the ppoll syscall's nfds argument, to avoid possible overflow in the calculation of the lock_user() size argument. The host kernel will later apply the rather lower limit based on RLIMIT_NOFILE as appropriate. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Check for bad event numbers in epoll_waitPeter Maydell1-0/+5
The kernel checks that the maxevents parameter to epoll_wait is non-negative and not larger than EP_MAX_EVENTS. Add this check to our implementation, so that: * we fail these cases EINVAL rather than EFAULT * we don't pass negative or overflowing values to the lock_user() size calculation Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Use direct syscall for utimensatPeter Maydell1-10/+1
The linux utimensat syscall differs in semantics from the libc function because the syscall combines the features of utimensat() and futimens(). Rather than trying to split these apart in order to call the two libc functions which then call the same underlying syscall, just always directly make the host syscall. This fixes bugs in some of the corner cases which should return errors from the syscall but which we were incorrectly directing to futimens(). This doesn't reduce the set of hosts that our syscall implementation will work on, because if the direct syscall fails ENOSYS then the libc functions would also fail ENOSYS. (The system call has been in the kernel since 2.6.22 anyway.) Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Allow bad msg_name for recvfrom on connected socketPeter Maydell1-2/+9
The POSIX standard mandates that for a connected socket recvfrom() must ignore the msg_name and msg_namelen fields. This is awkward for QEMU because we will attempt to copy them from guest address space. Handle this by not immediately returning a TARGET_EFAULT if the copy failed, but instead passing a known-bad address to the host kernel, which can then return EFAULT or ignore the value appropriately. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Fix errno for sendrecvmsg with large iovec lengthPeter Maydell1-0/+9
The sendmsg and recvmsg syscalls use a different errno to indicate an overlarge iovec length from readv and writev. Handle this special case in do_sendrcvmsg_locked() to avoid getting the default errno returned by lock_iovec(). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-09-21linux-user: Fix handling of iovec countsPeter Maydell1-4/+4
In the kernel the length of an iovec is generally handled as an unsigned long, not an integer; fix the parameter to lock_iovec() accordingly. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-08-19syscall.c: Redefine IFLA_* enumsMichal Privoznik1-109/+264
In 9c37146782 I've tried to fix a broken build with older linux-headers. However, I didn't do it properly. The solution implemented here is to grab the enums that caused the problem initially, and rename their values so that they are "QEMU_" prefixed. In order to guarantee matching values with actual enums from linux-headers, the enums are seeded with starting values from the original enums. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-id: 75c14d6e8a97c4ff3931d69c13eab7376968d8b4.1471593869.git.mprivozn@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-08-19Revert "syscall.c: Fix build with older linux-headers"Michal Privoznik1-86/+0
The fix I've made there was wrong. I mean, basically what I did there was equivalent to: #if 0 some code; #endif This reverts commit 9c37146782e7850877d452da47dc451ba73aa62d. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Laurent Vivier <laurent@vivier.eu> Message-id: 40d61349e445c1ad5fef795da704bf7ed6e19c86.1471593869.git.mprivozn@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-08-16linux-user: Fix llseek with high bit of offset_low setPeter Maydell1-1/+1
The llseek syscall takes two 32-bit arguments, offset_high and offset_low, which must be combined to form a single 64-bit offset. Unfortunately we were combining them with (uint64_t)arg2 << 32) | arg3 and arg3 is a signed type; this meant that when promoting arg3 to a 64-bit type it would be sign-extended. The effect was that if the offset happened to have bit 31 set then this bit would get sign-extended into all of bits 63..32. Explicitly cast arg3 to abi_ulong to avoid the erroneous sign extension. Reported-by: Chanho Park <parkch98@gmail.com> Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Tested-by: Chanho Park <parkch98@gmail.com> Message-id: 1470938379-1133-1-git-send-email-peter.maydell@linaro.org
2016-08-16syscall.c: Fix build with older linux-headersMichal Privoznik1-0/+86
In c5dff280 we tried to make us understand netlink messages more. So we've added a code that does some translation. However, the code assumed linux-headers to be at least version 4.4 of it because most of the symbols there (if not all of them) were added in just that release. This, however, breaks build on systems with older versions of the package. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Message-id: 23806aac6db3baf7e2cdab4c62d6e3468ce6b4dc.1471340849.git.mprivozn@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-08-04linux-user: Handle brk() attempts with very large sizesPeter Maydell1-1/+1
In do_brk(), we were inadvertently truncating the size of a requested brk() from the guest by putting it into an 'int' variable. This meant that we would incorrectly report success back to the guest rather than a failed allocation, typically resulting in the guest then segfaulting. Use abi_ulong instead. This fixes a crash in the '31370.cc' test in the gcc libstdc++ test suite (the test case starts by trying to allocate a very large size and reduces the size until the allocation succeeds). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-08-04linux-user: Fix target_semid_ds structure definitionPeter Maydell1-7/+10
The target_semid_ds structure is not correct for all architectures: the padding fields should only exist for: * 32-bit ABIs * x86 It is also misnamed, since it is following the kernel semid64_ds structure (QEMU doesn't support the legacy semid_ds structure at all). Rename the struct, provide a correct generic definition and allow the oddball x86 architecture to provide its own version. This fixes broken SYSV semaphores for all our 64-bit architectures except x86 and ppc. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-08-04linux-user: Don't write off end of new_utsname bufferPeter Maydell1-3/+5
Use g_strlcpy() rather than strcpy() to copy the uname string into the structure we return to the guest for the uname syscall. This avoids overrunning the buffer if the user passed us an overlong string via the QEMU command line. We fix a comment typo while we're in the neighbourhood. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
2016-08-04linux-user: Fix memchr() argument in open_self_cmdline()Peter Maydell1-1/+1
In open_self_cmdline() we look for a 0 in the buffer we read from /prc/self/cmdline. We were incorrectly passing the length of our buf[] array to memchr() as the length to search, rather than the number of bytes we actually read into it, which could be shorter. This was spotted by Coverity (because it could result in our trying to pass a negative length argument to write()). Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Riku Voipio <riku.voipio@linaro.org>