Commit Graph

10 Commits

Author SHA1 Message Date
zongmin.gu
c58f61c56e Enable simulation interrupt mode support 2021-12-14 10:58:09 +08:00
Hui, Chunyang
09b7828f44 Disable busyloop test case due to signal handling constraints in SIM mode 2021-06-25 21:12:42 +08:00
zongmin.gu
0252f98d60 Enable exception test cases under simulation mode 2021-03-03 16:07:51 +08:00
Tate, Hongliang Tian
a3ad465ce3 Fix SGX simulation mode broken by the interrupt subsystem
The new interrupt subsystem breaks the simulation mode in two ways:

1. The signal 64 is not handled by Intel SGX SDK in simulation mode. A
handled real-time signal crashes the process.

2. The newly-enabled test case exit_group depends on interrupts. But
enclave interrupts, like enclave exceptions, are not supported in
simulation mode.

This commit ensures signal 64 is ignored by default and exit_group test
case is not enabled in simulation mode.
2020-07-11 14:19:41 +00:00
Tate, Hongliang Tian
b585fce65d Add the interrupt subsystem
Before this commit, events like signals and exit_group are handled by
LibOS threads in a cooperative fashion: if the user code executed by a
LibOS thread does not invoke system calls (e.g., a busy loop), then the LibOS
won't have any opportunity to take control and handle events.

With the help from the POSIX signal-based interrupt mechanism of
Occlum's version of Intel SGX SDK, the LibOS can now interrupt the
execution of arbitrary user code in a LibOS thread by sending real-time
POSIX signals (the signal number is 64) to it. These signals are sent by
a helper thread spawn by Occlum PAL. The helper thread periodically
enters into the enclave to check if there are any LibOS threads with
pending events. If any, the helper thread broadcast POSIX signals to
them. When interrupted by a signal, the receiver LibOS thread may be in
one of the two previously problematic states in terms of event handling:

1. Executing non-cooperative user code (e.g., a busy loop). In this
case, the signal will trigger an interrupt handler inside the enclave,
which can then enter the LibOS kernel to deal with any pending events.

2. Executing an OCall that invokes blocking system calls (e.g., futex,
nanosleep, or blocking I/O). In this case, the signal will interrupt the
blocking system call so that the OCall can return back to the enclave.

Thanks to the new interrupt subsystem, some event-based system calls
are made robust. One such example is exit_group. We can now guarantee
that exit_group can force any thread in a process to exit.
2020-07-10 11:52:01 +00:00
Hui, Chunyang
5b695c9539 Format c/c++ files in src, tools and test 2020-05-27 07:09:18 +00:00
Zongmin
0c3466f4ad Add three new occlum commands: start, exec and stop
Usage:
//start the occlum server
occlum start

//execute the command inside occlum
occlum exec [cmd] [-- <args>]

//stop the occlum server
occlum stop
2020-05-15 03:02:42 +00:00
Tate, Hongliang Tian
e166382923 Add the signal subsystem
In this commit, we add eight signal-related syscalls
* kill
* tkill
* tgkill
* rt_sigaction
* rt_sigreturn
* rt_sigprocmask
* rt_sigpending
* exit_group

We implement the following major features for signals:
* Generate, mask, and deliver signals
* Support user-defined signal handlers
    * Support nested invocation of signal handlers
    * Support passing arguments: signum, sigaction, and ucontext
* Support both process-directed and thread-directed signals
* Capture hardware exceptions and convert them to signals
* Deliver fatal signals (like SIGKILL) to kill processes gracefully

But we still have gaps, including but not limited to the points below:
* Convert #PF (page fault) and #GP (general protection) exceptions to signals
* Force delivery of signals via interrupt
* Support simulation mode
2020-05-15 02:59:16 +00:00
sanqian.hcy
b08f5b9ceb Add support for SGX simulation mode
1. Use arch_prctl to replace RDFSBASE/WRFSBASE
Ptrace can't get right value if WRFSBASE is called which
will make debugger fail in simulation mode. Use arch_prctl
to replace these instructions in simulation mode.

2. Disable the busy thread in exit_group test
exit_group doesn't have a real implementation yet but test
under SGX simulation mode give core dump for exit_group test.
Disable the busy loop thread and the core dump disappear.

3. Add SDK lib path to LD_LIBRARY_PATH
Linker sometims can't find urts_sim and uae_service_sim when
running. Explicitly add path to LD_LIBRARY_PATH when running
occlum command.

Signed-off-by: sanqian.hcy <sanqian.hcy@antfin.com>
2020-03-01 06:42:33 +00:00
Tate, Hongliang Tian
663f548f94 Workaround exit_group syscall
BACKGROUND

The exit_group syscall, which is implicitly called by libc after the main function
returns, kills all threads in a thread group, even if these threads are
running, sleeping, or waiting on a futex.

PROBLEM

In normal use cases, exit_group does nothing since a well-written program
should terminate all threads before the main function returns. But when this is
not the case, exit_group can clean up the mess.

Currently, Occlum does not implement exit_group. And the Occlum PAL process
waits for all tasks (i.e., SGX threads) to finish before exiting. So without
exit_group implemented, some tasks may be still running if after the main task
exits. And this causes the Occlum PAL process to wait---forever.

WORKAROUND

To implement a real exit_group, we need signals to kill threads. But we do not
have signals, yet. So we come up with a workaround: instead of waiting all
tasks to finish in PAL, we just wait for the main task. As soon as the main
task exits, the PAL process terminates, killing the remaining tasks.
2019-11-07 13:34:53 +00:00