diff --git a/include/syscall.h b/include/syscall.h index 05752ba..3791a92 100644 --- a/include/syscall.h +++ b/include/syscall.h @@ -30,6 +30,7 @@ int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset); // Threads int OSThreadCreate(uint64_t rip, uint64_t arg); +int OSGetTID(); int OSThreadExit(uint64_t status); int OSThreadSleep(uint64_t time); int OSThreadWait(uint64_t tid); diff --git a/lib/libc/syscall.c b/lib/libc/syscall.c index 40e9905..d9c669e 100644 --- a/lib/libc/syscall.c +++ b/lib/libc/syscall.c @@ -103,6 +103,12 @@ OSThreadCreate(uint64_t rip, uint64_t arg) return syscall(SYSCALL_THREADCREATE, rip, arg); } +int +OSGetTID() +{ + return syscall(SYSCALL_GETTID); +} + int OSThreadExit(uint64_t status) { diff --git a/sys/include/syscall.h b/sys/include/syscall.h index b012a84..a2d27a5 100644 --- a/sys/include/syscall.h +++ b/sys/include/syscall.h @@ -30,9 +30,10 @@ // Threading #define SYSCALL_THREADCREATE 0x30 -#define SYSCALL_THREADEXIT 0x31 -#define SYSCALL_THREADSLEEP 0x32 -#define SYSCALL_THREADWAIT 0x33 +#define SYSCALL_GETTID 0x31 +#define SYSCALL_THREADEXIT 0x32 +#define SYSCALL_THREADSLEEP 0x33 +#define SYSCALL_THREADWAIT 0x34 // Network #define SYSCALL_NICSTAT 0x40 diff --git a/sys/kern/syscall.c b/sys/kern/syscall.c index 4c3057e..d8fcc71 100644 --- a/sys/kern/syscall.c +++ b/sys/kern/syscall.c @@ -139,10 +139,9 @@ uint64_t Syscall_MMap(uint64_t addr, uint64_t len, uint64_t prot) { Thread *cur = Sched_Current(); - uint64_t pgs = (len + PGSIZE - 1) / PGSIZE; bool status; - status = PMap_AllocMap(cur->space, addr, pgs, PTE_W); + status = PMap_AllocMap(cur->space, addr, len, PTE_W); Thread_Release(cur); if (!status) { // XXX: Need to unmap PMap_Unmap(cur->space, addr, pgs); @@ -375,6 +374,17 @@ Syscall_ThreadCreate(uint64_t rip, uint64_t arg) return threadId; } +uint64_t +Syscall_GetTID() +{ + Thread *cur = Sched_Current(); + uint64_t tid = cur->tid; + + Thread_Release(cur); + + return tid; +} + void Syscall_ThreadExit(uint64_t status) { @@ -562,6 +572,8 @@ Syscall_Entry(uint64_t syscall, uint64_t a1, uint64_t a2, return Syscall_ReadDir(a1, (char *)a2, a3, a4); case SYSCALL_THREADCREATE: return Syscall_ThreadCreate(a1, a2); + case SYSCALL_GETTID: + return Syscall_GetTID(); case SYSCALL_THREADEXIT: Syscall_ThreadExit(a1); return 0;