--- Gnu-Mach/kern/thread_swap.c 2020/09/02 04:36:57 1.1 +++ Gnu-Mach/kern/thread_swap.c 2020/09/02 04:49:52 1.1.1.4 @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -69,7 +70,7 @@ decl_simple_lock_data(, swapper_lock_dat * * Initialize the swapper module. */ -void swapper_init() +void swapper_init(void) { queue_init(&swapin_queue); simple_lock_init(&swapper_lock_data); @@ -85,8 +86,7 @@ void swapper_init() * our callers have already tried that route. */ -void thread_swapin(thread) - thread_t thread; +void thread_swapin(thread_t thread) { switch (thread->state & TH_SWAP_STATE) { case TH_SWAPPED: @@ -96,7 +96,7 @@ void thread_swapin(thread) thread->state = (thread->state & ~TH_SWAP_STATE) | TH_SW_COMING_IN; swapper_lock(); - enqueue_tail(&swapin_queue, (queue_entry_t) thread); + enqueue_tail(&swapin_queue, &(thread->links)); swapper_unlock(); thread_wakeup((event_t) &swapin_queue); break; @@ -123,16 +123,18 @@ void thread_swapin(thread) * it on a run queue. No locks should be held on entry, as it is * likely that this routine will sleep (waiting for stack allocation). */ -void thread_doswapin(thread) - register thread_t thread; +kern_return_t thread_doswapin(thread_t thread) { + kern_return_t kr; spl_t s; /* * Allocate the kernel stack. */ - stack_alloc(thread, thread_continue); + kr = stack_alloc(thread, thread_continue); + if (kr != KERN_SUCCESS) + return kr; /* * Place on run queue. @@ -145,6 +147,7 @@ void thread_doswapin(thread) thread_setrun(thread, TRUE); thread_unlock(thread); (void) splx(s); + return KERN_SUCCESS; } /* @@ -153,10 +156,10 @@ void thread_doswapin(thread) * This procedure executes as a kernel thread. Threads that need to * be swapped in are swapped in by this thread. */ -void swapin_thread_continue() +void __attribute__((noreturn)) swapin_thread_continue(void) { for (;;) { - register thread_t thread; + thread_t thread; spl_t s; s = splsched(); @@ -164,13 +167,20 @@ void swapin_thread_continue() while ((thread = (thread_t) dequeue_head(&swapin_queue)) != THREAD_NULL) { + kern_return_t kr; swapper_unlock(); (void) splx(s); - thread_doswapin(thread); /* may block */ + kr = thread_doswapin(thread); /* may block */ s = splsched(); swapper_lock(); + + if (kr != KERN_SUCCESS) { + enqueue_head(&swapin_queue, + (queue_entry_t) thread); + break; + } } assert_wait((event_t) &swapin_queue, FALSE); @@ -181,7 +191,7 @@ void swapin_thread_continue() } } -void swapin_thread() +void swapin_thread(void) { stack_privilege(current_thread());