license
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <zinnia/errno.h>
|
||||
#include <zinnia/sched.h>
|
||||
|
||||
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);
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_ARCHCTL_H
|
||||
#define __ZINNIA_UAPI_ARCHCTL_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
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_ERRNO_H
|
||||
#define __ZINNIA_UAPI_ERRNO_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
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_MMAN_H
|
||||
#define __ZINNIA_UAPI_MMAN_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
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_POLL_H
|
||||
#define __ZINNIA_UAPI_POLL_H
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_STAT_H
|
||||
#define __ZINNIA_UAPI_STAT_H
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_TIME_H
|
||||
#define __ZINNIA_UAPI_TIME_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
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#ifndef __ZINNIA_UAPI_UIO_H
|
||||
#define __ZINNIA_UAPI_UIO_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
|
||||
|
||||
|
||||
+22
-22
@@ -6,25 +6,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h> // IWYU pragma: keep
|
||||
#include <string.h> // IWYU pragma: keep
|
||||
#include <zinnia/alloc.h>
|
||||
#include <zinnia/errno.h>
|
||||
#include <stddef.h> // IWYU pragma: keep
|
||||
#include <string.h> // 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) \
|
||||
|
||||
Reference in New Issue
Block a user