Changeset 0116f21 in mainline
- Timestamp:
- 2019-07-18T15:30:31Z (5 years ago)
- Children:
- bb580548
- Parents:
- 40043e8
- git-author:
- Matthieu Riolo <matthieu.riolo@…> (2019-07-18 15:26:49)
- git-committer:
- Matthieu Riolo <matthieu.riolo@…> (2019-07-18 15:30:31)
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
abi/include/abi/syscall.h
r40043e8 r0116f21 102 102 SYS_DEBUG_CONSOLE, 103 103 104 SYS_SHUTDOWN, 105 104 106 SYS_KLOG, 105 107 -
kernel/generic/include/proc/thread.h
r40043e8 r0116f21 49 49 #include <abi/proc/thread.h> 50 50 #include <abi/sysinfo.h> 51 #include <arch.h>52 51 53 52 #define THREAD CURRENT->thread -
kernel/generic/include/shutdown.h
r40043e8 r0116f21 37 37 38 38 #include <atomic.h> 39 #include <typedefs.h> 40 41 typedef struct thread thread_t; 39 42 40 43 extern atomic_t haltstate; 44 extern thread_t *shutdown_thread; 41 45 42 46 extern void halt(void) __attribute__((noreturn)); 43 47 extern void reboot(void); 44 48 extern void arch_reboot(void); 49 extern sys_errno_t sys_shutdown(sysarg_t mode, sysarg_t delay, sysarg_t kconsole); 45 50 46 51 #endif -
kernel/generic/src/main/shutdown.c
r40043e8 r0116f21 37 37 */ 38 38 39 #include <abi/shutdown.h> 39 40 #include <shutdown.h> 40 41 #include <log.h> 41 42 #include <cpu.h> 42 #include <arch/asm.h>43 #include <arch.h>44 43 #include <console/kconsole.h> 45 #include <proc/task.h> 44 #include <console/console.h> 45 #include <proc/thread.h> 46 #include <stdlib.h> 47 48 /* pointer to the thread for the shutdown process */ 49 thread_t *shutdown_thread = NULL; 46 50 47 51 /** Halt flag */ … … 81 85 } 82 86 87 /* Reboots the kernel */ 83 88 void reboot(void) 84 89 { … … 93 98 } 94 99 100 /* argument structure for the shutdown thread */ 101 typedef struct { 102 sysarg_t mode; 103 sysarg_t delay; 104 } sys_shutdown_arg_t; 105 106 /* function for the shutdown thread */ 107 static void sys_shutdown_function(void *arguments) 108 { 109 sys_shutdown_arg_t *arg = (sys_shutdown_arg_t *)arguments; 110 111 if (arg->delay != 0) { 112 thread_sleep(arg->delay); 113 } 114 115 if (thread_interrupted(THREAD)) { 116 free(arguments); 117 return; 118 } 119 120 if (arg->mode == SHUTDOWN_REBOOT) { 121 reboot(); 122 } else { 123 halt(); 124 } 125 } 126 127 /* system call handler for shutdown */ 128 sys_errno_t sys_shutdown(sysarg_t mode, sysarg_t delay, sysarg_t kconsole) 129 { 130 131 #if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE)) 132 if (kconsole) { 133 grab_console(); 134 } 135 #endif 136 137 irq_spinlock_lock(&threads_lock, true); 138 thread_t *thread = atomic_load(&shutdown_thread); 139 if (thread != NULL) { 140 thread_interrupt(thread); 141 atomic_store(&shutdown_thread, NULL); 142 } 143 irq_spinlock_unlock(&threads_lock, true); 144 145 /* `cancel` or default has been called */ 146 if (mode != SHUTDOWN_HALT && mode != SHUTDOWN_REBOOT) { 147 return EOK; 148 } 149 150 sys_shutdown_arg_t *arg = malloc(sizeof(sys_shutdown_arg_t)); 151 if (arg == NULL) { 152 return ENOMEM; 153 } 154 155 //TODO: find a better way for accessing the kernel task 156 irq_spinlock_lock(&tasks_lock, true); 157 task_t *kernel_task = task_find_by_id(1); 158 irq_spinlock_unlock(&tasks_lock, true); 159 160 if (kernel_task == NULL) { 161 goto error; 162 } 163 164 arg->mode = mode; 165 arg->delay = delay; 166 167 thread = thread_create(sys_shutdown_function, arg, kernel_task, THREAD_FLAG_NONE, "shutdown"); 168 169 if (thread == NULL) { 170 goto error; 171 } 172 173 thread_ready(thread); 174 atomic_store(&shutdown_thread, thread); 175 return EOK; 176 177 error: 178 free(arg); 179 return ENOENT; 180 } 181 95 182 /** @} 96 183 */ -
kernel/generic/src/syscall/syscall.c
r40043e8 r0116f21 192 192 [SYS_SYSINFO_GET_DATA] = (syshandler_t) sys_sysinfo_get_data, 193 193 194 [SYS_SHUTDOWN] = (syshandler_t) sys_shutdown, 195 194 196 /* Kernel console syscalls. */ 195 197 [SYS_DEBUG_CONSOLE] = (syshandler_t) sys_debug_console,
Note:
See TracChangeset
for help on using the changeset viewer.