cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

safe-syscall.inc.S (2552B)


      1/*
      2 * safe-syscall.inc.S : host-specific assembly fragment
      3 * to handle signals occurring at the same time as system calls.
      4 * This is intended to be included by linux-user/safe-syscall.S
      5 *
      6 * Written by Richard Henderson <rth@twiddle.net>
      7 * Copyright (C) 2016 Red Hat, Inc.
      8 *
      9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
     10 * See the COPYING file in the top-level directory.
     11 */
     12
     13	.global safe_syscall_base
     14	.global safe_syscall_start
     15	.global safe_syscall_end
     16	.type	safe_syscall_base, #function
     17	.type	safe_syscall_start, #function
     18	.type	safe_syscall_end, #function
     19
     20	/* This is the entry point for making a system call. The calling
     21	 * convention here is that of a C varargs function with the
     22	 * first argument an 'int *' to the signal_pending flag, the
     23	 * second one the system call number (as a 'long'), and all further
     24	 * arguments being syscall arguments (also 'long').
     25	 * We return a long which is the syscall's return value, which
     26	 * may be negative-errno on failure. Conversion to the
     27	 * -1-and-errno-set convention is done by the calling wrapper.
     28	 */
     29safe_syscall_base:
     30	.cfi_startproc
     31	/* The syscall calling convention isn't the same as the
     32	 * C one:
     33	 * we enter with x0 == *signal_pending
     34	 *               x1 == syscall number
     35	 *               x2 ... x7, (stack) == syscall arguments
     36	 *               and return the result in x0
     37	 * and the syscall instruction needs
     38	 *               x8 == syscall number
     39	 *               x0 ... x6 == syscall arguments
     40	 *               and returns the result in x0
     41	 * Shuffle everything around appropriately.
     42	 */
     43	mov	x9, x0		/* signal_pending pointer */
     44	mov	x8, x1		/* syscall number */
     45	mov	x0, x2		/* syscall arguments */
     46	mov	x1, x3
     47	mov	x2, x4
     48	mov	x3, x5
     49	mov	x4, x6
     50	mov	x5, x7
     51	ldr	x6, [sp]
     52
     53	/* This next sequence of code works in conjunction with the
     54	 * rewind_if_safe_syscall_function(). If a signal is taken
     55	 * and the interrupted PC is anywhere between 'safe_syscall_start'
     56	 * and 'safe_syscall_end' then we rewind it to 'safe_syscall_start'.
     57	 * The code sequence must therefore be able to cope with this, and
     58	 * the syscall instruction must be the final one in the sequence.
     59	 */
     60safe_syscall_start:
     61	/* if signal_pending is non-zero, don't do the call */
     62	ldr	w10, [x9]
     63	cbnz	w10, 0f 
     64	svc	0x0
     65safe_syscall_end:
     66	/* code path for having successfully executed the syscall */
     67	ret
     68
     690:
     70	/* code path when we didn't execute the syscall */
     71	mov	x0, #-TARGET_ERESTARTSYS
     72	ret
     73	.cfi_endproc
     74
     75	.size	safe_syscall_base, .-safe_syscall_base