diff options
author | Richard Braun <rbraun@sceen.net> | 2018-02-24 06:45:44 +0100 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2018-02-24 06:48:21 +0100 |
commit | 7dcf6715ffb3cc2f00f6327b896d16f173a1b082 (patch) | |
tree | 210570e98e074d7abade0d22c64e05b9c02435ba /kern | |
parent | be5b9d6ab9f7e7a81c367e4bb0823ba11f85940f (diff) |
New errno.h standard header
Use standard errno codes. This change also adds strerror to string.h.
Diffstat (limited to 'kern')
-rw-r--r-- | kern/cbuf.c | 14 | ||||
-rw-r--r-- | kern/cbuf.h | 12 | ||||
-rw-r--r-- | kern/condition.h | 4 | ||||
-rw-r--r-- | kern/console.c | 4 | ||||
-rw-r--r-- | kern/cpumap.c | 6 | ||||
-rw-r--r-- | kern/cpumap.h | 2 | ||||
-rw-r--r-- | kern/error.c | 35 | ||||
-rw-r--r-- | kern/error.h | 16 | ||||
-rw-r--r-- | kern/fmt.c | 22 | ||||
-rw-r--r-- | kern/init.c | 2 | ||||
-rw-r--r-- | kern/init.h | 5 | ||||
-rw-r--r-- | kern/intr.c | 5 | ||||
-rw-r--r-- | kern/intr.h | 2 | ||||
-rw-r--r-- | kern/log.c | 3 | ||||
-rw-r--r-- | kern/mutex.h | 2 | ||||
-rw-r--r-- | kern/mutex/mutex_adaptive.c | 4 | ||||
-rw-r--r-- | kern/mutex/mutex_adaptive_i.h | 6 | ||||
-rw-r--r-- | kern/mutex/mutex_plain_i.h | 6 | ||||
-rw-r--r-- | kern/percpu.c | 8 | ||||
-rw-r--r-- | kern/rdxtree.c | 8 | ||||
-rw-r--r-- | kern/rtmutex.h | 6 | ||||
-rw-r--r-- | kern/semaphore.h | 6 | ||||
-rw-r--r-- | kern/shell.c | 32 | ||||
-rw-r--r-- | kern/shell.h | 3 | ||||
-rw-r--r-- | kern/sleepq.h | 4 | ||||
-rw-r--r-- | kern/spinlock.c | 4 | ||||
-rw-r--r-- | kern/spinlock.h | 4 | ||||
-rw-r--r-- | kern/spinlock_i.h | 6 | ||||
-rw-r--r-- | kern/sref.c | 8 | ||||
-rw-r--r-- | kern/sref.h | 2 | ||||
-rw-r--r-- | kern/string.c | 32 | ||||
-rw-r--r-- | kern/string.h | 1 | ||||
-rw-r--r-- | kern/task.c | 8 | ||||
-rw-r--r-- | kern/thread.c | 24 | ||||
-rw-r--r-- | kern/thread.h | 6 | ||||
-rw-r--r-- | kern/turnstile.h | 8 | ||||
-rw-r--r-- | kern/work.c | 3 |
37 files changed, 158 insertions, 165 deletions
diff --git a/kern/cbuf.c b/kern/cbuf.c index 2093f428..ad3bead6 100644 --- a/kern/cbuf.c +++ b/kern/cbuf.c @@ -16,12 +16,12 @@ */ #include <assert.h> +#include <errno.h> #include <stddef.h> #include <stdint.h> #include <string.h> #include <kern/cbuf.h> -#include <kern/error.h> #include <kern/macros.h> /* Negative close to 0 so that an overflow occurs early */ @@ -62,7 +62,7 @@ cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase) free_size = cbuf_capacity(cbuf) - cbuf_size(cbuf); if (size > free_size) { - return ERROR_AGAIN; + return EAGAIN; } } @@ -75,7 +75,7 @@ cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep) int error; if (cbuf_size(cbuf) == 0) { - return ERROR_AGAIN; + return EAGAIN; } error = cbuf_read(cbuf, cbuf_start(cbuf), buf, sizep); @@ -93,7 +93,7 @@ cbuf_pushb(struct cbuf *cbuf, uint8_t byte, bool erase) free_size = cbuf_capacity(cbuf) - cbuf_size(cbuf); if (free_size == 0) { - return ERROR_AGAIN; + return EAGAIN; } } @@ -109,7 +109,7 @@ cbuf_popb(struct cbuf *cbuf, void *bytep) uint8_t *ptr; if (cbuf_size(cbuf) == 0) { - return ERROR_AGAIN; + return EAGAIN; } ptr = bytep; @@ -125,7 +125,7 @@ cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size) size_t new_end, skip; if (!cbuf_range_valid(cbuf, index, cbuf->end)) { - return ERROR_INVAL; + return EINVAL; } new_end = index + size; @@ -166,7 +166,7 @@ cbuf_read(const struct cbuf *cbuf, size_t index, void *buf, size_t *sizep) /* At least one byte must be available */ if (!cbuf_range_valid(cbuf, index, index + 1)) { - return ERROR_INVAL; + return EINVAL; } size = cbuf->end - index; diff --git a/kern/cbuf.h b/kern/cbuf.h index d82d261e..4e9f57a9 100644 --- a/kern/cbuf.h +++ b/kern/cbuf.h @@ -88,7 +88,7 @@ void cbuf_init(struct cbuf *cbuf, void *buf, size_t capacity); * Push data to a circular buffer. * * If the function isn't allowed to erase old data and the circular buffer - * doesn't have enough unused bytes for the new data, ERROR_AGAIN is returned. + * doesn't have enough unused bytes for the new data, EAGAIN is returned. */ int cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase); @@ -98,7 +98,7 @@ int cbuf_push(struct cbuf *cbuf, const void *buf, size_t size, bool erase); * On entry, the sizep argument points to the size of the output buffer. * On exit, it is updated to the number of bytes actually transferred. * - * If the buffer is empty, ERROR_AGAIN is returned, and the size of the + * If the buffer is empty, EAGAIN is returned, and the size of the * output buffer is undefined. */ int cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep); @@ -107,21 +107,21 @@ int cbuf_pop(struct cbuf *cbuf, void *buf, size_t *sizep); * Push a byte to a circular buffer. * * If the function isn't allowed to erase old data and the circular buffer - * is full, ERROR_AGAIN is returned. + * is full, EAGAIN is returned. */ int cbuf_pushb(struct cbuf *cbuf, uint8_t byte, bool erase); /* * Pop a byte from a circular buffer. * - * If the buffer is empty, ERROR_AGAIN is returned. + * If the buffer is empty, EAGAIN is returned. */ int cbuf_popb(struct cbuf *cbuf, void *bytep); /* * Write into a circular buffer at a specific location. * - * If the given index is outside buffer boundaries, ERROR_INVAL is returned. + * If the given index is outside buffer boundaries, EINVAL is returned. * The given [index, size) range may extend beyond the end of the circular * buffer. */ @@ -133,7 +133,7 @@ int cbuf_write(struct cbuf *cbuf, size_t index, const void *buf, size_t size); * On entry, the sizep argument points to the size of the output buffer. * On exit, it is updated to the number of bytes actually transferred. * - * If the given index is outside buffer boundaries, ERROR_INVAL is returned. + * If the given index is outside buffer boundaries, EINVAL is returned. * * The circular buffer isn't changed by this operation. */ diff --git a/kern/condition.h b/kern/condition.h index 9c015459..f6d1fd65 100644 --- a/kern/condition.h +++ b/kern/condition.h @@ -46,8 +46,8 @@ struct condition; * It is unlocked before waiting and relocked before returning. * * When bounding the duration of the wait, the caller must pass an absolute - * time in ticks, and ERROR_TIMEDOUT is returned if that time is reached - * before the sleep queue is signalled. + * time in ticks, and ETIMEDOUT is returned if that time is reached before + * the sleep queue is signalled. */ void condition_wait(struct condition *condition, struct mutex *mutex); int condition_timedwait(struct condition *condition, diff --git a/kern/console.c b/kern/console.c index 0ed54b5e..a9a0f5d0 100644 --- a/kern/console.c +++ b/kern/console.c @@ -16,13 +16,13 @@ */ #include <assert.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <string.h> #include <kern/arg.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/console.h> #include <kern/list.h> @@ -76,7 +76,7 @@ console_process_ctrl_char(struct console *console, char c) case CONSOLE_SCROLL_DOWN: break; default: - return ERROR_INVAL; + return EINVAL; } console->ops->putc(console, c); diff --git a/kern/cpumap.c b/kern/cpumap.c index d166b237..729b22b5 100644 --- a/kern/cpumap.c +++ b/kern/cpumap.c @@ -15,11 +15,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stddef.h> #include <kern/bitmap.h> #include <kern/cpumap.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/kmem.h> #include <kern/macros.h> @@ -63,7 +63,7 @@ cpumap_create(struct cpumap **cpumapp) cpumap = kmem_cache_alloc(&cpumap_cache); if (cpumap == NULL) { - return ERROR_NOMEM; + return ENOMEM; } *cpumapp = cpumap; @@ -84,7 +84,7 @@ cpumap_check(const struct cpumap *cpumap) index = bitmap_find_first(cpumap->cpus, cpu_count()); if (index == -1) { - return ERROR_INVAL; + return EINVAL; } return 0; diff --git a/kern/cpumap.h b/kern/cpumap.h index 86d345da..e0ac9fce 100644 --- a/kern/cpumap.h +++ b/kern/cpumap.h @@ -159,7 +159,7 @@ void cpumap_destroy(struct cpumap *cpumap); * Check the validity of a CPU map. * * If the map doesn't identify at least one managed processor, return - * ERROR_INVAL. + * EINVAL. */ int cpumap_check(const struct cpumap *cpumap); diff --git a/kern/error.c b/kern/error.c index f5d43e48..10d69542 100644 --- a/kern/error.c +++ b/kern/error.c @@ -15,42 +15,13 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stddef.h> +#include <string.h> #include <kern/error.h> #include <kern/panic.h> -const char * -error_str(int error) -{ - switch (error) { - case 0: - return "success"; - case ERROR_NOMEM: - return "out of memory"; - case ERROR_AGAIN: - return "resource temporarily unavailable"; - case ERROR_INVAL: - return "invalid argument"; - case ERROR_BUSY: - return "device or resource busy"; - case ERROR_FAULT: - return "bad address"; - case ERROR_NODEV: - return "no such device"; - case ERROR_EXIST: - return "entry exists"; - case ERROR_IO: - return "input/output error"; - case ERROR_SRCH: - return "no such process"; - case ERROR_TIMEDOUT: - return "timeout error"; - default: - return "unknown error"; - } -} - void error_check(int error, const char *prefix) { @@ -61,5 +32,5 @@ error_check(int error, const char *prefix) panic("%s%s%s", (prefix == NULL) ? "" : prefix, (prefix == NULL) ? "" : ": ", - error_str(error)); + strerror(error)); } diff --git a/kern/error.h b/kern/error.h index 5db1dba7..3e98bed6 100644 --- a/kern/error.h +++ b/kern/error.h @@ -18,22 +18,6 @@ #ifndef KERN_ERROR_H #define KERN_ERROR_H -#define ERROR_NOMEM 1 -#define ERROR_AGAIN 2 -#define ERROR_INVAL 3 -#define ERROR_BUSY 4 -#define ERROR_FAULT 5 -#define ERROR_NODEV 6 -#define ERROR_EXIST 7 -#define ERROR_IO 8 -#define ERROR_SRCH 9 -#define ERROR_TIMEDOUT 10 - -/* - * Return a string describing the given error. - */ -const char * error_str(int error); - /* * If error denotes an actual error (i.e. is not 0), panic, using the given * string as a prefix for the error message. A NULL prefix is allowed. @@ -16,6 +16,7 @@ */ #include <assert.h> +#include <errno.h> #include <limits.h> #include <stdbool.h> #include <stdarg.h> @@ -24,7 +25,6 @@ #include <stdio.h> #include <string.h> -#include <kern/error.h> #include <kern/fmt.h> #include <kern/macros.h> #include <kern/types.h> @@ -401,12 +401,12 @@ fmt_sprintf_state_consume(struct fmt_sprintf_state *state) c = fmt_consume(&state->format); if (c == '\0') { - return ERROR_IO; + return EIO; } if (c != '%') { fmt_sprintf_state_produce_raw_char(state, c); - return ERROR_AGAIN; + return EAGAIN; } fmt_sprintf_state_consume_flags(state); @@ -783,7 +783,7 @@ fmt_vsnprintf(char *str, size_t size, const char *format, va_list ap) for (;;) { error = fmt_sprintf_state_consume(&state); - if (error == ERROR_AGAIN) { + if (error == EAGAIN) { continue; } else if (error) { break; @@ -1066,7 +1066,7 @@ fmt_sscanf_state_discard_char(struct fmt_sscanf_state *state, char c) state->nr_convs = EOF; } - return ERROR_INVAL; + return EINVAL; } return 0; @@ -1083,7 +1083,7 @@ fmt_sscanf_state_consume(struct fmt_sscanf_state *state) c = fmt_consume(&state->format); if (c == '\0') { - return ERROR_IO; + return EIO; } if (c != '%') { @@ -1093,7 +1093,7 @@ fmt_sscanf_state_consume(struct fmt_sscanf_state *state) return error; } - return ERROR_AGAIN; + return EAGAIN; } fmt_sscanf_state_consume_flags(state); @@ -1185,7 +1185,7 @@ fmt_sscanf_state_produce_int(struct fmt_sscanf_state *state) if (i == 0) { if (c == '\0') { fmt_sscanf_state_report_error(state); - return ERROR_INVAL; + return EINVAL; } buf[0] = '0'; @@ -1379,7 +1379,7 @@ fmt_sscanf_state_produce_str(struct fmt_sscanf_state *state) if (state->str == orig) { fmt_sscanf_state_report_error(state); - return ERROR_INVAL; + return EINVAL; } if (dest != NULL) { @@ -1414,7 +1414,7 @@ fmt_sscanf_state_produce(struct fmt_sscanf_state *state) return fmt_sscanf_state_discard_char(state, '%'); default: fmt_sscanf_state_report_error(state); - return ERROR_INVAL; + return EINVAL; } } @@ -1442,7 +1442,7 @@ fmt_vsscanf(const char *str, const char *format, va_list ap) for (;;) { error = fmt_sscanf_state_consume(&state); - if (error == ERROR_AGAIN) { + if (error == EAGAIN) { continue; } else if (error) { break; diff --git a/kern/init.c b/kern/init.c index 22db2957..dd699976 100644 --- a/kern/init.c +++ b/kern/init.c @@ -23,13 +23,13 @@ */ #include <assert.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/slist.h> #include <kern/macros.h> diff --git a/kern/init.h b/kern/init.h index 11a0c804..809123d4 100644 --- a/kern/init.h +++ b/kern/init.h @@ -42,7 +42,8 @@ #ifndef __ASSEMBLER__ -#include <kern/error.h> +#include <errno.h> + #include <kern/macros.h> #define __init __section(QUOTE(INIT_SECTION)) @@ -94,7 +95,7 @@ typedef int (*init_op_fn_t)(void); .name = QUOTE(_fn), \ .fn = _fn, \ .deps = INIT_OP_DEPS(_fn), \ - .error = ERROR_AGAIN, \ + .error = EAGAIN, \ .state = INIT_OP_STATE_UNLINKED, \ .nr_deps = ARRAY_SIZE(INIT_OP_DEPS(_fn)), \ .nr_parents = 0, \ diff --git a/kern/intr.c b/kern/intr.c index 9a1ad71e..541dc5cb 100644 --- a/kern/intr.c +++ b/kern/intr.c @@ -22,6 +22,7 @@ * Shared interrupts are supported. */ +#include <errno.h> #include <stdalign.h> #include <stdbool.h> #include <stddef.h> @@ -107,7 +108,7 @@ intr_handler_create(struct intr_handler **handlerp, handler = kmem_cache_alloc(&intr_handler_cache); if (handler == NULL) { - return ERROR_NOMEM; + return ENOMEM; } handler->fn = fn; @@ -259,7 +260,7 @@ intr_entry_add(struct intr_entry *entry, struct intr_handler *handler) ctl = intr_lookup_ctl(intr_entry_get_intr(entry)); if (ctl == NULL) { - error = ERROR_NODEV; + error = ENODEV; goto out; } diff --git a/kern/intr.h b/kern/intr.h index 820f8416..655c0986 100644 --- a/kern/intr.h +++ b/kern/intr.h @@ -28,7 +28,7 @@ * * Return codes : * - 0 Interrupt successfully handled - * - ERROR_AGAIN Spurious interrupt + * - EAGAIN Spurious interrupt */ typedef int (*intr_handler_fn_t)(void *arg); @@ -16,6 +16,7 @@ */ #include <assert.h> +#include <errno.h> #include <limits.h> #include <stdarg.h> #include <stdbool.h> @@ -217,7 +218,7 @@ log_record_init_consume(struct log_record *record, struct log_consume_ctx *ctx) for (;;) { if (log_consume_ctx_empty(ctx)) { if (!marker_found) { - return ERROR_INVAL; + return EINVAL; } break; diff --git a/kern/mutex.h b/kern/mutex.h index c222c837..f446f5fe 100644 --- a/kern/mutex.h +++ b/kern/mutex.h @@ -54,7 +54,7 @@ mutex_init(struct mutex *mutex) * * This function may not sleep. * - * Return 0 on success, ERROR_BUSY if the mutex is already locked. + * Return 0 on success, EBUSY if the mutex is already locked. */ static inline int mutex_trylock(struct mutex *mutex) diff --git a/kern/mutex/mutex_adaptive.c b/kern/mutex/mutex_adaptive.c index db92f9d5..b2af4561 100644 --- a/kern/mutex/mutex_adaptive.c +++ b/kern/mutex/mutex_adaptive.c @@ -16,13 +16,13 @@ */ #include <assert.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <kern/atomic.h> #include <kern/clock.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/mutex.h> #include <kern/mutex_types.h> @@ -152,7 +152,7 @@ mutex_adaptive_lock_slow_common(struct mutex *mutex, bool timed, uint64_t ticks) mutex_adaptive_inc_sc(MUTEX_ADAPTIVE_SC_SPINS); if (timed && clock_time_occurred(ticks, clock_get_time())) { - error = ERROR_TIMEDOUT; + error = ETIMEDOUT; break; } diff --git a/kern/mutex/mutex_adaptive_i.h b/kern/mutex/mutex_adaptive_i.h index ce2ac4f2..05e97640 100644 --- a/kern/mutex/mutex_adaptive_i.h +++ b/kern/mutex/mutex_adaptive_i.h @@ -24,10 +24,10 @@ #endif #include <assert.h> +#include <errno.h> #include <stdint.h> #include <kern/atomic.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/macros.h> #include <kern/mutex_types.h> @@ -58,7 +58,7 @@ mutex_adaptive_lock_fast(struct mutex *mutex) owner = atomic_cas_acquire(&mutex->owner, 0, (uintptr_t)thread_self()); if (unlikely(owner != 0)) { - return ERROR_BUSY; + return EBUSY; } return 0; @@ -72,7 +72,7 @@ mutex_adaptive_unlock_fast(struct mutex *mutex) owner = atomic_cas_release(&mutex->owner, (uintptr_t)thread_self(), 0); if (unlikely(owner & MUTEX_ADAPTIVE_CONTENDED)) { - return ERROR_BUSY; + return EBUSY; } return 0; diff --git a/kern/mutex/mutex_plain_i.h b/kern/mutex/mutex_plain_i.h index 0c58174b..d28fd92b 100644 --- a/kern/mutex/mutex_plain_i.h +++ b/kern/mutex/mutex_plain_i.h @@ -24,10 +24,10 @@ #endif #include <assert.h> +#include <errno.h> #include <stdint.h> #include <kern/atomic.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/mutex_types.h> @@ -52,7 +52,7 @@ mutex_plain_lock_fast(struct mutex *mutex) state = atomic_cas_acquire(&mutex->state, MUTEX_UNLOCKED, MUTEX_LOCKED); if (unlikely(state != MUTEX_UNLOCKED)) { - return ERROR_BUSY; + return EBUSY; } return 0; @@ -66,7 +66,7 @@ mutex_plain_unlock_fast(struct mutex *mutex) state = atomic_swap_release(&mutex->state, MUTEX_UNLOCKED); if (unlikely(state == MUTEX_CONTENDED)) { - return ERROR_BUSY; + return EBUSY; } return 0; diff --git a/kern/percpu.c b/kern/percpu.c index 62c3d22e..53861a30 100644 --- a/kern/percpu.c +++ b/kern/percpu.c @@ -16,11 +16,11 @@ */ #include <assert.h> +#include <errno.h> #include <stddef.h> #include <stdint.h> #include <string.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/log.h> #include <kern/macros.h> @@ -89,12 +89,12 @@ percpu_add(unsigned int cpu) percpu_skip_warning = 1; } - return ERROR_INVAL; + return EINVAL; } if (percpu_areas[cpu] != NULL) { log_err("percpu: id %u ignored, already registered", cpu); - return ERROR_INVAL; + return EINVAL; } if (percpu_area_size == 0) { @@ -106,7 +106,7 @@ percpu_add(unsigned int cpu) if (page == NULL) { log_err("percpu: unable to allocate percpu area"); - return ERROR_NOMEM; + return ENOMEM; } percpu_areas[cpu] = vm_page_direct_ptr(page); diff --git a/kern/rdxtree.c b/kern/rdxtree.c index 9e2e759c..ac73a107 100644 --- a/kern/rdxtree.c +++ b/kern/rdxtree.c @@ -16,13 +16,13 @@ */ #include <assert.h> +#include <errno.h> #include <limits.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <string.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/kmem.h> #include <kern/macros.h> @@ -150,7 +150,7 @@ rdxtree_node_create(struct rdxtree_node **nodep, unsigned short height) node = kmem_cache_alloc(&rdxtree_node_cache); if (node == NULL) { - return ERROR_NOMEM; + return ENOMEM; } rdxtree_assert_alignment(node); @@ -475,7 +475,7 @@ rdxtree_insert_common(struct rdxtree *tree, rdxtree_key_t key, if (unlikely(height == 0)) { if (tree->root != NULL) { - return ERROR_BUSY; + return EBUSY; } rcu_store_ptr(tree->root, ptr); @@ -521,7 +521,7 @@ rdxtree_insert_common(struct rdxtree *tree, rdxtree_key_t key, } while (height > 0); if (unlikely(node != NULL)) { - return ERROR_BUSY; + return EBUSY; } rdxtree_node_insert(prev, index, ptr); diff --git a/kern/rtmutex.h b/kern/rtmutex.h index 396b2dff..64c09241 100644 --- a/kern/rtmutex.h +++ b/kern/rtmutex.h @@ -25,9 +25,9 @@ #define KERN_RTMUTEX_H #include <assert.h> +#include <errno.h> #include <stdint.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/macros.h> #include <kern/rtmutex_i.h> @@ -51,7 +51,7 @@ rtmutex_init(struct rtmutex *rtmutex) * * This function may not sleep. * - * Return 0 on success, ERROR_BUSY if the mutex is already locked. + * Return 0 on success, EBUSY if the mutex is already locked. */ static inline int rtmutex_trylock(struct rtmutex *rtmutex) @@ -61,7 +61,7 @@ rtmutex_trylock(struct rtmutex *rtmutex) prev_owner = rtmutex_lock_fast(rtmutex); if (unlikely(prev_owner != 0)) { - return ERROR_BUSY; + return EBUSY; } return 0; diff --git a/kern/semaphore.h b/kern/semaphore.h index afe1646b..640d6d6c 100644 --- a/kern/semaphore.h +++ b/kern/semaphore.h @@ -45,10 +45,10 @@ #define KERN_SEMAPHORE_H #include <assert.h> +#include <errno.h> #include <stdint.h> #include <kern/atomic.h> -#include <kern/error.h> #define SEMAPHORE_VALUE_MAX 32768 @@ -71,7 +71,7 @@ semaphore_init(struct semaphore *semaphore, unsigned int value) * * This function may not sleep. * - * Return 0 on success, ERROR_AGAIN if the semaphore could not be decremented. + * Return 0 on success, EAGAIN if the semaphore could not be decremented. */ static inline int semaphore_trywait(struct semaphore *semaphore) @@ -81,7 +81,7 @@ semaphore_trywait(struct semaphore *semaphore) prev = semaphore_dec(semaphore); if (prev == 0) { - return ERROR_AGAIN; + return EAGAIN; } return 0; diff --git a/kern/shell.c b/kern/shell.c index a27c53f3..ebfa7647 100644 --- a/kern/shell.c +++ b/kern/shell.c @@ -15,10 +15,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stdio.h> #include <string.h> -#include <kern/error.h> #include <kern/hash.h> #include <kern/init.h> #include <kern/log.h> @@ -258,8 +258,8 @@ shell_cmd_match(const struct shell_cmd *cmd, const char *str, * eligible for completion. * * If there is a single match for the given string, return 0. If there - * are more than one match, return ERROR_AGAIN. If there is no match, - * return ERROR_INVAL. + * are more than one match, return EAGAIN. If there is no match, + * return EINVAL. * * The global lock must be acquired before calling this function. */ @@ -279,7 +279,7 @@ shell_cmd_complete(const char *str, unsigned long *sizep, cmd = shell_cmd_match(shell_list, str, size); if (cmd == NULL) { - return ERROR_INVAL; + return EINVAL; } *cmdp = cmd; @@ -324,7 +324,7 @@ shell_cmd_complete(const char *str, unsigned long *sizep, size--; *sizep = size; - return ERROR_AGAIN; + return EAGAIN; } /* @@ -370,7 +370,7 @@ shell_cmd_check_char(char c) return 0; } - return ERROR_INVAL; + return EINVAL; } static int @@ -388,7 +388,7 @@ shell_cmd_check(const struct shell_cmd *cmd) } if (i == 0) { - return ERROR_INVAL; + return EINVAL; } return 0; @@ -446,7 +446,7 @@ shell_cmd_add(struct shell_cmd *cmd) for (;;) { if (strcmp(cmd->name, tmp->name) == 0) { log_err("shell: %s: shell command name collision", cmd->name); - return ERROR_EXIST; + return EEXIST; } if (tmp->ht_next == NULL) { @@ -519,11 +519,11 @@ shell_line_insert(struct shell_line *line, unsigned long index, char c) unsigned long remaining_chars; if (index > line->size) { - return ERROR_INVAL; + return EINVAL; } if ((line->size + 1) == sizeof(line->str)) { - return ERROR_NOMEM; + return ENOMEM; } remaining_chars = line->size - index; @@ -544,7 +544,7 @@ shell_line_erase(struct shell_line *line, unsigned long index) unsigned long remaining_chars; if (index >= line->size) { - return ERROR_INVAL; + return EINVAL; } remaining_chars = line->size - index - 1; @@ -764,7 +764,7 @@ static int shell_process_right(void) { if (shell_cursor >= shell_line_size(shell_history_get_newest())) { - return ERROR_AGAIN; + return EAGAIN; } shell_cursor++; @@ -867,12 +867,12 @@ shell_process_tabulation(void) error = shell_cmd_complete(word, &size, &cmd); - if (error && (error != ERROR_AGAIN)) { + if (error && (error != EAGAIN)) { error = 0; goto out; } - if (error == ERROR_AGAIN) { + if (error == EAGAIN) { unsigned long cursor; cursor = shell_cursor; @@ -1056,7 +1056,7 @@ shell_process_args(void) if (j == ARRAY_SIZE(shell_argv)) { printf("shell: too many arguments\n"); - return ERROR_INVAL; + return EINVAL; } shell_argv[j] = NULL; @@ -1119,7 +1119,7 @@ shell_process_ctrl_char(char c) case '\r': putchar('\n'); shell_process_line(); - return ERROR_AGAIN; + return EAGAIN; default: return 0; } diff --git a/kern/shell.h b/kern/shell.h index 3b1f1f3e..bcc13026 100644 --- a/kern/shell.h +++ b/kern/shell.h @@ -21,8 +21,9 @@ #ifndef KERN_SHELL_H #define KERN_SHELL_H +#include <errno.h> + #include <kern/init.h> -#include <kern/error.h> #include <kern/macros.h> #define SHELL_REGISTER_CMDS(cmds) \ diff --git a/kern/sleepq.h b/kern/sleepq.h index 45e3cfd5..10b139fb 100644 --- a/kern/sleepq.h +++ b/kern/sleepq.h @@ -106,8 +106,8 @@ bool sleepq_empty(const struct sleepq *sleepq); * the queue, the queue is not immediately considered empty. * * When bounding the duration of the wait, the caller must pass an absolute - * time in ticks, and ERROR_TIMEDOUT is returned if that time is reached - * before the sleep queue is signalled. + * time in ticks, and ETIMEDOUT is returned if that time is reached before + * the sleep queue is signalled. */ void sleepq_wait(struct sleepq *sleepq, const char *wchan); int sleepq_timedwait(struct sleepq *sleepq, const char *wchan, uint64_t ticks); diff --git a/kern/spinlock.c b/kern/spinlock.c index 9857b388..5ba91169 100644 --- a/kern/spinlock.c +++ b/kern/spinlock.c @@ -64,11 +64,11 @@ */ #include <assert.h> +#include <errno.h> #include <stdalign.h> #include <stddef.h> #include <kern/atomic.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/macros.h> #include <kern/percpu.h> @@ -253,7 +253,7 @@ spinlock_try_downgrade(struct spinlock *lock, unsigned int oldqid) assert(prev != SPINLOCK_QID_NULL); if (prev != oldqid) { - return ERROR_BUSY; + return EBUSY; } return 0; diff --git a/kern/spinlock.h b/kern/spinlock.h index b90b5538..d88d535e 100644 --- a/kern/spinlock.h +++ b/kern/spinlock.h @@ -59,7 +59,7 @@ void spinlock_init(struct spinlock *lock); /* * Attempt to lock the given spin lock. * - * Return 0 on success, ERROR_BUSY if the spin lock is already locked. + * Return 0 on success, EBUSY if the spin lock is already locked. * * Preemption is disabled on success. */ @@ -118,7 +118,7 @@ spinlock_unlock(struct spinlock *lock) /* * Attempt to lock the given spin lock. * - * Return 0 on success, ERROR_BUSY if the spin lock is already locked. + * Return 0 on success, EBUSY if the spin lock is already locked. * * Preemption and interrupts are disabled on success, in which case the * flags passed by the caller are filled with the previous value of the diff --git a/kern/spinlock_i.h b/kern/spinlock_i.h index 113b556f..a54a5e3b 100644 --- a/kern/spinlock_i.h +++ b/kern/spinlock_i.h @@ -19,11 +19,11 @@ #define KERN_SPINLOCK_I_H #include <assert.h> +#include <errno.h> #include <stddef.h> #include <stdint.h> #include <kern/atomic.h> -#include <kern/error.h> #include <kern/macros.h> #include <kern/spinlock_types.h> #include <kern/thread.h> @@ -72,7 +72,7 @@ spinlock_lock_fast(struct spinlock *lock) prev = atomic_cas_acquire(&lock->value, SPINLOCK_UNLOCKED, SPINLOCK_LOCKED); if (unlikely(prev != SPINLOCK_UNLOCKED)) { - return ERROR_BUSY; + return EBUSY; } spinlock_own(lock); @@ -88,7 +88,7 @@ spinlock_unlock_fast(struct spinlock *lock) prev = atomic_cas_release(&lock->value, SPINLOCK_LOCKED, SPINLOCK_UNLOCKED); if (unlikely(prev != SPINLOCK_LOCKED)) { - return ERROR_BUSY; + return EBUSY; } return 0; diff --git a/kern/sref.c b/kern/sref.c index 2b20cb4d..3539e46d 100644 --- a/kern/sref.c +++ b/kern/sref.c @@ -43,13 +43,13 @@ */ #include <assert.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <stdio.h> #include <kern/condition.h> #include <kern/cpumap.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/list.h> #include <kern/log.h> @@ -256,7 +256,7 @@ sref_weakref_kill(struct sref_weakref *weakref) if (oldval != addr) { assert((oldval & SREF_WEAKREF_MASK) == (addr & SREF_WEAKREF_MASK)); - return ERROR_BUSY; + return EBUSY; } return 0; @@ -936,7 +936,7 @@ sref_unregister(void) if (dirty) { sref_cache_mark_registered(cache); - error = ERROR_BUSY; + error = EBUSY; goto out; } @@ -957,7 +957,7 @@ sref_unregister(void) error = 0; } else { sref_cache_manage(cache); - error = ERROR_BUSY; + error = EBUSY; } if (error) { diff --git a/kern/sref.h b/kern/sref.h index cb61b6e4..e224d167 100644 --- a/kern/sref.h +++ b/kern/sref.h @@ -61,7 +61,7 @@ typedef void (*sref_noref_fn_t)(struct sref_counter *); * impossible to obtain or release references while idling. * * Unregistration can fail if internal data still require processing, in - * which case a maintenance thread is awaken and ERROR_BUSY is returned. + * which case a maintenance thread is awaken and EBUSY is returned. * * Preemption must be disabled when calling these functions. */ diff --git a/kern/string.c b/kern/string.c index 70d03d02..0d3b735b 100644 --- a/kern/string.c +++ b/kern/string.c @@ -18,6 +18,7 @@ * Trivial, portable implementations. */ +#include <errno.h> #include <stddef.h> #include <string.h> @@ -226,3 +227,34 @@ strchr(const char *s, int c) } } #endif /* STRING_ARCH_STRCHR */ + +const char * +strerror(int error) +{ + switch (error) { + case 0: + return "success"; + case ENOMEM: + return "out of memory"; + case EAGAIN: + return "resource temporarily unavailable"; + case EINVAL: + return "invalid argument"; + case EBUSY: + return "device or resource busy"; + case EFAULT: + return "bad address"; + case ENODEV: + return "no such device"; + case EEXIST: + return "entry exists"; + case EIO: + return "input/output error"; + case ESRCH: + return "no such process"; + case ETIMEDOUT: + return "timeout error"; + default: + return "unknown error"; + } +} diff --git a/kern/string.h b/kern/string.h index 840ae115..51cdf9e8 100644 --- a/kern/string.h +++ b/kern/string.h @@ -30,5 +30,6 @@ size_t strlcpy(char * restrict dest, const char * restrict src, size_t n); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t n); char * strchr(const char *s, int c); +const char * strerror(int error); #endif /* KERN_STRING_H */ diff --git a/kern/task.c b/kern/task.c index 7039b426..5df72251 100644 --- a/kern/task.c +++ b/kern/task.c @@ -15,11 +15,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <errno.h> #include <stddef.h> #include <stdio.h> #include <string.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/kmem.h> #include <kern/list.h> @@ -74,7 +74,7 @@ task_shell_info(int argc, char *argv[]) task = task_lookup(argv[1]); if (task == NULL) { - error = ERROR_INVAL; + error = EINVAL; goto error; } @@ -85,7 +85,7 @@ task_shell_info(int argc, char *argv[]) return; error: - printf("task: info: %s\n", error_str(error)); + printf("task: info: %s\n", strerror(error)); } static struct shell_cmd task_shell_cmds[] = { @@ -138,7 +138,7 @@ task_create(struct task **taskp, const char *name) task = kmem_cache_alloc(&task_cache); if (task == NULL) { - error = ERROR_NOMEM; + error = ENOMEM; goto error_task; } diff --git a/kern/thread.c b/kern/thread.c index 5ba51b02..3ca0677e 100644 --- a/kern/thread.c +++ b/kern/thread.c @@ -82,6 +82,7 @@ */ #include <assert.h> +#include <errno.h> #include <stdalign.h> #include <stdbool.h> #include <stddef.h> @@ -93,7 +94,6 @@ #include <kern/atomic.h> #include <kern/clock.h> #include <kern/cpumap.h> -#include <kern/error.h> #include <kern/init.h> #include <kern/kmem.h> #include <kern/list.h> @@ -1813,14 +1813,14 @@ thread_init(struct thread *thread, void *stack, thread->priv_sleepq = sleepq_create(); if (thread->priv_sleepq == NULL) { - error = ERROR_NOMEM; + error = ENOMEM; goto error_sleepq; } thread->priv_turnstile = turnstile_create(); if (thread->priv_turnstile == NULL) { - error = ERROR_NOMEM; + error = ENOMEM; goto error_turnstile; } @@ -2208,7 +2208,7 @@ thread_shell_trace(int argc, char *argv[]) int error; if (argc != 3) { - error = ERROR_INVAL; + error = EINVAL; goto error; } @@ -2218,7 +2218,7 @@ thread_shell_trace(int argc, char *argv[]) task = task_lookup(task_name); if (task == NULL) { - error = ERROR_SRCH; + error = ESRCH; goto error; } @@ -2226,7 +2226,7 @@ thread_shell_trace(int argc, char *argv[]) task_unref(task); if (thread == NULL) { - error = ERROR_SRCH; + error = ESRCH; goto error; } @@ -2244,7 +2244,7 @@ thread_shell_trace(int argc, char *argv[]) return; error: - printf("thread: trace: %s\n", error_str(error)); + printf("thread: trace: %s\n", strerror(error)); } static struct shell_cmd thread_shell_cmds[] = { @@ -2346,14 +2346,14 @@ thread_create(struct thread **threadp, const struct thread_attr *attr, thread = kmem_cache_alloc(&thread_cache); if (thread == NULL) { - error = ERROR_NOMEM; + error = ENOMEM; goto error_thread; } stack = thread_alloc_stack(); if (stack == NULL) { - error = ERROR_NOMEM; + error = ENOMEM; goto error_stack; } @@ -2439,7 +2439,7 @@ thread_wakeup_common(struct thread *thread, int error) unsigned long flags; if ((thread == NULL) || (thread == thread_self())) { - return ERROR_INVAL; + return EINVAL; } /* @@ -2455,7 +2455,7 @@ thread_wakeup_common(struct thread *thread, int error) if (thread->state == THREAD_RUNNING) { thread_unlock_runq(runq, flags); - return ERROR_INVAL; + return EINVAL; } thread_clear_wchan(thread); @@ -2501,7 +2501,7 @@ thread_timeout(struct timer *timer) struct thread_timeout_waiter *waiter; waiter = structof(timer, struct thread_timeout_waiter, timer); - thread_wakeup_common(waiter->thread, ERROR_TIMEDOUT); + thread_wakeup_common(waiter->thread, ETIMEDOUT); } static int diff --git a/kern/thread.h b/kern/thread.h index 97e1de77..3f1ced37 100644 --- a/kern/thread.h +++ b/kern/thread.h @@ -213,8 +213,8 @@ void thread_join(struct thread *thread); * containing the interlock, but not necessarily. * * When bounding the duration of the sleep, the caller must pass an absolute - * time in ticks, and ERROR_TIMEDOUT is returned if that time is reached - * before the thread is awaken. + * time in ticks, and ETIMEDOUT is returned if that time is reached before + * the thread is awaken. * * Implies a memory barrier. */ @@ -227,7 +227,7 @@ int thread_timedsleep(struct spinlock *interlock, const void *wchan_addr, * Schedule a thread for execution on a processor. * * If the target thread is NULL, the calling thread, or already in the - * running state, no action is performed and ERROR_INVAL is returned. + * running state, no action is performed and EINVAL is returned. * * TODO Describe memory ordering with regard to thread_sleep(). */ diff --git a/kern/turnstile.h b/kern/turnstile.h index 8d427db9..6b59dd59 100644 --- a/kern/turnstile.h +++ b/kern/turnstile.h @@ -160,10 +160,10 @@ bool turnstile_empty(const struct turnstile *turnstile); * to prevent unbounded priority inversion. * * When bounding the duration of the wait, the caller must pass an absolute - * time in ticks, and ERROR_TIMEDOUT is returned if that time is reached - * before the turnstile is signalled. In addition, if a timeout occurs, - * the calling thread temporarily releases the turnstile before returning, - * causing other threads to consider the turnstile as empty. + * time in ticks, and ETIMEDOUT is returned if that time is reached before + * the turnstile is signalled. In addition, if a timeout occurs, the calling + * thread temporarily releases the turnstile before returning, causing other + * threads to consider the turnstile as empty. */ void turnstile_wait(struct turnstile *turnstile, const char *wchan, struct thread *owner); diff --git a/kern/work.c b/kern/work.c index d4969619..6151ba48 100644 --- a/kern/work.c +++ b/kern/work.c @@ -16,6 +16,7 @@ */ #include <assert.h> +#include <errno.h> #include <stdalign.h> #include <stddef.h> #include <stdio.h> @@ -414,7 +415,7 @@ work_thread_create(struct work_pool *pool, unsigned int id) worker = kmem_cache_alloc(&work_thread_cache); if (worker == NULL) { - return ERROR_NOMEM; + return ENOMEM; } worker->pool = pool; |