12#include <sys/kassert.h>
15#include <sys/ktimer.h>
16#include <sys/thread.h>
17#include <sys/loader.h>
18#include <sys/syscall.h>
21#include <sys/vfsuio.h>
23#include <sys/sysctl.h>
62 Panic(
"Returned to exited thread!\n");
79 status =
Copy_StrIn(user_path, &path,
sizeof(path));
91 for (
int i = 0; i < 8; i++) {
105 char *argstart = arg+
sizeof(
uintptr_t)*8;
106 for (
int i = 1; i < 8; i++) {
118 argstart +=
strlen(argstart)+1;
225 if (handle ==
NULL) {
228 status = (handle->
read)(handle, (
void *)
addr, off, length);
243 if (handle ==
NULL) {
246 status = (handle->
write)(handle, (
void *)
addr, off, length);
261 if (handle ==
NULL) {
264 status = (handle->
flush)(handle);
283 status =
Copy_StrIn(user_path, &path,
sizeof(path));
289 if (
strncmp(
"/dev/", path, 5) == 0) {
290 if (
strcmp(
"/dev/console", path) == 0) {
320 if (handle ==
NULL) {
323 status = (handle->
close)(handle);
338 status =
Copy_StrIn(user_path, &path,
sizeof(path));
365 if (handle ==
NULL) {
370 status =
Copy_In(user_off, &offset,
sizeof(offset));
387 status =
Copy_Out(&offset, user_off,
sizeof(offset));
406 if (newThread ==
NULL) {
410 threadId = newThread->
tid;
441 Panic(
"Returned to exited thread!\n");
579 status =
Copy_StrIn(user_node, &node,
sizeof(node));
589 if (user_oldval != 0) {
593 status =
Copy_Out(scStr, user_oldval,
sizeof(*scStr));
598 status =
Copy_Out(scInt, user_oldval,
sizeof(*scInt));
603 status =
Copy_Out(scBool, user_oldval,
sizeof(scBool));
616 if (user_newval != 0) {
620 status =
Copy_In(user_newval, &scStr,
sizeof(scStr));
629 status =
Copy_In(user_newval, &scInt,
sizeof(scInt));
638 status =
Copy_In(user_newval, &scBool,
sizeof(scBool));
void Thread_SetupUThread(Thread *thr, uintptr_t rip, uintptr_t arg)
int Copy_StrIn(uintptr_t fromuser, void *tokernel, uintptr_t len)
void Sched_SetWaiting(Thread *thr)
Thread * Thread_Create(Process *proc)
Thread * Thread_UThreadCreate(Thread *oldThr, uint64_t rip, uint64_t arg)
Handle * Handle_Lookup(Process *proc, uint64_t fd)
void Thread_Release(Thread *thr)
int Copy_In(uintptr_t fromuser, void *tokernel, uintptr_t len)
Process * Process_Create(Process *parent, const char *title)
void Sched_SetZombie(Thread *thr)
uint64_t Process_Wait(Process *proc, uint64_t pid)
void Sched_SetRunnable(Thread *thr)
int Copy_Out(void *fromkernel, uintptr_t touser, uintptr_t len)
uint64_t Handle_Add(Process *proc, Handle *handle)
uint64_t Thread_Wait(Thread *thr, uint64_t tid)
void Thread_Retain(Thread *thr)
#define Log(_module, _format,...)
#define NOT_IMPLEMENTED()
void PAlloc_Release(void *pg)
void * PAlloc_AllocPage()
UnixEpochNS KTime_GetEpochNS()
KTimerEvent * KTimer_Create(uint64_t timeout, KTimerCB cb, void *arg)
void KTimer_Release(KTimerEvent *evt)
uint64_t syscall(int num,...)
bool Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
bool Loader_CheckHeader(const Elf64_Ehdr *ehdr)
NIC * NIC_GetByID(uint64_t nicNo)
#define MEM_USERSPACE_STKTOP
uintptr_t PMap_Translate(AS *space, uintptr_t va)
bool PMap_Unmap(AS *as, uint64_t virt, uint64_t pages)
bool PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags)
void Semaphore_Release(Semaphore *sema)
void Semaphore_Acquire(Semaphore *sema)
size_t strlen(const char *str)
int strcmp(const char *s1, const char *s2)
int strncmp(const char *s1, const char *s2, size_t len)
int(* write)(Handle *, void *, uint64_t, uint64_t)
int(* read)(Handle *, void *, uint64_t, uint64_t)
int(* tx)(NIC *, MBuf *, NICCB, void *)
int(* rx)(NIC *, MBuf *, NICCB, void *)
Semaphore zombieSemaphore
#define SYSCALL_ERRCODE(_result)
#define SYSCALL_FSUNMOUNT
#define SYSCALL_THREADEXIT
#define SYSCALL_THREADCREATE
#define SYSCALL_THREADSLEEP
#define SYSCALL_PACK(_errcode, _val)
#define SYSCALL_THREADWAIT
uint64_t Syscall_Stat(uint64_t user_path, uint64_t user_stat)
uint64_t Syscall_MProtect(uint64_t addr, uint64_t len, uint64_t prot)
uint64_t Syscall_GetPID()
uint64_t Syscall_FSMount(uint64_t user_mntpt, uint64_t user_device, uint64_t flags)
uint64_t Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5)
uint64_t Syscall_NICRecv(uint64_t nicNo, uint64_t user_mbuf)
uint64_t Syscall_SysCtl(uint64_t user_node, uint64_t user_oldval, uint64_t user_newval)
uint64_t Syscall_GetTID()
uint64_t Syscall_Read(uint64_t fd, uint64_t addr, uint64_t off, uint64_t length)
uint64_t Syscall_Open(uint64_t user_path, uint64_t flags)
void Syscall_Exit(uint64_t status)
uint64_t Syscall_ThreadSleep(uint64_t time)
uint64_t Syscall_ReadDir(uint64_t fd, char *user_buf, size_t len, uintptr_t user_off)
uint64_t Syscall_FSInfo(uint64_t user_fsinfo, uint64_t max)
uint64_t Syscall_MMap(uint64_t addr, uint64_t len, uint64_t prot)
uint64_t Syscall_FSUnmount(uint64_t user_mntpt)
uint64_t Syscall_ThreadWait(uint64_t tid)
uint64_t Syscall_NICSend(uint64_t nicNo, uint64_t user_mbuf)
uint64_t Syscall_Write(uint64_t fd, uint64_t addr, uint64_t off, uint64_t length)
uint64_t Syscall_Spawn(uint64_t user_path, uint64_t user_argv)
uint64_t Syscall_ThreadCreate(uint64_t rip, uint64_t arg)
static void ThreadWakeupHelper(void *arg)
Handle * Console_OpenHandle()
void Syscall_ThreadExit(uint64_t status)
uint64_t Syscall_NICStat(uint64_t nicNo, uint64_t user_stat)
uint64_t Syscall_Flush(uint64_t fd)
uint64_t Syscall_MUnmap(uint64_t addr, uint64_t len)
uint64_t Syscall_Close(uint64_t fd)
uint64_t Syscall_Wait(uint64_t pid)
#define SYSCTL_TYPE_INVALID
uint64_t SysCtl_SetObject(const char *node, void *obj)
uint64_t SysCtl_GetType(const char *node)
void * SysCtl_GetObject(const char *node)
int VFS_Stat(const char *path, struct stat *sb)
int VFS_ReadDir(VNode *fn, void *buf, uint64_t len, uint64_t *off)
int VFSUIO_Open(const char *path, Handle **handle)
void Panic(const char *str)