[Kos-cvs] kos/modules/task _task_kres.c, 1.4, 1.5 _task_kstack.c, 1.24, 1.25 _task_kthread.c, 1.24, 1.25 _task_team.c, 1.14, 1.15 _task_ures.c, 1.3, 1.4 _task_utils.c, 1.23, 1.24 task.h, 1.41, 1.42

thomas at kos.enix.org thomas at kos.enix.org
Tue Dec 28 19:44:52 CET 2004


Update of /var/cvs/kos/kos/modules/task
In directory the-doors:/tmp/cvs-serv10813/modules/task

Modified Files:
	_task_kres.c _task_kstack.c _task_kthread.c _task_team.c 
	_task_ures.c _task_utils.c task.h 
Log Message:
2004-12-28  Thomas Petazzoni  <thomas at crazy.kos.nx>

	* modules/x86/task/task.c: Try to restrict access to exported
	symbol.

	* modules/x86/task/_thread_cpu_context.c: Move to the new PMM
	system.

	* modules/x86/task/Makefile (all): arch_task.ro instead of
	arch-task.ro.

	* modules/x86/mm/_team_mm_context.c: More informations.

	* modules/x86/mm/_mm.h, modules/x86/mm/mm.c, modules/x86/mm/_rmap.c,
	modules/x86/mm/_vmap.c: The new VMAP/RMAP system. We also make
	sure access to all exported function is restricted to the VMM
	module. 

	* modules/x86/mm/Makefile (all): arch_mm.ro instead of
	arch-mm.ro. 

	* modules/x86/lib/Makefile (all): Rename to arch_lib.ro instead of
	arch-lib.ro. 

	* modules/x86/internals.h: More definitions on the address space
	configuration. 

	* modules/vmm/vmm.h (struct address_space): Add a mutex and a
	spinlock to protect address space.

	* modules/vmm/vmm.c: Restrict access to some exported
	functions. More work has to be done in this area.

	* modules/vmm/_vmm_map.c: Part of the new vmap system.

	* modules/vmm/_vmm_as.c: Make the appropriate lock/unlock on the
	address space mutex. It's just a first try. More reflexion has to
	be made.

	* modules/task/task.h: Make sure DOXYGEN doesn't try to analyze
	the #if stuff, because it doesn't like it.

	* modules/task/_task_utils.c (show_all_thread_info): If team is
	NULL, it means that we want to display the threads of all teams.

	* modules/scheduler/synchq.h: Avoid inclusion of task.h.

	* modules/pmm/pmm.c: New PMM system.

	* modules/pmm/_pmm_put_page.c: New PMM system.

	* modules/pmm/_pmm_init.c: New PMM system.

	* modules/pmm/_pmm_get_page.c: New PMM system.

	* modules/pmm/_pmm_get_at_addr.c: New PMM system.

	* modules/pmm/_pmm.h: struct gpfme is now private.

	* modules/pmm/pmm.h: struct gpfme is now private (migrated to
	_pmm.h). 

	* modules/pmm/Makefile (OBJS): New PMM system, with fewer
	functionnalities. 

	* modules/kos/spinlock.h: New type spinlock_flags_t, that should
	be used instead of k_ui32_t for spinlock flags.

	* modules/kmem/_kvmem_utils.c: Migration to the new PMM
	system and various cleanups.

	* modules/kmem/_kvmem_init.c: Migration to the new PMM
	system and various cleanups.

	* modules/kmem/_kslab_cache_grow.c: Migration to the new PMM
	system and various cleanups.

	* modules/kmem/_kslab_cache_free.c: Migration to the new PMM
	system, and various cleanups.

	* modules/kitc/_kmutex.c: DEBUG_PRINT3 calls to show mutex
	lock/unlock/trylock.

	* modules/init/_init_modules.c (init_modules): A message is
	displayed when initializating modules.

	* modules/ide/_ide.c: Various cleanups.

	* modules/fs/fat/_fat.c: Various cleanups.

	* modules/fs/devfs/devfs.c: Various cleanups, including whitespace
	cleanification.

	* modules/debug/debug.h: Add the DEBUG_PRINT1, DEBUG_PRINT2,
	DEBUG_PRINT3 macros. Maybe there's a cleaner way to do it. David ?

	* modules/debug/debug.c (init_module_level0): Init the
	backtracking stuff a little later so that we have debugging
	messages during this initialization.

	* modules/debug/bt.c (_init_backtracing_stuff): bt_next is not
	anymore a valid candidate to determine if fomit-frame-pointer was
	selected or not, because of gcc optimizations. We use bt_init
	instead.

	* modules/Makefile (doc): Add a target that generates the doxygen
	documentation. 

	* loader/mod.h (EXPORT_FUNCTION_RESTRICTED): Change the symbol
	names generated by the macros, so that they include the name of
	the target module (the one allowed to import the exported
	symbol). This is needed in order to export the same symbol to
	multiple modules. Previously, the RESTRICTED system generated
	symbols that were identical for a given symbol exported to
	multiple modules.

	* doc/testingfr.tex: A big update to this documentation. Not
	finished. The english version should also be updated.

	* TODO: Some new things to do.

	* MkVars (CFLAGS): Pass the DEBUG_LEVEL Makefile variable to the C
	files. In each modules/.../Makefile, we can set a
	DEBUG_LEVEL=value that will set the level of verbosity of the
	module. Macros named DEBUG_PRINT1, DEBUG_PRINT2, DEBUG_PRINT3 have
	been added.
	(MODULES): Change all '-' to '_', because of the new
	EXPORT_FUNCTION_RESTRICTED system. This system creates symbol that
	contains the name of a module (the one allowed to import the
	exported symbol). But the '-' character is not allowed inside C
	identifiers. So, we use '_' instead.

	* CREDITS: Add Fabrice Bellard to the CREDITS, for his Qemu
	emulator.



