Skip to content

Instantly share code, notes, and snippets.

@BrzVlad
Created September 28, 2018 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrzVlad/dcee172c24cc532a02d887b96cd4704c to your computer and use it in GitHub Desktop.
Save BrzVlad/dcee172c24cc532a02d887b96cd4704c to your computer and use it in GitHub Desktop.
mmap/mprotect reversal
diff --git a/mono/mini/mini-exceptions.c b/mono/mini/mini-exceptions.c
index 6297bacf704..f78807139f0 100644
--- a/mono/mini/mini-exceptions.c
+++ b/mono/mini/mini-exceptions.c
@@ -2750,12 +2750,10 @@ mono_setup_altstack (MonoJitTlsData *tls)
g_assert ((guint8*)&sa >= (guint8*)tls->stack_ovf_guard_base + tls->stack_ovf_guard_size);
- if (mono_mprotect (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE)) {
- /* mprotect can fail for the main thread stack */
- gpointer gaddr = mono_valloc (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON|MONO_MMAP_FIXED, MONO_MEM_ACCOUNT_EXCEPTIONS);
- g_assert (gaddr == tls->stack_ovf_guard_base);
+ if (mono_valloc (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE | MONO_MMAP_PRIVATE | MONO_MMAP_ANON | MONO_MMAP_FIXED, MONO_MEM_ACCOUNT_EXCEPTIONS))
tls->stack_ovf_valloced = TRUE;
- }
+ else if (mono_mprotect (tls->stack_ovf_guard_base, tls->stack_ovf_guard_size, MONO_MMAP_NONE))
+ g_error ("Couldn't setup stack guard page");
/* Setup an alternate signal stack */
tls->signal_stack = mono_valloc (0, MONO_ARCH_SIGNAL_STACK_SIZE, MONO_MMAP_READ|MONO_MMAP_WRITE|MONO_MMAP_PRIVATE|MONO_MMAP_ANON, MONO_MEM_ACCOUNT_EXCEPTIONS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment