49static void process_ctor(
void* ptr)
185 LOG_DEBUG(
"created process pid=%d\n", process->
id);
264 LOG_DEBUG(
"sent kill note to %llu threads in process pid=%d\n", killCount, process->
id);
302 if (argv ==
NULL || argc == 0)
309 char** newArgv =
malloc(
sizeof(
char*) * (argc + 1));
317 for (; i < argc; i++)
323 size_t len =
strlen(argv[i]) + 1;
325 if (newArgv[i] ==
NULL)
335 memcpy(newArgv[i], argv[i], len);
352 process->
argv = newArgv;
353 process->
argc = newArgc;
365 if (thread->
id == tid)
381 panic(
NULL,
"Failed to create kernel namespace");
388 panic(
NULL,
"Failed to create kernel process");
#define assert(expression)
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
void cwd_init(cwd_t *cwd)
Initialize a CWD structure.
void cwd_clear(cwd_t *cwd)
Clear the current working directory.
void cwd_deinit(cwd_t *cwd)
Deinitialize a CWD structure.
void file_table_close_all(file_table_t *table)
Close all files in the file table.
void file_table_init(file_table_t *table)
Initialize a file table.
void file_table_deinit(file_table_t *table)
Deinitialize a file table.
namespace_t * namespace_new(namespace_t *parent)
Create a new namespace.
void ioring_ctx_deinit(ioring_ctx_t *ctx)
Deinitialize a I/O context.
void ioring_ctx_init(ioring_ctx_t *ctx)
Initialize a I/O context.
void note_handler_init(note_handler_t *handler)
Initialize a note handler.
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_INFO(format,...)
#define LOG_DEBUG(format,...)
void cache_free(void *obj)
Free an object back to its cache.
#define CACHE_LINE
Cache line size in bytes.
void * cache_alloc(cache_t *cache)
Allocate an object from the cache.
#define CACHE_CREATE(_cache, _name, _size, _alignment, _ctor, _dtor)
Macro to create a cache initializer.
void space_deinit(space_t *space)
Deinitializes a virtual address space.
uint64_t space_init(space_t *space, uintptr_t startAddress, uintptr_t endAddress, space_flags_t flags)
Initializes a virtual address space.
@ SPACE_MAP_KERNEL_HEAP
Map the kernel heap into the address space.
@ SPACE_MAP_IDENTITY
Map the identity mapped physical memory into the address space.
@ SPACE_MAP_KERNEL_BINARY
Map the kernel binary into the address space.
#define VMM_USER_SPACE_MAX
The maximum address for user space.
#define VMM_USER_SPACE_MIN
The minimum address for user space.
void env_init(env_t *env)
Initialize the environment.
void env_deinit(env_t *env)
Deinitialize the environment.
void group_member_deinit(group_member_t *member)
Deinitializes a group member.
uint64_t group_member_init(group_member_t *member, group_member_t *group)
Initializes a group member.
void group_remove(group_member_t *member)
Removes a process from its group.
void reaper_push(process_t *process)
Pushes a process to be reaped later.
void process_kill(process_t *process, const char *status)
Kills a process, pushing it to the reaper.
void process_set_ns(process_t *process, namespace_t *ns)
Sets the namespace of a process.
#define PROCESS_RCU_THREAD_FOR_EACH(thread, process)
Macro to iterate over all threads in a process.
process_t * process_get_kernel(void)
Gets the kernel process.
process_t * process_new(priority_t priority, group_member_t *group, namespace_t *ns)
Allocates and initializes a new process.
bool process_has_thread(process_t *process, tid_t tid)
Checks if a process has a thread with the specified thread ID.
#define PROCESS_STATUS_MAX
Maximum length of a process exit status.
void process_remove(process_t *process)
Removes a process from the system.
uint64_t process_set_cmdline(process_t *process, char **argv, uint64_t argc)
Sets the command line arguments for a process.
static process_t * process_current(void)
Retrieves the process of the currently running thread.
list_t _processes
Global list of all processes.
namespace_t * process_get_ns(process_t *process)
Gets the namespace of a process.
process_t * process_get(pid_t id)
Gets a process by its ID.
uint64_t thread_send_note(thread_t *thread, const char *string)
Send a note to a thread.
uint64_t wait_unblock(wait_queue_t *queue, uint64_t amount, errno_t err)
Unblock threads waiting on a wait queue.
void wait_queue_deinit(wait_queue_t *queue)
Deinitialize wait queue.
#define WAIT_ALL
Used to indicate that the wait should unblock all waiting threads.
void wait_queue_init(wait_queue_t *queue)
Initialize wait queue.
void futex_ctx_deinit(futex_ctx_t *ctx)
Deinitialize a per-process futex context. *.
void futex_ctx_init(futex_ctx_t *ctx)
Initialize a per-process futex context.
static void lock_init(lock_t *lock)
Initializes a lock.
#define LOCK_CREATE()
Create a lock initializer.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define RCU_READ_SCOPE()
RCU read-side critical section for the current scope.
void rcu_call_cache_free(void *arg)
Helper callback to free a cache object.
void rcu_call(rcu_entry_t *entry, rcu_callback_t func, void *arg)
Add a callback to be executed after a grace period.
void map_entry_init(map_entry_t *entry)
Initialize a map entry.
static map_key_t map_key_uint64(uint64_t uint64)
Create a map key from a uint64_t.
uint64_t map_insert(map_t *map, const map_key_t *key, map_entry_t *value)
Insert a key-value pair into the map.
void map_remove(map_t *map, map_entry_t *entry)
Remove a entry from the map.
map_entry_t * map_get(map_t *map, const map_key_t *key)
Get a value from the map by key.
#define MAP_CREATE()
Create a map initializer.
#define REF_TRY(ptr)
Increment reference count, but only if the current count is not zero.
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
static void ref_init(ref_t *ref, void *callback)
Initialize a reference counter.
#define UNREF(ptr)
Decrement reference count.
#define EINVAL
Invalid argument.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
#define LIST_CREATE(name)
Creates a list initializer.
static void list_remove_rcu(list_entry_t *entry)
Removes a list entry from its current list in a RCU-safe manner.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static void list_push_back_rcu(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list in a RCU-safe manner.
static void list_init(list_t *list)
Initializes a list.
#define PRIORITY_MAX
The maximum priority value, inclusive.
uint8_t priority_t
Priority type.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
__UINT64_TYPE__ tid_t
Thread Identifier.
__UINT64_TYPE__ pid_t
Process Identifier.
errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n)
static process_t * kernelProcess
static void process_free(process_t *process)
#define atomic_store(object, desired)
#define atomic_fetch_add_explicit(object, operand, order)
#define atomic_fetch_or(object, operand)
#define ATOMIC_VAR_INIT(value)
#define atomic_init(obj, value)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
Per-process futex context.
A simple ticket lock implementation.
Per-process note handler.
char buffer[PROCESS_STATUS_MAX]
note_handler_t noteHandler
wait_queue_t suspendQueue
ioring_ctx_t rings[CONFIG_MAX_RINGS]
process_threads_t threads
list_t list
Reads are RCU protected, writes require the lock.
Intrusive RCU head structure.
Reference counting structure.
Virtual address space structure.
Thread of execution structure.
tid_t id
The thread id, unique within a process_t.
The primitive that threads block on.