diff options
author | Flavio Cruz <flaviocruz@gmail.com> | 2023-04-02 23:56:31 -0400 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-04-04 02:16:37 +0200 |
commit | 4fd5e9c2c18fa71ebc6dce5fcfe077f8c9f29bab (patch) | |
tree | 10e2c1ba63c76627d79a587f666b074877c9f605 /i386 | |
parent | 4096bd9d9cbdbac9b1bfce99a393295f63a88cc5 (diff) | |
download | gnumach-4fd5e9c2c18fa71ebc6dce5fcfe077f8c9f29bab.tar.gz gnumach-4fd5e9c2c18fa71ebc6dce5fcfe077f8c9f29bab.tar.bz2 gnumach-4fd5e9c2c18fa71ebc6dce5fcfe077f8c9f29bab.zip |
Align the user stack correctly for 64 bit programs.
* i386/i386/thread.h: Define USER_STACK_ALIGN which is 16-byte for 64 bit
programs as recommended by the System V AMD64 guidelines. Also define
KERNEL_STACK_ALIGN which can differ from user land.
* i386/i386/pcb.c: Use USER_STACK_ALIGN to align the bootstrap arguments and
ultimately the stack where the program starts on.
* kern/bootstrap.c: Do not align arg_len here since it will be aligned
in set_user_regs.
Message-Id: <ZCpOb6vNEfPclKPr@jupiter.tail36e24.ts.net>
Diffstat (limited to 'i386')
-rw-r--r-- | i386/i386/pcb.c | 13 | ||||
-rw-r--r-- | i386/i386/thread.h | 13 |
2 files changed, 18 insertions, 8 deletions
diff --git a/i386/i386/pcb.c b/i386/i386/pcb.c index 9210656b..61125fe8 100644 --- a/i386/i386/pcb.c +++ b/i386/i386/pcb.c @@ -379,12 +379,7 @@ thread_t switch_context( void pcb_module_init(void) { kmem_cache_init(&pcb_cache, "pcb", sizeof(struct pcb), -#ifdef __x86_64__ - 16, -#else - 0, -#endif - NULL, 0); + KERNEL_STACK_ALIGN, NULL, 0); fpu_module_init(); } @@ -893,11 +888,13 @@ set_user_regs(vm_offset_t stack_base, /* low address */ vm_offset_t arg_addr; struct i386_saved_state *saved_state; - arg_size = (arg_size + sizeof(int) - 1) & ~(sizeof(int)-1); + assert(P2ALIGNED(stack_size, USER_STACK_ALIGN)); + assert(P2ALIGNED(stack_base, USER_STACK_ALIGN)); + arg_size = P2ROUND(arg_size, USER_STACK_ALIGN); arg_addr = stack_base + stack_size - arg_size; saved_state = USER_REGS(current_thread()); - saved_state->uesp = (long)arg_addr; + saved_state->uesp = (rpc_vm_offset_t)arg_addr; saved_state->eip = exec_info->entry; return (arg_addr); diff --git a/i386/i386/thread.h b/i386/i386/thread.h index cb317bee..933b43d8 100644 --- a/i386/i386/thread.h +++ b/i386/i386/thread.h @@ -225,6 +225,19 @@ typedef struct pcb { #define STACK_IEL(stack) \ ((struct i386_exception_link *)STACK_IKS(stack) - 1) +#ifdef __x86_64__ +#define KERNEL_STACK_ALIGN 16 +#else +#define KERNEL_STACK_ALIGN 4 +#endif + +#if defined(__x86_64__) && !defined(USER32) +/* Follow System V AMD64 ABI guidelines. */ +#define USER_STACK_ALIGN 16 +#else +#define USER_STACK_ALIGN 4 +#endif + #define USER_REGS(thread) (&(thread)->pcb->iss) |