Skip to content

Commit

Permalink
[LibOS] Use -1 for special signal value instead of 0xff
Browse files Browse the repository at this point in the history
Gramine allows to inject only one SIGTERM (signal number 15). To
distinguish a case when SIGTERM was already injected, LibOS atomically
updates a global variable to a special value meaning "SIGTERM was
injected". Previously, this special value was chosen as `0xff` for no
obvious reason. This leads to an artificial requirement that valid
signals cannot have numbers greater than or equal to 255 (`0xff`).

This commit removes this artificial requirement by replacing `0xff` with
`-1`. This is possible because signals are always of type `int`.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
  • Loading branch information
Dmitrii Kuvaiskii committed Feb 12, 2024
1 parent 339ce59 commit 748514a
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions libos/src/bookkeep/libos_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void get_all_pending_signals(__sigset_t* set) {
__sigemptyset(set);

int host_sig = __atomic_load_n(&g_host_injected_signal, __ATOMIC_RELAXED);
if (host_sig && host_sig != 0xff) {
if (host_sig && host_sig != -1) {
__sigaddset(set, host_sig);
}

Expand Down Expand Up @@ -711,13 +711,12 @@ void pop_unblocked_signal(__sigset_t* mask, struct libos_signal* signal) {
unlock(&g_process_signal_queue_lock);
unlock(&current->lock);
} else if (__atomic_load_n(&g_host_injected_signal, __ATOMIC_RELAXED) != 0) {
static_assert(SIGS_CNT < 0xff, "This code requires 0xff to be an invalid signal number");
lock(&current->lock);
bool sigterm_allowed_on_this_thread = false;
if (!__sigismember(mask ? : &current->signal_mask, SIGTERM)) {
sigterm_allowed_on_this_thread = true;
int sig = __atomic_exchange_n(&g_host_injected_signal, 0xff, __ATOMIC_RELAXED);
if (sig != 0xff) {
int sig = __atomic_exchange_n(&g_host_injected_signal, -1, __ATOMIC_RELAXED);
if (sig != -1) {
signal->siginfo.si_signo = sig;
signal->siginfo.si_code = SI_USER;
}
Expand Down

0 comments on commit 748514a

Please sign in to comment.