[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH 6/6] lib/syscall_shim: Binary system call handler
Reviewed-by: Gaulthier Gain <gaulthier.gain@xxxxxxxxx> > On 11 Dec 2019, at 15:19, Simon Kuenzer <simon.kuenzer@xxxxxxxxx> wrote: > > Provide the option to handle binary system call requests with > libsyscall_shim. Linux-style ABI is implemented. System calls are > handled with the raw variant `uk_syscall_r()`. > > Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> > --- > lib/syscall_shim/Config.uk | 15 ++++++++- > lib/syscall_shim/Makefile.uk | 2 ++ > lib/syscall_shim/regmap_linuxabi.h | 46 ++++++++++++++++++++++++++ > lib/syscall_shim/uk_syscall_r.c.in_end | 18 ++++++++++ > 4 files changed, 80 insertions(+), 1 deletion(-) > create mode 100644 lib/syscall_shim/regmap_linuxabi.h > > diff --git a/lib/syscall_shim/Config.uk b/lib/syscall_shim/Config.uk > index 7bf4ca8c..20962590 100644 > --- a/lib/syscall_shim/Config.uk > +++ b/lib/syscall_shim/Config.uk > @@ -1,3 +1,16 @@ > -config LIBSYSCALL_SHIM > +menuconfig LIBSYSCALL_SHIM > bool "syscall_shim: Syscall shim layer" > default n > + > +if LIBSYSCALL_SHIM > + config LIBSYSCALL_SHIM_HANDLER > + bool "Binary system call handler (Linux ABI)" > + default n > + depends on ARCH_X86_64 > + select HAVE_SYSCALL > + help > + Enables a system call handler for binary system call > + requests (e.g., sysenter/sysexit). The handler maps > + register values accordingly to the Linux ABI standard > + (see: man syscalls[2]). > +endif > diff --git a/lib/syscall_shim/Makefile.uk b/lib/syscall_shim/Makefile.uk > index 7afa2014..17de49cd 100644 > --- a/lib/syscall_shim/Makefile.uk > +++ b/lib/syscall_shim/Makefile.uk > @@ -74,6 +74,8 @@ CXXINCLUDES-$(CONFIG_LIBSYSCALL_SHIM) += > -I$(LIBSYSCALL_SHIM_BUILD)/include > CINCLUDES-y += -I$(LIBSYSCALL_SHIM_BASE)/include > CXXINCLUDES-y += -I$(LIBSYSCALL_SHIM_BASE)/include > > +LIBSYSCALL_SHIM_CINCLUDES += -I$(LIBSYSCALL_SHIM_BASE) > + > LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall.c > LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_r.c > LIBSYSCALL_SHIM_SRCS-y += $(LIBSYSCALL_SHIM_BUILD)/uk_syscall_name.c > diff --git a/lib/syscall_shim/regmap_linuxabi.h > b/lib/syscall_shim/regmap_linuxabi.h > new file mode 100644 > index 00000000..1bface67 > --- /dev/null > +++ b/lib/syscall_shim/regmap_linuxabi.h > @@ -0,0 +1,46 @@ > +#ifndef _REGMAP_LINUXABI_H_ > + > +#include <uk/arch/lcpu.h> > + > +/* > + * Mappings of `struct __reg` register fields > + * according to Linux ABI definition for system calls > + * (see: man syscall(2)) > + * rip - Instruction pointer > + * rsyscall - Syscall number > + * rargX - Arguments 0..5 > + * rretX - System call return values 0..1 > + */ > + > +#if (defined __X86_64__) > +#define rip rcx > +#define rsyscall orig_rax > +#define rarg0 rdi > +#define rarg1 rsi > +#define rarg2 rdx > +#define rarg3 r10 > +#define rarg4 r8 > +#define rarg5 r9 > + > +#define rret0 rax > +#define rret1 rdx > + > +#elif (defined __ARM64__) > +#define rip x[15] /* TODO: Is this correct? */ > +#define rsyscall x[8] > +#define rarg0 x[0] > +#define rarg1 x[1] > +#define rarg2 x[2] > +#define rarg3 x[3] > +#define rarg4 x[4] > +#define rarg5 x[5] > + > +#define rret0 x[0] > +#define rret1 x[1] > + > +#else > +#error "Missing register mappings for selected target architecture" > + > +#endif > + > +#endif /* _REGMAP_LINUXABI_H_ */ > diff --git a/lib/syscall_shim/uk_syscall_r.c.in_end > b/lib/syscall_shim/uk_syscall_r.c.in_end > index f2b9fc8e..ee8a5689 100644 > --- a/lib/syscall_shim/uk_syscall_r.c.in_end > +++ b/lib/syscall_shim/uk_syscall_r.c.in_end > @@ -13,3 +13,21 @@ long uk_syscall_r(long n, ...) > va_end(ap); > return __uk_syscall_r(n,a,b,c,d,e,f); > } > + > +#if CONFIG_LIBSYSCALL_SHIM_HANDLER > +#include <uk/plat/syscall.h> > +#include <uk/assert.h> > +#include <regmap_linuxabi.h> > + > +void ukplat_syscall_handler(struct __regs *r) > +{ > + UK_ASSERT(r); > + > + uk_pr_debug("Binary system call request \"%s\" (%lu) at ip:%p > (arg0=0x%lx, arg1=0x%lx, ...)\n", > + uk_syscall_name(r->rsyscall), r->rsyscall, > + (void *) r->rip, r->rarg0, r->rarg1); > + r->rret0 = __uk_syscall_r(r->rsyscall, > + r->rarg0, r->rarg1, r->rarg2, > + r->rarg3, r->rarg4, r->rarg5); > +} > +#endif /* CONFIG_LIBSYSCALL_SHIM_HANDLER */ > -- > 2.20.1 > _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |