From 8f9e4dbcbf2765ec25e7978609a471f374ae43db Mon Sep 17 00:00:00 2001 From: Marin Ramesa Date: Tue, 12 Nov 2013 14:26:28 +0100 Subject: kern: remove register qualifiers * kern/task.c: Remove register qualifiers. --- kern/task.c | 68 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 114dd319..f62e47be 100644 --- a/kern/task.c +++ b/kern/task.c @@ -78,8 +78,8 @@ kern_return_t task_create( boolean_t inherit_memory, task_t *child_task) /* OUT */ { - register task_t new_task; - register processor_set_t pset; + task_t new_task; + processor_set_t pset; #if FAST_TAS int i; #endif @@ -181,10 +181,10 @@ kern_return_t task_create( * is never in this task. */ void task_deallocate( - register task_t task) + task_t task) { - register int c; - register processor_set_t pset; + int c; + processor_set_t pset; if (task == TASK_NULL) return; @@ -210,7 +210,7 @@ void task_deallocate( } void task_reference( - register task_t task) + task_t task) { if (task == TASK_NULL) return; @@ -227,11 +227,11 @@ void task_reference( * (kern/thread.c) about problems with terminating the "current task." */ kern_return_t task_terminate( - register task_t task) + task_t task) { - register thread_t thread, cur_thread; - register queue_head_t *list; - register task_t cur_task; + thread_t thread, cur_thread; + queue_head_t *list; + task_t cur_task; spl_t s; if (task == TASK_NULL) @@ -402,10 +402,10 @@ kern_return_t task_terminate( * suspends is maintained. */ kern_return_t task_hold( - register task_t task) + task_t task) { - register queue_head_t *list; - register thread_t thread, cur_thread; + queue_head_t *list; + thread_t thread, cur_thread; cur_thread = current_thread(); @@ -441,12 +441,12 @@ kern_return_t task_hold( * must_wait is true. */ kern_return_t task_dowait( - register task_t task, + task_t task, boolean_t must_wait) { - register queue_head_t *list; - register thread_t thread, cur_thread, prev_thread; - register kern_return_t ret = KERN_SUCCESS; + queue_head_t *list; + thread_t thread, cur_thread, prev_thread; + kern_return_t ret = KERN_SUCCESS; /* * Iterate through all the threads. @@ -493,10 +493,10 @@ kern_return_t task_dowait( } kern_return_t task_release( - register task_t task) + task_t task) { - register queue_head_t *list; - register thread_t thread, next; + queue_head_t *list; + thread_t thread, next; task_lock(task); if (!task->active) { @@ -624,9 +624,9 @@ kern_return_t task_threads( } kern_return_t task_suspend( - register task_t task) + task_t task) { - register boolean_t hold; + boolean_t hold; if (task == TASK_NULL) return KERN_INVALID_ARGUMENT; @@ -675,9 +675,9 @@ kern_return_t task_suspend( } kern_return_t task_resume( - register task_t task) + task_t task) { - register boolean_t release; + boolean_t release; if (task == TASK_NULL) return KERN_INVALID_ARGUMENT; @@ -717,7 +717,7 @@ kern_return_t task_info( switch (flavor) { case TASK_BASIC_INFO: { - register task_basic_info_t basic_info; + task_basic_info_t basic_info; /* Allow *task_info_count to be two words smaller than the usual amount, because creation_time is a new member @@ -756,7 +756,7 @@ kern_return_t task_info( case TASK_EVENTS_INFO: { - register task_events_info_t event_info; + task_events_info_t event_info; if (*task_info_count < TASK_EVENTS_INFO_COUNT) { return KERN_INVALID_ARGUMENT; @@ -780,8 +780,8 @@ kern_return_t task_info( case TASK_THREAD_TIMES_INFO: { - register task_thread_times_info_t times_info; - register thread_t thread; + task_thread_times_info_t times_info; + thread_t thread; if (*task_info_count < TASK_THREAD_TIMES_INFO_COUNT) { return KERN_INVALID_ARGUMENT; @@ -837,9 +837,9 @@ task_assign( boolean_t assign_threads) { kern_return_t ret = KERN_SUCCESS; - register thread_t thread, prev_thread; - register queue_head_t *list; - register processor_set_t pset; + thread_t thread, prev_thread; + queue_head_t *list; + processor_set_t pset; if (task == TASK_NULL || new_pset == PROCESSOR_SET_NULL) { return KERN_INVALID_ARGUMENT; @@ -1055,8 +1055,8 @@ task_priority( task->priority = priority; if (change_threads) { - register thread_t thread; - register queue_head_t *list; + thread_t thread; + queue_head_t *list; list = &task->thread_list; queue_iterate(list, thread, thread_t, thread_list) { @@ -1078,7 +1078,7 @@ task_priority( void task_collect_scan(void) { - register task_t task, prev_task; + task_t task, prev_task; processor_set_t pset, prev_pset; prev_task = TASK_NULL; -- cgit v1.2.3 From 4c427f351acb585bf06f63218cb8ced221d889e0 Mon Sep 17 00:00:00 2001 From: Marin Ramesa Date: Fri, 29 Nov 2013 22:54:07 +0100 Subject: kern/task.c: remove forward declarations * ipc/ipc_mqueue.h: Include ipc/ipc_kmsg_queue.h. * kern/ipc_kobject.h: Move includes into ifndef. * kern/syscall_emulation.h: Include kern/task.h. (eml_init, eml_task_reference, eml_task_deallocate): Add prototypes. * kern/task.c: Include kern/syscall_emulation.h. (eml_init, eml_task_reference, eml_task_deallocate): Remove forward declarations --- ipc/ipc_mqueue.h | 1 + kern/ipc_kobject.h | 5 ++--- kern/syscall_emulation.h | 6 ++++++ kern/task.c | 5 +---- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'kern/task.c') diff --git a/ipc/ipc_mqueue.h b/ipc/ipc_mqueue.h index ef0f9425..f8a2f1e7 100644 --- a/ipc/ipc_mqueue.h +++ b/ipc/ipc_mqueue.h @@ -38,6 +38,7 @@ #include #include #include +#include #include #include diff --git a/kern/ipc_kobject.h b/kern/ipc_kobject.h index cb795741..606a66a9 100644 --- a/kern/ipc_kobject.h +++ b/kern/ipc_kobject.h @@ -36,13 +36,12 @@ * Declarations for letting a port represent a kernel object. */ -#include -#include - #ifndef _KERN_IPC_KOBJECT_H_ #define _KERN_IPC_KOBJECT_H_ #include +#include +#include typedef vm_offset_t ipc_kobject_t; diff --git a/kern/syscall_emulation.h b/kern/syscall_emulation.h index 501b0a83..bf20e441 100644 --- a/kern/syscall_emulation.h +++ b/kern/syscall_emulation.h @@ -33,6 +33,7 @@ #ifndef __ASSEMBLER__ #include #include +#include typedef vm_offset_t eml_routine_t; @@ -56,6 +57,11 @@ typedef vm_offset_t *emulation_vector_t; /* Variable-length array */ #define EML_MOD (err_kern|err_sub(2)) #define EML_BAD_TASK (EML_MOD|0x0001) #define EML_BAD_CNT (EML_MOD|0x0002) + +extern void eml_init(void); +extern void eml_task_reference(task_t task, task_t parent); +extern void eml_task_deallocate(task_t task); + #endif /* __ASSEMBLER__ */ #endif /* _KERN_SYSCALL_EMULATION_H_ */ diff --git a/kern/task.c b/kern/task.c index f62e47be..933a90e8 100644 --- a/kern/task.c +++ b/kern/task.c @@ -47,16 +47,13 @@ #include #include /* for thread_wakeup */ #include +#include #include /* for kernel_map, ipc_kernel_map */ #include /* for splsched */ task_t kernel_task = TASK_NULL; struct kmem_cache task_cache; -extern void eml_init(void); -extern void eml_task_reference(task_t, task_t); -extern void eml_task_deallocate(task_t); - void task_init(void) { kmem_cache_init(&task_cache, "task", sizeof(struct task), 0, -- cgit v1.2.3 From 5eb7693cd909511308b6c2828686d51375a3506a Mon Sep 17 00:00:00 2001 From: Marin Ramesa Date: Sat, 30 Nov 2013 11:16:01 +0100 Subject: Add comments after endifs * device/cons.c [MACH_KMSG]: Likewise. [CONSBUFSIZE > 0]: Likewise. * i386/i386/trap.c [MACH_KDB]: Likewise. [MACH_PV_PAGETABLES]: Likewise. * i386/i386at/kd.c [ENABLE_IMMEDIATE_CONSOLE]: Likewise. * ipc/ipc_kmsg_queue.h [_IPC_KMSG_QUEUE_H_]: Likewise. * kern/act.c [ACTWATCH]: Likewise. * kern/refcount.h [MACHINE_REFCOUNT]: Likewise. * kern/task.c [FAST_TAS]: Likewise. --- device/cons.c | 8 ++++---- i386/i386/trap.c | 8 ++++---- i386/i386at/kd.c | 2 +- ipc/ipc_kmsg_queue.h | 2 +- kern/act.c | 2 +- kern/refcount.h | 2 +- kern/task.c | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) (limited to 'kern/task.c') diff --git a/device/cons.c b/device/cons.c index ceba7f24..b35e79f4 100644 --- a/device/cons.c +++ b/device/cons.c @@ -30,7 +30,7 @@ #ifdef MACH_KMSG #include #include -#endif +#endif /* MACH_KMSG */ static boolean_t cn_inited = FALSE; static struct consdev *cn_tab = 0; /* physical console device info */ @@ -55,7 +55,7 @@ void (*romputc)() = 0; static char consbuf[CONSBUFSIZE] = { 0 }; static char *consbp = consbuf; static boolean_t consbufused = FALSE; -#endif +#endif /* CONSBUFSIZE > 0 */ void cninit() @@ -108,7 +108,7 @@ cninit() } while (cbp != consbp); consbufused = FALSE; } -#endif +#endif /* CONSBUFSIZE > 0 */ cn_inited = TRUE; return; } @@ -180,5 +180,5 @@ cnputc(c) if (consbp >= &consbuf[CONSBUFSIZE]) consbp = consbuf; } -#endif +#endif /* CONSBUFSIZE > 0 */ } diff --git a/i386/i386/trap.c b/i386/i386/trap.c index e104e122..ccbc94cc 100644 --- a/i386/i386/trap.c +++ b/i386/i386/trap.c @@ -400,7 +400,7 @@ printf("user trap %d error %d sub %08x\n", type, code, subcode); if (kdb_trap(type, regs->err, regs)) return 0; } -#endif +#endif /* MACH_KDB */ exc = EXC_BREAKPOINT; code = EXC_I386_SGL; break; @@ -422,7 +422,7 @@ printf("user trap %d error %d sub %08x\n", type, code, subcode); return 0; } } -#endif +#endif /* MACH_KDB */ exc = EXC_BREAKPOINT; code = EXC_I386_BPT; break; @@ -521,7 +521,7 @@ printf("user trap %d error %d sub %08x\n", type, code, subcode); } return 0; } -#endif +#endif /* MACH_PV_PAGETABLES */ case T_FLOATING_POINT_ERROR: fpexterrflt(); @@ -647,4 +647,4 @@ interrupted_pc(t) iss = USER_REGS(t); return iss->eip; } -#endif /* MACH_PCSAMPLE > 0*/ +#endif /* MACH_PCSAMPLE > 0 */ diff --git a/i386/i386at/kd.c b/i386/i386at/kd.c index 5605257f..def8a0ce 100644 --- a/i386/i386at/kd.c +++ b/i386/i386at/kd.c @@ -1197,7 +1197,7 @@ kdinit() screen rather than at the cursor position, so that's where we should start. */ kd_setpos(ONE_PAGE - ONE_LINE); printf("\n"); -#endif +#endif /* ENABLE_IMMEDIATE_CONSOLE */ cnsetleds(kd_state = KS_NORMAL); /* clear the LEDs AFTER we diff --git a/ipc/ipc_kmsg_queue.h b/ipc/ipc_kmsg_queue.h index 51ccbe24..b4b3df1d 100644 --- a/ipc/ipc_kmsg_queue.h +++ b/ipc/ipc_kmsg_queue.h @@ -27,5 +27,5 @@ #define _IPC_KMSG_QUEUE_H_ struct ipc_kmsg_queue { struct ipc_kmsg *ikmq_base; }; -#endif +#endif /* _IPC_KMSG_QUEUE_H_ */ diff --git a/kern/act.c b/kern/act.c index 321ff98d..d76fe0ef 100644 --- a/kern/act.c +++ b/kern/act.c @@ -1114,6 +1114,6 @@ get_next_act(sp) return act; } } -#endif +#endif /* ACTWATCH */ #endif /* MIGRATING_THREADS */ diff --git a/kern/refcount.h b/kern/refcount.h index 7fd6cdfb..c5275477 100644 --- a/kern/refcount.h +++ b/kern/refcount.h @@ -65,6 +65,6 @@ typedef struct RefCount RefCount; if (new_value == 0) { func; } \ MACRO_END -#endif +#endif /* MACHINE_REFCOUNT */ #endif _KERN_REFCOUNT_H_ diff --git a/kern/task.c b/kern/task.c index 933a90e8..8fe3672f 100644 --- a/kern/task.c +++ b/kern/task.c @@ -1206,6 +1206,6 @@ task_ras_control( break; } task_unlock(task); -#endif +#endif /* FAST_TAS */ return ret; } -- cgit v1.2.3 From f3593b77a6ab8550c119e0617e3dee4abf144533 Mon Sep 17 00:00:00 2001 From: Marin Ramesa Date: Mon, 16 Dec 2013 00:18:41 +0100 Subject: kern: quiet GCC warnings about set but unused variables * kern/lock.h (simple_lock_data_empty): Define. (decl_simple_lock_data, simple_unlock): Likewise. * kern/sched_prim.c (lock): Declare. [MACH_SLOCKS]: Remove #ifs. * kern/task.c (task_lock, task_unlock): Remove address operator. --- kern/lock.h | 6 ++++-- kern/sched_prim.c | 18 +++--------------- kern/task.c | 4 ++-- 3 files changed, 9 insertions(+), 19 deletions(-) (limited to 'kern/task.c') diff --git a/kern/lock.h b/kern/lock.h index 4f38ea33..a6d286a1 100644 --- a/kern/lock.h +++ b/kern/lock.h @@ -94,7 +94,9 @@ extern void check_simple_locks(void); /* * Do not allocate storage for locks if not needed. */ -#define decl_simple_lock_data(class,name) +struct simple_lock_data_empty {}; +#define decl_simple_lock_data(class,name) \ +class struct simple_lock_data_empty name; #define simple_lock_addr(lock) ((simple_lock_t)0) /* @@ -102,7 +104,7 @@ extern void check_simple_locks(void); */ #define simple_lock_init(l) #define simple_lock(l) -#define simple_unlock(l) +#define simple_unlock(l) ((void)(l)) #define simple_lock_try(l) (TRUE) /* always succeeds */ #define simple_lock_taken(l) (1) /* always succeeds */ #define check_simple_locks() diff --git a/kern/sched_prim.c b/kern/sched_prim.c index ec041fc8..8aad1462 100644 --- a/kern/sched_prim.c +++ b/kern/sched_prim.c @@ -226,9 +226,7 @@ void assert_wait( queue_t q; int index; thread_t thread; -#if MACH_SLOCKS - simple_lock_t lock; -#endif /* MACH_SLOCKS */ + decl_simple_lock_data( , *lock); spl_t s; thread = current_thread(); @@ -240,9 +238,7 @@ void assert_wait( if (event != 0) { index = wait_hash(event); q = &wait_queue[index]; -#if MACH_SLOCKS lock = &wait_lock[index]; -#endif /* MACH_SLOCKS */ simple_lock(lock); thread_lock(thread); enqueue_tail(q, &(thread->links)); @@ -284,9 +280,7 @@ void clear_wait( { int index; queue_t q; -#if MACH_SLOCKS - simple_lock_t lock; -#endif /* MACH_SLOCKS */ + decl_simple_lock_data( , *lock); event_t event; spl_t s; @@ -306,9 +300,7 @@ void clear_wait( thread_unlock(thread); index = wait_hash(event); q = &wait_queue[index]; -#if MACH_SLOCKS lock = &wait_lock[index]; -#endif /* MACH_SLOCKS */ simple_lock(lock); /* * If the thread is still waiting on that event, @@ -387,18 +379,14 @@ void thread_wakeup_prim( queue_t q; int index; thread_t thread, next_th; -#if MACH_SLOCKS - simple_lock_t lock; -#endif /* MACH_SLOCKS */ + decl_simple_lock_data( , *lock); spl_t s; int state; index = wait_hash(event); q = &wait_queue[index]; s = splsched(); -#if MACH_SLOCKS lock = &wait_lock[index]; -#endif /* MACH_SLOCKS */ simple_lock(lock); thread = (thread_t) queue_first(q); while (!queue_end(q, (queue_entry_t)thread)) { diff --git a/kern/task.c b/kern/task.c index 8fe3672f..13b3c761 100644 --- a/kern/task.c +++ b/kern/task.c @@ -761,7 +761,7 @@ kern_return_t task_info( event_info = (task_events_info_t) task_info_out; - task_lock(&task); + task_lock(task); event_info->faults = task->faults; event_info->zero_fills = task->zero_fills; event_info->reactivations = task->reactivations; @@ -769,7 +769,7 @@ kern_return_t task_info( event_info->cow_faults = task->cow_faults; event_info->messages_sent = task->messages_sent; event_info->messages_received = task->messages_received; - task_unlock(&task); + task_unlock(task); *task_info_count = TASK_EVENTS_INFO_COUNT; break; -- cgit v1.2.3 From df47f83ed98e4ce356af8d34de05b549f4f9c912 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 1 Feb 2014 02:15:05 +0100 Subject: kern: add a name field to struct task * kern/task.c (task_create): Initialize name with the address of the task. * kern/task.h (TASK_NAME_SIZE): New definition. (struct task): Add field name. --- kern/task.c | 3 +++ kern/task.h | 9 +++++++++ 2 files changed, 12 insertions(+) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 13b3c761..0b5a6f7f 100644 --- a/kern/task.c +++ b/kern/task.c @@ -45,6 +45,7 @@ #include #include #include +#include #include /* for thread_wakeup */ #include #include @@ -164,6 +165,8 @@ kern_return_t task_create( } #endif /* FAST_TAS */ + snprintf (new_task->name, sizeof new_task->name, "%p", new_task); + ipc_task_enable(new_task); *child_task = new_task; diff --git a/kern/task.h b/kern/task.h index e8520331..7ae10cde 100644 --- a/kern/task.h +++ b/kern/task.h @@ -48,6 +48,13 @@ #include #include +/* + * Task name buffer size. The size is chosen so that struct task fits + * into three cache lines. The size of a cache line on a typical CPU + * is 64 bytes. + */ +#define TASK_NAME_SIZE 32 + struct task { /* Synchronization/destruction information */ decl_simple_lock_data(,lock) /* Task's lock */ @@ -113,6 +120,8 @@ struct task { natural_t cow_faults; /* copy-on-write faults counter */ natural_t messages_sent; /* messages sent counter */ natural_t messages_received; /* messages received counter */ + + char name[TASK_NAME_SIZE]; }; #define task_lock(task) simple_lock(&(task)->lock) -- cgit v1.2.3 From de74f85990dc39bc6723f046f83d4e53c45f4343 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sat, 1 Feb 2014 02:23:07 +0100 Subject: kern: implement task_set_name task_set_name sets the name of a task. This is a debugging aid. The name will be used in error messages printed by the kernel. * kern/task.c (task_set_name): New function. * kern/task.h (task_set_name): New declaration. --- kern/task.c | 17 +++++++++++++++++ kern/task.h | 4 ++++ 2 files changed, 21 insertions(+) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 0b5a6f7f..66eb25ce 100644 --- a/kern/task.c +++ b/kern/task.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1070,6 +1071,22 @@ task_priority( return ret; } +/* + * task_set_name + * + * Set the name of task TASK to NAME. This is a debugging aid. + * NAME will be used in error messages printed by the kernel. + */ +kern_return_t +task_set_name( + task_t task, + kernel_debug_name_t name) +{ + strncpy(task->name, name, sizeof task->name - 1); + task->name[sizeof task->name - 1] = '\0'; + return KERN_SUCCESS; +} + /* * task_collect_scan: * diff --git a/kern/task.h b/kern/task.h index 7ae10cde..3c10dc0c 100644 --- a/kern/task.h +++ b/kern/task.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -169,6 +170,9 @@ extern kern_return_t task_assign( extern kern_return_t task_assign_default( task_t task, boolean_t assign_threads); +extern kern_return_t task_set_name( + task_t task, + kernel_debug_name_t name); extern void consider_task_collect(void); /* -- cgit v1.2.3 From e4b4e64ba7d2679df6508f27ce75d90cba7f5cb5 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Mon, 9 Jun 2014 15:12:03 +0200 Subject: kern: set the name of the kernel task to 'gnumach' * kern/taks.c (task_init): Set the name of the kernel task to 'gnumach'. --- kern/task.c | 1 + 1 file changed, 1 insertion(+) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 66eb25ce..20acc6ac 100644 --- a/kern/task.c +++ b/kern/task.c @@ -70,6 +70,7 @@ void task_init(void) * for other initialization. (:-() */ (void) task_create(TASK_NULL, FALSE, &kernel_task); + (void) task_set_name(kernel_task, "gnumach"); } kern_return_t task_create( -- cgit v1.2.3 From be05086a4b9de42ba7c596905e8980d8713eae49 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 7 Dec 2014 23:05:48 +0100 Subject: Fix pthread_create warning on translator termination This was due to task_terminate not actually properly suspending threads before disable the task port, which was thus preventing pthread_create from being able to create a stack. Thanks Gabriele Giacone for finding out a reproducer of this. * kern/task.h (task_hold_locked): New declaration. * kern/task.c (task_hold): Move the locked part of the code into... (task_hold_locked): ... new function. (task_terminate): Call task_hold_locked just before deactivating the task. Call ipc_task_disable after waiting for threads to actually suspend with task_dowait. --- kern/task.c | 37 ++++++++++++++++++++++++++++--------- kern/task.h | 1 + 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 20acc6ac..44963c68 100644 --- a/kern/task.c +++ b/kern/task.c @@ -272,6 +272,7 @@ kern_return_t task_terminate( thread_terminate(cur_thread); return KERN_FAILURE; } + task_hold_locked(task); task->active = FALSE; queue_remove(list, cur_thread, thread_t, thread_list); thread_unlock(cur_thread); @@ -325,6 +326,7 @@ kern_return_t task_terminate( task_unlock(task); return KERN_FAILURE; } + task_hold_locked(task); task->active = FALSE; task_unlock(task); } @@ -335,9 +337,8 @@ kern_return_t task_terminate( * If this is the current task, the current thread will * be left running. */ - ipc_task_disable(task); - (void) task_hold(task); (void) task_dowait(task,TRUE); /* may block */ + ipc_task_disable(task); /* * Terminate each thread in the task. @@ -402,20 +403,18 @@ kern_return_t task_terminate( * Suspend execution of the specified task. * This is a recursive-style suspension of the task, a count of * suspends is maintained. + * + * CONDITIONS: the task is locked and active. */ -kern_return_t task_hold( +void task_hold_locked( task_t task) { queue_head_t *list; thread_t thread, cur_thread; - cur_thread = current_thread(); + assert(task->active); - task_lock(task); - if (!task->active) { - task_unlock(task); - return KERN_FAILURE; - } + cur_thread = current_thread(); task->suspend_count++; @@ -429,6 +428,26 @@ kern_return_t task_hold( if (thread != cur_thread) thread_hold(thread); } +} + +/* + * task_hold: + * + * Suspend execution of the specified task. + * This is a recursive-style suspension of the task, a count of + * suspends is maintained. + */ +kern_return_t task_hold( + task_t task) +{ + task_lock(task); + if (!task->active) { + task_unlock(task); + return KERN_FAILURE; + } + + task_hold_locked(task); + task_unlock(task); return KERN_SUCCESS; } diff --git a/kern/task.h b/kern/task.h index 3c10dc0c..2a4c28fc 100644 --- a/kern/task.h +++ b/kern/task.h @@ -182,6 +182,7 @@ extern void consider_task_collect(void); extern void task_init(void); extern void task_reference(task_t); extern void task_deallocate(task_t); +extern void task_hold_locked(task_t); extern kern_return_t task_hold(task_t); extern kern_return_t task_dowait(task_t, boolean_t); extern kern_return_t task_release(task_t); -- cgit v1.2.3 From 8c4d15d5b824fd02bd6909f6d254828732f3bb7b Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Tue, 4 Nov 2014 18:46:42 +0100 Subject: kern: provide notifications about new tasks These notifications are sent to the port registered via `register_new_task_notification' and provide a robust parental relation between tasks to a userspace server. * Makefrag.am: Add task_notify.defs. * include/mach/gnumach.defs: Add register_new_task_notification. * include/mach/task_notify.defs: New file. * kern/task.c (new_task_notification): New variable. (task_create): Send new task notifications. (register_new_task_notification): Add server function. * kern/task_notify.cli: New file. --- Makefrag.am | 8 ++++++++ include/mach/gnumach.defs | 8 ++++++++ include/mach/task_notify.defs | 36 ++++++++++++++++++++++++++++++++++++ kern/task.c | 33 +++++++++++++++++++++++++++++++++ kern/task_notify.cli | 7 +++++++ 5 files changed, 92 insertions(+) create mode 100644 include/mach/task_notify.defs create mode 100644 kern/task_notify.cli (limited to 'kern/task.c') diff --git a/Makefrag.am b/Makefrag.am index 5e98b219..410f56d6 100644 --- a/Makefrag.am +++ b/Makefrag.am @@ -364,6 +364,7 @@ include_mach_HEADERS = \ include/mach/mach.defs \ include/mach/mach4.defs \ include/mach/gnumach.defs \ + include/mach/task_notify.defs \ include/mach/mach_host.defs \ include/mach/mach_port.defs \ include/mach/mach_types.defs \ @@ -488,6 +489,13 @@ nodist_libkernel_a_SOURCES += \ # device/device_reply.user.defs # device/memory_object_reply.user.defs +nodist_lib_dep_tr_for_defs_a_SOURCES += \ + kern/task_notify.user.defs.c +nodist_libkernel_a_SOURCES += \ + kern/task_notify.user.h \ + kern/task_notify.user.c \ + kern/task_notify.user.msgids + # Server stubs. nodist_lib_dep_tr_for_defs_a_SOURCES += \ device/device.server.defs.c \ diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs index 6cfbb0d0..bac3b097 100644 --- a/include/mach/gnumach.defs +++ b/include/mach/gnumach.defs @@ -72,3 +72,11 @@ simpleroutine thread_terminate_release( simpleroutine task_set_name( task : task_t; name : kernel_debug_name_t); + +/* + * Register a port to which a notification about newly created tasks + * are sent. + */ +routine register_new_task_notification( + host_priv : host_priv_t; + notification : mach_port_send_t); diff --git a/include/mach/task_notify.defs b/include/mach/task_notify.defs new file mode 100644 index 00000000..5485d4e3 --- /dev/null +++ b/include/mach/task_notify.defs @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 Free Software Foundation + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +subsystem +#if KERNEL_SERVER + KernelServer +#endif /* KERNEL_SERVER */ +#if KERNEL_USER + KernelUser +#endif /* KERNEL_USER */ + task_notify 4400; + +#include +#include + +/* These notifications are sent to the port registered via + `register_new_task_notification' and provide a robust parental + relation between tasks. */ +simpleroutine mach_notify_new_task( + notify : mach_port_t; + task : task_t; + parent : task_t); diff --git a/kern/task.c b/kern/task.c index 44963c68..a11fb8ee 100644 --- a/kern/task.c +++ b/kern/task.c @@ -50,12 +50,16 @@ #include /* for thread_wakeup */ #include #include +#include #include /* for kernel_map, ipc_kernel_map */ #include /* for splsched */ task_t kernel_task = TASK_NULL; struct kmem_cache task_cache; +/* Where to send notifications about newly created tasks. */ +ipc_port_t new_task_notification = NULL; + void task_init(void) { kmem_cache_init(&task_cache, "task", sizeof(struct task), 0, @@ -169,6 +173,14 @@ kern_return_t task_create( snprintf (new_task->name, sizeof new_task->name, "%p", new_task); + if (new_task_notification != NULL) { + task_reference (new_task); + task_reference (parent_task); + mach_notify_new_task (new_task_notification, + convert_task_to_port (new_task), + convert_task_to_port (parent_task)); + } + ipc_task_enable(new_task); *child_task = new_task; @@ -1249,3 +1261,24 @@ task_ras_control( #endif /* FAST_TAS */ return ret; } + +/* + * register_new_task_notification + * + * Register a port to which a notification about newly created + * tasks are sent. + */ +kern_return_t +register_new_task_notification( + const host_t host, + ipc_port_t notification) +{ + if (host == HOST_NULL) + return KERN_INVALID_HOST; + + if (new_task_notification != NULL) + return KERN_NO_ACCESS; + + new_task_notification = notification; + return KERN_SUCCESS; +} diff --git a/kern/task_notify.cli b/kern/task_notify.cli new file mode 100644 index 00000000..c6c85d99 --- /dev/null +++ b/kern/task_notify.cli @@ -0,0 +1,7 @@ +/* XXX */ + +/* This is a client presentation file. */ + +#define KERNEL_USER 1 + +#include -- cgit v1.2.3 From fe820bd2e22e5a0b5aa5bd50de3b06759e42af78 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Thu, 16 Oct 2014 18:13:39 +0200 Subject: kern: inherit the name of the parent task * kern/task.c (task_create): Inherit the name of the parent task. --- kern/task.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index a11fb8ee..57e7f413 100644 --- a/kern/task.c +++ b/kern/task.c @@ -171,7 +171,12 @@ kern_return_t task_create( } #endif /* FAST_TAS */ - snprintf (new_task->name, sizeof new_task->name, "%p", new_task); + if (parent_task == TASK_NULL) + snprintf (new_task->name, sizeof new_task->name, "%p", + new_task); + else + snprintf (new_task->name, sizeof new_task->name, "(%.*s)", + sizeof new_task->name - 3, parent_task->name); if (new_task_notification != NULL) { task_reference (new_task); -- cgit v1.2.3 From 82305c623900ce30a666bd14ae6901a1bf149bb7 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Sun, 26 Apr 2015 15:35:43 +0200 Subject: kern: gracefully handle resource shortage * kern/task.c (task_create): Gracefully handle resource shortage. --- kern/task.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'kern/task.c') diff --git a/kern/task.c b/kern/task.c index 57e7f413..dcd53712 100644 --- a/kern/task.c +++ b/kern/task.c @@ -89,9 +89,8 @@ kern_return_t task_create( #endif new_task = (task_t) kmem_cache_alloc(&task_cache); - if (new_task == TASK_NULL) { - panic("task_create: no memory for task structure"); - } + if (new_task == TASK_NULL) + return KERN_RESOURCE_SHORTAGE; /* one ref for just being alive; one for our caller */ new_task->ref_count = 2; -- cgit v1.2.3 From 99a43d36c83d318f24edd8c6d80f060686a6c398 Mon Sep 17 00:00:00 2001 From: Justus Winter <4winter@informatik.uni-hamburg.de> Date: Fri, 29 May 2015 14:44:39 +0200 Subject: kern: fix argument handling Previously, the processor argument was not checked. If called with a non-processor argument (like a task), `processor' is set to NULL, triggering a page fault. Likewise for the other functions. * kern/processor.c (processor_get_assignment): Fix argument handling. * kern/task.c (task_get_assignment): Likewise. * kern/thread.c (thread_get_assignment): Likewise. --- kern/processor.c | 2 ++ kern/task.c | 3 +++ kern/thread.c | 3 +++ 3 files changed, 8 insertions(+) (limited to 'kern/task.c') diff --git a/kern/processor.c b/kern/processor.c index 865c3247..48e92731 100644 --- a/kern/processor.c +++ b/kern/processor.c @@ -657,6 +657,8 @@ processor_get_assignment( processor_set_t *pset) { int state; + if (processor == PROCESSOR_NULL) + return KERN_INVALID_ARGUMENT; state = processor->state; if (state == PROCESSOR_SHUTDOWN || state == PROCESSOR_OFF_LINE) diff --git a/kern/task.c b/kern/task.c index dcd53712..b384347f 100644 --- a/kern/task.c +++ b/kern/task.c @@ -1063,6 +1063,9 @@ kern_return_t task_get_assignment( task_t task, processor_set_t *pset) { + if (task == TASK_NULL) + return KERN_INVALID_ARGUMENT; + if (!task->active) return KERN_FAILURE; diff --git a/kern/thread.c b/kern/thread.c index f52c95b8..8b1e9f58 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -1974,6 +1974,9 @@ kern_return_t thread_get_assignment( thread_t thread, processor_set_t *pset) { + if (thread == THREAD_NULL) + return KERN_INVALID_ARGUMENT; + *pset = thread->processor_set; pset_reference(*pset); return KERN_SUCCESS; -- cgit v1.2.3