Skip to content

Commit

Permalink
c18n: Make stack resolution re-entrant
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgao committed Mar 28, 2024
1 parent 8002ae8 commit 1394537
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libexec/rtld-elf/rtld_c18n.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,14 @@ allocate_rstk_impl(unsigned index)
unsigned cid_off;
size_t capacity, size;
struct stk_table *table;
sigset_t nset, oset;

/*
* Make the function re-entrant by blocking all signals and re-check
* whether the stack needs to be allocated.
*/
sigfillset(&nset);
sigprocmask(SIG_SETMASK, &nset, &oset);

table = stk_table_get();

Expand All @@ -710,8 +718,10 @@ allocate_rstk_impl(unsigned index)
capacity = MAX(capacity * 2, cid_off + 1);
table = stk_table_expand(table, capacity, true);
stk_table_set(table);
} else if (table->stacks[cid_off].size != 0) {
stk = table->stacks[cid_off].bottom;
goto finish;
}
assert(table->stacks[cid_off].size == 0);

size = C18N_STACK_SIZE;
stk = stk_create(size);
Expand All @@ -720,6 +730,9 @@ allocate_rstk_impl(unsigned index)
table->stacks[cid_off].bottom = stk;
table->stacks[cid_off].size = size;

finish:
sigprocmask(SIG_SETMASK, &oset, NULL);

return (stk);
}

Expand Down

0 comments on commit 1394537

Please sign in to comment.