[2677758] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2003 Josef Cejka
|
---|
| 3 | * Copyright (c) 2005 Jakub Jermar
|
---|
[d5b37b6] | 4 | * Copyright (c) 2025 Jiří Zárevúcky
|
---|
[2677758] | 5 | * All rights reserved.
|
---|
| 6 | *
|
---|
| 7 | * Redistribution and use in source and binary forms, with or without
|
---|
| 8 | * modification, are permitted provided that the following conditions
|
---|
| 9 | * are met:
|
---|
| 10 | *
|
---|
| 11 | * - Redistributions of source code must retain the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer.
|
---|
| 13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 14 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 15 | * documentation and/or other materials provided with the distribution.
|
---|
| 16 | * - The name of the author may not be used to endorse or promote products
|
---|
| 17 | * derived from this software without specific prior written permission.
|
---|
| 18 | *
|
---|
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 29 | */
|
---|
| 30 |
|
---|
[174156fd] | 31 | /** @addtogroup kernel_generic_console
|
---|
[b45c443] | 32 | * @{
|
---|
| 33 | */
|
---|
| 34 | /** @file
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[90dd8aee] | 37 | #include <abi/kio.h>
|
---|
[2677758] | 38 | #include <console/chardev.h>
|
---|
[90dd8aee] | 39 | #include <console/console.h>
|
---|
| 40 | #include <errno.h>
|
---|
[13a638d] | 41 | #include <ipc/event.h>
|
---|
[b8da2a3] | 42 | #include <panic.h>
|
---|
[90dd8aee] | 43 | #include <preemption.h>
|
---|
[d5b37b6] | 44 | #include <proc/task.h>
|
---|
[eec616b] | 45 | #include <putchar.h>
|
---|
[e90cfa6] | 46 | #include <stdatomic.h>
|
---|
[90dd8aee] | 47 | #include <stdio.h>
|
---|
[aafed15] | 48 | #include <stdlib.h> /* malloc */
|
---|
[90dd8aee] | 49 | #include <synch/mutex.h>
|
---|
| 50 | #include <synch/spinlock.h>
|
---|
| 51 | #include <syscall/copy.h>
|
---|
| 52 | #include <sysinfo/sysinfo.h>
|
---|
[2677758] | 53 |
|
---|
[6fa9a99d] | 54 | #define KIO_PAGES 8
|
---|
[28a5ebd] | 55 | #define KIO_LENGTH (KIO_PAGES * PAGE_SIZE / sizeof(char32_t))
|
---|
[c859753] | 56 |
|
---|
[c0855a0] | 57 | /** Kernel log cyclic buffer */
|
---|
[d5b37b6] | 58 | static char32_t kio[KIO_LENGTH];
|
---|
[c859753] | 59 |
|
---|
[c0855a0] | 60 | /** Kernel log initialized */
|
---|
[c88d91e8] | 61 | static atomic_bool kio_inited = ATOMIC_VAR_INIT(false);
|
---|
[da1bafb] | 62 |
|
---|
[90dd8aee] | 63 | /** A mutex for preventing interleaving of output lines from different threads.
|
---|
| 64 | * May not be held in some circumstances, so locking of any internal shared
|
---|
| 65 | * structures is still necessary.
|
---|
| 66 | */
|
---|
| 67 | static MUTEX_INITIALIZE(console_mutex, MUTEX_RECURSIVE);
|
---|
| 68 |
|
---|
[af77459] | 69 | /** Number of characters written to buffer. Periodically overflows. */
|
---|
| 70 | static size_t kio_written = 0;
|
---|
[da1bafb] | 71 |
|
---|
[af77459] | 72 | /** Number of characters written to output devices. Periodically overflows. */
|
---|
| 73 | static size_t kio_processed = 0;
|
---|
[da1bafb] | 74 |
|
---|
[af77459] | 75 | /** Last notification sent to uspace. */
|
---|
| 76 | static size_t kio_notified = 0;
|
---|
[82b71ef1] | 77 |
|
---|
[c0855a0] | 78 | /** Kernel log spinlock */
|
---|
[571cc2d] | 79 | IRQ_SPINLOCK_INITIALIZE(kio_lock);
|
---|
[82b71ef1] | 80 |
|
---|
[b9c7425] | 81 | static indev_t stdin_sink;
|
---|
| 82 | static outdev_t stdout_source;
|
---|
| 83 |
|
---|
[7ddc2c7] | 84 | static void stdin_signal(indev_t *, indev_signal_t);
|
---|
| 85 |
|
---|
[44b7783] | 86 | static indev_operations_t stdin_ops = {
|
---|
[7ddc2c7] | 87 | .poll = NULL,
|
---|
| 88 | .signal = stdin_signal
|
---|
[44b7783] | 89 | };
|
---|
| 90 |
|
---|
[28a5ebd] | 91 | static void stdout_write(outdev_t *, char32_t);
|
---|
[da1bafb] | 92 | static void stdout_redraw(outdev_t *);
|
---|
[7ddc2c7] | 93 | static void stdout_scroll_up(outdev_t *);
|
---|
| 94 | static void stdout_scroll_down(outdev_t *);
|
---|
[b9c7425] | 95 |
|
---|
| 96 | static outdev_operations_t stdout_ops = {
|
---|
[a71c158] | 97 | .write = stdout_write,
|
---|
[7ddc2c7] | 98 | .redraw = stdout_redraw,
|
---|
| 99 | .scroll_up = stdout_scroll_up,
|
---|
| 100 | .scroll_down = stdout_scroll_down
|
---|
[b9c7425] | 101 | };
|
---|
| 102 |
|
---|
[b366a6f4] | 103 | /** Override kernel console lockout */
|
---|
| 104 | bool console_override = false;
|
---|
[44b7783] | 105 |
|
---|
[ac8e7a9] | 106 | /** Standard input and output character devices */
|
---|
| 107 | indev_t *stdin = NULL;
|
---|
| 108 | outdev_t *stdout = NULL;
|
---|
[411b6a6] | 109 |
|
---|
[44b7783] | 110 | indev_t *stdin_wire(void)
|
---|
| 111 | {
|
---|
| 112 | if (stdin == NULL) {
|
---|
[b9c7425] | 113 | indev_initialize("stdin", &stdin_sink, &stdin_ops);
|
---|
| 114 | stdin = &stdin_sink;
|
---|
[44b7783] | 115 | }
|
---|
[a35b458] | 116 |
|
---|
[44b7783] | 117 | return stdin;
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[7ddc2c7] | 120 | static void stdin_signal(indev_t *indev, indev_signal_t signal)
|
---|
| 121 | {
|
---|
| 122 | switch (signal) {
|
---|
| 123 | case INDEV_SIGNAL_SCROLL_UP:
|
---|
| 124 | if (stdout != NULL)
|
---|
| 125 | stdout_scroll_up(stdout);
|
---|
| 126 | break;
|
---|
| 127 | case INDEV_SIGNAL_SCROLL_DOWN:
|
---|
| 128 | if (stdout != NULL)
|
---|
| 129 | stdout_scroll_down(stdout);
|
---|
| 130 | break;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[b9c7425] | 134 | void stdout_wire(outdev_t *outdev)
|
---|
| 135 | {
|
---|
| 136 | if (stdout == NULL) {
|
---|
| 137 | outdev_initialize("stdout", &stdout_source, &stdout_ops);
|
---|
| 138 | stdout = &stdout_source;
|
---|
| 139 | }
|
---|
[a35b458] | 140 |
|
---|
[b9c7425] | 141 | list_append(&outdev->link, &stdout->list);
|
---|
| 142 | }
|
---|
| 143 |
|
---|
[28a5ebd] | 144 | static void stdout_write(outdev_t *dev, char32_t ch)
|
---|
[b9c7425] | 145 | {
|
---|
[feeac0d] | 146 | list_foreach(dev->list, link, outdev_t, sink) {
|
---|
[a71c158] | 147 | if ((sink) && (sink->op->write))
|
---|
[b366a6f4] | 148 | sink->op->write(sink, ch);
|
---|
[a71c158] | 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | static void stdout_redraw(outdev_t *dev)
|
---|
| 153 | {
|
---|
[feeac0d] | 154 | list_foreach(dev->list, link, outdev_t, sink) {
|
---|
[a71c158] | 155 | if ((sink) && (sink->op->redraw))
|
---|
| 156 | sink->op->redraw(sink);
|
---|
[b9c7425] | 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[7ddc2c7] | 160 | static void stdout_scroll_up(outdev_t *dev)
|
---|
| 161 | {
|
---|
| 162 | list_foreach(dev->list, link, outdev_t, sink) {
|
---|
| 163 | if ((sink) && (sink->op->scroll_up))
|
---|
| 164 | sink->op->scroll_up(sink);
|
---|
| 165 | }
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | static void stdout_scroll_down(outdev_t *dev)
|
---|
| 169 | {
|
---|
| 170 | list_foreach(dev->list, link, outdev_t, sink) {
|
---|
| 171 | if ((sink) && (sink->op->scroll_down))
|
---|
| 172 | sink->op->scroll_down(sink);
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 |
|
---|
[82b71ef1] | 176 | /** Initialize kernel logging facility
|
---|
| 177 | */
|
---|
[6fa9a99d] | 178 | void kio_init(void)
|
---|
[82b71ef1] | 179 | {
|
---|
[6fa9a99d] | 180 | event_set_unmask_callback(EVENT_KIO, kio_update);
|
---|
[e3306d04] | 181 | atomic_store(&kio_inited, true);
|
---|
[82b71ef1] | 182 | }
|
---|
| 183 |
|
---|
[516ff92] | 184 | void grab_console(void)
|
---|
| 185 | {
|
---|
[392f0e7] | 186 | sysinfo_set_item_val("kconsole", NULL, true);
|
---|
[593e023] | 187 | event_notify_1(EVENT_KCONSOLE, false, true);
|
---|
[b366a6f4] | 188 | bool prev = console_override;
|
---|
[a35b458] | 189 |
|
---|
[b366a6f4] | 190 | console_override = true;
|
---|
[a71c158] | 191 | if ((stdout) && (stdout->op->redraw))
|
---|
| 192 | stdout->op->redraw(stdout);
|
---|
[a35b458] | 193 |
|
---|
[b366a6f4] | 194 | if ((stdin) && (!prev)) {
|
---|
[da1bafb] | 195 | /*
|
---|
| 196 | * Force the console to print the prompt.
|
---|
| 197 | */
|
---|
[402de0c] | 198 | indev_push_character(stdin, '\n');
|
---|
[da1bafb] | 199 | }
|
---|
[516ff92] | 200 | }
|
---|
| 201 |
|
---|
| 202 | void release_console(void)
|
---|
| 203 | {
|
---|
[392f0e7] | 204 | sysinfo_set_item_val("kconsole", NULL, false);
|
---|
[b366a6f4] | 205 | console_override = false;
|
---|
[593e023] | 206 | event_notify_1(EVENT_KCONSOLE, false, false);
|
---|
[516ff92] | 207 | }
|
---|
| 208 |
|
---|
[b366a6f4] | 209 | /** Activate kernel console override */
|
---|
[f6ab787] | 210 | sysarg_t sys_debug_console(void)
|
---|
[312cc68] | 211 | {
|
---|
| 212 | #ifdef CONFIG_KCONSOLE
|
---|
| 213 | grab_console();
|
---|
| 214 | return true;
|
---|
| 215 | #else
|
---|
| 216 | return false;
|
---|
| 217 | #endif
|
---|
| 218 | }
|
---|
| 219 |
|
---|
[6fa9a99d] | 220 | void kio_update(void *event)
|
---|
[82b71ef1] | 221 | {
|
---|
[036e97c] | 222 | if (!atomic_load(&kio_inited))
|
---|
[712c4ba] | 223 | return;
|
---|
[a35b458] | 224 |
|
---|
[571cc2d] | 225 | irq_spinlock_lock(&kio_lock, true);
|
---|
[a35b458] | 226 |
|
---|
[af77459] | 227 | if (kio_notified != kio_written) {
|
---|
| 228 | if (event_notify_1(EVENT_KIO, true, kio_written) == EOK)
|
---|
| 229 | kio_notified = kio_written;
|
---|
[05641a9e] | 230 | }
|
---|
[a35b458] | 231 |
|
---|
[571cc2d] | 232 | irq_spinlock_unlock(&kio_lock, true);
|
---|
[82b71ef1] | 233 | }
|
---|
| 234 |
|
---|
[91db0280] | 235 | /** Flush characters that are stored in the output buffer
|
---|
[7ddc2c7] | 236 | *
|
---|
[91db0280] | 237 | */
|
---|
| 238 | void kio_flush(void)
|
---|
[973be64e] | 239 | {
|
---|
[712c4ba] | 240 | bool ordy = ((stdout) && (stdout->op->write));
|
---|
[a35b458] | 241 |
|
---|
[91db0280] | 242 | if (!ordy)
|
---|
| 243 | return;
|
---|
| 244 |
|
---|
[571cc2d] | 245 | irq_spinlock_lock(&kio_lock, true);
|
---|
[91db0280] | 246 |
|
---|
| 247 | /* Print characters that weren't printed earlier */
|
---|
[af77459] | 248 | while (kio_written != kio_processed) {
|
---|
| 249 | char32_t tmp = kio[kio_processed % KIO_LENGTH];
|
---|
| 250 | kio_processed++;
|
---|
[91db0280] | 251 |
|
---|
| 252 | /*
|
---|
| 253 | * We need to give up the spinlock for
|
---|
| 254 | * the physical operation of writing out
|
---|
| 255 | * the character.
|
---|
| 256 | */
|
---|
[571cc2d] | 257 | irq_spinlock_unlock(&kio_lock, true);
|
---|
[91db0280] | 258 | stdout->op->write(stdout, tmp);
|
---|
[571cc2d] | 259 | irq_spinlock_lock(&kio_lock, true);
|
---|
[c859753] | 260 | }
|
---|
[91db0280] | 261 |
|
---|
[571cc2d] | 262 | irq_spinlock_unlock(&kio_lock, true);
|
---|
[91db0280] | 263 | }
|
---|
| 264 |
|
---|
| 265 | /** Put a character into the output buffer.
|
---|
[7ddc2c7] | 266 | *
|
---|
[91db0280] | 267 | * The caller is required to hold kio_lock
|
---|
| 268 | */
|
---|
[28a5ebd] | 269 | void kio_push_char(const char32_t ch)
|
---|
[91db0280] | 270 | {
|
---|
[af77459] | 271 | kio[kio_written % KIO_LENGTH] = ch;
|
---|
| 272 | kio_written++;
|
---|
[91db0280] | 273 | }
|
---|
| 274 |
|
---|
[28a5ebd] | 275 | void putuchar(const char32_t ch)
|
---|
[91db0280] | 276 | {
|
---|
| 277 | bool ordy = ((stdout) && (stdout->op->write));
|
---|
[a35b458] | 278 |
|
---|
[571cc2d] | 279 | irq_spinlock_lock(&kio_lock, true);
|
---|
[91db0280] | 280 | kio_push_char(ch);
|
---|
[571cc2d] | 281 | irq_spinlock_unlock(&kio_lock, true);
|
---|
[a35b458] | 282 |
|
---|
[91db0280] | 283 | /* Output stored characters */
|
---|
| 284 | kio_flush();
|
---|
[a35b458] | 285 |
|
---|
[91db0280] | 286 | if (!ordy) {
|
---|
[da52547] | 287 | /*
|
---|
| 288 | * No standard output routine defined yet.
|
---|
| 289 | * The character is still stored in the kernel log
|
---|
| 290 | * for possible future output.
|
---|
| 291 | *
|
---|
[28a5ebd] | 292 | * The early_putuchar() function is used to output
|
---|
[da52547] | 293 | * the character for low-level debugging purposes.
|
---|
[ebb3538] | 294 | * Note that the early_putuchar() function might be
|
---|
[da52547] | 295 | * a no-op on certain hardware configurations.
|
---|
| 296 | */
|
---|
[28a5ebd] | 297 | early_putuchar(ch);
|
---|
[c859753] | 298 | }
|
---|
[a35b458] | 299 |
|
---|
[97d42d5] | 300 | /* Force notification on newline */
|
---|
| 301 | if (ch == '\n')
|
---|
[6fa9a99d] | 302 | kio_update(NULL);
|
---|
[973be64e] | 303 | }
|
---|
[b45c443] | 304 |
|
---|
[d5b37b6] | 305 | /** Reads up to `size` characters from kio buffer starting at character `at`.
|
---|
| 306 | *
|
---|
| 307 | * @param size Maximum number of characters that can be stored in buffer.
|
---|
| 308 | * Values greater than KIO_LENGTH are silently treated as KIO_LENGTH
|
---|
| 309 | * for the purposes of calculating the return value.
|
---|
| 310 | * @return Number of characters read. Can be more than `size`.
|
---|
| 311 | * In that case, `size` characters are written to user buffer
|
---|
| 312 | * and the extra amount is the number of characters missed.
|
---|
| 313 | */
|
---|
| 314 | sysarg_t sys_kio_read(uspace_addr_t buf, size_t size, size_t at)
|
---|
| 315 | {
|
---|
| 316 | errno_t rc;
|
---|
| 317 | size_t missed = 0;
|
---|
| 318 |
|
---|
| 319 | irq_spinlock_lock(&kio_lock, true);
|
---|
| 320 |
|
---|
| 321 | if (at == kio_written) {
|
---|
| 322 | irq_spinlock_unlock(&kio_lock, true);
|
---|
| 323 | return 0;
|
---|
| 324 | }
|
---|
| 325 |
|
---|
| 326 | size_t readable_chars = kio_written - at;
|
---|
| 327 | if (readable_chars > KIO_LENGTH) {
|
---|
| 328 | missed = readable_chars - KIO_LENGTH;
|
---|
| 329 | readable_chars = KIO_LENGTH;
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | size_t actual_read = min(readable_chars, size);
|
---|
| 333 | size_t offset = (kio_written - readable_chars) % KIO_LENGTH;
|
---|
| 334 |
|
---|
| 335 | if (offset + actual_read > KIO_LENGTH) {
|
---|
| 336 | size_t first = KIO_LENGTH - offset;
|
---|
| 337 | size_t last = actual_read - first;
|
---|
| 338 | size_t first_bytes = first * sizeof(kio[0]);
|
---|
| 339 | size_t last_bytes = last * sizeof(kio[0]);
|
---|
| 340 |
|
---|
| 341 | rc = copy_to_uspace(buf, &kio[offset], first_bytes);
|
---|
| 342 | if (rc == EOK)
|
---|
| 343 | rc = copy_to_uspace(buf + first_bytes, &kio[0], last_bytes);
|
---|
| 344 | } else {
|
---|
| 345 | rc = copy_to_uspace(buf, &kio[offset], actual_read * sizeof(kio[0]));
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | irq_spinlock_unlock(&kio_lock, true);
|
---|
| 349 |
|
---|
| 350 | if (rc != EOK) {
|
---|
| 351 | log(LF_OTHER, LVL_WARN,
|
---|
| 352 | "[%s(%" PRIu64 ")] Terminating due to invalid memory buffer"
|
---|
| 353 | " in SYS_KIO_READ.\n", TASK->name, TASK->taskid);
|
---|
| 354 | task_kill_self(true);
|
---|
| 355 | }
|
---|
| 356 |
|
---|
| 357 | return actual_read + missed;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
[312cc68] | 360 | /** Print using kernel facility
|
---|
| 361 | *
|
---|
| 362 | * Print to kernel log.
|
---|
| 363 | *
|
---|
| 364 | */
|
---|
[5a5269d] | 365 | sys_errno_t sys_kio(int cmd, uspace_addr_t buf, size_t size)
|
---|
[312cc68] | 366 | {
|
---|
| 367 | char *data;
|
---|
[b7fd2a0] | 368 | errno_t rc;
|
---|
[a801688b] | 369 |
|
---|
| 370 | switch (cmd) {
|
---|
[6fa9a99d] | 371 | case KIO_UPDATE:
|
---|
| 372 | kio_update(NULL);
|
---|
[a801688b] | 373 | return EOK;
|
---|
[6fa9a99d] | 374 | case KIO_WRITE:
|
---|
| 375 | case KIO_COMMAND:
|
---|
[a801688b] | 376 | break;
|
---|
| 377 | default:
|
---|
| 378 | return ENOTSUP;
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[c583970] | 381 | if (size > PAGE_SIZE)
|
---|
[b7fd2a0] | 382 | return (sys_errno_t) ELIMIT;
|
---|
[a35b458] | 383 |
|
---|
[c583970] | 384 | if (size > 0) {
|
---|
[11b285d] | 385 | data = (char *) malloc(size + 1);
|
---|
[312cc68] | 386 | if (!data)
|
---|
[b7fd2a0] | 387 | return (sys_errno_t) ENOMEM;
|
---|
[a35b458] | 388 |
|
---|
[c583970] | 389 | rc = copy_from_uspace(data, buf, size);
|
---|
[312cc68] | 390 | if (rc) {
|
---|
| 391 | free(data);
|
---|
[b7fd2a0] | 392 | return (sys_errno_t) rc;
|
---|
[312cc68] | 393 | }
|
---|
[c583970] | 394 | data[size] = 0;
|
---|
[a35b458] | 395 |
|
---|
[1db4e2ae] | 396 | uint8_t substitute = '\x1a';
|
---|
| 397 | str_sanitize(data, size, substitute);
|
---|
| 398 |
|
---|
[297cb73] | 399 | switch (cmd) {
|
---|
[6fa9a99d] | 400 | case KIO_WRITE:
|
---|
[5e904dd] | 401 | printf("[%s(%lu)] %s\n", TASK->name,
|
---|
| 402 | (unsigned long) TASK->taskid, data);
|
---|
[297cb73] | 403 | break;
|
---|
[6fa9a99d] | 404 | case KIO_COMMAND:
|
---|
[11527051] | 405 | if (!stdin)
|
---|
| 406 | break;
|
---|
[297cb73] | 407 | for (unsigned int i = 0; i < size; i++)
|
---|
| 408 | indev_push_character(stdin, data[i]);
|
---|
| 409 | indev_push_character(stdin, '\n');
|
---|
| 410 | break;
|
---|
| 411 | }
|
---|
| 412 |
|
---|
[312cc68] | 413 | free(data);
|
---|
[297cb73] | 414 | }
|
---|
| 415 |
|
---|
[6afc9d7] | 416 | return EOK;
|
---|
[312cc68] | 417 | }
|
---|
| 418 |
|
---|
[90dd8aee] | 419 | /** Lock console output, ensuring that lines from different threads don't
|
---|
| 420 | * interleave. Does nothing when preemption is disabled, so that debugging
|
---|
| 421 | * and error printouts in sensitive areas still work.
|
---|
| 422 | */
|
---|
| 423 | void console_lock(void)
|
---|
| 424 | {
|
---|
| 425 | if (!PREEMPTION_DISABLED)
|
---|
| 426 | mutex_lock(&console_mutex);
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | /** Unlocks console output. See console_lock()
|
---|
| 430 | */
|
---|
| 431 | void console_unlock(void)
|
---|
| 432 | {
|
---|
| 433 | if (!PREEMPTION_DISABLED)
|
---|
| 434 | mutex_unlock(&console_mutex);
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[06e1e95] | 437 | /** @}
|
---|
[b45c443] | 438 | */
|
---|