[Kos-cvs] kos/modules/task _task_uthread.c,1.23,1.24

thomas at kos.enix.org thomas at kos.enix.org
Sun Jan 16 15:19:30 CET 2005


Update of /home/kos/cvs/kos/modules/task
In directory the-doors:/tmp/cvs-serv1655/modules/task

Modified Files:
	_task_uthread.c 
Log Message:
2005-01-16  Thomas Petazzoni  <thomas at crazy.kos.nx>

	* modules/task/_task_uthread.c (create_user_thread): struct thread
	was not initialized to zero, leading to bugs discovered by David
	Mentré.



Index: _task_uthread.c
===================================================================
RCS file: /home/kos/cvs/kos/modules/task/_task_uthread.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- _task_uthread.c	26 Dec 2003 11:27:37 -0000	1.23
+++ _task_uthread.c	16 Jan 2005 14:19:28 -0000	1.24
@@ -17,7 +17,7 @@
 #include <arch/mm/mm.h>
 #include <kos/macros.h>
 
-struct thread *create_user_thread(struct team *team, 
+struct thread *create_user_thread(struct team *team,
 				  size_t rq_stack_size,
 				  user_thread_fct_t *ut)
 {
@@ -33,15 +33,17 @@
   new_user_thread = kmalloc(sizeof(struct thread));
   CONCEPTION_ASSERT(new_user_thread != NULL);
 
-  strzcpy(new_user_thread->name, "<user thread>", 
+  memset(new_user_thread, 0x0, sizeof(struct thread));
+
+  strzcpy(new_user_thread->name, "<user thread>",
 	  sizeof(new_user_thread->name));
-  
+
   new_user_thread->state = STOPPED;
   new_user_thread->type  = USER_THREAD;
 
   /* Assign thread's team */
   new_user_thread->mother_team = team;
-  
+
   write_spin_lock(kernel_thread_list_lock, flags);
 
   if (allocate_cpl0_stack(new_user_thread))
@@ -54,7 +56,7 @@
   __dbg_printk("Allocating user stack ...\n");
 
   retval = alloc_user_stack_slots(team->user_stack_slots,
-				  & stack_size, 
+				  & stack_size,
 				  & new_user_thread->user_stack_id);
   if(retval < 0)
     {
@@ -64,7 +66,7 @@
     }
 
   new_user_thread->user_stack_size = stack_size;
-  new_user_thread->user_stack_addr = USER_STACK_AREA_START 
+  new_user_thread->user_stack_addr = USER_STACK_AREA_START
     + new_user_thread->user_stack_id * USER_STACK_GRANULARITY ;
 
   __dbg_printk("USer stack allocated @ 0x%x, sz=%d for thread 0x%x\n",
@@ -73,12 +75,12 @@
 	       new_user_thread);
 
   /* Map the stack */
-  retval = as_map_ures(& team->address_space, NULL, 0, 
+  retval = as_map_ures(& team->address_space, NULL, 0,
 		       (new_user_thread->user_stack_addr
 			+ new_user_thread->user_stack_size - PAGE_SIZE),
 		       PAGE_SIZE,
 		       MAP_PRIVATE, VM_ACCESS_READ | VM_ACCESS_WRITE,
-		       (MAP_FIXED | MAP_ANONYMOUS | MAP_GROWSDOWN), 
+		       (MAP_FIXED | MAP_ANONYMOUS | MAP_GROWSDOWN),
 		       & stack_addr);
 
   if(retval < 0)
@@ -87,9 +89,9 @@
 			    new_user_thread->user_stack_id);
       unallocate_cpl0_stack(new_user_thread);
       write_spin_unlock(kernel_thread_list_lock, flags);
-      return NULL;      
+      return NULL;
     }
-			      
+
   register_thread (new_user_thread, team);
   init_user_thread_context (new_user_thread, ut);
   new_user_thread->state = READY;
@@ -99,7 +101,7 @@
   as_dump(&get_current_team()->address_space);
 
   write_spin_unlock(kernel_thread_list_lock, flags);
-  
+
   return new_user_thread;
 }
 
@@ -113,18 +115,18 @@
 {
   struct thread *new;
   k_ui32_t flags;
-  
+
   new = kmalloc(sizeof(struct thread));
   CONCEPTION_ASSERT(new != NULL);
 
   strzcpy(new->name, t->name, sizeof(new->name));
-  
+
   new->state = STOPPED;
   new->type  = USER_THREAD;
 
   /* Assign thread's team */
   new->mother_team = to;
-  
+
   write_spin_lock(kernel_thread_list_lock, flags);
 
   if (allocate_cpl0_stack(new))
@@ -137,7 +139,7 @@
   new->user_stack_size = t->user_stack_size;
   new->user_stack_addr = t->user_stack_addr;
   new->user_stack_id   = t->user_stack_id;
-  
+
   register_thread (new, to);
   copy_user_thread_context (t, new);
 
@@ -145,7 +147,7 @@
   scheduler_register_ready_thread(new);
 
   write_spin_unlock(kernel_thread_list_lock, flags);
-  
+
   return ESUCCESS;
 }
 



More information about the Kos-cvs mailing list