Index: _task_utils.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_utils.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- _task_utils.c	26 Dec 2003 11:27:37 -0000	1.23
+++ _task_utils.c	28 Dec 2004 18:44:49 -0000	1.24
@@ -51,7 +51,7 @@
   read_spin_lock(kernel_thread_list_lock, flags);
   list_foreach_forward_named(thread_global_list, thread, nb_elements, prev_global, next_global)
     {
-      if(thread->mother_team != team)
+      if(team != NULL && thread->mother_team != team)
 	{
 	  continue;
 	}

Index: _task_team.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_team.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- _task_team.c	29 Dec 2003 13:42:51 -0000	1.14
+++ _task_team.c	28 Dec 2004 18:44:49 -0000	1.15
@@ -30,11 +30,11 @@
   new = kslab_cache_alloc(kmem_team_cache);
   if(new == NULL)
     return NULL;
-  
+
   new->thread_list  = NULL;
   new->pid          = last_pid++;
   new->parent       = parent;
-  new->thread_count = 0; 
+  new->thread_count = 0;
 
   for (i = 0; i < MAX_RD_PER_TEAM; i++)
     {
@@ -48,13 +48,18 @@
       return NULL;
     }
 
+  __dbg_printk("[create_team] Calling as_init(0x%x, 0x%x)\n",
+	       & new->address_space, new);
+
   retval = as_init(& new->address_space, new);
   if(retval < 0)
     {
       kslab_cache_free(kmem_team_cache, new);
       return NULL;
     }
-  
+
+  __dbg_printk("[create_team] After the call to as_init()\n");
+
   write_spin_lock(kernel_team_list_lock, flags);
 
   list_add_tail(team_global_list, new);
@@ -70,7 +75,7 @@
   RETURN_VAL_IF_FAIL_VERBOSE(team == get_kernel_team(), -1);
 
   TBI("Virer le mm_context du team + team de la liste");
-  
+
   return 0;
 }
 
@@ -86,9 +91,9 @@
   team = get_current_team();
 
   CONCEPTION_ASSERT(team != NULL);
-  
+
   *pid = team->pid;
-  
+
   return ESUCCESS;
 }
 
@@ -104,16 +109,16 @@
   team = get_current_team();
 
   CONCEPTION_ASSERT(team != NULL);
-  
+
   if(team->parent)
     {
       *pid = team->parent->pid;
     }
-  else 
+  else
     {
       *pid = 0;
     }
-  
+
   return ESUCCESS;
 }
 
@@ -139,6 +144,8 @@
       return -EPERM;
     }
 
+  __dbg_printk("[_task_fork] Create_team()\n");
+
   team = create_team(current_team);
   if(team == NULL)
     {
@@ -146,6 +153,8 @@
       return -ENOMEM;
     }
 
+  __dbg_printk("[_task_fork] ures_array_copy()\n");
+
   result = ures_array_copy(current_team->ures_array, team->ures_array);
   if(result < 0)
     {
@@ -153,6 +162,8 @@
       return result;
     }
 
+  __dbg_printk("[_task_fork] as_copy()\n");
+
   result = as_copy(& current_team->address_space, team);
   if(result < 0)
     {
@@ -160,7 +171,9 @@
       return result;
     }
 
