# HG changeset patch # User Paul Boddie # Date 1655074701 -7200 # Node ID 571ff28dabfb88e8080d998f63633b375e93225c # Parent b782ee2e677736c6f5961b5eea5f86460bee68cc Moved pager initiation into a function. diff -r b782ee2e6777 -r 571ff28dabfb tests/dstest_exec.cc --- a/tests/dstest_exec.cc Mon Jun 13 00:43:15 2022 +0200 +++ b/tests/dstest_exec.cc Mon Jun 13 00:58:21 2022 +0200 @@ -40,6 +40,30 @@ static ExternalPager exec_pager; +static const offset_t initial_stack_size = 16 * L4_PAGESIZE; + + + +/* Start the system pager in a separate thread. */ + +static long start_pager(ipc_server_config_type &config) +{ + pthread_t pager_thread; + pthread_attr_t attr; + + pthread_attr_init(&attr); + pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + + ipc_server_init_for(&config, PagerObject, &exec_pager); + + long err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config); + + if (err) + return err; + + return ipc_server_start_config_thread(&config, pthread_l4_cap(pager_thread)); +} + int main(int argc, char *argv[]) @@ -54,7 +78,6 @@ /* Initialise the memory of the new task. */ - offset_t initial_stack_size = 16 * L4_PAGESIZE; ExplicitSegment stack(Utcb_area_start - initial_stack_size, initial_stack_size, L4_FPAGE_RW); Payload *payload; @@ -80,27 +103,13 @@ exec_pager.add(stack.region()); - /* Start the pager. */ - - pthread_t pager_thread; - pthread_attr_t attr; - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); + /* Start the pager in a separate thread. */ ipc_server_config_type config; - ipc_server_init_for(&config, PagerObject, &exec_pager); - - err = pthread_create(&pager_thread, &attr, ipc_server_start_mainloop, &config); - - if (err) - { - printf("Could not start pager thread.\n"); - return 1; - } printf("Starting pager thread...\n"); - err = ipc_server_start_config_thread(&config, pthread_l4_cap(pager_thread)); + + err = start_pager(config); if (err) { @@ -131,19 +140,19 @@ /* Populate a thread stack with argument and environment details. */ - Stack st(stack); + Stack program_st(stack); /* NOTE: Environment vector is currently not defined. */ char *envp[] = {NULL}; - st.populate(argc - 1, argv + 1, envp); + program_st.populate(argc - 1, argv + 1, envp); /* Start the new thread in the given stack. */ printf("Run thread...\n"); - err = process.thread_start(payload->entry_point(), st); + err = process.thread_start(payload->entry_point(), program_st); if (err) { @@ -152,7 +161,8 @@ } printf("Finished.\n"); - while (1); + while (1) + l4_sleep_forever(); return 0; }