voiddo_exec(void (*func)(), size_t size, uint64_t pc) { /* * If the task was created by privilege_task_create() and hasn't initlized * page table, the default value of TTBR0_EL1 is 0x0 */ consttask_t *task = get_current(); uintptr_t sp = USER_VIRT_TOP - sizeof(uintptr_t); // stack address grows towards lower memory address
// allocate pages for user program size_t upper_bound = ROUNDUP(size, PAGE_SIZE); for (size_t offset = 0; offset < upper_bound; offset += PAGE_SIZE, size -= PAGE_SIZE) { void *utext = map_addr_user((void *) (pc + offset)); if (!utext) { goto _do_exec_err; } memcpy(utext, (char *) func + offset, MIN(size, PAGE_SIZE)); }
[PID 2] Hello world x35 [PID 2] Hello world x36 [PID 2] Hello world x37 [PID 2] Hello world x38 [PID 2] Hello world x39 [PID 2] Hello world x40 [PID 2] Hello world x41 [PID 2] Hello world x42 [PID 2] Hello world x43 [PID 2] Hello world x44 [PID 2] Hello world x45 [PID 2] Hello world x46 [PID 2] Hello world x47 [PID 2] Hello world x48 [PID 2] Hello world x49 [PID 2] Hello world x50 [PID 2] Hello world x51