summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Braun <rbraun@sceen.net>2018-02-24 06:45:44 +0100
committerRichard Braun <rbraun@sceen.net>2018-02-24 06:48:21 +0100
commit7dcf6715ffb3cc2f00f6327b896d16f173a1b082 (patch)
tree210570e98e074d7abade0d22c64e05b9c02435ba
parentbe5b9d6ab9f7e7a81c367e4bb0823ba11f85940f (diff)
New errno.h standard header
Use standard errno codes. This change also adds strerror to string.h.
-rw-r--r--arch/x86/machine/atcons.c7
-rw-r--r--arch/x86/machine/atkbd.c18
-rw-r--r--arch/x86/machine/cga.c4
-rw-r--r--arch/x86/machine/ioapic.c2
-rw-r--r--arch/x86/machine/pic.c1
-rw-r--r--arch/x86/machine/pmap.c10
-rw-r--r--arch/x86/machine/uart.c10
-rw-r--r--doc/cenv.9.txt1
-rw-r--r--doc/style.9.txt12
-rw-r--r--include/errno.h32
-rw-r--r--kern/cbuf.c14
-rw-r--r--kern/cbuf.h12
-rw-r--r--kern/condition.h4
-rw-r--r--kern/console.c4
-rw-r--r--kern/cpumap.c6
-rw-r--r--kern/cpumap.h2
-rw-r--r--kern/error.c35
-rw-r--r--kern/error.h16
-rw-r--r--kern/fmt.c22
-rw-r--r--kern/init.c2
-rw-r--r--kern/init.h5
-rw-r--r--kern/intr.c5
-rw-r--r--kern/intr.h2
-rw-r--r--kern/log.c3
-rw-r--r--kern/mutex.h2
-rw-r--r--kern/mutex/mutex_adaptive.c4
-rw-r--r--kern/mutex/mutex_adaptive_i.h6
-rw-r--r--kern/mutex/mutex_plain_i.h6
-rw-r--r--kern/percpu.c8
-rw-r--r--kern/rdxtree.c8
-rw-r--r--kern/rtmutex.h6
-rw-r--r--kern/semaphore.h6
-rw-r--r--kern/shell.c32
-rw-r--r--kern/shell.h3
-rw-r--r--kern/sleepq.h4
-rw-r--r--kern/spinlock.c4
-rw-r--r--kern/spinlock.h4
-rw-r--r--kern/spinlock_i.h6
-rw-r--r--kern/sref.c8
-rw-r--r--kern/sref.h2
-rw-r--r--kern/string.c32
-rw-r--r--kern/string.h1
-rw-r--r--kern/task.c8
-rw-r--r--kern/thread.c24
-rw-r--r--kern/thread.h6
-rw-r--r--kern/turnstile.h8
-rw-r--r--kern/work.c3
-rw-r--r--test/test_sref_noref.c8
-rw-r--r--vm/vm_map.c12
-rw-r--r--vm/vm_object.c3
-rw-r--r--vm/vm_page.h3
51 files changed, 239 insertions, 207 deletions
diff --git a/arch/x86/machine/atcons.c b/arch/x86/machine/atcons.c
index 0c35266f..a94ae91c 100644
--- a/arch/x86/machine/atcons.c
+++ b/arch/x86/machine/atcons.c
@@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <errno.h>
#include <stdbool.h>
#include <string.h>
@@ -76,12 +77,12 @@ atcons_esc_seq_lookup(const struct atcons_esc_seq **seqp)
*seqp = seq;
return 0;
} else {
- return ERROR_AGAIN;
+ return EAGAIN;
}
}
}
- return ERROR_SRCH;
+ return ESRCH;
}
static void
@@ -101,7 +102,7 @@ atcons_process_esc_seq(char c)
error = atcons_esc_seq_lookup(&seq);
if (error) {
- if (error != ERROR_AGAIN) {
+ if (error != EAGAIN) {
atcons_reset_esc_seq();
}
} else {
diff --git a/arch/x86/machine/atkbd.c b/arch/x86/machine/atkbd.c
index 59f8d681..6b530e79 100644
--- a/arch/x86/machine/atkbd.c
+++ b/arch/x86/machine/atkbd.c
@@ -21,12 +21,12 @@
* supported. This includes any communication with the keyboard itself.
*/
+#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <kern/console.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/intr.h>
#include <kern/log.h>
@@ -501,19 +501,19 @@ atkbd_read_status(bool check_out)
*/
if (status == 0xff) {
log_info("atkbd: no keyboard controller");
- return ERROR_NODEV;
+ return ENODEV;
} else if (status & ATKBD_STATUS_PARITY_ERROR) {
log_err("atkbd: parity error");
- return ERROR_IO;
+ return EIO;
} else if (status & ATKBD_STATUS_TIMEOUT_ERROR) {
log_err("atkbd: timeout error");
- return ERROR_TIMEDOUT;
+ return ETIMEDOUT;
}
if (check_out) {
- return (status & ATKBD_STATUS_OUT_FULL) ? 0 : ERROR_AGAIN;
+ return (status & ATKBD_STATUS_OUT_FULL) ? 0 : EAGAIN;
} else {
- return (status & ATKBD_STATUS_IN_FULL) ? ERROR_AGAIN : 0;
+ return (status & ATKBD_STATUS_IN_FULL) ? EAGAIN : 0;
}
}
@@ -531,7 +531,7 @@ atkbd_out_wait(void)
for (;;) {
error = atkbd_read_status(true);
- if (error != ERROR_AGAIN) {
+ if (error != EAGAIN) {
break;
}
}
@@ -547,7 +547,7 @@ atkbd_in_wait(void)
for (;;) {
error = atkbd_read_status(false);
- if (error != ERROR_AGAIN) {
+ if (error != EAGAIN) {
break;
}
}
@@ -599,7 +599,7 @@ atkbd_flush(void)
error = atkbd_read(&byte, false);
} while (!error);
- if (error == ERROR_AGAIN) {
+ if (error == EAGAIN) {
error = 0;
}
diff --git a/arch/x86/machine/cga.c b/arch/x86/machine/cga.c
index b519ba1f..2fdb6085 100644
--- a/arch/x86/machine/cga.c
+++ b/arch/x86/machine/cga.c
@@ -16,12 +16,12 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <kern/console.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/cbuf.h>
#include <kern/macros.h>
@@ -180,7 +180,7 @@ cga_bbuf_get_phys_cursor(const struct cga_bbuf *bbuf, uint16_t *cursorp)
assert((cursor & 1) == 0);
if (cursor >= CGA_MEMORY_SIZE) {
- return ERROR_NODEV;
+ return ENODEV;
}
*cursorp = (cursor >> 1);
diff --git a/arch/x86/machine/ioapic.c b/arch/x86/machine/ioapic.c
index 82fbd6d5..f90e1209 100644
--- a/arch/x86/machine/ioapic.c
+++ b/arch/x86/machine/ioapic.c
@@ -16,10 +16,10 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/intr.h>
#include <kern/kmem.h>
diff --git a/arch/x86/machine/pic.c b/arch/x86/machine/pic.c
index 8ef57538..3c7e7623 100644
--- a/arch/x86/machine/pic.c
+++ b/arch/x86/machine/pic.c
@@ -16,6 +16,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/arch/x86/machine/pmap.c b/arch/x86/machine/pmap.c
index 2b4c23c3..182c765c 100644
--- a/arch/x86/machine/pmap.c
+++ b/arch/x86/machine/pmap.c
@@ -19,13 +19,13 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <kern/cpumap.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/kmem.h>
#include <kern/list.h>
@@ -666,7 +666,7 @@ pmap_update_oplist_create(struct pmap_update_oplist **oplistp)
oplist = kmem_cache_alloc(&pmap_update_oplist_cache);
if (oplist == NULL) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
*oplistp = oplist;
@@ -1122,7 +1122,7 @@ pmap_kextract(uintptr_t va, phys_addr_t *pap)
pte = &ptp[pmap_pte_index(va, pt_level)];
if (!pmap_pte_valid(*pte)) {
- return ERROR_FAULT;
+ return EFAULT;
}
if ((level == 0) || pmap_pte_large(*pte)) {
@@ -1146,7 +1146,7 @@ pmap_create(struct pmap **pmapp)
pmap = kmem_cache_alloc(&pmap_cache);
if (pmap == NULL) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
for (i = 0; i < ARRAY_SIZE(pmap->cpu_tables); i++) {
@@ -1194,7 +1194,7 @@ pmap_enter_local(struct pmap *pmap, uintptr_t va, phys_addr_t pa,
if (page == NULL) {
log_warning("pmap: page table page allocation failure");
- return ERROR_NOMEM;
+ return ENOMEM;
}
ptp_pa = vm_page_to_pa(page);
diff --git a/arch/x86/machine/uart.c b/arch/x86/machine/uart.c
index 10a32886..be9ad725 100644
--- a/arch/x86/machine/uart.c
+++ b/arch/x86/machine/uart.c
@@ -16,11 +16,11 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stdint.h>
#include <kern/arg.h>
#include <kern/console.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/intr.h>
#include <kern/log.h>
@@ -173,7 +173,7 @@ uart_intr(void *arg)
byte = uart_read(uart, UART_REG_IIR);
if (byte & UART_IIR_NOT_PENDING) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
byte &= UART_IIR_SRC_MASK;
@@ -268,7 +268,7 @@ static int __init
uart_init_check_speed(unsigned int speed)
{
if (speed > UART_SPEED_MAX) {
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
@@ -288,7 +288,7 @@ uart_init_convert_parity_char(char c, unsigned int *parity)
*parity = UART_PARITY_EVEN;
break;
default:
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
@@ -301,7 +301,7 @@ uart_init_check_data_bits(unsigned int data_bits)
case 5 ... 8:
break;
default:
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
diff --git a/doc/cenv.9.txt b/doc/cenv.9.txt
index 693d813f..14a9dee3 100644
--- a/doc/cenv.9.txt
+++ b/doc/cenv.9.txt
@@ -42,6 +42,7 @@ X15 augments the environment with a small subset of the functions provided
in hosted environments. The additional headers are :
** cheader:assert
+** cheader:errno
** cheader:limits
** cheader:stdio
** cheader:string
diff --git a/doc/style.9.txt b/doc/style.9.txt
index 01a84e7b..d5b8b3fb 100644
--- a/doc/style.9.txt
+++ b/doc/style.9.txt
@@ -425,11 +425,11 @@ error code, let a NULL value encode that error, otherwise return
it explicitely :
struct my_struct * my_struct_create(...)::
- Return NULL if an error occurs, which may only be ERROR_NOMEM.
+ Return NULL if an error occurs, which may only be ENOMEM.
int my_struct_create(struct my_struct **my_structp, ...)::
- Return an error (ERROR_NOMEM or something else) if creation fails,
- otherwise pass the new object to the caller through the double pointer
- argument and return 0.
+ Return an error (ENOMEM or something else) if creation fails, otherwise
+ pass the new object to the caller through the double pointer argument
+ and return 0.
Methods, which are functions invoked on an object instance, must be
defined so that their first argument is always the object instance
@@ -464,7 +464,7 @@ obj_create(struct obj **objp, int var)
obj = kmem_cache_alloc(&obj_cache);
if (obj == NULL) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
error = subobj_create(&subobj);
@@ -637,7 +637,7 @@ error = do_something();
/* Valid */
if (error) {
- if (error != ERROR_AGAIN) {
+ if (error != EAGAIN) {
printf("unexpected error\n");
}
diff --git a/include/errno.h b/include/errno.h
new file mode 100644
index 00000000..63dd3314
--- /dev/null
+++ b/include/errno.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2018 Richard Braun.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ERRNO_H
+#define ERRNO_H
+
+#define ENOMEM 1
+#define EAGAIN 2
+#define EINVAL 3
+#define EBUSY 4
+#define EFAULT 5
+#define ENODEV 6
+#define EEXIST 7
+#define EIO 8
+#define ESRCH 9
+#define ETIMEDOUT 10
+
+#endif /* ERRNO_H */
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.
diff --git a/kern/fmt.c b/kern/fmt.c
index 097ba234..f43a6084 100644
--- a/kern/fmt.c
+++ b/kern/fmt.c
@@ -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);
diff --git a/kern/log.c b/kern/log.c
index e04eea63..04afbcd8 100644
--- a/kern/log.c
+++ b/kern/log.c
@@ -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;
diff --git a/test/test_sref_noref.c b/test/test_sref_noref.c
index 40f1d8fe..f5b1875e 100644
--- a/test/test_sref_noref.c
+++ b/test/test_sref_noref.c
@@ -32,12 +32,14 @@
* to occur.
*/
+#include <errno.h>
#include <stddef.h>
#include <stdio.h>
+#include <string.h>
#include <kern/condition.h>
-#include <kern/error.h>
#include <kern/init.h>
+#include <kern/error.h>
#include <kern/kmem.h>
#include <kern/macros.h>
#include <kern/mutex.h>
@@ -126,7 +128,7 @@ test_run(void *arg)
threads = kmem_alloc(sizeof(*threads) * nr_threads);
if (threads == NULL) {
- panic("kmem_alloc: %s", error_str(ERROR_NOMEM));
+ panic("kmem_alloc: %s", strerror(ENOMEM));
}
for (i = 0; i < nr_threads; i++) {
@@ -140,7 +142,7 @@ test_run(void *arg)
obj = vm_kmem_alloc(sizeof(*obj));
if (obj == NULL) {
- panic("vm_kmem_alloc: %s", error_str(ERROR_NOMEM));
+ panic("vm_kmem_alloc: %s", strerror(ENOMEM));
}
sref_counter_init(&obj->ref_counter, 1, NULL, test_obj_noref);
diff --git a/vm/vm_map.c b/vm/vm_map.c
index c0e9e116..91eedf85 100644
--- a/vm/vm_map.c
+++ b/vm/vm_map.c
@@ -20,11 +20,11 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
-#include <kern/error.h>
#include <kern/init.h>
#include <kern/kmem.h>
#include <kern/list.h>
@@ -202,14 +202,14 @@ vm_map_find_fixed(struct vm_map *map, struct vm_map_request *request)
size = request->size;
if ((start < map->start) || (start + size) > map->end) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
next = vm_map_lookup_nearest(map, start);
if (next == NULL) {
if ((map->end - start) < size) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
request->next = NULL;
@@ -217,7 +217,7 @@ vm_map_find_fixed(struct vm_map *map, struct vm_map_request *request)
}
if ((start >= next->start) || ((next->start - start) < size)) {
- return ERROR_NOMEM;
+ return ENOMEM;
}
request->next = next;
@@ -281,7 +281,7 @@ retry:
goto retry;
}
- return ERROR_NOMEM;
+ return ENOMEM;
}
if (next == NULL) {
@@ -784,7 +784,7 @@ vm_map_create(struct vm_map **mapp)
map = kmem_cache_alloc(&vm_map_cache);
if (map == NULL) {
- error = ERROR_NOMEM;
+ error = ENOMEM;
goto error_map;
}
diff --git a/vm/vm_object.c b/vm/vm_object.c
index 2cb4eed3..0d04b002 100644
--- a/vm/vm_object.c
+++ b/vm/vm_object.c
@@ -20,6 +20,7 @@
*/
#include <assert.h>
+#include <errno.h>
#include <stddef.h>
#include <stdint.h>
@@ -72,7 +73,7 @@ vm_object_insert(struct vm_object *object, struct vm_page *page,
mutex_lock(&object->lock);
if (offset >= object->size) {
- error = ERROR_INVAL;
+ error = EINVAL;
goto error;
}
diff --git a/vm/vm_page.h b/vm/vm_page.h
index 49daa098..6a161c07 100644
--- a/vm/vm_page.h
+++ b/vm/vm_page.h
@@ -25,6 +25,7 @@
#define VM_VM_PAGE_H
#include <assert.h>
+#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -268,7 +269,7 @@ vm_page_tryref(struct vm_page *page)
nr_refs = atomic_load(&page->nr_refs, ATOMIC_RELAXED);
if (nr_refs == 0) {
- return ERROR_AGAIN;
+ return EAGAIN;
}
prev = atomic_cas_acquire(&page->nr_refs, nr_refs, nr_refs + 1);