linux-user: handle /proc/$$ like /proc/self

Some applications use /proc/$$/... (where $$ is the own pid) instead of
/proc/self/... to refer to their own proc files.  Extend the interception
for open and readlink to handle this case.  Also, do the same interception
in readlinkat.

Signed-off-by: Andreas Schwab <schwab@suse.de>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
linux-user: add SIOCADDRT/SIOCDELRT support

This allows to pass the device name.

You can test this with the "route" command.

WITHOUT this patch:

$ sudo route add -net default gw 10.0.3.1 eth0
SIOCADDRT: Bad address
$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Ifa
10.0.3.0        0.0.0.0         255.255.255.0   U         0 0          0 eth

WITH this patch:

$ sudo route add -net default gw 10.0.3.1 eth0
$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Ifa
0.0.0.0         10.0.3.1        0.0.0.0         UG        0 0          0 eth
10.0.3.0        0.0.0.0         255.255.255.0   U         0 0          0 eth

Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
linux-user: fix signal number range check

When translating between host and target signal numbers keep negative
numbers unchanged, avoiding access beyond array bounds.

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 878v2b8sek.fsf@igel.home
linux-user: Fix sys_utimensat (would not compile on old glibc)

Commit c0d472b12e accidentally dropped the definition of
__NR_SYS_utimensat even though its use is guarded by
CONFIG_UTIMENSAT, not CONFIG_ATFILE. Some older glibc don't
have utimensat() (even if they have the other *at() functions).
Fix this by correctly cleaning up the sys_utimensat()
implementation and #defines, so that we always provide the
syscall if needed whether we're doing it via glibc or not.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Tested-by: Laurent Desnogues <laurent.desnogues@gmail.com>
Message-id: 1371743841-26110-1-git-send-email-peter.maydell@linaro.org
user-exec.c: Set is_write correctly in the ARM cpu_signal_handler()

In the ARM implementation of cpu_signal_handler(), set is_write
correctly using the FSR value which the kernel passes us in the
error_code field of uc_mcontext. Since the WnR bit of the FSR was
only introduced in ARMv6, this means that v5 cores will continue
to behave as before this patch, but they are not really supported
as hosts for linux-user mode anyway since they do not have the
modern behaviour for unaligned accesses.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1370352705-27590-1-git-send-email-peter.maydell@linaro.org
linux-user: improve target_to_host_sock_type conversion

Previous implementation has failed to take into account different value of
SOCK_NONBLOCK on target and host, and existence of SOCK_CLOEXEC.
The same conversion has to be applied both for do_socket and do_socketpair,
so the code has been isolated in a static inline function.

enum sock_type in linux-user/socket.h has been extended to include
TARGET_SOCK_CLOEXEC and TARGET_SOCK_NONBLOCK, similar to definition in libc.
The patch also includes necessary code style changes (tab to spaces) in the
header file since most of the file has been touched by this change.

Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
Message-id: 1372639454-7560-1-git-send-email-petar.jovanovic@rt-rk.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
linux-user: Do not ignore mmap failure from host

File mapping may fail with EACCES.

Signed-off-by: Jürg Billeter <j@bitron.ch>
Message-id: 1372498892-23676-1-git-send-email-j@bitron.ch
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
tcg: Add myself to general TCG maintainership

Acked-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg: Split rem requirement from div requirement

There are several hosts with only a "div" insn.  Remainder is computed
manually from the quotient and inputs.  We can do this generically.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-arm: Don't implement rem

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-ppc: Don't implement rem

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-ppc64: Don't implement rem

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg: Allow non-constant control macros

This allows TCG_TARGET_HAS_* to be a variable rather than a constant,
which allows easier support for differing ISA levels for the host.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg: Simplify logic using TCG_OPF_NOT_PRESENT

Expand the definition of "not present" to include "should not be present".
This means we can simplify the logic surrounding the generic tcg opcodes
for which the host backend ought not be providing definitions.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-arm: Make use of conditional availability of opcodes for divide

We can now detect and use divide instructions at runtime, rather than
having to restrict their availability to compile-time.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-arm: Rename use_armv5_instructions to use_armvt5_instructions

As it really controls the availability of a thumb interworking
instruction on armv5t.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-arm: Simplify logic in detecting the ARM ISA in use

GCC 4.8 defines a handy __ARM_ARCH symbol that we can use, which
will make us nicely forward compatible with ARMv8 AArch32.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg-arm: Use AT_PLATFORM to detect the host ISA

With this we can generate armv7 insns even when the OS compiles for a
lower common denominator.  The macros are arranged so that when we do
compile for a given ISA, all of the runtime checks for that ISA are
optimized away.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg: Fix high_pc fields in .debug_info

I don't think the debugger actually looks at this for anything,
using the correct .debug_frame contents, but might as well get
it all correct.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>
tcg: Move the CIE and FDE header definitions to common code

These will necessarily be the same layout for all hosts.  This limits
the amount of boilerplate required to implement jit debug for a host.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <rth@twiddle.net>