37static clock_t lastReaperTime = 0;
55 list_t* current = &zombies;
77 LOG_DEBUG(
"process_file_get_process: inode private is NULL\n");
124 prioStr[
count] =
'\0';
126 long long int prio =
atoll(prioStr);
341 LOG_DEBUG(
"freeing process pid=%d\n", process->
id);
360 panic(
NULL,
"Freeing process pid=%d with children", process->
id);
402 else if (parent !=
NULL)
454 LOG_DEBUG(
"new pid=%d parent=%d priority=%d\n", process->
id, parent ? parent->
id : 0, priority);
485 LOG_DEBUG(
"killing process pid=%d with status=%llu refCount=%d\n", process->
id, status, process->
ref.
count);
505 LOG_DEBUG(
"sent kill note to %llu threads in process pid=%d\n", killCount, process->
id);
533 while (current !=
NULL)
548 if (current->
parent->id == parentId)
570 if (procMount ==
NULL)
572 panic(
NULL,
"Failed to mount /proc filesystem");
578 panic(
NULL,
"Failed to create /proc/self directory");
588 panic(
NULL,
"Failed to create /proc/[pid] directory for kernel process");
600 panic(
NULL,
"Failed to init kernel process");
#define MAX_NAME
Maximum length of names.
#define MAX_PATH
Maximum length of filepaths.
#define assert(expression)
static cpu_t * smp_self_unsafe(void)
Returns a pointer to the cpu_t structure of the current CPU.
#define SYSCALL_DEFINE(num, returnType,...)
Macro to define a syscall.
void namespace_deinit(namespace_t *ns)
Deinitializes a namespace.
mount_t * namespace_bind(namespace_t *ns, dentry_t *source, path_t *mountpoint)
Bind a directory to a mountpoint in a namespace.
uint64_t namespace_init(namespace_t *ns, namespace_t *parent, process_t *owner)
Initializes a namespace.
void path_put(path_t *path)
Put a path.
#define PATH_CREATE(inMount, inDentry)
Helper to create a path.
#define PATH_DEFER(path)
Defer path put.
uint64_t path_to_name(const path_t *path, pathname_t *pathname)
Convert a path to a pathname.
#define PATH_EMPTY
Helper to create an empty path.
void vfs_ctx_deinit(vfs_ctx_t *ctx)
Deinitialize a VFS context.
void vfs_ctx_init(vfs_ctx_t *ctx, const path_t *cwd)
Initialize a VFS context.
uint64_t vfs_ctx_get_cwd(vfs_ctx_t *ctx, path_t *outCwd)
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
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 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 argv_deinit(argv_t *argv)
Deinitializes an argument vector, freeing any allocated memory.
uint64_t argv_init(argv_t *argv, const char **src)
Initializes an argument vector from a source array of strings.
const char * argv_get_strings(const argv_t *argv, uint64_t *length)
Retrieves a pointer to the start of the first string.
void process_kill(process_t *process, uint64_t status)
Kills a process.
bool process_is_child(process_t *process, pid_t parentId)
Checks if a process is a child of another process.
process_t * process_get_kernel(void)
Gets the kernel process.
process_t * process_new(process_t *parent, const char **argv, const path_t *cwd, priority_t priority)
Allocates and initializes a new process.
void process_procfs_init(void)
Initializes the /proc directory.
uint64_t thread_send_note(thread_t *thread, const void *buffer, uint64_t count)
Send a note to a thread.
uint64_t wait_unblock(wait_queue_t *waitQueue, uint64_t amount, errno_t err)
Unblock threads waiting on a wait queue.
void wait_queue_init(wait_queue_t *waitQueue)
Initialize wait queue.
#define WAIT_ALL
Wait for all.
#define WAIT_BLOCK(waitQueue, condition)
Basic block.
void wait_queue_deinit(wait_queue_t *waitQueue)
Deinitialize wait queue.
process_t * sched_process(void)
Retrieves the process of the currently running thread.
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. @macro LOCK_CREATE.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
void rwlock_write_acquire(rwlock_t *lock)
Acquires a rwlock for writing, blocking until it is available.
#define RWLOCK_READ_SCOPE(lock)
Acquires a rwlock for reading for the reminder of the current scope.
void rwlock_write_release(rwlock_t *lock)
Releases a rwlock from writing.
void rwlock_init(rwlock_t *lock)
Initializes a rwlock.
#define RWLOCK_WRITE_SCOPE(lock)
Acquires a rwlock for writing for the reminder of the current scope.
void timer_subscribe(timer_ctx_t *ctx, timer_callback_t callback)
Subscribe to timer interrupts.
clock_t timer_uptime(void)
Time since boot.
static void ref_init(ref_t *ref, void *free)
Initialize a reference counter.
#define REF(ptr)
Increment reference count.
#define DEREF(ptr)
Decrement reference count.
#define CONFIG_PROCESS_REAPER_INTERVAL
Process reaper interval configuration.
#define EINVAL
Invalid argument.
#define errno
Error number variable.
#define EACCES
Permission denied.
poll_events_t
Poll events type.
@ POLLIN
File descriptor is ready to read.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static list_entry_t * list_first(list_t *list)
Gets the first entry in the list without removing it.
#define LIST_CREATE(name)
Creates a list initializer.
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
static void list_push(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
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_init(list_t *list)
Initializes a list.
static list_entry_t * list_pop(list_t *list)
Pops the first entry from the list.
#define PRIORITY_MAX_USER
clock_t uptime(void)
System call for retreving the time since boot.
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__ pid_t
Process Identifier.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
__UINT64_TYPE__ clock_t
A nanosecond time.
EFI_PHYSICAL_ADDRESS buffer
static inode_ops_t inodeOps
static uint64_t process_cmdline_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static void process_inode_cleanup(inode_t *inode)
static process_t * process_file_get_process(file_t *file)
static wait_queue_t * process_wait_poll(file_t *file, poll_events_t *revents)
static file_ops_t noteOps
static uint64_t process_wait_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static process_t kernelProcess
static file_ops_t prioOps
static uint64_t process_note_write(file_t *file, const void *buffer, uint64_t count, uint64_t *offset)
static uint64_t process_prio_write(file_t *file, const void *buffer, uint64_t count, uint64_t *offset)
static void process_free(process_t *process)
static uint64_t process_prio_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static uint64_t process_init(process_t *process, process_t *parent, const char **argv, const path_t *cwd, priority_t priority)
static file_ops_t waitOps
static uint64_t process_cwd_read(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
static uint64_t process_dir_init(process_t *process, const char *name)
static bool kernelProcessInitalized
static file_ops_t cmdlineOps
#define atomic_store(object, desired)
#define atomic_exchange(object, desired)
#define atomic_load(object)
#define ATOMIC_VAR_INIT(value)
#define atomic_fetch_add(object, operand)
#define atomic_init(obj, value)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC long long int atoll(const char *nptr)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
_PUBLIC size_t strlen(const char *s)
Directory entry structure.
File operations structure.
uint64_t(* write)(file_t *file, const void *buffer, uint64_t count, uint64_t *offset)
uint64_t(* read)(file_t *file, void *buffer, uint64_t count, uint64_t *offset)
void(* cleanup)(inode_t *inode)
A simple ticket lock implementation.
dentry_t * root
The root dentry of the mounted filesystem.
dentry_t * prioFile
The /proc/[pid]/prio file.
mount_t * self
The /proc/[pid]/self mount point.
list_entry_t siblingEntry
dentry_t * dir
The /proc/[pid] directory for this process.
dentry_t * noteFile
The /proc/[pid]/note file.
dentry_t * waitFile
The /proc/[pid]/wait file.
process_threads_t threads
dentry_t * cwdFile
The /proc/[pid]/cwd file.
dentry_t * cmdlineFile
The /proc/[pid]/cmdline file.
wait_queue_t dyingWaitQueue
atomic_uint32_t count
Atomic reference counter.
Thread of execution structure.
mount_t * sysfs_mount_new(const path_t *parent, const char *name, namespace_t *ns, const superblock_ops_t *superblockOps)
Mount a new instance of SysFS.
dentry_t * sysfs_dir_new(dentry_t *parent, const char *name, const inode_ops_t *inodeOps, void *private)
Create a new directory inside a mounted SysFS instance.
dentry_t * sysfs_file_new(dentry_t *parent, const char *name, const inode_ops_t *inodeOps, const file_ops_t *fileOps, void *private)
Create a new file inside a mounted SysFS instance.