-  result = copy_stack_slots(current_team->user_stack_slots, 
+  __dbg_printk("[_task_fork] copy_stack_slots\n");
+
+  result = copy_stack_slots(current_team->user_stack_slots,
 			    team->user_stack_slots);
   if(result < 0)
     {
@@ -168,6 +181,10 @@
       return result;
     }
 
+  as_dump(& team->address_space);
+
+  __dbg_printk("[_task_fork] Copy_user_thread()\n");
+
   result = copy_user_thread(current_team->thread_list, team);
   if(result < 0)
     {
@@ -175,8 +192,6 @@
       return result;
     }
 
-  as_dump(& team->address_space);
-
   return team->pid;
 }
 
@@ -195,7 +210,7 @@
   int i;
 
   show_all_thread_info(get_current_team());
-  
+
   if(file == NULL || argv == NULL || envp == NULL)
     {
       return -EINVAL;
@@ -213,11 +228,11 @@
     {
       return result;
     }
-  
+
   result = as_empty(& team->address_space);
   if(result < 0)
     {
-      close(ures);
+      //      close(ures);
       return result;
     }
 
@@ -233,7 +248,7 @@
   /** Point of no return ! */
 
   /* We keep ressources 0, 1, 2 (aka standard input, standard output,
-   * error output) and ressource 3 ('process' ressource) 
+   * error output) and ressource 3 ('process' ressource)
    */
   for (i = 4; i < MAX_RD_PER_TEAM; i++)
     {
@@ -269,7 +284,7 @@
       FAILED_VERBOSE("Failure while loading file");
       return -42;
     }
-  
+
   DEBUG("[_task_team.c] update heap start @0x%x\n", binld.start_heap);
   result = as_update_heap_start(& team->address_space, binld.start_heap);
   if(result < 0)
@@ -281,19 +296,19 @@
 
   thread = team->thread_list;
 
-  __dbg_printk("Exec(%s/0x%x) : stack 0x%x sz %d\n", 
+  __dbg_printk("Exec(%s/0x%x) : stack 0x%x sz %d\n",
 	       (thread->type == KERNEL_THREAD) ? "KERNEL" : "USER",
 	       thread,
 	       thread->user_stack_addr,
 	       thread->user_stack_size);
 
   /* Map the stack */
-  result = as_map_ures(& team->address_space, NULL, 0, 
+  result = as_map_ures(& team->address_space, NULL, 0,
 		       (thread->user_stack_addr
 			+ 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(result < 0)
     {
@@ -303,8 +318,8 @@
 
   init_user_thread_context(thread,
 			   (user_thread_fct_t *) binld.entry_addr);
-  
-  DEBUG("[_task_team.c] Exec should have succeeded entry @0x%x!\n", 
+
+  DEBUG("[_task_team.c] Exec should have succeeded entry @0x%x!\n",
 	binld.entry_addr);
 
   as_dump(& get_current_team()->address_space);

Index: _task_kthread.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_kthread.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- _task_kthread.c	21 Aug 2003 23:19:28 -0000	1.24
+++ _task_kthread.c	28 Dec 2004 18:44:49 -0000	1.25
@@ -26,7 +26,9 @@
   write_spin_lock(kernel_thread_list_lock, flags);
 
   unregister_thread(thread);
+
   unallocate_cpl0_stack(thread);
+
   kfree_size_known(thread, sizeof(struct thread));
 
   write_spin_unlock(kernel_thread_list_lock, flags);

Index: _task_ures.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_ures.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- _task_ures.c	27 Oct 2003 15:37:30 -0000	1.3
+++ _task_ures.c	28 Dec 2004 18:44:49 -0000	1.4
@@ -23,13 +23,13 @@
  *
  * @return Error code.
  */
-result_t task_insert_ures(struct team *team, struct ures *ures, 
+result_t task_insert_ures(struct team *team, struct ures *ures,
 			  /*out*/ int *rd)
 {
   int i;
-  
+
   __dbg_printk("[task_insert_ures] beginning\n");
-  
+
   if(ures == NULL || rd == NULL)
     {
       return -EINVAL;
@@ -42,7 +42,7 @@
     }
 
   /* What happens here if we get interrupted, and that during that
-     time, the current team get destroyed ? 
+     time, the current team get destroyed ?
 
      Maybe we should have a more global lock, that we could hold only
      to say that we are using a team. For example :
@@ -82,14 +82,14 @@
     }
 
   /* If we didn't find a slot, exit */
-  if(i >= MAX_RD_PER_TEAM) 
+  if(i >= MAX_RD_PER_TEAM)
     {
       /* TODO : release semaphore on team */
       return -ENFILE;
     }
-  
+
   team->ures_array[i] = ures;
-  
+
   /* ures is now registered in the ures array */
   ures->ures_index    = i;
   *rd = i;
@@ -121,7 +121,7 @@
       struct thread *thread = get_current_thread();
       team   = thread->mother_team;
     }
-      
+
   /* Same remark as above */
 
   /* TODO : Take the semaphore on the team */
@@ -144,6 +144,7 @@
  *
  * @param team The team (if NULL, takes the current team)
  * @param rd   The ressource descriptor
+ * @param ures Where to return a pointer to the removed user ressource
  *
  * @return Error code.
  */
@@ -172,7 +173,7 @@
   /* ures is not anymore in the ures array */
   team->ures_array[rd]->ures_index = -1;
   *ures = team->ures_array[rd];
-  
+
   team->ures_array[rd] = NULL;
 
   return ESUCCESS;

Index: _task_kres.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_kres.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- _task_kres.c	29 Dec 2003 13:42:51 -0000	1.4
+++ _task_kres.c	28 Dec 2004 18:44:49 -0000	1.5
@@ -10,7 +10,7 @@
   return process_kres;
 }
 
-static result_t process_open(struct ures *ur, const char *pathname, 
+static result_t process_open(struct ures *ur, const char *pathname,
 			     unsigned interface, int *rd)
 {
   struct ures *ures;
@@ -23,7 +23,7 @@
       return -EINVAL;
     }
 
-  __dbg_printk("[process_open] calling open (%s, %d)\n", 
+  __dbg_printk("[process_open] calling open (%s, %d)\n",
 	       pathname, interface);
 
   result = open(pathname, interface, & ures);
@@ -76,7 +76,7 @@
 
 static result_t process_exec(struct ures *ur,
 			     const char *file,
-			     const char * const argv[], 
+			     const char * const argv[],
 			     const char * const envp[])
 {
   UNUSED(ur);
@@ -177,7 +177,7 @@
       kfree(process_kres);
       return -ENOMEM;
     }
-  
+
   memset(view, 0x0, sizeof(struct view));
   view->iid          = INTERFACE_PROCESS_ID;
   view->nb_ops       = INTERFACE_PROCESS_NB_OPS;

Index: _task_kstack.c
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/_task_kstack.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- _task_kstack.c	21 Aug 2003 23:19:28 -0000	1.24
+++ _task_kstack.c	28 Dec 2004 18:44:49 -0000	1.25
@@ -30,33 +30,33 @@
 void unallocate_cpl0_stack (struct thread *thread)
 {
   vaddr_t stack_start;
-  
+
   CONCEPTION_ASSERT(thread->mother_team);
 
   switch (thread->type) {
     size_t stack_index;
-    
+
   case KERNEL_THREAD:
-    stack_index = 
-      (thread->cpl0_stack_base_addr - CPL0_KERNEL_STACK_VIRTUAL_ADDR) 
+    stack_index =
+      (thread->cpl0_stack_base_addr - CPL0_KERNEL_STACK_VIRTUAL_ADDR)
       / CPL0_KERNEL_STACK_VIRTUAL_SIZE;
-    
+
     set_bit_in_bitmap ((vaddr_t) free_cpl0_kernel_stack_bitmap.data,
-		       stack_index, 1);		       
+		       stack_index, 1);
 
     stack_start = thread->cpl0_stack_base_addr;
 
-    unmap_virtual_range(thread->mother_team, stack_start, 
+    unmap_virtual_range(thread->mother_team, stack_start,
 			CPL0_KERNEL_STACK_VIRTUAL_SIZE);
 
     break;
-    
+
   case USER_THREAD:
-    stack_index = 
-      (thread->cpl0_stack_base_addr - CPL0_USER_STACK_VIRTUAL_ADDR) 
+    stack_index =
+      (thread->cpl0_stack_base_addr - CPL0_USER_STACK_VIRTUAL_ADDR)
       / CPL0_USER_STACK_VIRTUAL_SIZE;
     set_bit_in_bitmap ((vaddr_t) free_cpl0_user_stack_bitmap.data,
-		       stack_index, 1);		       
+		       stack_index, 1);
 
     stack_start = thread->cpl0_stack_base_addr;
 
@@ -64,11 +64,10 @@
 			CPL0_USER_STACK_VIRTUAL_SIZE);
 
     break;
-   
+
   default:
     FAILED_VERBOSE("Unknown thread type\n");
   }
-  
 }
 
 
@@ -81,17 +80,18 @@
 
   switch (thread->type) {
     size_t stack_index;
-    
+
   case KERNEL_THREAD:
+    __dbg_printk("Allocate CPL0 stack\n");
     stack_index = bsf_bitmap ((vaddr_t) free_cpl0_kernel_stack_bitmap.data,
 			      free_cpl0_kernel_stack_bitmap.size);
     if (stack_index > free_cpl0_kernel_stack_bitmap.size * 8)
       return -1;
-    thread->cpl0_stack_base_addr = CPL0_KERNEL_STACK_VIRTUAL_ADDR 
+    thread->cpl0_stack_base_addr = CPL0_KERNEL_STACK_VIRTUAL_ADDR
       + stack_index * CPL0_KERNEL_STACK_VIRTUAL_SIZE;
-    
+
     set_bit_in_bitmap ((vaddr_t) free_cpl0_kernel_stack_bitmap.data,
-		       stack_index, 0);		       
+		       stack_index, 0);
     for(vpage = (thread->cpl0_stack_base_addr +
 		 CPL0_KERNEL_STACK_VIRTUAL_SIZE -
 		 CPL0_KERNEL_STACK_PHYSICAL_SIZE);
@@ -99,17 +99,18 @@
 		 CPL0_KERNEL_STACK_VIRTUAL_SIZE);
 	vpage += PAGE_SIZE)
       {
-	ppage = get_physical_page(PHYS_PAGE_KERNEL, PHYS_PAGE_NON_SWAPPABLE);
+	ppage = physmem_get_page(PHYS_PAGE_KERNEL, PHYS_PAGE_NON_SWAPPABLE);
 	if(!ppage)
 	  FAILED_VERBOSE("[allocate_cpl0_stack] No more physical memory\n");
 
-	map_virtual_page(thread->mother_team, vpage, ppage, 
+	map_virtual_page(NULL, vpage, ppage,
 			 VM_ACCESS_READ | VM_ACCESS_WRITE);
       }
-    
+
+    __dbg_printk("end of allocate CPL0 stack\n");
 
     break;
-      
+
   case USER_THREAD:
     stack_index = bsf_bitmap ((vaddr_t) free_cpl0_user_stack_bitmap.data,
 			      free_cpl0_user_stack_bitmap.size);
@@ -127,7 +128,7 @@
 		 CPL0_USER_STACK_VIRTUAL_SIZE);
 	vpage += PAGE_SIZE)
       {
-	ppage = get_physical_page(PHYS_PAGE_KERNEL, PHYS_PAGE_NON_SWAPPABLE);
+	ppage = physmem_get_page(PHYS_PAGE_KERNEL, PHYS_PAGE_NON_SWAPPABLE);
 	if(!ppage)
 	  FAILED_VERBOSE("[allocate_cpl0_stack] No more physical memory\n");
 

Index: task.h
===================================================================
RCS file: /var/cvs/kos/kos/modules/task/task.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- task.h	29 Dec 2003 13:42:51 -0000	1.41
+++ task.h	28 Dec 2004 18:44:49 -0000	1.42
@@ -13,6 +13,7 @@
 
 #include <karm/ures.h>
 #include <karm/interface/process.h>
+#include <kitc/ksem.h>
 #include <vmm/vmm.h>
 #include <arch/mm/mm.h>
 #include <arch/task/task.h>
@@ -26,16 +27,23 @@
 
 #define USER_STACK_NB_SLOTS (USER_STACK_AREA_SIZE / USER_STACK_GRANULARITY)
 
+/* The following part of code is skipped if scanned by Doxygen because
+   it cannot handle it. A bug has been reported to the Debian BTS
+   October, 3rd by Thomas. */
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+
 /* 2^15 (because value in stack_slot is on 15 bits) */
-#if (USER_STACK_NB_SLOTS > 32768) 
+#if (USER_STACK_NB_SLOTS > 32768)
 #error "[user stack allocation] Failed : USER_STACK_NB_SLOTS > 2^15"
 #endif
+#endif
 
 #if (! IS_POWER_OF_2(USER_STACK_GRANULARITY))
 #error "[user stack allocation] Stack granularity is not a power of 2"
 #endif
 
-typedef enum { USER_STACK_SLOT_FREE, 
+typedef enum { USER_STACK_SLOT_FREE,
 	       USER_STACK_SLOT_USED } user_stack_slot_state_t;
 
 struct user_stack_slot



More information about the Kos-cvs mailing list