Remove duplicate ucontext from shim_types-arch.h

Use the ucontext from PAL instead. LibOS now has access to the inline
functions for copying PAL_CONTEXT to ucontext and vice versa and we use
them where possible.

We need to introduce a ucontext.h for Skeleton. It does need ucontext
to be defined for being able to compile shim_signal.c. The easiest way
to achieve this is to rely on Linux's ucontext.h.

SGX can reuse Linux's ucontext.h and sigcontext.h.
This commit is contained in:
Stefan Berger
2020-05-28 21:08:49 +02:00
committed by Michał Kowalczyk
parent 9e5e94d7eb
commit c1c085ca15
8 changed files with 157 additions and 135 deletions
@@ -13,139 +13,6 @@ typedef struct {
unsigned long __val[NUM_SIGS / (8 * sizeof(unsigned long))];
} __sigset_t;
/* sys/ucontext.h */
/* Type for general register. */
typedef long int greg_t;
/* Number of general registers. */
#define NGREG 23
/* Container for all general registers. */
typedef greg_t gregset_t[NGREG];
/* Number of each register in the `gregset_t' array. */
enum
{
REG_R8 = 0,
# define REG_R8 REG_R8
REG_R9,
# define REG_R9 REG_R9
REG_R10,
# define REG_R10 REG_R10
REG_R11,
# define REG_R11 REG_R11
REG_R12,
# define REG_R12 REG_R12
REG_R13,
# define REG_R13 REG_R13
REG_R14,
# define REG_R14 REG_R14
REG_R15,
# define REG_R15 REG_R15
REG_RDI,
# define REG_RDI REG_RDI
REG_RSI,
# define REG_RSI REG_RSI
REG_RBP,
# define REG_RBP REG_RBP
REG_RBX,
# define REG_RBX REG_RBX
REG_RDX,
# define REG_RDX REG_RDX
REG_RAX,
# define REG_RAX REG_RAX
REG_RCX,
# define REG_RCX REG_RCX
REG_RSP,
# define REG_RSP REG_RSP
REG_RIP,
# define REG_RIP REG_RIP
REG_EFL,
# define REG_EFL REG_EFL
REG_CSGSFS, /* Actually short cs, gs, fs, __pad0. */
# define REG_CSGSFS REG_CSGSFS
REG_ERR,
# define REG_ERR REG_ERR
REG_TRAPNO,
# define REG_TRAPNO REG_TRAPNO
REG_OLDMASK,
# define REG_OLDMASK REG_OLDMASK
REG_CR2
# define REG_CR2 REG_CR2
};
struct _libc_fpxreg {
unsigned short int significand[4];
unsigned short int exponent;
unsigned short int padding[3];
};
struct _libc_xmmreg {
__uint32_t element[4];
};
struct _libc_fpstate {
/* 64-bit FXSAVE format. */
__uint16_t cwd;
__uint16_t swd;
__uint16_t ftw;
__uint16_t fop;
__uint64_t rip;
__uint64_t rdp;
__uint32_t mxcsr;
__uint32_t mxcr_mask;
struct _libc_fpxreg st[8];
struct _libc_xmmreg _xmm[16];
__uint32_t padding[24];
};
/* Structure to describe FPU registers. */
typedef struct _libc_fpstate *fpregset_t;
/* Context to describe whole processor state. */
typedef struct {
gregset_t gregs;
/* Note that fpregs is a pointer. */
fpregset_t fpregs;
unsigned long __reserved1 [8];
} mcontext_t;
/* Userlevel context. */
typedef struct ucontext {
unsigned long int uc_flags;
struct ucontext* uc_link;
stack_t uc_stack;
mcontext_t uc_mcontext;
__sigset_t uc_sigmask;
struct _libc_fpstate __fpregs_mem;
} ucontext_t;
static inline void shim_regs_to_ucontext(ucontext_t* context, struct shim_regs* regs) {
context->uc_mcontext.gregs[REG_R8] = regs->r8;
context->uc_mcontext.gregs[REG_R9] = regs->r9;
context->uc_mcontext.gregs[REG_R10] = regs->r10;
context->uc_mcontext.gregs[REG_R11] = regs->r11;
context->uc_mcontext.gregs[REG_R12] = regs->r12;
context->uc_mcontext.gregs[REG_R13] = regs->r13;
context->uc_mcontext.gregs[REG_R14] = regs->r14;
context->uc_mcontext.gregs[REG_R15] = regs->r15;
context->uc_mcontext.gregs[REG_RDI] = regs->rdi;
context->uc_mcontext.gregs[REG_RSI] = regs->rsi;
context->uc_mcontext.gregs[REG_RBP] = regs->rbp;
context->uc_mcontext.gregs[REG_RBX] = regs->rbx;
context->uc_mcontext.gregs[REG_RDX] = regs->rdx;
context->uc_mcontext.gregs[REG_RAX] = regs->orig_rax;
context->uc_mcontext.gregs[REG_RCX] = regs->rcx;
context->uc_mcontext.gregs[REG_RSP] = regs->rsp;
context->uc_mcontext.gregs[REG_RIP] = regs->rip;
context->uc_mcontext.gregs[REG_EFL] = regs->rflags;
context->uc_mcontext.gregs[REG_CSGSFS] = 0;
context->uc_mcontext.gregs[REG_ERR] = 0;
context->uc_mcontext.gregs[REG_TRAPNO] = 0;
context->uc_mcontext.gregs[REG_OLDMASK] = 0;
context->uc_mcontext.gregs[REG_CR2] = 0;
}
#define RED_ZONE_SIZE 128
#endif /* _SHIM_TYPES_ARCH_H_ */
@@ -0,0 +1,49 @@
/*
This file is part of Graphene Library OS.
Graphene Library OS is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Graphene Library OS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _SHIM_UCONTEXT_ARCH_H_
#define _SHIM_UCONTEXT_ARCH_H_
#include <shim_types.h>
#include <ucontext.h>
static inline void shim_regs_to_ucontext(ucontext_t* context, struct shim_regs* regs) {
context->uc_mcontext.gregs[REG_R8] = regs->r8;
context->uc_mcontext.gregs[REG_R9] = regs->r9;
context->uc_mcontext.gregs[REG_R10] = regs->r10;
context->uc_mcontext.gregs[REG_R11] = regs->r11;
context->uc_mcontext.gregs[REG_R12] = regs->r12;
context->uc_mcontext.gregs[REG_R13] = regs->r13;
context->uc_mcontext.gregs[REG_R14] = regs->r14;
context->uc_mcontext.gregs[REG_R15] = regs->r15;
context->uc_mcontext.gregs[REG_RDI] = regs->rdi;
context->uc_mcontext.gregs[REG_RSI] = regs->rsi;
context->uc_mcontext.gregs[REG_RBP] = regs->rbp;
context->uc_mcontext.gregs[REG_RBX] = regs->rbx;
context->uc_mcontext.gregs[REG_RDX] = regs->rdx;
context->uc_mcontext.gregs[REG_RAX] = regs->orig_rax;
context->uc_mcontext.gregs[REG_RCX] = regs->rcx;
context->uc_mcontext.gregs[REG_RSP] = regs->rsp;
context->uc_mcontext.gregs[REG_RIP] = regs->rip;
context->uc_mcontext.gregs[REG_EFL] = regs->rflags;
context->uc_mcontext.gregs[REG_CSGSFS] = 0;
context->uc_mcontext.gregs[REG_ERR] = 0;
context->uc_mcontext.gregs[REG_TRAPNO] = 0;
context->uc_mcontext.gregs[REG_OLDMASK] = 0;
context->uc_mcontext.gregs[REG_CR2] = 0;
}
#endif /* _SHIM_UCONTEXT_ARCH_H_ */
+1
View File
@@ -3,6 +3,7 @@
#include <shim_types.h>
#include <shim_defs.h>
#include <ucontext.h>
void sigaction_make_defaults(struct __kernel_sigaction* sig_action);
+3 -2
View File
@@ -30,6 +30,7 @@
#include <shim_vma.h>
#include <shim_checkpoint.h>
#include <shim_signal.h>
#include <shim_ucontext-arch.h>
#include <shim_unistd.h>
#include <pal.h>
@@ -186,7 +187,7 @@ void __store_context (shim_tcb_t * tcb, PAL_CONTEXT * pal_context,
}
if (pal_context) {
memcpy(context->uc_mcontext.gregs, pal_context, sizeof(PAL_CONTEXT));
pal_context_to_ucontext(context, pal_context);
signal->context_stored = true;
}
}
@@ -738,7 +739,7 @@ __handle_one_signal(shim_tcb_t* tcb, int sig, struct shim_signal* signal) {
tcb->context = *context;
if (signal->pal_context)
memcpy(signal->pal_context, signal->context.uc_mcontext.gregs, sizeof(PAL_CONTEXT));
ucontext_to_pal_context(signal->pal_context, &signal->context);
}
void __handle_signal (shim_tcb_t * tcb, int sig)
@@ -0,0 +1,28 @@
/*
This file is part of Graphene Library OS.
Graphene Library OS is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Graphene Library OS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
* sigcontext.h
*
* Linux-SGX PAL uses Linux's sigcontext.h
*/
#ifndef _LINUX_SGX_SIGCONTEXT_H
#define _LINUX_SGX_SIGCONTEXT_H
#include <Linux/sigcontext.h>
#endif /* _LINUX_SGX_SIGCONTEXT_H */
@@ -0,0 +1,28 @@
/*
This file is part of Graphene Library OS.
Graphene Library OS is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Graphene Library OS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
* ucontext.h
*
* Linux-SGX PAL uses Linux's ucontext.h
*/
#ifndef _LINUX_SGX_UCONTEXT_H
#define _LINUX_SGX_UCONTEXT_H
#include <Linux/ucontext.h>
#endif /* _LINUX_SGX_UCONTEXT_H */
@@ -0,0 +1,20 @@
/*
This file is part of Graphene Library OS.
Graphene Library OS is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Graphene Library OS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _SKELETON_SIGCONTEXT_H
#define _SKELETON_SIGCONTEXT_H
#endif /* _SKELETON_SIGCONTEXT_H */
@@ -0,0 +1,28 @@
/*
This file is part of Graphene Library OS.
Graphene Library OS is free software: you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Graphene Library OS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
* ucontext.h
*
* Skeleton uses Linux's ucontext.h (for now)
*/
#ifndef _SKELETON_UCONTEXT_H
#define _SKELETON_UCONTEXT_H
#include <Linux/ucontext.h>
#endif /* _SKELETON_UCONTEXT_H */