Allocate URPC thread stack on main thread

This commit is contained in:
Jan Schär 2022-04-28 19:18:19 +02:00
parent df146c227a
commit 36530499fb
3 changed files with 33 additions and 10 deletions

View File

@ -122,6 +122,8 @@ static inline void thread_once(thread_once_t *control, void (*func)(void)) {
*/
void thread_set_status(int status);
void thread_allocate_stack(struct thread *thread);
__END_DECLS
#endif // LIBBARRELFISH_THREADS_H

View File

@ -347,9 +347,8 @@ struct thread *thread_create_unrunnable(thread_func_t start_func, void *arg,
// allocate stack
// debug_printf("[thread_create_unrunnable] stacksize = %x\n", stacksize);
assert((stacksize % sizeof(uintptr_t)) == 0);
stacksize += BASE_PAGE_SIZE;
size_t bytes_allocated;
void *stack = paging_malloc(stacksize, &bytes_allocated, BASE_PAGE_SIZE);
void *stack = paging_malloc(stacksize + BASE_PAGE_SIZE, &bytes_allocated, BASE_PAGE_SIZE) + BASE_PAGE_SIZE;
if (stack == NULL) {
return NULL;
}
@ -362,7 +361,7 @@ struct thread *thread_create_unrunnable(thread_func_t start_func, void *arg,
release_spinlock(&thread_slabs_spinlock);
// thread_mutex_unlock(&thread_slabs_mutex);
if (space == NULL) {
free(stack);
// free(stack);
return NULL;
}
@ -1463,3 +1462,13 @@ void thread_deliver_exception_disabled(dispatcher_handle_t handle,
disp_resume(handle, &thread->regs);
}
/**
* \brief Allocate all pages of the thread stack.
*/
void thread_allocate_stack(struct thread *thread)
{
for (volatile uint8_t *p = thread->stack; (void*)p < thread->stack_top; p += BASE_PAGE_SIZE) {
*p; // cause a page fault
}
}

View File

@ -230,8 +230,6 @@ app_main(int argc, char *argv[]) {
// - grading_test_early();
// - grading_test_late();
// Grading
grading_setup_app_init(bi);
// TODO: initialize mem allocator, vspace management here
err = cap_retype(cap_selfep, cap_dispatcher, 0, ObjType_EndPointLMP, 0, 1);
@ -248,22 +246,36 @@ app_main(int argc, char *argv[]) {
ram_alloc_set(ram_alloc_remote_core);
thread_create(urpc_server, &urpc_to_app_server);
struct thread *urpc_server_thread = thread_create(urpc_server, &urpc_to_app_server);
// Allocate all pages of the thread stack now.
// We can't have page fault while the thread is running,
// because URPC calls may only be done from the main thread.
thread_allocate_stack(urpc_server_thread);
// Grading
grading_test_early();
// TODO: Spawn system processes etc. here
struct bootinfo_serialized * bi_ser;
err = aos_urpc_get_bootinfo(&urpc_to_bsp, &bi_ser);
if (err_is_fail(err)) return err;
if (err_is_fail(err)) {
DEBUG_ERR(err, "in aos_urpc_get_bootinfo");
abort();
}
err = deserialize_bootinfo(bi_ser, &bi);
if (err_is_fail(err)) {
DEBUG_ERR(err, "in deserialize_bootinfo");
abort();
}
free(bi_ser);
if (err_is_fail(err)) return err;
debug_printf("[app_main]: received bootinfo with %d regions\n", bi->regions_length);
// Grading
grading_setup_app_init(bi);
// Grading
grading_test_early();
// Grading
grading_test_late();