[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 14/17] tests: Use vm_page_size
From: |
Samuel Thibault |
Subject: |
Re: [PATCH 14/17] tests: Use vm_page_size |
Date: |
Wed, 27 Mar 2024 19:58:48 +0100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
Applied, thanks!
Sergey Bugaev, le mer. 27 mars 2024 19:18:38 +0300, a ecrit:
> ---
> tests/testlib_thread_start.c | 19 +++++++++++--------
> 1 file changed, 11 insertions(+), 8 deletions(-)
>
> diff --git a/tests/testlib_thread_start.c b/tests/testlib_thread_start.c
> index fa8af0ea..df4b19ab 100644
> --- a/tests/testlib_thread_start.c
> +++ b/tests/testlib_thread_start.c
> @@ -30,30 +30,33 @@
> #include <mach/vm_param.h>
> #include <mach.user.h>
>
> -/* This is just a temporary mapping to set up the stack */
> -static long stack_top[PAGE_SIZE/sizeof(long)] __attribute__ ((aligned
> (PAGE_SIZE)));
> -
> thread_t test_thread_start(task_t task, void(*routine)(void*), void* arg) {
> - const vm_size_t stack_size = PAGE_SIZE * 16;
> + const vm_size_t stack_size = vm_page_size * 16;
> kern_return_t ret;
> - vm_address_t stack;
> + vm_address_t stack, local_stack;
> +
> + ret = vm_allocate(mach_task_self(), &local_stack, vm_page_size, TRUE);
> + ASSERT_RET(ret, "can't allocate local stack");
>
> ret = vm_allocate(task, &stack, stack_size, TRUE);
> ASSERT_RET(ret, "can't allocate the stack for a new thread");
>
> - ret = vm_protect(task, stack, PAGE_SIZE, FALSE, VM_PROT_NONE);
> + ret = vm_protect(task, stack, vm_page_size, FALSE, VM_PROT_NONE);
> ASSERT_RET(ret, "can't protect the stack from overflows");
>
> - long *top = (long*)((vm_offset_t)stack_top + PAGE_SIZE) - 1;
> + long *top = (long*)(local_stack + vm_page_size) - 1;
> #ifdef __i386__
> *top = (long)arg; /* The argument is passed on the stack on x86_32 */
> *(top - 1) = 0; /* The return address */
> #elif defined(__x86_64__)
> *top = 0; /* The return address */
> #endif
> - ret = vm_write(task, stack + stack_size - PAGE_SIZE,
> (vm_offset_t)stack_top, PAGE_SIZE);
> + ret = vm_write(task, stack + stack_size - vm_page_size, local_stack,
> vm_page_size);
> ASSERT_RET(ret, "can't initialize the stack for the new thread");
>
> + ret = vm_deallocate(mach_task_self(), local_stack, vm_page_size);
> + ASSERT_RET(ret, "can't deallocate local stack");
> +
> thread_t thread;
> ret = thread_create(task, &thread);
> ASSERT_RET(ret, "thread_create()");
> --
> 2.44.0
>
>
--
Samuel
---
Pour une évaluation indépendante, transparente et rigoureuse !
Je soutiens la Commission d'Évaluation de l'Inria.
- Re: [PATCH 07/17] kern/rdxtree: Fix undefined behavior, (continued)
- [PATCH 17/17] tests: Create tests/ in the build tree before trying to use it, Sergey Bugaev, 2024/03/27
- [PATCH 16/17] tests: Don't ask for executable stack, Sergey Bugaev, 2024/03/27
- [PATCH 10/17] Make -fno-PIE etc. architecture-dependent, Sergey Bugaev, 2024/03/27
- [PATCH 13/17] tests: Add vm_page_size, Sergey Bugaev, 2024/03/27
- [PATCH 14/17] tests: Use vm_page_size, Sergey Bugaev, 2024/03/27
- Re: [PATCH 14/17] tests: Use vm_page_size,
Samuel Thibault <=