Specify the logical type of the reference in a comment near its pointer. Fix bugs...
authorcoderain <coderain@sdf.org>
Fri, 21 Jul 2017 05:59:07 +0000 (07:59 +0200)
committercoderain <coderain@sdf.org>
Fri, 21 Jul 2017 05:59:07 +0000 (07:59 +0200)
kernel/include/filesystem.h
kernel/include/memory.h
kernel/include/process.h
kernel/include/thread.h
kernel/src/memory.c
kernel/src/object.c
kernel/src/process.c

index f0c010d3ceb2f06d14e8f29de61d6e2a152f8cc2..f104596dba97889387f78ce1d9d2aac2b9b488a5 100644 (file)
@@ -114,7 +114,7 @@ typedef struct
 {
     list_entry_t list;
     lock_t lock;
-    file_instance_t *directory;
+    file_instance_t *directory; /* weak reference */
     dword_t event_mask;
     semaphore_t event_semaphore;
     list_entry_t event_queue;
@@ -134,7 +134,7 @@ struct file
 struct file_instance
 {
     object_t header;
-    file_t *global;
+    file_t *global; /* strong reference */
     dword_t mode;
     event_watch_entry_t *watch;
 };
index 556a3587f92365de21fdedc15a7598bc61a0c83c..f7b10dc34934caa851d47c4daddbee8c823d5d51 100644 (file)
@@ -131,7 +131,7 @@ typedef struct
     dword_t flags;
     list_entry_t page_list;
     size_t size;
-    file_instance_t *file;
+    file_instance_t *file; /* strong reference */
 } memory_section_t;
 
 struct memory_block
@@ -224,5 +224,6 @@ dword_t create_memory_section(const char *name, handle_t file, size_t size, dwor
 dword_t open_memory_section(const char *name, handle_t *handle);
 dword_t map_memory_section(handle_t process, handle_t section, void **address, qword_t offset, size_t size, dword_t flags);
 dword_t flush_memory_section(handle_t process, void *address);
+void memory_cleanup(object_t *obj);
 
 #endif
index 29e3ea63593f60acab82c808999634255204efb0..f2a42b79f0c1a22ae007f1ce23518227f1e37aea 100644 (file)
@@ -59,7 +59,7 @@ typedef struct thread thread_t;
 
 typedef struct
 {
-    object_t *obj;
+    object_t *obj; /* strong reference */
     access_flags_t access_flags;
 } handle_info_t;
 
@@ -79,7 +79,8 @@ struct process
     handle_info_t *handle_table;
     dword_t handle_count, handle_table_size;
     resource_t handle_table_res;
-    user_t *original_user, *current_user;
+    user_t *original_user; /* weak reference */
+    user_t *current_user; /* strong reference */
 };
 
 #ifndef PROCESS_TYPEDEF
index f55bd69039b9cd952a60ad6688412d440cbaf657..9faff1b95ab67aecbdc134ca4738807b63790461 100644 (file)
@@ -101,7 +101,7 @@ struct thread
     dword_t exit_code;
     dword_t quantum;
     qword_t running_ticks;
-    process_t *owner_process;
+    process_t *owner_process; /* weak reference */
     dword_t terminated;
     int32_t frozen;
 
index e40ec7bc8e21463c05e7de353b009be2ccb1af95..5f30af340cf46bf1266c3d243dfdb3bde0d20229 100644 (file)
@@ -812,6 +812,12 @@ static inline memory_block_t *combine_blocks_backward(memory_block_t *mem_block)
     return mem_block;
 }
 
+void memory_cleanup(object_t *obj)
+{
+    memory_section_t *section = (memory_section_t*)obj;
+    if (section->file) dereference(&section->file->header);
+}
+
 void *get_page_directory(void)
 {
     return current_page_directory;
index 01bd20961b18889ebbe56dd1b35ad9ae95318a06..277e1ef1e932dab37a0d06febb385154ffc5283f 100644 (file)
@@ -37,7 +37,7 @@ static object_cleanup_proc_t cleanup_procedures[OBJECT_TYPE_MAX] =
     pipe_cleanup,
     process_cleanup,
     NULL,
-    NULL,
+    memory_cleanup,
     NULL,
     NULL,
 };
index 5c0933d3f02793634a9084ed61054504bd209718..470a985659d6c7eb7bf5cfdfbf4c8f9b356d9967 100644 (file)
@@ -90,6 +90,7 @@ void process_cleanup(object_t *obj)
     process_t *proc = (process_t*)obj;
 
     free(proc->name);
+    dereference(&proc->current_user->header);
 
     acquire_lock(&pid_bitmap_lock);
     clear_bit(pid_alloc_bitmap, proc->pid);
@@ -259,6 +260,7 @@ dword_t create_process(const char *path, dword_t flags, process_params_t *parame
     list_init(&proc->threads);
     proc->thread_list_res = 0;
 
+    reference(&current->current_user->header);
     proc->original_user = proc->current_user = current->current_user;
 
     if (!(flags & PROCESS_CREATE_NO_INHERIT) && current != kernel_process)