From 1e9a1ebf4d41a96ca8b65c3788a7b121ad6d1251 Mon Sep 17 00:00:00 2001 From: Marvin Friedrich Date: Thu, 17 Sep 2026 18:29:33 +0200 Subject: [PATCH] license --- LICENSE | 1 + LICENSES/ISC.txt | 7 +++++++ LICENSES/Unlicense.txt | 10 +++++++++ README.md | 6 +++++- include/arch/sched.h | 19 +++++++++++++++++ include/uapi/archctl.h | 2 +- include/uapi/epoll.h | 2 +- include/uapi/errno.h | 2 +- include/uapi/fcntl.h | 2 +- include/uapi/mman.h | 2 +- include/uapi/mount.h | 2 +- include/uapi/poll.h | 2 +- include/uapi/stat.h | 2 +- include/uapi/time.h | 2 +- include/uapi/types.h | 2 +- include/uapi/uio.h | 2 +- include/uapi/utsname.h | 2 +- include/zinnia/hashmap.h | 44 ++++++++++++++++++++-------------------- include/zinnia/sched.h | 15 -------------- include/zinnia/vec.h | 12 +++++------ meson.build | 2 +- 21 files changed, 83 insertions(+), 57 deletions(-) create mode 120000 LICENSE create mode 100644 LICENSES/ISC.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 include/arch/sched.h diff --git a/LICENSE b/LICENSE new file mode 120000 index 0000000..afdb398 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +LICENSES/ISC.txt \ No newline at end of file diff --git a/LICENSES/ISC.txt b/LICENSES/ISC.txt new file mode 100644 index 0000000..237bde9 --- /dev/null +++ b/LICENSES/ISC.txt @@ -0,0 +1,7 @@ +ISC License + +Copyright 2026 Marvin Friedrich and contributors + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..cde4ac6 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,10 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md index 9d1829c..95a8658 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,14 @@ Zinnia is a lightweight Unix-like monolithic kernel targeting 64-bit devices. ## Building Zinnia -To build the kernel you need `meson` and a GNU-like C compiler with support for C23. +To build the kernel you need: +- `meson` +- a `kconfig` frontend (like `kconfiglib` via `pip`) +- a GNU-like C compiler with support for C23 (e.g. `gcc` or `clang`) To configure, run: ```sh +alldefconfig meson setup $build_dir ``` diff --git a/include/arch/sched.h b/include/arch/sched.h new file mode 100644 index 0000000..99ac429 --- /dev/null +++ b/include/arch/sched.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +void arch_sched_preempt_disable(); +bool arch_sched_preempt_enable(); +struct task* arch_sched_switch(struct task* from, struct task* to); +errno_t arch_task_init( + struct arch_task_context* context, + void* entry, + uintptr_t arg0, + uintptr_t stack_start, + bool is_user +); +[[noreturn]] +void arch_sched_jump_to_context(struct arch_context* context); +[[noreturn]] +void arch_sched_jump_to_user(uintptr_t ip, uintptr_t sp, uintptr_t arg); diff --git a/include/uapi/archctl.h b/include/uapi/archctl.h index be6c8b6..3f55cb4 100644 --- a/include/uapi/archctl.h +++ b/include/uapi/archctl.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_ARCHCTL_H #define __ZINNIA_UAPI_ARCHCTL_H diff --git a/include/uapi/epoll.h b/include/uapi/epoll.h index 36526c7..2a69387 100644 --- a/include/uapi/epoll.h +++ b/include/uapi/epoll.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_EPOLL_H #define __ZINNIA_UAPI_EPOLL_H diff --git a/include/uapi/errno.h b/include/uapi/errno.h index 6d8d0ca..b02a7de 100644 --- a/include/uapi/errno.h +++ b/include/uapi/errno.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_ERRNO_H #define __ZINNIA_UAPI_ERRNO_H diff --git a/include/uapi/fcntl.h b/include/uapi/fcntl.h index e96ada1..83068c1 100644 --- a/include/uapi/fcntl.h +++ b/include/uapi/fcntl.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_FCNTL_H #define __ZINNIA_UAPI_FCNTL_H diff --git a/include/uapi/mman.h b/include/uapi/mman.h index 509c6cb..4083bb3 100644 --- a/include/uapi/mman.h +++ b/include/uapi/mman.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_MMAN_H #define __ZINNIA_UAPI_MMAN_H diff --git a/include/uapi/mount.h b/include/uapi/mount.h index e31b901..24ffdc0 100644 --- a/include/uapi/mount.h +++ b/include/uapi/mount.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_MOUNT_H #define __ZINNIA_UAPI_MOUNT_H diff --git a/include/uapi/poll.h b/include/uapi/poll.h index 771decf..30d6558 100644 --- a/include/uapi/poll.h +++ b/include/uapi/poll.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_POLL_H #define __ZINNIA_UAPI_POLL_H diff --git a/include/uapi/stat.h b/include/uapi/stat.h index d291d62..3eeaa68 100644 --- a/include/uapi/stat.h +++ b/include/uapi/stat.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_STAT_H #define __ZINNIA_UAPI_STAT_H diff --git a/include/uapi/time.h b/include/uapi/time.h index 1fbd429..6d5a940 100644 --- a/include/uapi/time.h +++ b/include/uapi/time.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_TIME_H #define __ZINNIA_UAPI_TIME_H diff --git a/include/uapi/types.h b/include/uapi/types.h index 071c727..1efa32b 100644 --- a/include/uapi/types.h +++ b/include/uapi/types.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_TYPES_H #define __ZINNIA_UAPI_TYPES_H diff --git a/include/uapi/uio.h b/include/uapi/uio.h index 0b3110c..c407908 100644 --- a/include/uapi/uio.h +++ b/include/uapi/uio.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_UIO_H #define __ZINNIA_UAPI_UIO_H diff --git a/include/uapi/utsname.h b/include/uapi/utsname.h index 9163606..eb26d7c 100644 --- a/include/uapi/utsname.h +++ b/include/uapi/utsname.h @@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0 */ +/* SPDX-License-Identifier: Unlicense */ #ifndef __ZINNIA_UAPI_UTSNAME_H #define __ZINNIA_UAPI_UTSNAME_H diff --git a/include/zinnia/hashmap.h b/include/zinnia/hashmap.h index f00e475..66bf342 100644 --- a/include/zinnia/hashmap.h +++ b/include/zinnia/hashmap.h @@ -6,25 +6,6 @@ #include #include -// FNV-1a hash over raw bytes. -static inline uint64_t hashmap_hash_default(const void* key, size_t len) { - const uint8_t* data = (const uint8_t*)key; - uint64_t hash = 0xcbf29ce484222325; - for (size_t i = 0; i < len; i++) { - hash ^= data[i]; - hash *= 0x100000001b3; - } - return hash; -} - -// Byte-wise equality. -static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) { - return memcmp(a, b, len) == 0; -} - -// Ensure a hash is never zero (zero is the empty sentinel). -#define _HASHMAP_FIXHASH(h) ((h) == 0 ? (uint64_t)1 : (h)) - #define hashmap(K, V) \ struct { \ K* keys; \ @@ -57,6 +38,9 @@ static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) #define hashmap_count(map) ((map)->count) +// Ensure a hash is never zero (zero is the empty sentinel). +#define _HASHMAP_FIXHASH(h) ((h) == 0 ? (uint64_t)1 : (h)) + // Internal: probe distance from ideal position. #define _HASHMAP_PROBE_DIST(hash, pos, cap) (((pos) - ((hash) & ((cap) - 1))) & ((cap) - 1)) @@ -116,10 +100,10 @@ static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) } \ } while (0) -// Insert or update a key-value pair. Returns 0 or ZN_ERR_NO_MEMORY. +// Insert or update a key-value pair. Returns 0 or ENOMEM. #define hashmap_insert(map, key, val, hash_fn, eq_fn) \ ({ \ - zn_status_t _status = 0; \ + errno_t _status = 0; \ typeof(*(map)->keys) _k = (key); \ uint64_t _h = _HASHMAP_FIXHASH((hash_fn)(&_k, sizeof(_k))); \ /* Check for existing key first. */ \ @@ -144,7 +128,7 @@ static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) if ((map)->count * 4 >= (map)->capacity * 3 || (map)->capacity == 0) { \ _HASHMAP_GROW(map, hash_fn, eq_fn); \ if ((map)->keys == nullptr || (map)->values == nullptr || (map)->hashes == nullptr) { \ - _status = ZN_ERR_NO_MEMORY; \ + _status = ENOMEM; \ } \ } \ if (_status == 0) { \ @@ -221,3 +205,19 @@ static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) #define hashmap_foreach(map, idx) \ for (size_t idx = 0; idx < (map)->capacity; idx++) \ if ((map)->hashes[idx] != 0) + +// FNV-1a hash over raw bytes. +static inline uint64_t hashmap_hash_default(const void* key, size_t len) { + const uint8_t* data = (const uint8_t*)key; + uint64_t hash = 0xcbf29ce484222325; + for (size_t i = 0; i < len; i++) { + hash ^= data[i]; + hash *= 0x100000001b3; + } + return hash; +} + +// Byte-wise equality. +static inline bool hashmap_eq_default(const void* a, const void* b, size_t len) { + return memcmp(a, b, len) == 0; +} diff --git a/include/zinnia/sched.h b/include/zinnia/sched.h index 553e773..51ce886 100644 --- a/include/zinnia/sched.h +++ b/include/zinnia/sched.h @@ -77,18 +77,3 @@ struct task_start_info { uintptr_t sp; uintptr_t arg; }; - -void arch_sched_preempt_disable(); -bool arch_sched_preempt_enable(); -struct task* arch_sched_switch(struct task* from, struct task* to); -errno_t arch_task_init( - struct arch_task_context* context, - void* entry, - uintptr_t arg0, - uintptr_t stack_start, - bool is_user -); -[[noreturn]] -void arch_sched_jump_to_context(struct arch_context* context); -[[noreturn]] -void arch_sched_jump_to_user(uintptr_t ip, uintptr_t sp, uintptr_t arg); diff --git a/include/zinnia/vec.h b/include/zinnia/vec.h index ea6aada..d2207e1 100644 --- a/include/zinnia/vec.h +++ b/include/zinnia/vec.h @@ -1,9 +1,9 @@ #pragma once -#include // IWYU pragma: keep -#include // IWYU pragma: keep #include #include +#include // IWYU pragma: keep +#include // IWYU pragma: keep #define vec(T) \ struct { \ @@ -27,10 +27,10 @@ (vec)->capacity = 0; \ } while (0) -#define vec_length(vec) ((vec)->length) -#define vec_capacity(vec) ((vec)->capacity) -#define vec_empty(vec) ((vec)->length == 0) -#define vec_at(vec, i) ((vec)->data[i]) +#define vec_length(vec) ((vec)->length) +#define vec_capacity(vec) ((vec)->capacity) +#define vec_is_empty(vec) ((vec)->length == 0) +#define vec_elem_get(vec, i) ((vec)->data[i]) // Internal: grow to at least `needed` capacity. #define _vec_grow(vec, needed) \ diff --git a/meson.build b/meson.build index 0b29930..11a41f0 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,6 @@ project( 'zinnia', - license: 'MIT', + license: 'ISC', version: '0.1.0', meson_version: '>=1.3.0', default_options: [