Make cpu_set_syscall_retval common between the existing FreeBSD ABI and

the Linuxulator. We need to translate error values onto Linux errno values
and return them to userspace when a syscall fails. We also need to preserve
x1 as all registers are preserved other than the return value.

Reviewed by:	emaste
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D16008
This commit is contained in:
Andrew Turner 2018-06-25 22:36:25 +00:00
parent 4a28eaada4
commit 8e5d76e654
2 changed files with 4 additions and 19 deletions

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/proc.h>
#include <sys/sf_buf.h>
#include <sys/signal.h>
#include <sys/sysent.h>
#include <sys/unistd.h>
#include <vm/vm.h>
@ -154,7 +155,7 @@ cpu_set_syscall_retval(struct thread *td, int error)
break;
default:
frame->tf_spsr |= PSR_C; /* carry bit */
frame->tf_x[0] = error;
frame->tf_x[0] = SV_ABI_ERRNO(td->td_proc, error);
break;
}
}

View File

@ -143,25 +143,9 @@ linux_fetch_syscall_args(struct thread *td)
static void
linux_set_syscall_retval(struct thread *td, int error)
{
struct trapframe *frame;
frame = td->td_frame;
switch (error) {
case 0:
frame->tf_x[0] = td->td_retval[0];
frame->tf_x[1] = td->td_retval[1];
break;
case ERESTART:
/* LINUXTODO: verify */
frame->tf_elr -= 4;
break;
case EJUSTRETURN:
break;
default:
frame->tf_x[0] = error;
break;
}
td->td_retval[1] = td->td_frame->tf_x[1];
cpu_set_syscall_retval(td, error);
}
static int