Fix mmap and expose gettid system call

This commit is contained in:
Ali Mashtizadeh 2015-01-30 20:43:28 -08:00
parent cfee2dd1e8
commit 8b45f56bf5
4 changed files with 25 additions and 5 deletions

View File

@ -30,6 +30,7 @@ int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset);
// Threads // Threads
int OSThreadCreate(uint64_t rip, uint64_t arg); int OSThreadCreate(uint64_t rip, uint64_t arg);
int OSGetTID();
int OSThreadExit(uint64_t status); int OSThreadExit(uint64_t status);
int OSThreadSleep(uint64_t time); int OSThreadSleep(uint64_t time);
int OSThreadWait(uint64_t tid); int OSThreadWait(uint64_t tid);

View File

@ -103,6 +103,12 @@ OSThreadCreate(uint64_t rip, uint64_t arg)
return syscall(SYSCALL_THREADCREATE, rip, arg); return syscall(SYSCALL_THREADCREATE, rip, arg);
} }
int
OSGetTID()
{
return syscall(SYSCALL_GETTID);
}
int int
OSThreadExit(uint64_t status) OSThreadExit(uint64_t status)
{ {

View File

@ -30,9 +30,10 @@
// Threading // Threading
#define SYSCALL_THREADCREATE 0x30 #define SYSCALL_THREADCREATE 0x30
#define SYSCALL_THREADEXIT 0x31 #define SYSCALL_GETTID 0x31
#define SYSCALL_THREADSLEEP 0x32 #define SYSCALL_THREADEXIT 0x32
#define SYSCALL_THREADWAIT 0x33 #define SYSCALL_THREADSLEEP 0x33
#define SYSCALL_THREADWAIT 0x34
// Network // Network
#define SYSCALL_NICSTAT 0x40 #define SYSCALL_NICSTAT 0x40

View File

@ -139,10 +139,9 @@ uint64_t
Syscall_MMap(uint64_t addr, uint64_t len, uint64_t prot) Syscall_MMap(uint64_t addr, uint64_t len, uint64_t prot)
{ {
Thread *cur = Sched_Current(); Thread *cur = Sched_Current();
uint64_t pgs = (len + PGSIZE - 1) / PGSIZE;
bool status; bool status;
status = PMap_AllocMap(cur->space, addr, pgs, PTE_W); status = PMap_AllocMap(cur->space, addr, len, PTE_W);
Thread_Release(cur); Thread_Release(cur);
if (!status) { if (!status) {
// XXX: Need to unmap PMap_Unmap(cur->space, addr, pgs); // XXX: Need to unmap PMap_Unmap(cur->space, addr, pgs);
@ -375,6 +374,17 @@ Syscall_ThreadCreate(uint64_t rip, uint64_t arg)
return threadId; return threadId;
} }
uint64_t
Syscall_GetTID()
{
Thread *cur = Sched_Current();
uint64_t tid = cur->tid;
Thread_Release(cur);
return tid;
}
void void
Syscall_ThreadExit(uint64_t status) 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); return Syscall_ReadDir(a1, (char *)a2, a3, a4);
case SYSCALL_THREADCREATE: case SYSCALL_THREADCREATE:
return Syscall_ThreadCreate(a1, a2); return Syscall_ThreadCreate(a1, a2);
case SYSCALL_GETTID:
return Syscall_GetTID();
case SYSCALL_THREADEXIT: case SYSCALL_THREADEXIT:
Syscall_ThreadExit(a1); Syscall_ThreadExit(a1);
return 0; return 0;