1/* 2 * Copyright 2017, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#pragma once 14 15#include <sel4/types.h> 16#include <sel4utils/thread.h> 17#include <stdbool.h> 18#include <vka/vka.h> 19#include <vspace/vspace.h> 20 21#if CONFIG_WORD_SIZE == 64 22#define Elf_auxv_t Elf64_auxv_t 23#elif CONFIG_WORD_SIZE == 32 24#define Elf_auxv_t Elf32_auxv_t 25#else 26#error "Word size unsupported" 27#endif /* CONFIG_WORD_SIZE */ 28 29/* write to a remote stack */ 30int sel4utils_stack_write(vspace_t *current_vspace, vspace_t *target_vspace, 31 vka_t *vka, void *buf, size_t len, uintptr_t *stack_top); 32 33/* 34 * Initialize a threads user context for a specific architecture 35 * 36 * Unlike sel4utils_arch_init_context_with_args, the specified entry_point 37 * does not need to be a function. 38 * 39 * @return 0 on success. 40 */ 41int sel4utils_arch_init_context(void *entry_point, void *stack_top, seL4_UserContext *context); 42 43/* 44 * Legacy function to initialise a threads user context for a specific architecture, and put 45 * some arguments into registers/stack. 46 * 47 * stack_top must be aligned to STACK_CALL_ALIGNMENT 48 * 49 * On x86, entry_point must be the address of a function without the NORETURN attribute. 50 * Specifically, the function must be compiled under the assumption that the return 51 * address was pushed onto the stack when the function is called. We aren't going to call 52 * the function, but we will align the stack pointer as if it was called. This is 53 * important, since the compiler emits instructions that assume alignment of the stack 54 * pointer, under the assumption that functions will be called (as opposed to jumped to). 55 * 56 * On arm, the restriction is relaxed, as the return address is not pushed onto the stack 57 * when a function is called. 58 * 59 * @param local_stack true of the stack is mapped in the current address space. If local stack is 60 * false and we are running on x86 (32-bit) this function will not copy arg* unless vka, 61 * local_vspace and remote_vspace are provided. 62 * 63 * @return 0 on success. 64 */ 65int sel4utils_arch_init_context_with_args(sel4utils_thread_entry_fn entry_point, 66 void *arg0, void *arg1, void *arg2, 67 bool local_stack, void *stack_top, seL4_UserContext *context, 68 vka_t *vka, vspace_t *local_vspace, vspace_t *remote_vspace); 69 70/* convenient wrappers */ 71static inline int 72sel4utils_arch_init_local_context(sel4utils_thread_entry_fn entry_point, 73 void *arg0, void *arg1, void *arg2, 74 void *stack_top, seL4_UserContext *context) 75{ 76 return sel4utils_arch_init_context_with_args(entry_point, arg0, arg1, arg2, true, stack_top, context, NULL, NULL, NULL); 77} 78 79