Skip to content

Commit e7ca87b

Browse files
author
KristofferC
committed
Revert "Don't expose guard pages to malloc_stack API consumers (#54591)"
This reverts commit 5dfd57d.
1 parent 972d618 commit e7ca87b

File tree

1 file changed

+1
-29
lines changed

1 file changed

+1
-29
lines changed

src/gc-stacks.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,13 @@
2222
// number of stacks to always keep available per pool
2323
#define MIN_STACK_MAPPINGS_PER_POOL 5
2424

25-
#if defined(_OS_WINDOWS_) || (!defined(_OS_OPENBSD_) && !defined(JL_HAVE_UCONTEXT) && !defined(JL_HAVE_SIGALTSTACK))
26-
#define JL_USE_GUARD_PAGE 1
2725
const size_t jl_guard_size = (4096 * 8);
28-
#else
29-
const size_t jl_guard_size = 0;
30-
#endif
31-
3226
static _Atomic(uint32_t) num_stack_mappings = 0;
3327

3428
#ifdef _OS_WINDOWS_
3529
#define MAP_FAILED NULL
3630
static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
3731
{
38-
size_t guard_size = LLT_ALIGN(jl_guard_size, jl_page_size);
39-
bufsz += guard_size;
40-
4132
void *stk = VirtualAlloc(NULL, bufsz, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
4233
if (stk == NULL)
4334
return MAP_FAILED;
@@ -46,7 +37,6 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
4637
VirtualFree(stk, 0, MEM_RELEASE);
4738
return MAP_FAILED;
4839
}
49-
stk = (char *)stk + guard_size;
5040

5141
jl_atomic_fetch_add(&num_stack_mappings, 1);
5242
return stk;
@@ -55,12 +45,6 @@ static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
5545

5646
static void free_stack(void *stkbuf, size_t bufsz)
5747
{
58-
#ifdef JL_USE_GUARD_PAGE
59-
size_t guard_size = LLT_ALIGN(jl_guard_size, jl_page_size);
60-
bufsz += guard_size;
61-
stkbuf = (char *)stkbuf - guard_size;
62-
#endif
63-
6448
VirtualFree(stkbuf, 0, MEM_RELEASE);
6549
jl_atomic_fetch_add(&num_stack_mappings, -1);
6650
}
@@ -69,35 +53,23 @@ static void free_stack(void *stkbuf, size_t bufsz)
6953

7054
static void *malloc_stack(size_t bufsz) JL_NOTSAFEPOINT
7155
{
72-
#ifdef JL_USE_GUARD_PAGE
73-
size_t guard_size = LLT_ALIGN(jl_guard_size, jl_page_size);
74-
bufsz += guard_size;
75-
#endif
76-
7756
void* stk = mmap(0, bufsz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
7857
if (stk == MAP_FAILED)
7958
return MAP_FAILED;
8059

81-
#ifdef JL_USE_GUARD_PAGE
60+
#if !defined(JL_HAVE_UCONTEXT) && !defined(JL_HAVE_SIGALTSTACK)
8261
// set up a guard page to detect stack overflow
8362
if (mprotect(stk, jl_guard_size, PROT_NONE) == -1) {
8463
munmap(stk, bufsz);
8564
return MAP_FAILED;
8665
}
87-
stk = (char *)stk + guard_size;
8866
#endif
8967
jl_atomic_fetch_add(&num_stack_mappings, 1);
9068
return stk;
9169
}
9270

9371
static void free_stack(void *stkbuf, size_t bufsz)
9472
{
95-
#ifdef JL_USE_GUARD_PAGE
96-
size_t guard_size = LLT_ALIGN(jl_guard_size, jl_page_size);
97-
bufsz += guard_size;
98-
stkbuf = (char *)stkbuf - guard_size;
99-
#endif
100-
10173
munmap(stkbuf, bufsz);
10274
jl_atomic_fetch_add(&num_stack_mappings, -1);
10375
}

0 commit comments

Comments
 (0)