mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 23:16:14 +01:00
Merge branch 'wip/pwithnall/3315-sigaltstack-again' into 'main'
tests: Move alternate stack onto the heap rather than the main stack Closes #3315 See merge request GNOME/glib!4194
This commit is contained in:
commit
e113052558
@ -588,14 +588,27 @@ test_signal_alternate_stack (int signal)
|
|||||||
#ifndef SA_ONSTACK
|
#ifndef SA_ONSTACK
|
||||||
g_test_skip ("alternate stack is not supported");
|
g_test_skip ("alternate stack is not supported");
|
||||||
#else
|
#else
|
||||||
guint8 stack_memory[MINSIGSTKSZ];
|
size_t minsigstksz = MINSIGSTKSZ;
|
||||||
guint8 zero_mem[MINSIGSTKSZ];
|
guint8 *stack_memory = NULL;
|
||||||
stack_t stack = { .ss_sp = stack_memory, .ss_size = MINSIGSTKSZ };
|
guint8 *zero_mem = NULL;
|
||||||
|
stack_t stack = { 0 };
|
||||||
stack_t old_stack = { 0 };
|
stack_t old_stack = { 0 };
|
||||||
|
|
||||||
memset (stack_memory, 0, MINSIGSTKSZ);
|
#ifdef _SC_MINSIGSTKSZ
|
||||||
memset (zero_mem, 0, MINSIGSTKSZ);
|
/* Use the kernel-provided minimum stack size, if available. Otherwise default
|
||||||
g_assert_cmpmem (stack_memory, MINSIGSTKSZ, zero_mem, MINSIGSTKSZ);
|
* to MINSIGSTKSZ. Unfortunately that might not be big enough for huge
|
||||||
|
* register files for big CPU instruction set extensions. */
|
||||||
|
minsigstksz = sysconf (_SC_MINSIGSTKSZ);
|
||||||
|
if (minsigstksz == (size_t) -1 || minsigstksz < (size_t) MINSIGSTKSZ)
|
||||||
|
minsigstksz = MINSIGSTKSZ;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
stack_memory = g_malloc0 (minsigstksz);
|
||||||
|
zero_mem = g_malloc0 (minsigstksz);
|
||||||
|
g_assert_cmpmem (stack_memory, minsigstksz, zero_mem, minsigstksz);
|
||||||
|
|
||||||
|
stack.ss_sp = stack_memory;
|
||||||
|
stack.ss_size = minsigstksz;
|
||||||
|
|
||||||
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
||||||
|
|
||||||
@ -620,6 +633,10 @@ test_signal_alternate_stack (int signal)
|
|||||||
|
|
||||||
stack.ss_flags = SS_DISABLE;
|
stack.ss_flags = SS_DISABLE;
|
||||||
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
||||||
|
|
||||||
|
g_free (zero_mem);
|
||||||
|
g_free (stack_memory);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -627,20 +644,23 @@ test_signal_alternate_stack (int signal)
|
|||||||
/* Very stupid check to ensure that the alternate stack is used instead of
|
/* Very stupid check to ensure that the alternate stack is used instead of
|
||||||
* the default one. This test would fail if SA_ONSTACK wouldn't be set.
|
* the default one. This test would fail if SA_ONSTACK wouldn't be set.
|
||||||
*/
|
*/
|
||||||
g_assert_cmpint (memcmp (stack_memory, zero_mem, MINSIGSTKSZ), !=, 0);
|
g_assert_cmpint (memcmp (stack_memory, zero_mem, minsigstksz), !=, 0);
|
||||||
|
|
||||||
/* We need to memset again zero_mem since compiler may have optimized it out
|
/* We need to memset again zero_mem since compiler may have optimized it out
|
||||||
* as we've seen in freebsd CI.
|
* as we've seen in freebsd CI.
|
||||||
*/
|
*/
|
||||||
memset (zero_mem, 0, MINSIGSTKSZ);
|
memset (zero_mem, 0, minsigstksz);
|
||||||
memset (stack_memory, 0, MINSIGSTKSZ);
|
memset (stack_memory, 0, minsigstksz);
|
||||||
g_assert_cmpmem (stack_memory, MINSIGSTKSZ, zero_mem, MINSIGSTKSZ);
|
g_assert_cmpmem (stack_memory, minsigstksz, zero_mem, minsigstksz);
|
||||||
|
|
||||||
stack.ss_flags = SS_DISABLE;
|
stack.ss_flags = SS_DISABLE;
|
||||||
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
g_assert_no_errno (sigaltstack (&stack, &old_stack));
|
||||||
|
|
||||||
test_signal (signal);
|
test_signal (signal);
|
||||||
g_assert_cmpmem (stack_memory, MINSIGSTKSZ, zero_mem, MINSIGSTKSZ);
|
g_assert_cmpmem (stack_memory, minsigstksz, zero_mem, minsigstksz);
|
||||||
|
|
||||||
|
g_free (zero_mem);
|
||||||
|
g_free (stack_memory);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user