]> git.corax.cc Git - corax/commitdiff
Protect tasks with a spinlock
authorMatthias Kruk <m@m10k.eu>
Mon, 25 Nov 2019 05:36:15 +0000 (14:36 +0900)
committerMatthias Kruk <m@m10k.eu>
Mon, 25 Nov 2019 05:36:15 +0000 (14:36 +0900)
kernel/arch/defs.h
kernel/arch/task.S
kernel/include/arch.h

index 42bfaa8e4a7f19fc3b0449c1f81f2accd31e45dc..161568efa0810f4c096b2b77ac1f98c482b8a3c5 100644 (file)
@@ -77,6 +77,7 @@
 #define OFFSET_TASK_PRIVL  12
 #define OFFSET_TASK_STATE  16
 #define OFFSET_TASK_EBP0   20
+#define OFFSET_TASK_LOCK   24
 
 #define CPU_SIZE           (TSS_OFFSET + TSS_SIZE + 4)
 #define OFFSET_CPU_CTASK   (TSS_OFFSET + TSS_SIZE)
index 1897a6dad94d8d955f977fd9f743c8cd63b13d04..fb55a2754a564055b01c11dcb856e3f320978dad 100644 (file)
@@ -30,6 +30,8 @@
 .global task_get_current
 .global task_set_current
 .global task_move_stack
+.global task_lock
+.global task_unlock
 
 task_prepare:
        /*
@@ -484,3 +486,15 @@ task_move_stack:
 
        /* Stacks have been copied and stack pointers updated. We're done. */
 4:     ret
+
+task_lock:
+       addl    $OFFSET_TASK_LOCK, 4(%esp)
+       call    spinlock_lock
+       subl    $OFFSET_TASK_LOCK, 4(%esp)
+       ret
+
+task_unlock:
+       addl    $OFFSET_TASK_LOCK, 4(%esp)
+       call    spinlock_unlock
+       subl    $OFFSET_TASK_LOCK, 4(%esp)
+       ret
index 522e0dcc9d61da8a194d4c5d7177d7576b8d44ca..9ae6dfa72ecf296ea3077d66f3f2922c86876fe3 100644 (file)
@@ -30,6 +30,7 @@
 #ifndef __ASSEMBLY_SOURCE
 
 #include <corax/types.h>
+#include <spinlock.h>
 
 typedef struct stack_frame stack_frame_t;
 
@@ -62,6 +63,7 @@ struct task {
        u32_t t_privl;
        u32_t t_state;
        u32_t t_bp;
+       spinlock_t t_lock;
 
        u32_t t_tslice;
        u32_t t_rslice;
@@ -108,6 +110,9 @@ task_t* task_get_current(void);
 void    task_set_current(task_t*);
 void    task_move_stack(void*, void*, u32_t);
 
+void    task_lock(task_t*);
+int     task_unlock(task_t*);
+
 /*
  * Definitions, types, and prototypes related to paging
  */