summaryrefslogtreecommitdiff
path: root/kern
diff options
context:
space:
mode:
authorRemy Noel <mocramis@gmail.com>2018-02-25 17:36:21 +0100
committerRemy Noel <mocramis@gmail.com>2018-02-25 18:19:05 +0100
commitc8030a59c79846363587381a41f1d71f1bde5177 (patch)
tree898d36fb4f5de32a8600a1d6be9c099b17210869 /kern
parentcba7db6931932953fd0113a70019049234eb0b08 (diff)
parent045500a2c88f4e6b877a4695908eb129340f6782 (diff)
Merge branch 'master' into perfmon
Diffstat (limited to 'kern')
-rw-r--r--kern/Kconfig6
-rw-r--r--kern/arg.h6
-rw-r--r--kern/atomic.h16
-rw-r--r--kern/bitmap.c5
-rw-r--r--kern/bitmap.h11
-rw-r--r--kern/bitmap_i.h11
-rw-r--r--kern/cbuf.c17
-rw-r--r--kern/cbuf.h27
-rw-r--r--kern/clock.h6
-rw-r--r--kern/clock_i.h6
-rw-r--r--kern/condition.h10
-rw-r--r--kern/condition_types.h6
-rw-r--r--kern/console.c4
-rw-r--r--kern/console.h6
-rw-r--r--kern/cpumap.c6
-rw-r--r--kern/cpumap.h8
-rw-r--r--kern/error.c35
-rw-r--r--kern/error.h22
-rw-r--r--kern/fmt.c27
-rw-r--r--kern/fmt.h13
-rw-r--r--kern/hash.h11
-rw-r--r--kern/hlist.h45
-rw-r--r--kern/hlist_types.h6
-rw-r--r--kern/init.c2
-rw-r--r--kern/init.h11
-rw-r--r--kern/init_i.h6
-rw-r--r--kern/intr.c5
-rw-r--r--kern/intr.h8
-rw-r--r--kern/kernel.h6
-rw-r--r--kern/kmem.c8
-rw-r--r--kern/kmem.h6
-rw-r--r--kern/kmem_i.h6
-rw-r--r--kern/list.h31
-rw-r--r--kern/list_types.h6
-rw-r--r--kern/log.c3
-rw-r--r--kern/log.h6
-rw-r--r--kern/log2.h16
-rw-r--r--kern/macros.h9
-rw-r--r--kern/mutex.h8
-rw-r--r--kern/mutex/mutex_adaptive.c4
-rw-r--r--kern/mutex/mutex_adaptive_i.h14
-rw-r--r--kern/mutex/mutex_adaptive_types.h8
-rw-r--r--kern/mutex/mutex_pi_i.h8
-rw-r--r--kern/mutex/mutex_pi_types.h8
-rw-r--r--kern/mutex/mutex_plain_i.h14
-rw-r--r--kern/mutex/mutex_plain_types.h8
-rw-r--r--kern/mutex_types.h6
-rw-r--r--kern/panic.h6
-rw-r--r--kern/percpu.c8
-rw-r--r--kern/percpu.h6
-rw-r--r--kern/perfmon.c22
-rw-r--r--kern/perfmon.h4
-rw-r--r--kern/plist.c7
-rw-r--r--kern/plist.h9
-rw-r--r--kern/plist_types.h6
-rw-r--r--kern/printf.h10
-rw-r--r--kern/rbtree.c3
-rw-r--r--kern/rbtree.h105
-rw-r--r--kern/rbtree_i.h9
-rw-r--r--kern/rcu.h6
-rw-r--r--kern/rcu_i.h6
-rw-r--r--kern/rcu_types.h6
-rw-r--r--kern/rdxtree.c25
-rw-r--r--kern/rdxtree.h17
-rw-r--r--kern/rdxtree_i.h16
-rw-r--r--kern/rtmutex.h12
-rw-r--r--kern/rtmutex_i.h6
-rw-r--r--kern/rtmutex_types.h6
-rw-r--r--kern/semaphore.h12
-rw-r--r--kern/semaphore_i.h6
-rw-r--r--kern/shell.c39
-rw-r--r--kern/shell.h25
-rw-r--r--kern/shutdown.h6
-rw-r--r--kern/sleepq.h10
-rw-r--r--kern/slist.h55
-rw-r--r--kern/slist_types.h6
-rw-r--r--kern/spinlock.c4
-rw-r--r--kern/spinlock.h10
-rw-r--r--kern/spinlock_i.h12
-rw-r--r--kern/spinlock_types.h6
-rw-r--r--kern/sref.c8
-rw-r--r--kern/sref.h8
-rw-r--r--kern/sref_i.h6
-rw-r--r--kern/string.c34
-rw-r--r--kern/string.h7
-rw-r--r--kern/syscnt.h6
-rw-r--r--kern/syscnt_types.h6
-rw-r--r--kern/task.c8
-rw-r--r--kern/task.h6
-rw-r--r--kern/thread.c30
-rw-r--r--kern/thread.h12
-rw-r--r--kern/thread_i.h6
-rw-r--r--kern/timer.h6
-rw-r--r--kern/timer_i.h6
-rw-r--r--kern/turnstile.h14
-rw-r--r--kern/turnstile_types.h6
-rw-r--r--kern/types.h6
-rw-r--r--kern/work.c3
-rw-r--r--kern/work.h6
-rw-r--r--kern/work_i.h6
-rw-r--r--kern/xcall.h6
101 files changed, 640 insertions, 559 deletions
diff --git a/kern/Kconfig b/kern/Kconfig
index 39ed902..3101b7f 100644
--- a/kern/Kconfig
+++ b/kern/Kconfig
@@ -90,6 +90,12 @@ endmenu
menu "Debugging"
+config KMEM_DEBUG
+ bool "Kernel allocator debugging"
+ default n
+ ---help---
+ Enable the debugging of the kernel allocator.
+
config INIT_DEBUG
bool "Initialization debugging"
default n
diff --git a/kern/arg.h b/kern/arg.h
index c7b70a3..c4c2a2b 100644
--- a/kern/arg.h
+++ b/kern/arg.h
@@ -22,8 +22,8 @@
* or not), or "name=value".
*/
-#ifndef _KERN_ARG_H
-#define _KERN_ARG_H
+#ifndef KERN_ARG_H
+#define KERN_ARG_H
#include <stdbool.h>
@@ -64,4 +64,4 @@ const char * arg_value(const char *name);
*/
INIT_OP_DECLARE(arg_setup);
-#endif /* _KERN_ARG_H */
+#endif /* KERN_ARG_H */
diff --git a/kern/atomic.h b/kern/atomic.h
index 940720a..e106dac 100644
--- a/kern/atomic.h
+++ b/kern/atomic.h
@@ -21,8 +21,8 @@
* C11 memory model terminology.
*/
-#ifndef _KERN_ATOMIC_H
-#define _KERN_ATOMIC_H
+#ifndef KERN_ATOMIC_H
+#define KERN_ATOMIC_H
#include <stdbool.h>
@@ -91,13 +91,13 @@
*/
#define atomic_cas(ptr, oval, nval, mo) \
MACRO_BEGIN \
- typeof(*(ptr)) ___oval, ___nval; \
+ typeof(*(ptr)) oval___, nval___; \
\
- ___oval = (oval); \
- ___nval = (nval); \
- __atomic_compare_exchange_n(ptr, &___oval, ___nval, false, \
+ oval___ = (oval); \
+ nval___ = (nval); \
+ __atomic_compare_exchange_n(ptr, &oval___, nval___, false, \
mo, ATOMIC_RELAXED); \
- ___oval; \
+ oval___; \
MACRO_END
/*
@@ -147,4 +147,4 @@ MACRO_END
#define atomic_fetch_sub_acq_rel(ptr, val) \
atomic_fetch_sub(ptr, val, ATOMIC_ACQ_REL)
-#endif /* _KERN_ATOMIC_H */
+#endif /* KERN_ATOMIC_H */
diff --git a/kern/bitmap.c b/kern/bitmap.c
index 97e497d..11f33df 100644
--- a/kern/bitmap.c
+++ b/kern/bitmap.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 Richard Braun.
+ * Copyright (c) 2013-2015 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
@@ -13,6 +13,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#include <limits.h>
diff --git a/kern/bitmap.h b/kern/bitmap.h
index 9a3d7a0..0932c39 100644
--- a/kern/bitmap.h
+++ b/kern/bitmap.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013-2014 Richard Braun.
+ * Copyright (c) 2013-2015 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
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Arbitrary-length bit arrays.
*
@@ -21,8 +24,8 @@
* is the responsibility of the caller.
*/
-#ifndef _KERN_BITMAP_H
-#define _KERN_BITMAP_H
+#ifndef KERN_BITMAP_H
+#define KERN_BITMAP_H
#include <limits.h>
#include <string.h>
@@ -193,4 +196,4 @@ for ((bit) = 0; \
&& (((bit) = bitmap_find_next_zero(bm, nr_bits, bit)) != -1); \
(bit)++)
-#endif /* _KERN_BITMAP_H */
+#endif /* KERN_BITMAP_H */
diff --git a/kern/bitmap_i.h b/kern/bitmap_i.h
index dc91a0a..cc4eff6 100644
--- a/kern/bitmap_i.h
+++ b/kern/bitmap_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Richard Braun.
+ * Copyright (c) 2013-2015 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
@@ -13,10 +13,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
-#ifndef _KERN_BITMAP_I_H
-#define _KERN_BITMAP_I_H
+#ifndef KERN_BITMAP_I_H
+#define KERN_BITMAP_I_H
#include <limits.h>
@@ -54,4 +57,4 @@ bitmap_mask(int bit)
int bitmap_find_next_bit(const unsigned long *bm, int nr_bits, int bit,
int complement);
-#endif /* _KERN_BITMAP_I_H */
+#endif /* KERN_BITMAP_I_H */
diff --git a/kern/cbuf.c b/kern/cbuf.c
index 2093f42..fcfcc1d 100644
--- a/kern/cbuf.c
+++ b/kern/cbuf.c
@@ -13,15 +13,18 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#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 +65,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 +78,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 +96,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 +112,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 +128,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 +169,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 a64121d..38215c1 100644
--- a/kern/cbuf.h
+++ b/kern/cbuf.h
@@ -14,12 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Circular byte buffer.
*/
-#ifndef _KERN_CBUF_H
-#define _KERN_CBUF_H
+#ifndef KERN_CBUF_H
+#define KERN_CBUF_H
#include <stdbool.h>
#include <stddef.h>
@@ -62,6 +65,12 @@ cbuf_size(const struct cbuf *cbuf)
return cbuf->end - cbuf->start;
}
+static inline size_t
+cbuf_avail_size(const struct cbuf *cbuf)
+{
+ return cbuf_capacity(cbuf) - cbuf_size(cbuf);
+}
+
static inline void
cbuf_clear(struct cbuf *cbuf)
{
@@ -88,7 +97,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 +107,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 +116,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,10 +142,10 @@ 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.
*/
int cbuf_read(const struct cbuf *cbuf, size_t index, void *buf, size_t *sizep);
-#endif /* _KERN_CBUF_H */
+#endif /* KERN_CBUF_H */
diff --git a/kern/clock.h b/kern/clock.h
index 3b695d5..7beae9c 100644
--- a/kern/clock.h
+++ b/kern/clock.h
@@ -18,8 +18,8 @@
* Timekeeping module.
*/
-#ifndef _KERN_CLOCK_H
-#define _KERN_CLOCK_H
+#ifndef KERN_CLOCK_H
+#define KERN_CLOCK_H
#include <stdbool.h>
#include <stdint.h>
@@ -116,4 +116,4 @@ clock_time_occurred(uint64_t t, uint64_t ref)
void clock_tick_intr(void);
-#endif /* _KERN_CLOCK_H */
+#endif /* KERN_CLOCK_H */
diff --git a/kern/clock_i.h b/kern/clock_i.h
index 8b98f5e..bf8d431 100644
--- a/kern/clock_i.h
+++ b/kern/clock_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_CLOCK_I_H
-#define _KERN_CLOCK_I_H
+#ifndef KERN_CLOCK_I_H
+#define KERN_CLOCK_I_H
#include <stdalign.h>
#include <stdint.h>
@@ -40,4 +40,4 @@ union clock_global_time {
#endif /* ATOMIC_HAVE_64B_OPS */
};
-#endif /* _KERN_CLOCK_I_H */
+#endif /* KERN_CLOCK_I_H */
diff --git a/kern/condition.h b/kern/condition.h
index 2082bee..f6d1fd6 100644
--- a/kern/condition.h
+++ b/kern/condition.h
@@ -24,8 +24,8 @@
* with a mutex.
*/
-#ifndef _KERN_CONDITION_H
-#define _KERN_CONDITION_H
+#ifndef KERN_CONDITION_H
+#define KERN_CONDITION_H
#include <stdint.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,
@@ -65,4 +65,4 @@ int condition_timedwait(struct condition *condition,
void condition_signal(struct condition *condition);
void condition_broadcast(struct condition *condition);
-#endif /* _KERN_CONDITION_H */
+#endif /* KERN_CONDITION_H */
diff --git a/kern/condition_types.h b/kern/condition_types.h
index abd42f2..ddff2ae 100644
--- a/kern/condition_types.h
+++ b/kern/condition_types.h
@@ -18,11 +18,11 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_CONDITION_TYPES_H
-#define _KERN_CONDITION_TYPES_H
+#ifndef KERN_CONDITION_TYPES_H
+#define KERN_CONDITION_TYPES_H
struct condition {
unsigned int _unused;
};
-#endif /* _KERN_CONDITION_TYPES_H */
+#endif /* KERN_CONDITION_TYPES_H */
diff --git a/kern/console.c b/kern/console.c
index 0ed54b5..a9a0f5d 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/console.h b/kern/console.h
index 1578997..2c242d0 100644
--- a/kern/console.h
+++ b/kern/console.h
@@ -18,8 +18,8 @@
* Device-independent console interface.
*/
-#ifndef _KERN_CONSOLE_H
-#define _KERN_CONSOLE_H
+#ifndef KERN_CONSOLE_H
+#define KERN_CONSOLE_H
#include <kern/cbuf.h>
#include <kern/init.h>
@@ -104,4 +104,4 @@ INIT_OP_DECLARE(console_bootstrap);
*/
INIT_OP_DECLARE(console_setup);
-#endif /* _KERN_CONSOLE_H */
+#endif /* KERN_CONSOLE_H */
diff --git a/kern/cpumap.c b/kern/cpumap.c
index d166b23..729b22b 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 89873b5..e0ac9fc 100644
--- a/kern/cpumap.h
+++ b/kern/cpumap.h
@@ -23,8 +23,8 @@
* stack.
*/
-#ifndef _KERN_CPUMAP_H
-#define _KERN_CPUMAP_H
+#ifndef KERN_CPUMAP_H
+#define KERN_CPUMAP_H
#include <kern/bitmap.h>
#include <kern/init.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);
@@ -170,4 +170,4 @@ int cpumap_check(const struct cpumap *cpumap);
*/
INIT_OP_DECLARE(cpumap_setup);
-#endif /* _KERN_CPUMAP_H */
+#endif /* KERN_CPUMAP_H */
diff --git a/kern/error.c b/kern/error.c
index f5d43e4..10d6954 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 a77db97..3e98bed 100644
--- a/kern/error.h
+++ b/kern/error.h
@@ -15,24 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#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);
+#ifndef KERN_ERROR_H
+#define KERN_ERROR_H
/*
* If error denotes an actual error (i.e. is not 0), panic, using the given
@@ -40,4 +24,4 @@ const char * error_str(int error);
*/
void error_check(int error, const char *prefix);
-#endif /* _KERN_ERROR_H */
+#endif /* KERN_ERROR_H */
diff --git a/kern/fmt.c b/kern/fmt.c
index 097ba23..61eef79 100644
--- a/kern/fmt.c
+++ b/kern/fmt.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2017 Richard Braun.
+ * Copyright (c) 2010-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
@@ -13,9 +13,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#include <assert.h>
+#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdarg.h>
@@ -24,7 +28,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 +404,12 @@ fmt_sprintf_state_consume(struct fmt_sprintf_state *state)
c = fmt_consume(&state->format);
if (c == '\0') {
- return ERROR_IO;
+ return ENOENT;
}
if (c != '%') {
fmt_sprintf_state_produce_raw_char(state, c);
- return ERROR_AGAIN;
+ return EAGAIN;
}
fmt_sprintf_state_consume_flags(state);
@@ -783,7 +786,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 +1069,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 +1086,7 @@ fmt_sscanf_state_consume(struct fmt_sscanf_state *state)
c = fmt_consume(&state->format);
if (c == '\0') {
- return ERROR_IO;
+ return ENOENT;
}
if (c != '%') {
@@ -1093,7 +1096,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 +1188,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 +1382,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 +1417,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 +1445,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/fmt.h b/kern/fmt.h
index 9715d82..c23a6a0 100644
--- a/kern/fmt.h
+++ b/kern/fmt.h
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Formatted string functions.
*
@@ -32,14 +35,10 @@
* common:
* - modifiers: hh h l ll z t
* - specifiers: d i o u x X c s p n %
- *
- *
- * Upstream site with license notes :
- * http://git.sceen.net/rbraun/librbraun.git/
*/
-#ifndef _FMT_H
-#define _FMT_H
+#ifndef KERN_FMT_H
+#define KERN_FMT_H
#include <stdarg.h>
#include <stddef.h>
@@ -62,4 +61,4 @@ int fmt_sscanf(const char *str, const char *format, ...)
int fmt_vsscanf(const char *str, const char *format, va_list ap)
__attribute__((format(scanf, 2, 0)));
-#endif /* _FMT_H */
+#endif /* KERN_FMT_H */
diff --git a/kern/hash.h b/kern/hash.h
index 666f10d..9d7778e 100644
--- a/kern/hash.h
+++ b/kern/hash.h
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Hash functions for integers and strings.
*
@@ -36,8 +39,8 @@
* HASH_ALLBITS macro.
*/
-#ifndef _KERN_HASH_H
-#define _KERN_HASH_H
+#ifndef KERN_HASH_H
+#define KERN_HASH_H
#include <assert.h>
#include <stdint.h>
@@ -110,7 +113,7 @@ hash_str(const char *str, unsigned int bits)
hash = ((hash << 5) - hash) + c;
}
- return hash & ((1 << bits) - 1);
+ return hash & ((1UL << bits) - 1);
}
-#endif /* _KERN_HASH_H */
+#endif /* KERN_HASH_H */
diff --git a/kern/hlist.h b/kern/hlist.h
index 83d64fe..61fad4f 100644
--- a/kern/hlist.h
+++ b/kern/hlist.h
@@ -14,12 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Doubly-linked list specialized for forward traversals and O(1) removals.
*/
-#ifndef _KERN_HLIST_H
-#define _KERN_HLIST_H
+#ifndef KERN_HLIST_H
+#define KERN_HLIST_H
#include <stdbool.h>
#include <stddef.h>
@@ -149,7 +152,7 @@ hlist_insert_head(struct hlist *list, struct hlist_node *node)
* Insert a node before another node.
*/
static inline void
-hlist_insert_before(struct hlist_node *next, struct hlist_node *node)
+hlist_insert_before(struct hlist_node *node, struct hlist_node *next)
{
node->next = next;
node->pprev = next->pprev;
@@ -161,7 +164,7 @@ hlist_insert_before(struct hlist_node *next, struct hlist_node *node)
* Insert a node after another node.
*/
static inline void
-hlist_insert_after(struct hlist_node *prev, struct hlist_node *node)
+hlist_insert_after(struct hlist_node *node, struct hlist_node *prev)
{
node->next = prev->next;
node->pprev = &prev->next;
@@ -197,10 +200,10 @@ hlist_remove(struct hlist_node *node)
*/
#define hlist_first_entry(list, type, member) \
MACRO_BEGIN \
- struct hlist_node *___first; \
+ struct hlist_node *first___; \
\
- ___first = (list)->first; \
- hlist_end(___first) ? NULL : hlist_entry(___first, type, member); \
+ first___ = (list)->first; \
+ hlist_end(first___) ? NULL : hlist_entry(first___, type, member); \
MACRO_END
/*
@@ -208,12 +211,12 @@ MACRO_END
*/
#define hlist_next_entry(entry, member) \
MACRO_BEGIN \
- struct hlist_node *___next; \
+ struct hlist_node *next___; \
\
- ___next = (entry)->member.next; \
- hlist_end(___next) \
+ next___ = (entry)->member.next; \
+ hlist_end(next___) \
? NULL \
- : hlist_entry(___next, typeof(*entry), member); \
+ : hlist_entry(next___, typeof(*entry), member); \
MACRO_END
/*
@@ -303,7 +306,7 @@ hlist_rcu_insert_head(struct hlist *list, struct hlist_node *node)
* Insert a node before another node.
*/
static inline void
-hlist_rcu_insert_before(struct hlist_node *next, struct hlist_node *node)
+hlist_rcu_insert_before(struct hlist_node *node, struct hlist_node *next)
{
node->next = next;
node->pprev = next->pprev;
@@ -315,7 +318,7 @@ hlist_rcu_insert_before(struct hlist_node *next, struct hlist_node *node)
* Insert a node after another node.
*/
static inline void
-hlist_rcu_insert_after(struct hlist_node *prev, struct hlist_node *node)
+hlist_rcu_insert_after(struct hlist_node *node, struct hlist_node *prev)
{
node->next = prev->next;
node->pprev = &prev->next;
@@ -352,10 +355,10 @@ hlist_rcu_remove(struct hlist_node *node)
*/
#define hlist_rcu_first_entry(list, type, member) \
MACRO_BEGIN \
- struct hlist_node *___first; \
+ struct hlist_node *first___; \
\
- ___first = hlist_rcu_first(list); \
- hlist_end(___first) ? NULL : hlist_entry(___first, type, member); \
+ first___ = hlist_rcu_first(list); \
+ hlist_end(first___) ? NULL : hlist_entry(first___, type, member); \
MACRO_END
/*
@@ -363,12 +366,12 @@ MACRO_END
*/
#define hlist_rcu_next_entry(entry, member) \
MACRO_BEGIN \
- struct hlist_node *___next; \
+ struct hlist_node *next___; \
\
- ___next = hlist_rcu_next(&entry->member); \
- hlist_end(___next) \
+ next___ = hlist_rcu_next(&entry->member); \
+ hlist_end(next___) \
? NULL \
- : hlist_entry(___next, typeof(*entry), member); \
+ : hlist_entry(next___, typeof(*entry), member); \
MACRO_END
/*
@@ -387,4 +390,4 @@ for (entry = hlist_rcu_first_entry(list, typeof(*entry), member); \
entry != NULL; \
entry = hlist_rcu_next_entry(entry, member))
-#endif /* _KERN_HLIST_H */
+#endif /* KERN_HLIST_H */
diff --git a/kern/hlist_types.h b/kern/hlist_types.h
index f50b62d..facb01a 100644
--- a/kern/hlist_types.h
+++ b/kern/hlist_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_HLIST_TYPES_H
-#define _KERN_HLIST_TYPES_H
+#ifndef KERN_HLIST_TYPES_H
+#define KERN_HLIST_TYPES_H
/*
* List node.
@@ -37,4 +37,4 @@ struct hlist {
struct hlist_node *first;
};
-#endif /* _KERN_HLIST_TYPES_H */
+#endif /* KERN_HLIST_TYPES_H */
diff --git a/kern/init.c b/kern/init.c
index 22db295..dd69997 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 7c3522e..809123d 100644
--- a/kern/init.h
+++ b/kern/init.h
@@ -18,8 +18,8 @@
* Init sections and operations.
*/
-#ifndef _KERN_INIT_H
-#define _KERN_INIT_H
+#ifndef KERN_INIT_H
+#define KERN_INIT_H
/*
* These sections should contain code and data which can be discarded once
@@ -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, \
@@ -110,4 +111,4 @@ void init_setup(void);
#endif /* __ASSEMBLER__ */
-#endif /* _KERN_INIT_H */
+#endif /* KERN_INIT_H */
diff --git a/kern/init_i.h b/kern/init_i.h
index ed59062..fb65f3a 100644
--- a/kern/init_i.h
+++ b/kern/init_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_INIT_I_H
-#define _KERN_INIT_I_H
+#ifndef KERN_INIT_I_H
+#define KERN_INIT_I_H
#include <stdalign.h>
#include <stdbool.h>
@@ -54,4 +54,4 @@ struct init_op_dep {
#define __INIT_OP(fn) fn ## _init_op
#define INIT_OP(fn) __INIT_OP(fn)
-#endif /* _KERN_INIT_I_H */
+#endif /* KERN_INIT_I_H */
diff --git a/kern/intr.c b/kern/intr.c
index 9a1ad71..541dc5c 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 ac3f8cf..655c098 100644
--- a/kern/intr.h
+++ b/kern/intr.h
@@ -18,8 +18,8 @@
* Machine-independent interrupt management.
*/
-#ifndef _KERN_INTR_H
-#define _KERN_INTR_H
+#ifndef KERN_INTR_H
+#define KERN_INTR_H
#include <kern/init.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);
@@ -76,4 +76,4 @@ INIT_OP_DECLARE(intr_bootstrap);
*/
INIT_OP_DECLARE(intr_setup);
-#endif /* _KERN_INTR_H */
+#endif /* KERN_INTR_H */
diff --git a/kern/kernel.h b/kern/kernel.h
index f14b95b..959f2a2 100644
--- a/kern/kernel.h
+++ b/kern/kernel.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_KERNEL_H
-#define _KERN_KERNEL_H
+#ifndef KERN_KERNEL_H
+#define KERN_KERNEL_H
#include <stdnoreturn.h>
@@ -40,4 +40,4 @@ noreturn void kernel_main(void);
*/
noreturn void kernel_ap_main(void);
-#endif /* _KERN_KERNEL_H */
+#endif /* KERN_KERNEL_H */
diff --git a/kern/kmem.c b/kern/kmem.c
index 1d9fe4e..b87f4b1 100644
--- a/kern/kmem.c
+++ b/kern/kmem.c
@@ -550,11 +550,11 @@ kmem_cache_init(struct kmem_cache *cache, const char *name, size_t obj_size,
struct kmem_cpu_pool_type *cpu_pool_type;
size_t i, buf_size;
-#ifdef KMEM_VERIFY
+#ifdef CONFIG_KMEM_DEBUG
cache->flags = KMEM_CF_VERIFY;
-#else /* KMEM_CF_VERIFY */
+#else /* CONFIG_KMEM_DEBUG */
cache->flags = 0;
-#endif /* KMEM_CF_VERIFY */
+#endif /* CONFIG_KMEM_DEBUG */
if (flags & KMEM_CACHE_VERIFY) {
cache->flags |= KMEM_CF_VERIFY;
@@ -1242,7 +1242,7 @@ INIT_OP_DEFINE(kmem_setup,
static inline size_t
kmem_get_index(unsigned long size)
{
- return iorder2(size) - KMEM_CACHES_FIRST_ORDER;
+ return log2_order(size) - KMEM_CACHES_FIRST_ORDER;
}
static void
diff --git a/kern/kmem.h b/kern/kmem.h
index 3296ddb..3a3afb5 100644
--- a/kern/kmem.h
+++ b/kern/kmem.h
@@ -18,8 +18,8 @@
* Object caching and general purpose memory allocator.
*/
-#ifndef _KERN_KMEM_H
-#define _KERN_KMEM_H
+#ifndef KERN_KMEM_H
+#define KERN_KMEM_H
#include <stddef.h>
@@ -112,4 +112,4 @@ INIT_OP_DECLARE(kmem_bootstrap);
*/
INIT_OP_DECLARE(kmem_setup);
-#endif /* _KERN_KMEM_H */
+#endif /* KERN_KMEM_H */
diff --git a/kern/kmem_i.h b/kern/kmem_i.h
index 0c0afd3..f170596 100644
--- a/kern/kmem_i.h
+++ b/kern/kmem_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_KMEM_I_H
-#define _KERN_KMEM_I_H
+#ifndef KERN_KMEM_I_H
+#define KERN_KMEM_I_H
#include <stdalign.h>
#include <stddef.h>
@@ -197,4 +197,4 @@ struct kmem_cache {
size_t redzone_pad; /* Bytes from end of object to redzone word */
};
-#endif /* _KERN_KMEM_I_H */
+#endif /* KERN_KMEM_I_H */
diff --git a/kern/list.h b/kern/list.h
index 7ea3992..832d94f 100644
--- a/kern/list.h
+++ b/kern/list.h
@@ -14,12 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Doubly-linked list.
*/
-#ifndef _KERN_LIST_H
-#define _KERN_LIST_H
+#ifndef KERN_LIST_H
+#define KERN_LIST_H
#include <stdbool.h>
#include <stddef.h>
@@ -136,7 +139,7 @@ list_empty(const struct list *list)
static inline bool
list_singular(const struct list *list)
{
- return (list != list->next) && (list->next == list->prev);
+ return !list_empty(list) && (list->next == list->prev);
}
/*
@@ -248,7 +251,7 @@ list_insert_tail(struct list *list, struct list *node)
* Insert a node before another node.
*/
static inline void
-list_insert_before(struct list *next, struct list *node)
+list_insert_before(struct list *node, struct list *next)
{
list_add(next->prev, next, node);
}
@@ -257,7 +260,7 @@ list_insert_before(struct list *next, struct list *node)
* Insert a node after another node.
*/
static inline void
-list_insert_after(struct list *prev, struct list *node)
+list_insert_after(struct list *node, struct list *prev)
{
list_add(prev, prev->next, node);
}
@@ -435,7 +438,7 @@ list_rcu_insert_tail(struct list *list, struct list *node)
* Insert a node before another node.
*/
static inline void
-list_rcu_insert_before(struct list *next, struct list *node)
+list_rcu_insert_before(struct list *node, struct list *next)
{
list_rcu_add(next->prev, next, node);
}
@@ -444,7 +447,7 @@ list_rcu_insert_before(struct list *next, struct list *node)
* Insert a node after another node.
*/
static inline void
-list_rcu_insert_after(struct list *prev, struct list *node)
+list_rcu_insert_after(struct list *node, struct list *prev)
{
list_rcu_add(prev, prev->next, node);
}
@@ -477,14 +480,14 @@ list_rcu_remove(struct list *node)
*/
#define list_rcu_first_entry(list, type, member) \
MACRO_BEGIN \
- struct list *___list; \
- struct list *___first; \
+ struct list *list___; \
+ struct list *first___; \
\
- ___list = (list); \
- ___first = list_rcu_first(___list); \
- list_end(___list, ___first) \
+ list___ = (list); \
+ first___ = list_rcu_first(list___); \
+ list_end(list___, first___) \
? NULL \
- : list_entry(___first, type, member); \
+ : list_entry(first___, type, member); \
MACRO_END
/*
@@ -519,4 +522,4 @@ for (entry = list_rcu_entry(list_first(list), \
entry = list_rcu_entry(list_next(&entry->member), \
typeof(*entry), member))
-#endif /* _KERN_LIST_H */
+#endif /* KERN_LIST_H */
diff --git a/kern/list_types.h b/kern/list_types.h
index d6573cf..b76064a 100644
--- a/kern/list_types.h
+++ b/kern/list_types.h
@@ -18,12 +18,12 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_LIST_TYPES_H
-#define _KERN_LIST_TYPES_H
+#ifndef KERN_LIST_TYPES_H
+#define KERN_LIST_TYPES_H
struct list {
struct list *prev;
struct list *next;
};
-#endif /* _KERN_LIST_TYPES_H */
+#endif /* KERN_LIST_TYPES_H */
diff --git a/kern/log.c b/kern/log.c
index e04eea6..04afbcd 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/log.h b/kern/log.h
index 581a784..1a05334 100644
--- a/kern/log.h
+++ b/kern/log.h
@@ -18,8 +18,8 @@
* System logging.
*/
-#ifndef _KERN_LOG_H
-#define _KERN_LOG_H
+#ifndef KERN_LOG_H
+#define KERN_LOG_H
#include <stdarg.h>
@@ -93,4 +93,4 @@ int log_vdebug(const char *format, va_list ap)
*/
INIT_OP_DECLARE(log_setup);
-#endif /* _KERN_LOG_H */
+#endif /* KERN_LOG_H */
diff --git a/kern/log2.h b/kern/log2.h
index 762aaa7..1799b82 100644
--- a/kern/log2.h
+++ b/kern/log2.h
@@ -16,8 +16,6 @@
*
*
* Integer base 2 logarithm operations.
- *
- * TODO Fix naming.
*/
#ifndef _KERN_LOG2_H
@@ -26,15 +24,23 @@
#include <assert.h>
#include <limits.h>
+/*
+ * Return the base-2 logarithm of the given value, or of the first
+ * power-of-two below the given value if it's not a power-of-two.
+ */
static inline unsigned int
-ilog2(unsigned long x)
+log2(unsigned long x)
{
assert(x != 0);
return LONG_BIT - __builtin_clzl(x) - 1;
}
+/*
+ * Return the base-2 logarithm of the given value, or of the first
+ * power-of-two above the given value if it's not a power-of-two.
+ */
static inline unsigned int
-iorder2(unsigned long size)
+log2_order(unsigned long size)
{
assert(size != 0);
@@ -42,7 +48,7 @@ iorder2(unsigned long size)
return 0;
}
- return ilog2(size - 1) + 1;
+ return log2(size - 1) + 1;
}
#endif /* _KERN_LOG2_H */
diff --git a/kern/macros.h b/kern/macros.h
index 0411da2..6d136e3 100644
--- a/kern/macros.h
+++ b/kern/macros.h
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Helper macros.
*
@@ -23,8 +26,8 @@
* TODO Improve documentation.
*/
-#ifndef _KERN_MACROS_H
-#define _KERN_MACROS_H
+#ifndef KERN_MACROS_H
+#define KERN_MACROS_H
#if !defined(__GNUC__) || (__GNUC__ < 4)
#error "GCC 4+ required"
@@ -110,4 +113,4 @@
#endif /* __GNUC__ >= 7 */
#endif
-#endif /* _KERN_MACROS_H */
+#endif /* KERN_MACROS_H */
diff --git a/kern/mutex.h b/kern/mutex.h
index b4332de..f446f5f 100644
--- a/kern/mutex.h
+++ b/kern/mutex.h
@@ -20,8 +20,8 @@
* Unlike spin locks, acquiring a mutex may make the calling thread sleep.
*/
-#ifndef _KERN_MUTEX_H
-#define _KERN_MUTEX_H
+#ifndef KERN_MUTEX_H
+#define KERN_MUTEX_H
#include <stdint.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)
@@ -120,4 +120,4 @@ INIT_OP_DECLARE(mutex_bootstrap);
*/
INIT_OP_DECLARE(mutex_setup);
-#endif /* _KERN_MUTEX_H */
+#endif /* KERN_MUTEX_H */
diff --git a/kern/mutex/mutex_adaptive.c b/kern/mutex/mutex_adaptive.c
index db92f9d..b2af456 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 6ff1277..05e9764 100644
--- a/kern/mutex/mutex_adaptive_i.h
+++ b/kern/mutex/mutex_adaptive_i.h
@@ -15,19 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_MUTEX_ADAPTIVE_I_H
-#define _KERN_MUTEX_ADAPTIVE_I_H
+#ifndef KERN_MUTEX_ADAPTIVE_I_H
+#define KERN_MUTEX_ADAPTIVE_I_H
-#ifndef _KERN_MUTEX_H
+#ifndef KERN_MUTEX_H
#error "don't include <kern/mutex/mutex_adaptive_i.h> directly," \
" use <kern/mutex.h> instead"
#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;
@@ -143,4 +143,4 @@ INIT_OP_DECLARE(mutex_adaptive_bootstrap);
#define mutex_impl_setup mutex_adaptive_setup
INIT_OP_DECLARE(mutex_adaptive_setup);
-#endif /* _KERN_MUTEX_ADAPTIVE_I_H */
+#endif /* KERN_MUTEX_ADAPTIVE_I_H */
diff --git a/kern/mutex/mutex_adaptive_types.h b/kern/mutex/mutex_adaptive_types.h
index efbbf21..40270f6 100644
--- a/kern/mutex/mutex_adaptive_types.h
+++ b/kern/mutex/mutex_adaptive_types.h
@@ -18,10 +18,10 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_MUTEX_ADAPTIVE_TYPES_H
-#define _KERN_MUTEX_ADAPTIVE_TYPES_H
+#ifndef KERN_MUTEX_ADAPTIVE_TYPES_H
+#define KERN_MUTEX_ADAPTIVE_TYPES_H
-#ifndef _KERN_MUTEX_TYPES_H
+#ifndef KERN_MUTEX_TYPES_H
#error "don't include <kern/mutex/mutex_adaptive_types.h> directly," \
" use <kern/mutex_types.h> instead"
#endif
@@ -32,4 +32,4 @@ struct mutex {
uintptr_t owner;
};
-#endif /* _KERN_MUTEX_ADAPTIVE_TYPES_H */
+#endif /* KERN_MUTEX_ADAPTIVE_TYPES_H */
diff --git a/kern/mutex/mutex_pi_i.h b/kern/mutex/mutex_pi_i.h
index 14f63be..f3bb28f 100644
--- a/kern/mutex/mutex_pi_i.h
+++ b/kern/mutex/mutex_pi_i.h
@@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_MUTEX_PI_I_H
-#define _KERN_MUTEX_PI_I_H
+#ifndef KERN_MUTEX_PI_I_H
+#define KERN_MUTEX_PI_I_H
-#ifndef _KERN_MUTEX_H
+#ifndef KERN_MUTEX_H
#error "don't include <kern/mutex/mutex_pi_i.h> directly," \
" use <kern/mutex.h> instead"
#endif
@@ -72,4 +72,4 @@ mutex_impl_unlock(struct mutex *mutex)
#define mutex_impl_bootstrap rtmutex_bootstrap
#define mutex_impl_setup rtmutex_setup
-#endif /* _KERN_MUTEX_PI_I_H */
+#endif /* KERN_MUTEX_PI_I_H */
diff --git a/kern/mutex/mutex_pi_types.h b/kern/mutex/mutex_pi_types.h
index d9ebb6e..f511cbc 100644
--- a/kern/mutex/mutex_pi_types.h
+++ b/kern/mutex/mutex_pi_types.h
@@ -18,10 +18,10 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_MUTEX_PI_TYPES_H
-#define _KERN_MUTEX_PI_TYPES_H
+#ifndef KERN_MUTEX_PI_TYPES_H
+#define KERN_MUTEX_PI_TYPES_H
-#ifndef _KERN_MUTEX_TYPES_H
+#ifndef KERN_MUTEX_TYPES_H
#error "don't include <kern/mutex/mutex_pi_types.h> directly," \
" use <kern/mutex_types.h> instead"
#endif
@@ -36,4 +36,4 @@ struct mutex {
struct rtmutex rtmutex;
};
-#endif /* _KERN_MUTEX_PI_TYPES_H */
+#endif /* KERN_MUTEX_PI_TYPES_H */
diff --git a/kern/mutex/mutex_plain_i.h b/kern/mutex/mutex_plain_i.h
index 74def89..d28fd92 100644
--- a/kern/mutex/mutex_plain_i.h
+++ b/kern/mutex/mutex_plain_i.h
@@ -15,19 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_MUTEX_PLAIN_I_H
-#define _KERN_MUTEX_PLAIN_I_H
+#ifndef KERN_MUTEX_PLAIN_I_H
+#define KERN_MUTEX_PLAIN_I_H
-#ifndef _KERN_MUTEX_H
+#ifndef KERN_MUTEX_H
#error "don't include <kern/mutex/mutex_plain_i.h> directly," \
" use <kern/mutex.h> instead"
#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;
@@ -137,4 +137,4 @@ INIT_OP_DECLARE(mutex_plain_bootstrap);
#define mutex_impl_setup mutex_plain_setup
INIT_OP_DECLARE(mutex_plain_setup);
-#endif /* _KERN_MUTEX_PLAIN_I_H */
+#endif /* KERN_MUTEX_PLAIN_I_H */
diff --git a/kern/mutex/mutex_plain_types.h b/kern/mutex/mutex_plain_types.h
index 02731e9..c666f66 100644
--- a/kern/mutex/mutex_plain_types.h
+++ b/kern/mutex/mutex_plain_types.h
@@ -18,10 +18,10 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_MUTEX_PLAIN_TYPES_H
-#define _KERN_MUTEX_PLAIN_TYPES_H
+#ifndef KERN_MUTEX_PLAIN_TYPES_H
+#define KERN_MUTEX_PLAIN_TYPES_H
-#ifndef _KERN_MUTEX_TYPES_H
+#ifndef KERN_MUTEX_TYPES_H
#error "don't include <kern/mutex/mutex_plain_types.h> directly," \
" use <kern/mutex_types.h> instead"
#endif
@@ -30,4 +30,4 @@ struct mutex {
unsigned int state;
};
-#endif /* _KERN_MUTEX_PLAIN_TYPES_H */
+#endif /* KERN_MUTEX_PLAIN_TYPES_H */
diff --git a/kern/mutex_types.h b/kern/mutex_types.h
index 574f475..01b4c4d 100644
--- a/kern/mutex_types.h
+++ b/kern/mutex_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_MUTEX_TYPES_H
-#define _KERN_MUTEX_TYPES_H
+#ifndef KERN_MUTEX_TYPES_H
+#define KERN_MUTEX_TYPES_H
#if defined(CONFIG_MUTEX_ADAPTIVE)
#include <kern/mutex/mutex_adaptive_types.h>
@@ -31,4 +31,4 @@
#error "unknown mutex implementation"
#endif
-#endif /* _KERN_MUTEX_TYPES_H */
+#endif /* KERN_MUTEX_TYPES_H */
diff --git a/kern/panic.h b/kern/panic.h
index e6cbe8b..af858c7 100644
--- a/kern/panic.h
+++ b/kern/panic.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_PANIC_H
-#define _KERN_PANIC_H
+#ifndef KERN_PANIC_H
+#define KERN_PANIC_H
#include <stdnoreturn.h>
@@ -34,4 +34,4 @@ noreturn void panic(const char *format, ...)
*/
INIT_OP_DECLARE(panic_setup);
-#endif /* _KERN_PANIC_H */
+#endif /* KERN_PANIC_H */
diff --git a/kern/percpu.c b/kern/percpu.c
index 62c3d22..53861a3 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/percpu.h b/kern/percpu.h
index e53f4e5..96f706e 100644
--- a/kern/percpu.h
+++ b/kern/percpu.h
@@ -50,8 +50,8 @@
* interrupt-safe.
*/
-#ifndef _KERN_PERCPU_H
-#define _KERN_PERCPU_H
+#ifndef KERN_PERCPU_H
+#define KERN_PERCPU_H
#include <assert.h>
#include <stddef.h>
@@ -121,4 +121,4 @@ INIT_OP_DECLARE(percpu_bootstrap);
*/
INIT_OP_DECLARE(percpu_setup);
-#endif /* _KERN_PERCPU_H */
+#endif /* KERN_PERCPU_H */
diff --git a/kern/perfmon.c b/kern/perfmon.c
index 6c545ca..9c9c257 100644
--- a/kern/perfmon.c
+++ b/kern/perfmon.c
@@ -218,7 +218,7 @@ perfmon_pmc_alloc(struct perfmon_pmc **pmcp, unsigned int raw_event_id)
int error;
if (perfmon_pmu.nr_pmcs == ARRAY_SIZE(perfmon_pmu.pmcs))
- return ERROR_AGAIN;
+ return EAGAIN;
for (i = 0; i < ARRAY_SIZE(perfmon_pmu.pmcs); i++) {
pmc = &perfmon_pmu.pmcs[i];
@@ -409,7 +409,7 @@ perfmon_pmu_register(struct perfmon_pmu_ops *driver)
if (pmu_driver.info) {
/* Already initialized */
assert(0);
- return ERROR_INVAL;
+ return EINVAL;
}
pmu_driver = *driver;
@@ -452,10 +452,10 @@ perfmon_setup(void)
percpu_var(perfmon_cpu_grouplist, i) = grouplist;
}
-
+
if (!pmu_driver.info) {
log_err("unable to start perfmon: no compatible pmu driver available");
- return ERROR_NODEV;
+ return ENODEV;
}
pmu_driver.info();
@@ -496,7 +496,7 @@ perfmon_event_create(struct perfmon_event **eventp, unsigned int type,
event = kmem_alloc(sizeof(*event));
if (event == NULL)
- return ERROR_NOMEM;
+ return ENOMEM;
event->count = 0;
list_node_init(&event->node);
@@ -570,7 +570,7 @@ perfmon_group_create(struct perfmon_group **groupp)
group = kmem_alloc(sizeof(*group));
if (group == NULL)
- return ERROR_NOMEM;
+ return ENOMEM;
list_init(&group->events);
spinlock_init(&group->lock);
@@ -587,7 +587,7 @@ perfmon_group_destroy(struct perfmon_group *group)
struct perfmon_event *event;
if (perfmon_group_attached(group)) {
- return ERROR_INVAL;
+ return EINVAL;
}
assert (!perfmon_group_enabled(group));
@@ -746,7 +746,7 @@ perfmon_group_detach(struct perfmon_group *group)
if (perfmon_group_enabled(group)) {
- ret = ERROR_INVAL;
+ ret = EINVAL;
goto out;
}
@@ -922,7 +922,7 @@ perfmon_group_start(struct perfmon_group *group)
spinlock_lock_intr_save(&group->lock, &flags);
if (!perfmon_group_attached(group) || perfmon_group_loaded(group)) {
- ret = ERROR_INVAL;
+ ret = EINVAL;
goto end;
}
assert(!perfmon_group_enabled(group));
@@ -1045,7 +1045,7 @@ perfmon_group_stop(struct perfmon_group *group)
spinlock_lock_intr_save(&group->lock, &flags);
if (!perfmon_group_attached(group) || !perfmon_group_enabled(group)) {
- ret = ERROR_INVAL;
+ ret = EINVAL;
goto end;
}
@@ -1093,7 +1093,7 @@ perfmon_thread_init(struct thread *thread)
grouplist = perfmon_grouplist_create();
if (grouplist == NULL)
- return ERROR_NOMEM;
+ return ENOMEM;
thread->perfmon_groups = grouplist;
return 0;
diff --git a/kern/perfmon.h b/kern/perfmon.h
index 1ab24be..a899a01 100644
--- a/kern/perfmon.h
+++ b/kern/perfmon.h
@@ -134,7 +134,7 @@ int perfmon_group_create(struct perfmon_group **groupp);
*
* A group can only be destroyed once stopped and detached.
*
- * Will return ERROR_INVAL if the group is not detached.
+ * Will return EINVAL if the group is not detached.
*/
int perfmon_group_destroy(struct perfmon_group *group);
@@ -160,7 +160,7 @@ int perfmon_group_attach_cpu(struct perfmon_group *group, unsigned int cpu);
*
* It frees associated logical counters..
*
- * returns ERROR_INVAL if the group is still enabled (not stopped).
+ * returns EINVAL if the group is still enabled (not stopped).
*/
int perfmon_group_detach(struct perfmon_group *group);
diff --git a/kern/plist.c b/kern/plist.c
index 851de62..2e543c3 100644
--- a/kern/plist.c
+++ b/kern/plist.c
@@ -13,6 +13,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#include <kern/list.h>
@@ -37,12 +40,12 @@ plist_add(struct plist *plist, struct plist_node *pnode)
if (list_end(&plist->prio_list, &next->prio_node)
|| (pnode->priority != next->priority)) {
- list_insert_before(&next->prio_node, &pnode->prio_node);
+ list_insert_before(&pnode->prio_node, &next->prio_node);
} else {
list_init(&pnode->prio_node);
}
- list_insert_before(&next->node, &pnode->node);
+ list_insert_before(&pnode->node, &next->node);
}
void
diff --git a/kern/plist.h b/kern/plist.h
index dd8fdd0..9cde0d3 100644
--- a/kern/plist.h
+++ b/kern/plist.h
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Priority list.
*
@@ -23,8 +26,8 @@
* among the entries.
*/
-#ifndef _KERN_PLIST_H
-#define _KERN_PLIST_H
+#ifndef KERN_PLIST_H
+#define KERN_PLIST_H
#include <stdbool.h>
@@ -267,4 +270,4 @@ for (pnode = plist_last(plist), tmp = plist_prev(pnode); \
#define plist_for_each_entry_reverse_safe(plist, entry, tmp, member) \
list_for_each_entry_reverse_safe(&(plist)->list, entry, tmp, member.node)
-#endif /* _KERN_PLIST_H */
+#endif /* KERN_PLIST_H */
diff --git a/kern/plist_types.h b/kern/plist_types.h
index 653d63f..aedb653 100644
--- a/kern/plist_types.h
+++ b/kern/plist_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_PLIST_TYPES_H
-#define _KERN_PLIST_TYPES_H
+#ifndef KERN_PLIST_TYPES_H
+#define KERN_PLIST_TYPES_H
#include <kern/list_types.h>
@@ -47,4 +47,4 @@ struct plist_node {
struct list prio_node;
};
-#endif /* _KERN_PLIST_TYPES_H */
+#endif /* KERN_PLIST_TYPES_H */
diff --git a/kern/printf.h b/kern/printf.h
index 8185c73..eba5562 100644
--- a/kern/printf.h
+++ b/kern/printf.h
@@ -24,12 +24,12 @@
* See the sprintf module for information about the supported formats.
*/
-#ifndef _KERN_PRINTF_H
-#define _KERN_PRINTF_H
+#ifndef KERN_PRINTF_H
+#define KERN_PRINTF_H
-#ifndef _STDIO_H
+#ifndef STDIO_H
#error "do not use <kern/printf.h> directly; include <stdio.h> instead"
-#endif /* _STDIO_H */
+#endif /* STDIO_H */
#include <stdarg.h>
@@ -47,4 +47,4 @@ int vprintf(const char *format, va_list ap)
*/
INIT_OP_DECLARE(printf_setup);
-#endif /* _KERN_PRINTF_H */
+#endif /* KERN_PRINTF_H */
diff --git a/kern/rbtree.c b/kern/rbtree.c
index 95873b9..df8d094 100644
--- a/kern/rbtree.c
+++ b/kern/rbtree.c
@@ -13,6 +13,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#include <assert.h>
diff --git a/kern/rbtree.h b/kern/rbtree.h
index e805bd9..7ec83fe 100644
--- a/kern/rbtree.h
+++ b/kern/rbtree.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2017 Richard Braun.
+ * Copyright (c) 2010-2015 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
@@ -14,12 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Red-black tree.
*/
-#ifndef _KERN_RBTREE_H
-#define _KERN_RBTREE_H
+#ifndef KERN_RBTREE_H
+#define KERN_RBTREE_H
#include <assert.h>
#include <stddef.h>
@@ -117,22 +120,22 @@ rbtree_empty(const struct rbtree *tree)
*/
#define rbtree_lookup(tree, key, cmp_fn) \
MACRO_BEGIN \
- struct rbtree_node *___cur; \
- int ___diff; \
+ struct rbtree_node *cur___; \
+ int diff___; \
\
- ___cur = (tree)->root; \
+ cur___ = (tree)->root; \
\
- while (___cur != NULL) { \
- ___diff = cmp_fn(key, ___cur); \
+ while (cur___ != NULL) { \
+ diff___ = cmp_fn(key, cur___); \
\
- if (___diff == 0) { \
+ if (diff___ == 0) { \
break; \
} \
\
- ___cur = ___cur->children[rbtree_d2i(___diff)]; \
+ cur___ = cur___->children[rbtree_d2i(diff___)]; \
} \
\
- ___cur; \
+ cur___; \
MACRO_END
/*
@@ -147,30 +150,30 @@ MACRO_END
*/
#define rbtree_lookup_nearest(tree, key, cmp_fn, dir) \
MACRO_BEGIN \
- struct rbtree_node *___cur, *___prev; \
- int ___diff, ___index; \
+ struct rbtree_node *cur___, *prev___; \
+ int diff___, index___; \
\
- ___prev = NULL; \
- ___index = -1; \
- ___cur = (tree)->root; \
+ prev___ = NULL; \
+ index___ = -1; \
+ cur___ = (tree)->root; \
\
- while (___cur != NULL) { \
- ___diff = cmp_fn(key, ___cur); \
+ while (cur___ != NULL) { \
+ diff___ = cmp_fn(key, cur___); \
\
- if (___diff == 0) { \
+ if (diff___ == 0) { \
break; \
} \
\
- ___prev = ___cur; \
- ___index = rbtree_d2i(___diff); \
- ___cur = ___cur->children[___index]; \
+ prev___ = cur___; \
+ index___ = rbtree_d2i(diff___); \
+ cur___ = cur___->children[index___]; \
} \
\
- if (___cur == NULL) { \
- ___cur = rbtree_nearest(___prev, ___index, dir); \
+ if (cur___ == NULL) { \
+ cur___ = rbtree_nearest(prev___, index___, dir); \
} \
\
- ___cur; \
+ cur___; \
MACRO_END
/*
@@ -191,22 +194,22 @@ MACRO_END
*/
#define rbtree_insert(tree, node, cmp_fn) \
MACRO_BEGIN \
- struct rbtree_node *___cur, *___prev; \
- int ___diff, ___index; \
+ struct rbtree_node *cur___, *prev___; \
+ int diff___, index___; \
\
- ___prev = NULL; \
- ___index = -1; \
- ___cur = (tree)->root; \
+ prev___ = NULL; \
+ index___ = -1; \
+ cur___ = (tree)->root; \
\
- while (___cur != NULL) { \
- ___diff = cmp_fn(node, ___cur); \
- assert(___diff != 0); \
- ___prev = ___cur; \
- ___index = rbtree_d2i(___diff); \
- ___cur = ___cur->children[___index]; \
+ while (cur___ != NULL) { \
+ diff___ = cmp_fn(node, cur___); \
+ assert(diff___ != 0); \
+ prev___ = cur___; \
+ index___ = rbtree_d2i(diff___); \
+ cur___ = cur___->children[index___]; \
} \
\
- rbtree_insert_rebalance(tree, ___prev, ___index, node); \
+ rbtree_insert_rebalance(tree, prev___, index___, node); \
MACRO_END
/*
@@ -222,27 +225,27 @@ MACRO_END
*/
#define rbtree_lookup_slot(tree, key, cmp_fn, slot) \
MACRO_BEGIN \
- struct rbtree_node *___cur, *___prev; \
- int ___diff, ___index; \
+ struct rbtree_node *cur___, *prev___; \
+ int diff___, index___; \
\
- ___prev = NULL; \
- ___index = 0; \
- ___cur = (tree)->root; \
+ prev___ = NULL; \
+ index___ = 0; \
+ cur___ = (tree)->root; \
\
- while (___cur != NULL) { \
- ___diff = cmp_fn(key, ___cur); \
+ while (cur___ != NULL) { \
+ diff___ = cmp_fn(key, cur___); \
\
- if (___diff == 0) { \
+ if (diff___ == 0) { \
break; \
} \
\
- ___prev = ___cur; \
- ___index = rbtree_d2i(___diff); \
- ___cur = ___cur->children[___index]; \
+ prev___ = cur___; \
+ index___ = rbtree_d2i(diff___); \
+ cur___ = cur___->children[index___]; \
} \
\
- (slot) = rbtree_slot(___prev, ___index); \
- ___cur; \
+ (slot) = rbtree_slot(prev___, index___); \
+ cur___; \
MACRO_END
/*
@@ -317,4 +320,4 @@ for (node = rbtree_postwalk_deepest(tree), \
node != NULL; \
node = tmp, tmp = rbtree_postwalk_unlink(node))
-#endif /* _KERN_RBTREE_H */
+#endif /* KERN_RBTREE_H */
diff --git a/kern/rbtree_i.h b/kern/rbtree_i.h
index 973899b..569810d 100644
--- a/kern/rbtree_i.h
+++ b/kern/rbtree_i.h
@@ -13,10 +13,13 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
-#ifndef _KERN_RBTREE_I_H
-#define _KERN_RBTREE_I_H
+#ifndef KERN_RBTREE_I_H
+#define KERN_RBTREE_I_H
#include <assert.h>
#include <stddef.h>
@@ -186,4 +189,4 @@ struct rbtree_node * rbtree_postwalk_deepest(const struct rbtree *tree);
*/
struct rbtree_node * rbtree_postwalk_unlink(struct rbtree_node *node);
-#endif /* _KERN_RBTREE_I_H */
+#endif /* KERN_RBTREE_I_H */
diff --git a/kern/rcu.h b/kern/rcu.h
index 48079d0..3820e85 100644
--- a/kern/rcu.h
+++ b/kern/rcu.h
@@ -43,8 +43,8 @@
* [1] https://www.kernel.org/doc/Documentation/RCU/Design/Requirements/Requirements.html.
*/
-#ifndef _KERN_RCU_H
-#define _KERN_RCU_H
+#ifndef KERN_RCU_H
+#define KERN_RCU_H
#include <kern/atomic.h>
#include <kern/init.h>
@@ -142,4 +142,4 @@ void rcu_wait(void);
*/
INIT_OP_DECLARE(rcu_bootstrap);
-#endif /* _KERN_RCU_H */
+#endif /* KERN_RCU_H */
diff --git a/kern/rcu_i.h b/kern/rcu_i.h
index 6be933d..2606bf8 100644
--- a/kern/rcu_i.h
+++ b/kern/rcu_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_RCU_I_H
-#define _KERN_RCU_I_H
+#ifndef KERN_RCU_I_H
+#define KERN_RCU_I_H
#include <assert.h>
#include <stdbool.h>
@@ -58,4 +58,4 @@ rcu_reader_dec(struct rcu_reader *reader)
}
}
-#endif /* _KERN_RCU_I_H */
+#endif /* KERN_RCU_I_H */
diff --git a/kern/rcu_types.h b/kern/rcu_types.h
index 12b8913..058d34f 100644
--- a/kern/rcu_types.h
+++ b/kern/rcu_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_RCU_TYPES_H
-#define _KERN_RCU_TYPES_H
+#ifndef KERN_RCU_TYPES_H
+#define KERN_RCU_TYPES_H
#include <stdbool.h>
@@ -37,4 +37,4 @@ struct rcu_reader {
bool linked;
};
-#endif /* _KERN_RCU_TYPES_H */
+#endif /* KERN_RCU_TYPES_H */
diff --git a/kern/rdxtree.c b/kern/rdxtree.c
index 9e2e759..e7abaf0 100644
--- a/kern/rdxtree.c
+++ b/kern/rdxtree.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2017 Richard Braun.
+ * Copyright (c) 2011-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
@@ -13,16 +13,19 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
#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>
@@ -119,7 +122,7 @@ rdxtree_entry_addr(void *entry)
return (void *)((uintptr_t)entry & RDXTREE_ENTRY_ADDR_MASK);
}
-static inline int
+static inline bool
rdxtree_entry_is_node(const void *entry)
{
return ((uintptr_t)entry & 1) != 0;
@@ -150,7 +153,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);
@@ -208,13 +211,13 @@ rdxtree_node_unlink(struct rdxtree_node *node)
node->parent = NULL;
}
-static inline int
+static inline bool
rdxtree_node_full(struct rdxtree_node *node)
{
return (node->nr_entries == ARRAY_SIZE(node->entries));
}
-static inline int
+static inline bool
rdxtree_node_empty(struct rdxtree_node *node)
{
return (node->nr_entries == 0);
@@ -282,13 +285,13 @@ rdxtree_node_bm_clear(struct rdxtree_node *node, unsigned short index)
node->alloc_bm &= ~((rdxtree_bm_t)1 << index);
}
-static inline int
+static inline bool
rdxtree_node_bm_is_set(struct rdxtree_node *node, unsigned short index)
{
return (node->alloc_bm & ((rdxtree_bm_t)1 << index));
}
-static inline int
+static inline bool
rdxtree_node_bm_empty(struct rdxtree_node *node)
{
return (node->alloc_bm == RDXTREE_BM_EMPTY);
@@ -475,7 +478,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 +524,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);
@@ -684,7 +687,7 @@ rdxtree_remove(struct rdxtree *tree, rdxtree_key_t key)
void *
rdxtree_lookup_common(const struct rdxtree *tree, rdxtree_key_t key,
- int get_slot)
+ bool get_slot)
{
struct rdxtree_node *node, *prev;
unsigned short height, shift, index;
diff --git a/kern/rdxtree.h b/kern/rdxtree.h
index f19f349..b80cd97 100644
--- a/kern/rdxtree.h
+++ b/kern/rdxtree.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2017 Richard Braun.
+ * Copyright (c) 2011-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
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Radix tree.
*
@@ -22,9 +25,11 @@
* occur concurrently with updates using RCU.
*/
-#ifndef _KERN_RDXTREE_H
-#define _KERN_RDXTREE_H
+#ifndef KERN_RDXTREE_H
+#define KERN_RDXTREE_H
+#include <assert.h>
+#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@@ -136,7 +141,7 @@ void * rdxtree_remove(struct rdxtree *tree, rdxtree_key_t key);
static inline void *
rdxtree_lookup(const struct rdxtree *tree, rdxtree_key_t key)
{
- return rdxtree_lookup_common(tree, key, 0);
+ return rdxtree_lookup_common(tree, key, false);
}
/*
@@ -153,7 +158,7 @@ rdxtree_lookup(const struct rdxtree *tree, rdxtree_key_t key)
static inline void **
rdxtree_lookup_slot(const struct rdxtree *tree, rdxtree_key_t key)
{
- return rdxtree_lookup_common(tree, key, 1);
+ return rdxtree_lookup_common(tree, key, true);
}
static inline void *
@@ -205,4 +210,4 @@ void rdxtree_remove_all(struct rdxtree *tree);
*/
INIT_OP_DECLARE(rdxtree_setup);
-#endif /* _KERN_RDXTREE_H */
+#endif /* KERN_RDXTREE_H */
diff --git a/kern/rdxtree_i.h b/kern/rdxtree_i.h
index 4dcf88e..4373192 100644
--- a/kern/rdxtree_i.h
+++ b/kern/rdxtree_i.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011-2017 Richard Braun.
+ * Copyright (c) 2011-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
@@ -13,10 +13,16 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
-#ifndef _KERN_RDXTREE_I_H
-#define _KERN_RDXTREE_I_H
+#ifndef KERN_RDXTREE_I_H
+#define KERN_RDXTREE_I_H
+
+#include <stdbool.h>
+#include <stddef.h>
/*
* Radix tree.
@@ -56,8 +62,8 @@ int rdxtree_insert_alloc_common(struct rdxtree *tree, void *ptr,
rdxtree_key_t *keyp, void ***slotp);
void * rdxtree_lookup_common(const struct rdxtree *tree, rdxtree_key_t key,
- int get_slot);
+ bool get_slot);
void * rdxtree_walk(struct rdxtree *tree, struct rdxtree_iter *iter);
-#endif /* _KERN_RDXTREE_I_H */
+#endif /* KERN_RDXTREE_I_H */
diff --git a/kern/rtmutex.h b/kern/rtmutex.h
index 90b3438..64c0924 100644
--- a/kern/rtmutex.h
+++ b/kern/rtmutex.h
@@ -21,13 +21,13 @@
* inheritance is unconditionally enabled.
*/
-#ifndef _KERN_RTMUTEX_H
-#define _KERN_RTMUTEX_H
+#ifndef KERN_RTMUTEX_H
+#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;
@@ -138,4 +138,4 @@ rtmutex_unlock(struct rtmutex *rtmutex)
INIT_OP_DECLARE(rtmutex_bootstrap);
INIT_OP_DECLARE(rtmutex_setup);
-#endif /* _KERN_RTMUTEX_H */
+#endif /* KERN_RTMUTEX_H */
diff --git a/kern/rtmutex_i.h b/kern/rtmutex_i.h
index 75ac5e4..9d3689d 100644
--- a/kern/rtmutex_i.h
+++ b/kern/rtmutex_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_RTMUTEX_I_H
-#define _KERN_RTMUTEX_I_H
+#ifndef KERN_RTMUTEX_I_H
+#define KERN_RTMUTEX_I_H
#include <assert.h>
#include <stdbool.h>
@@ -78,4 +78,4 @@ int rtmutex_timedlock_slow(struct rtmutex *rtmutex, uint64_t ticks);
void rtmutex_unlock_slow(struct rtmutex *rtmutex);
-#endif /* _KERN_RTMUTEX_I_H */
+#endif /* KERN_RTMUTEX_I_H */
diff --git a/kern/rtmutex_types.h b/kern/rtmutex_types.h
index c03e048..ba372a3 100644
--- a/kern/rtmutex_types.h
+++ b/kern/rtmutex_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_RTMUTEX_TYPES_H
-#define _KERN_RTMUTEX_TYPES_H
+#ifndef KERN_RTMUTEX_TYPES_H
+#define KERN_RTMUTEX_TYPES_H
#include <stdint.h>
@@ -27,4 +27,4 @@ struct rtmutex {
uintptr_t owner;
};
-#endif /* _KERN_RTMUTEX_TYPES_H */
+#endif /* KERN_RTMUTEX_TYPES_H */
diff --git a/kern/semaphore.h b/kern/semaphore.h
index ee4c355..640d6d6 100644
--- a/kern/semaphore.h
+++ b/kern/semaphore.h
@@ -41,14 +41,14 @@
* As a result, semaphores may only be used by application code.
*/
-#ifndef _KERN_SEMAPHORE_H
-#define _KERN_SEMAPHORE_H
+#ifndef KERN_SEMAPHORE_H
+#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;
@@ -155,4 +155,4 @@ semaphore_getvalue(const struct semaphore *semaphore)
return atomic_load(&semaphore->value, ATOMIC_RELAXED);
}
-#endif /* _KERN_SEMAPHORE_H */
+#endif /* KERN_SEMAPHORE_H */
diff --git a/kern/semaphore_i.h b/kern/semaphore_i.h
index 21f76cf..a4c50b8 100644
--- a/kern/semaphore_i.h
+++ b/kern/semaphore_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_SEMAPHORE_I_H
-#define _KERN_SEMAPHORE_I_H
+#ifndef KERN_SEMAPHORE_I_H
+#define KERN_SEMAPHORE_I_H
#include <assert.h>
#include <stdint.h>
@@ -61,4 +61,4 @@ int semaphore_timedwait_slow(struct semaphore *semaphore, uint64_t ticks);
void semaphore_post_slow(struct semaphore *semaphore);
-#endif /* _KERN_SEMAPHORE_I_H */
+#endif /* KERN_SEMAPHORE_I_H */
diff --git a/kern/shell.c b/kern/shell.c
index a27c53f..e99f911 100644
--- a/kern/shell.c
+++ b/kern/shell.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Richard Braun.
+ * Copyright (c) 2015-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
@@ -13,12 +13,15 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
*/
+#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 +261,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 +282,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 +327,7 @@ shell_cmd_complete(const char *str, unsigned long *sizep,
size--;
*sizep = size;
- return ERROR_AGAIN;
+ return EAGAIN;
}
/*
@@ -370,7 +373,7 @@ shell_cmd_check_char(char c)
return 0;
}
- return ERROR_INVAL;
+ return EINVAL;
}
static int
@@ -388,7 +391,7 @@ shell_cmd_check(const struct shell_cmd *cmd)
}
if (i == 0) {
- return ERROR_INVAL;
+ return EINVAL;
}
return 0;
@@ -446,7 +449,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 +522,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 +547,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;
@@ -691,7 +694,7 @@ shell_cmd_history(int argc, char *argv[])
static struct shell_cmd shell_default_cmds[] = {
SHELL_CMD_INITIALIZER("help", shell_cmd_help,
"help [command]",
- "display help about shell commands"),
+ "obtain help about shell commands"),
SHELL_CMD_INITIALIZER("history", shell_cmd_history,
"history",
"display history list"),
@@ -764,7 +767,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 +870,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 +1059,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 +1122,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 bdd02d9..db055e7 100644
--- a/kern/shell.h
+++ b/kern/shell.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Richard Braun.
+ * Copyright (c) 2015-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
@@ -14,25 +14,30 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Minimalist shell for embedded systems.
*/
-#ifndef _KERN_SHELL_H
-#define _KERN_SHELL_H
+#ifndef KERN_SHELL_H
+#define KERN_SHELL_H
+
+#include <stddef.h>
-#include <kern/init.h>
#include <kern/error.h>
+#include <kern/init.h>
#include <kern/macros.h>
#define SHELL_REGISTER_CMDS(cmds) \
MACRO_BEGIN \
- size_t ___i; \
- int ___error; \
+ size_t i___; \
+ int error___; \
\
- for (___i = 0; ___i < ARRAY_SIZE(cmds); ___i++) { \
- ___error = shell_cmd_register(&(cmds)[___i]); \
- error_check(___error, __func__); \
+ for (i___ = 0; i___ < ARRAY_SIZE(cmds); i___++) { \
+ error___ = shell_cmd_register(&(cmds)[i___]); \
+ error_check(error___, __func__); \
} \
MACRO_END
@@ -86,4 +91,4 @@ int shell_cmd_register(struct shell_cmd *cmd);
*/
INIT_OP_DECLARE(shell_setup);
-#endif /* _KERN_SHELL_H */
+#endif /* KERN_SHELL_H */
diff --git a/kern/shutdown.h b/kern/shutdown.h
index f61079b..6f89e01 100644
--- a/kern/shutdown.h
+++ b/kern/shutdown.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_SHUTDOWN_H
-#define _KERN_SHUTDOWN_H
+#ifndef KERN_SHUTDOWN_H
+#define KERN_SHUTDOWN_H
#include <stdnoreturn.h>
@@ -46,4 +46,4 @@ INIT_OP_DECLARE(shutdown_bootstrap);
*/
INIT_OP_DECLARE(shutdown_setup);
-#endif /* _KERN_SHUTDOWN_H */
+#endif /* KERN_SHUTDOWN_H */
diff --git a/kern/sleepq.h b/kern/sleepq.h
index 213925c..10b139f 100644
--- a/kern/sleepq.h
+++ b/kern/sleepq.h
@@ -28,8 +28,8 @@
* allows preventing deadlocks while keeping overall complexity low.
*/
-#ifndef _KERN_SLEEPQ_H
-#define _KERN_SLEEPQ_H
+#ifndef KERN_SLEEPQ_H
+#define KERN_SLEEPQ_H
#include <stdbool.h>
#include <stdint.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);
@@ -137,4 +137,4 @@ void sleepq_broadcast(struct sleepq *sleepq);
*/
INIT_OP_DECLARE(sleepq_setup);
-#endif /* _KERN_SLEEPQ_H */
+#endif /* KERN_SLEEPQ_H */
diff --git a/kern/slist.h b/kern/slist.h
index d708f38..424cdb2 100644
--- a/kern/slist.h
+++ b/kern/slist.h
@@ -14,12 +14,15 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
+ * Upstream site with license notes :
+ * http://git.sceen.net/rbraun/librbraun.git/
+ *
*
* Singly-linked list.
*/
-#ifndef _KERN_SLIST_H
-#define _KERN_SLIST_H
+#ifndef KERN_SLIST_H
+#define KERN_SLIST_H
#include <stdbool.h>
#include <stddef.h>
@@ -172,8 +175,8 @@ slist_insert_tail(struct slist *list, struct slist_node *node)
* The prev node must be valid.
*/
static inline void
-slist_insert_after(struct slist *list, struct slist_node *prev,
- struct slist_node *node)
+slist_insert_after(struct slist *list, struct slist_node *node,
+ struct slist_node *prev)
{
node->next = prev->next;
prev->next = node;
@@ -187,8 +190,8 @@ slist_insert_after(struct slist *list, struct slist_node *prev,
* Remove a node from a list.
*
* The prev argument must point to the node immediately preceding the target
- * node. It may safely denote the end of the given list, in which case the
- * first node is removed.
+ * node. It may safely denote the end of the given list (NULL), in which case
+ * the first node is removed.
*/
static inline void
slist_remove(struct slist *list, struct slist_node *prev)
@@ -223,10 +226,10 @@ slist_remove(struct slist *list, struct slist_node *prev)
*/
#define slist_first_entry(list, type, member) \
MACRO_BEGIN \
- struct slist_node *___first; \
+ struct slist_node *first___; \
\
- ___first = (list)->first; \
- slist_end(___first) ? NULL : slist_entry(___first, type, member); \
+ first___ = (list)->first; \
+ slist_end(first___) ? NULL : slist_entry(first___, type, member); \
MACRO_END
/*
@@ -234,10 +237,10 @@ MACRO_END
*/
#define slist_last_entry(list, type, member) \
MACRO_BEGIN \
- struct slist_node *___last; \
+ struct slist_node *last___; \
\
- ___last = (list)->last; \
- slist_end(___last) ? NULL : slist_entry(___last, type, member); \
+ last___ = (list)->last; \
+ slist_end(last___) ? NULL : slist_entry(last___, type, member); \
MACRO_END
/*
@@ -245,12 +248,12 @@ MACRO_END
*/
#define slist_next_entry(entry, member) \
MACRO_BEGIN \
- struct slist_node *___next; \
+ struct slist_node *next___; \
\
- ___next = (entry)->member.next; \
- slist_end(___next) \
+ next___ = (entry)->member.next; \
+ slist_end(next___) \
? NULL \
- : slist_entry(___next, typeof(*entry), member); \
+ : slist_entry(next___, typeof(*entry), member); \
MACRO_END
/*
@@ -354,8 +357,8 @@ slist_rcu_insert_tail(struct slist *list, struct slist_node *node)
* The prev node must be valid.
*/
static inline void
-slist_rcu_insert_after(struct slist *list, struct slist_node *prev,
- struct slist_node *node)
+slist_rcu_insert_after(struct slist *list, struct slist_node *node,
+ struct slist_node *prev)
{
node->next = prev->next;
rcu_store_ptr(prev->next, node);
@@ -406,10 +409,10 @@ slist_rcu_remove(struct slist *list, struct slist_node *prev)
*/
#define slist_rcu_first_entry(list, type, member) \
MACRO_BEGIN \
- struct slist_node *___first; \
+ struct slist_node *first___; \
\
- ___first = slist_rcu_first(list); \
- slist_end(___first) ? NULL : slist_entry(___first, type, member); \
+ first___ = slist_rcu_first(list); \
+ slist_end(first___) ? NULL : slist_entry(first___, type, member); \
MACRO_END
/*
@@ -417,12 +420,12 @@ MACRO_END
*/
#define slist_rcu_next_entry(entry, member) \
MACRO_BEGIN \
- struct slist_node *___next; \
+ struct slist_node *next___; \
\
- ___next = slist_rcu_next(&entry->member); \
- slist_end(___next) \
+ next___ = slist_rcu_next(&entry->member); \
+ slist_end(next___) \
? NULL \
- : slist_entry(___next, typeof(*entry), member); \
+ : slist_entry(next___, typeof(*entry), member); \
MACRO_END
/*
@@ -441,4 +444,4 @@ for (entry = slist_rcu_first_entry(list, typeof(*entry), member); \
entry != NULL; \
entry = slist_rcu_next_entry(entry, member))
-#endif /* _KERN_SLIST_H */
+#endif /* KERN_SLIST_H */
diff --git a/kern/slist_types.h b/kern/slist_types.h
index 78d7ffb..97121ec 100644
--- a/kern/slist_types.h
+++ b/kern/slist_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_SLIST_TYPES_H
-#define _KERN_SLIST_TYPES_H
+#ifndef KERN_SLIST_TYPES_H
+#define KERN_SLIST_TYPES_H
#include <stdbool.h>
#include <stddef.h>
@@ -35,4 +35,4 @@ struct slist {
struct slist_node *last;
};
-#endif /* _KERN_SLIST_TYPES_H */
+#endif /* KERN_SLIST_TYPES_H */
diff --git a/kern/spinlock.c b/kern/spinlock.c
index 9857b38..5ba9116 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 30fc1e5..d88d535 100644
--- a/kern/spinlock.h
+++ b/kern/spinlock.h
@@ -23,8 +23,8 @@
* acquisition depending only on the number of contending processors.
*/
-#ifndef _KERN_SPINLOCK_H
-#define _KERN_SPINLOCK_H
+#ifndef KERN_SPINLOCK_H
+#define KERN_SPINLOCK_H
#include <kern/init.h>
#include <kern/macros.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
@@ -181,4 +181,4 @@ spinlock_unlock_intr_restore(struct spinlock *lock, unsigned long flags)
*/
INIT_OP_DECLARE(spinlock_setup);
-#endif /* _KERN_SPINLOCK_H */
+#endif /* KERN_SPINLOCK_H */
diff --git a/kern/spinlock_i.h b/kern/spinlock_i.h
index a9f5fce..a54a5e3 100644
--- a/kern/spinlock_i.h
+++ b/kern/spinlock_i.h
@@ -15,15 +15,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_SPINLOCK_I_H
-#define _KERN_SPINLOCK_I_H
+#ifndef KERN_SPINLOCK_I_H
+#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;
@@ -122,4 +122,4 @@ spinlock_unlock_common(struct spinlock *lock)
}
}
-#endif /* _KERN_SPINLOCK_I_H */
+#endif /* KERN_SPINLOCK_I_H */
diff --git a/kern/spinlock_types.h b/kern/spinlock_types.h
index 93f85f7..89d7982 100644
--- a/kern/spinlock_types.h
+++ b/kern/spinlock_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_SPINLOCK_TYPES_H
-#define _KERN_SPINLOCK_TYPES_H
+#ifndef KERN_SPINLOCK_TYPES_H
+#define KERN_SPINLOCK_TYPES_H
struct thread;
@@ -31,4 +31,4 @@ struct spinlock {
#endif /* CONFIG_SPINLOCK_DEBUG */
};
-#endif /* _KERN_SPINLOCK_TYPES_H */
+#endif /* KERN_SPINLOCK_TYPES_H */
diff --git a/kern/sref.c b/kern/sref.c
index 2b20cb4..3539e46 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 fb62d83..e224d16 100644
--- a/kern/sref.h
+++ b/kern/sref.h
@@ -28,8 +28,8 @@
* using sref counters in the work module itself.
*/
-#ifndef _KERN_SREF_H
-#define _KERN_SREF_H
+#ifndef KERN_SREF_H
+#define KERN_SREF_H
#include <kern/init.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.
*/
@@ -113,4 +113,4 @@ struct sref_counter * sref_weakref_get(struct sref_weakref *weakref);
*/
INIT_OP_DECLARE(sref_bootstrap);
-#endif /* _KERN_SREF_H */
+#endif /* KERN_SREF_H */
diff --git a/kern/sref_i.h b/kern/sref_i.h
index 65d0c1b..7b2b07f 100644
--- a/kern/sref_i.h
+++ b/kern/sref_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_SREF_I_H
-#define _KERN_SREF_I_H
+#ifndef KERN_SREF_I_H
+#define KERN_SREF_I_H
#include <stdint.h>
@@ -73,4 +73,4 @@ struct sref_counter {
};
};
-#endif /* _KERN_SREF_I_H */
+#endif /* KERN_SREF_I_H */
diff --git a/kern/string.c b/kern/string.c
index 70d03d0..ba95f77 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,36 @@ 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";
+ case ENOENT:
+ return "no such file or directory";
+ default:
+ return "unknown error";
+ }
+}
diff --git a/kern/string.h b/kern/string.h
index 7cd79a6..51cdf9e 100644
--- a/kern/string.h
+++ b/kern/string.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_STRING_H
-#define _KERN_STRING_H
+#ifndef KERN_STRING_H
+#define KERN_STRING_H
#include <stddef.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 */
+#endif /* KERN_STRING_H */
diff --git a/kern/syscnt.h b/kern/syscnt.h
index fb00b75..167be09 100644
--- a/kern/syscnt.h
+++ b/kern/syscnt.h
@@ -21,8 +21,8 @@
* accessed and modified atomically from any context.
*/
-#ifndef _KERN_SYSCNT_H
-#define _KERN_SYSCNT_H
+#ifndef KERN_SYSCNT_H
+#define KERN_SYSCNT_H
#include <stdint.h>
@@ -134,4 +134,4 @@ void syscnt_info(const char *prefix);
*/
INIT_OP_DECLARE(syscnt_setup);
-#endif /* _KERN_SYSCNT_H */
+#endif /* KERN_SYSCNT_H */
diff --git a/kern/syscnt_types.h b/kern/syscnt_types.h
index 81fb798..dc084eb 100644
--- a/kern/syscnt_types.h
+++ b/kern/syscnt_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_SYSCNT_TYPES_H
-#define _KERN_SYSCNT_TYPES_H
+#ifndef KERN_SYSCNT_TYPES_H
+#define KERN_SYSCNT_TYPES_H
#include <stdint.h>
@@ -41,4 +41,4 @@ struct syscnt {
char name[SYSCNT_NAME_SIZE];
};
-#endif /* _KERN_SYSCNT_TYPES_H */
+#endif /* KERN_SYSCNT_TYPES_H */
diff --git a/kern/task.c b/kern/task.c
index 7039b42..5df7225 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/task.h b/kern/task.h
index 4d9142c..5355c47 100644
--- a/kern/task.h
+++ b/kern/task.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_TASK_H
-#define _KERN_TASK_H
+#ifndef KERN_TASK_H
+#define KERN_TASK_H
#include <kern/atomic.h>
#include <kern/init.h>
@@ -125,4 +125,4 @@ void task_info(struct task *task);
*/
INIT_OP_DECLARE(task_setup);
-#endif /* _KERN_TASK_H */
+#endif /* KERN_TASK_H */
diff --git a/kern/thread.c b/kern/thread.c
index 9fe6434..a5d63b9 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>
@@ -953,10 +953,10 @@ thread_sched_fs_enqueue(struct thread_fs_runq *fs_runq, unsigned long round,
}
if (group->weight == 0) {
- list_insert_after(node, &group->node);
+ list_insert_after(&group->node, node);
} else if (node != init_node) {
list_remove(&group->node);
- list_insert_after(node, &group->node);
+ list_insert_after(&group->node, node);
}
/*
@@ -1075,7 +1075,7 @@ thread_sched_fs_dequeue(struct thread *thread)
if (node != init_node) {
list_remove(&group->node);
- list_insert_before(node, &group->node);
+ list_insert_before(&group->node, node);
}
}
}
@@ -1828,14 +1828,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;
}
@@ -2238,7 +2238,7 @@ thread_shell_trace(int argc, char *argv[])
int error;
if (argc != 3) {
- error = ERROR_INVAL;
+ error = EINVAL;
goto error;
}
@@ -2248,7 +2248,7 @@ thread_shell_trace(int argc, char *argv[])
task = task_lookup(task_name);
if (task == NULL) {
- error = ERROR_SRCH;
+ error = ESRCH;
goto error;
}
@@ -2256,7 +2256,7 @@ thread_shell_trace(int argc, char *argv[])
task_unref(task);
if (thread == NULL) {
- error = ERROR_SRCH;
+ error = ESRCH;
goto error;
}
@@ -2274,7 +2274,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[] = {
@@ -2384,14 +2384,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;
}
@@ -2477,7 +2477,7 @@ thread_wakeup_common(struct thread *thread, int error)
unsigned long flags;
if ((thread == NULL) || (thread == thread_self())) {
- return ERROR_INVAL;
+ return EINVAL;
}
/*
@@ -2493,7 +2493,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);
@@ -2539,7 +2539,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 a6faa95..4953035 100644
--- a/kern/thread.h
+++ b/kern/thread.h
@@ -30,8 +30,8 @@
* balancer thread of the second processor.
*/
-#ifndef _KERN_THREAD_H
-#define _KERN_THREAD_H
+#ifndef KERN_THREAD_H
+#define KERN_THREAD_H
#include <assert.h>
#include <stdbool.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().
*/
@@ -738,4 +738,4 @@ INIT_OP_DECLARE(thread_bootstrap);
*/
INIT_OP_DECLARE(thread_setup);
-#endif /* _KERN_THREAD_H */
+#endif /* KERN_THREAD_H */
diff --git a/kern/thread_i.h b/kern/thread_i.h
index 476d013..066e6b7 100644
--- a/kern/thread_i.h
+++ b/kern/thread_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_THREAD_I_H
-#define _KERN_THREAD_I_H
+#ifndef KERN_THREAD_I_H
+#define KERN_THREAD_I_H
#include <stdalign.h>
#include <stdbool.h>
@@ -221,4 +221,4 @@ thread_test_flag(struct thread *thread, unsigned long flag)
return (atomic_load(&thread->flags, ATOMIC_ACQUIRE) & flag) != 0;
}
-#endif /* _KERN_THREAD_I_H */
+#endif /* KERN_THREAD_I_H */
diff --git a/kern/timer.h b/kern/timer.h
index d47e5a7..43b7d90 100644
--- a/kern/timer.h
+++ b/kern/timer.h
@@ -18,8 +18,8 @@
* Low resolution timer system.
*/
-#ifndef _KERN_TIMER_H
-#define _KERN_TIMER_H
+#ifndef KERN_TIMER_H
+#define KERN_TIMER_H
#include <stdint.h>
@@ -102,4 +102,4 @@ void timer_report_periodic_event(void);
*/
INIT_OP_DECLARE(timer_bootstrap);
-#endif /* _KERN_TIMER_H */
+#endif /* KERN_TIMER_H */
diff --git a/kern/timer_i.h b/kern/timer_i.h
index bbe07f9..799b5ac 100644
--- a/kern/timer_i.h
+++ b/kern/timer_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_TIMER_I_H
-#define _KERN_TIMER_I_H
+#ifndef KERN_TIMER_I_H
+#define KERN_TIMER_I_H
#include <stdbool.h>
#include <stdint.h>
@@ -47,4 +47,4 @@ struct timer {
struct thread *joiner; /* (c) */
};
-#endif /* _KERN_TIMER_I_H */
+#endif /* KERN_TIMER_I_H */
diff --git a/kern/turnstile.h b/kern/turnstile.h
index e7b4a5e..6b59dd5 100644
--- a/kern/turnstile.h
+++ b/kern/turnstile.h
@@ -23,8 +23,8 @@
* unbounded priority inversion.
*/
-#ifndef _KERN_TURNSTILE_H
-#define _KERN_TURNSTILE_H
+#ifndef KERN_TURNSTILE_H
+#define KERN_TURNSTILE_H
#include <stdbool.h>
#include <stddef.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);
@@ -199,4 +199,4 @@ void turnstile_disown(struct turnstile *turnstile);
*/
INIT_OP_DECLARE(turnstile_setup);
-#endif /* _KERN_TURNSTILE_H */
+#endif /* KERN_TURNSTILE_H */
diff --git a/kern/turnstile_types.h b/kern/turnstile_types.h
index a95b691..1462356 100644
--- a/kern/turnstile_types.h
+++ b/kern/turnstile_types.h
@@ -18,8 +18,8 @@
* Isolated type definition used to avoid inclusion circular dependencies.
*/
-#ifndef _KERN_TURNSTILE_TYPES_H
-#define _KERN_TURNSTILE_TYPES_H
+#ifndef KERN_TURNSTILE_TYPES_H
+#define KERN_TURNSTILE_TYPES_H
#include <kern/plist_types.h>
#include <kern/spinlock_types.h>
@@ -55,4 +55,4 @@ struct turnstile_td {
unsigned short top_priority; /* (t) */
};
-#endif /* _KERN_TURNSTILE_TYPES_H */
+#endif /* KERN_TURNSTILE_TYPES_H */
diff --git a/kern/types.h b/kern/types.h
index 2eb1064..b03ef0c 100644
--- a/kern/types.h
+++ b/kern/types.h
@@ -18,9 +18,9 @@
* Machine-independent definitions for non-standard C types.
*/
-#ifndef _KERN_TYPES_H
-#define _KERN_TYPES_H
+#ifndef KERN_TYPES_H
+#define KERN_TYPES_H
typedef long ssize_t;
-#endif /* _KERN_TYPES_H */
+#endif /* KERN_TYPES_H */
diff --git a/kern/work.c b/kern/work.c
index d496961..6151ba4 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/kern/work.h b/kern/work.h
index ccd3c50..6053020 100644
--- a/kern/work.h
+++ b/kern/work.h
@@ -23,8 +23,8 @@
* concurrently handle queued works.
*/
-#ifndef _KERN_WORK_H
-#define _KERN_WORK_H
+#ifndef KERN_WORK_H
+#define KERN_WORK_H
#include <kern/init.h>
@@ -155,4 +155,4 @@ void work_report_periodic_event(void);
*/
INIT_OP_DECLARE(work_bootstrap);
-#endif /* _KERN_WORK_H */
+#endif /* KERN_WORK_H */
diff --git a/kern/work_i.h b/kern/work_i.h
index b5bc872..2cc655b 100644
--- a/kern/work_i.h
+++ b/kern/work_i.h
@@ -15,8 +15,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _KERN_WORK_I_H
-#define _KERN_WORK_I_H
+#ifndef KERN_WORK_I_H
+#define KERN_WORK_I_H
struct work {
struct work *next;
@@ -29,4 +29,4 @@ struct work_queue {
unsigned int nr_works;
};
-#endif /* _KERN_WORK_I_H */
+#endif /* KERN_WORK_I_H */
diff --git a/kern/xcall.h b/kern/xcall.h
index 4733152..666f24f 100644
--- a/kern/xcall.h
+++ b/kern/xcall.h
@@ -23,8 +23,8 @@
* TODO Asynchronous cross-calls.
*/
-#ifndef _KERN_XCALL_H
-#define _KERN_XCALL_H
+#ifndef KERN_XCALL_H
+#define KERN_XCALL_H
#include <kern/init.h>
@@ -61,4 +61,4 @@ void xcall_intr(void);
*/
INIT_OP_DECLARE(xcall_setup);
-#endif /* _KERN_XCALL_H */
+#endif /* KERN_XCALL_H */