Rename userlevel system call wrappers

This commit is contained in:
Ali Mashtizadeh 2015-01-02 14:04:14 -08:00
parent 9b4e8af58c
commit 582f83ca54
8 changed files with 46 additions and 46 deletions

View File

@ -63,7 +63,7 @@ Cmd_List(int argc, const char *argv[])
return; return;
} }
fd = SystemOpen(argv[1], 0); fd = OSOpen(argv[1], 0);
if (fd < 0) { if (fd < 0) {
fputs("Cannot open directory\n", stdout); fputs("Cannot open directory\n", stdout);
return; return;
@ -72,7 +72,7 @@ Cmd_List(int argc, const char *argv[])
while (1) { while (1) {
struct dirent de; struct dirent de;
status = SystemReadDir(fd, (char *)&de, sizeof(de), &offset); status = OSReadDir(fd, (char *)&de, sizeof(de), &offset);
if (status == 0) { if (status == 0) {
break; break;
} }
@ -98,17 +98,17 @@ Cmd_Cat(int argc, const char *argv[])
return; return;
} }
status = SystemStat(argv[1], &sb); status = OSStat(argv[1], &sb);
if (status != 0) { if (status != 0) {
fputs("Cannot stat file\n", stdout); fputs("Cannot stat file\n", stdout);
return; return;
} }
fd = SystemOpen(argv[1], 0); fd = OSOpen(argv[1], 0);
for (i = 0; i < sb.st_size; i += 256) { for (i = 0; i < sb.st_size; i += 256) {
int len = (sb.st_size - i > 256) ? 256 : (sb.st_size - i); int len = (sb.st_size - i > 256) ? 256 : (sb.st_size - i);
SystemRead(fd, &buf, i, len); OSRead(fd, &buf, i, len);
SystemWrite(1, &buf, 0, len); OSWrite(1, &buf, 0, len);
} }
} }

View File

@ -4,29 +4,29 @@
#include <sys/stat.h> #include <sys/stat.h>
uint64_t SystemTime(); uint64_t OSTime();
void SystemExit(int status); void OSExit(int status);
uint64_t SystemGetPID(); uint64_t OSGetPID();
uint64_t SystemSpawn(const char *path); uint64_t OSSpawn(const char *path);
// Memory // Memory
void *SystemMemMap(void *addr, uint64_t len, int flags); void *OSMemMap(void *addr, uint64_t len, int flags);
int SystemMemUnmap(void *addr, uint64_t len); int OSMemUnmap(void *addr, uint64_t len);
int SystemMemProtect(void *addr, uint64_t len, int flags); int OSMemProtect(void *addr, uint64_t len, int flags);
// IO // IO
int SystemRead(uint64_t fd, void *addr, uint64_t off, uint64_t length); int OSRead(uint64_t fd, void *addr, uint64_t off, uint64_t length);
int SystemWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length); int OSWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length);
int SystemFlush(uint64_t fd); int OSFlush(uint64_t fd);
uint64_t SystemOpen(const char *path, uint64_t flags); uint64_t OSOpen(const char *path, uint64_t flags);
int SystemClose(uint64_t fd); int OSClose(uint64_t fd);
// Directory // Directory
int SystemStat(const char *path, struct stat *sb); int OSStat(const char *path, struct stat *sb);
int SystemReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset); int OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset);
// Threads // Threads
int SystemThreadSleep(uint64_t time); int OSThreadSleep(uint64_t time);
#endif /* __SYSCALL_H__ */ #endif /* __SYSCALL_H__ */

View File

@ -9,6 +9,6 @@
_start: _start:
call main call main
movq %rax, %rdi movq %rax, %rdi
call SystemExit call OSExit
int $3 int $3

View File

@ -40,7 +40,7 @@ exit(int status)
_atexit_last = _atexit_last->next; _atexit_last = _atexit_last->next;
} }
SystemExit(status); OSExit(status);
__builtin_unreachable(); __builtin_unreachable();
} }

View File

@ -66,7 +66,7 @@ fopen(const char *path, const char *mode)
FILE *fh; FILE *fh;
// XXX: handle mode // XXX: handle mode
fd = SystemOpen(path, 0); fd = OSOpen(path, 0);
if (fd == 0) if (fd == 0)
return NULL; return NULL;
@ -82,7 +82,7 @@ fopen(const char *path, const char *mode)
int int
fclose(FILE *fh) fclose(FILE *fh)
{ {
int status = SystemClose(fh->fd); int status = OSClose(fh->fd);
_free_file(fh); _free_file(fh);
@ -102,14 +102,14 @@ fflush(FILE *fh)
size_t size_t
fread(void *buf, size_t size, size_t nmemb, FILE *fh) fread(void *buf, size_t size, size_t nmemb, FILE *fh)
{ {
return SystemRead(fh->fd, buf, 0, size * nmemb); return OSRead(fh->fd, buf, 0, size * nmemb);
// set errno // set errno
} }
size_t size_t
fwrite(const void *buf, size_t size, size_t nmemb, FILE *fh) fwrite(const void *buf, size_t size, size_t nmemb, FILE *fh)
{ {
return SystemWrite(fh->fd, buf, 0, size * nmemb); return OSWrite(fh->fd, buf, 0, size * nmemb);
// set errno // set errno
} }

View File

@ -8,91 +8,91 @@
uint64_t syscall(int num, ...); uint64_t syscall(int num, ...);
uint64_t uint64_t
SystemTime() OSTime()
{ {
return syscall(SYSCALL_TIME); return syscall(SYSCALL_TIME);
} }
void void
SystemExit(int status) OSExit(int status)
{ {
syscall(SYSCALL_EXIT); syscall(SYSCALL_EXIT);
} }
uint64_t uint64_t
SystemGetPID() OSGetPID()
{ {
return syscall(SYSCALL_GETPID); return syscall(SYSCALL_GETPID);
} }
uint64_t uint64_t
SystemSpawn(const char *path) OSSpawn(const char *path)
{ {
return syscall(SYSCALL_SPAWN, path); return syscall(SYSCALL_SPAWN, path);
} }
void * void *
SystemMemMap(void *addr, uint64_t len, int flags) OSMemMap(void *addr, uint64_t len, int flags)
{ {
return (void *)syscall(SYSCALL_MMAP, addr, len, flags); return (void *)syscall(SYSCALL_MMAP, addr, len, flags);
} }
int int
SystemMemUnmap(void *addr, uint64_t len) OSMemUnmap(void *addr, uint64_t len)
{ {
return syscall(SYSCALL_MUNMAP, addr, len); return syscall(SYSCALL_MUNMAP, addr, len);
} }
int int
SystemMemProtect(void *addr, uint64_t len, int flags) OSMemProtect(void *addr, uint64_t len, int flags)
{ {
return syscall(SYSCALL_MPROTECT, addr, len, flags); return syscall(SYSCALL_MPROTECT, addr, len, flags);
} }
int int
SystemRead(uint64_t fd, void *addr, uint64_t off, uint64_t length) OSRead(uint64_t fd, void *addr, uint64_t off, uint64_t length)
{ {
return syscall(SYSCALL_READ, fd, addr, off, length); return syscall(SYSCALL_READ, fd, addr, off, length);
} }
int int
SystemWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length) OSWrite(uint64_t fd, const void *addr, uint64_t off, uint64_t length)
{ {
return syscall(SYSCALL_WRITE, fd, addr, off, length); return syscall(SYSCALL_WRITE, fd, addr, off, length);
} }
int int
SystemFlush(uint64_t fd) OSFlush(uint64_t fd)
{ {
return syscall(SYSCALL_FLUSH, fd); return syscall(SYSCALL_FLUSH, fd);
} }
uint64_t uint64_t
SystemOpen(const char *path, uint64_t flags) OSOpen(const char *path, uint64_t flags)
{ {
return syscall(SYSCALL_OPEN, path, flags); return syscall(SYSCALL_OPEN, path, flags);
} }
int int
SystemClose(uint64_t fd) OSClose(uint64_t fd)
{ {
return syscall(SYSCALL_CLOSE, fd); return syscall(SYSCALL_CLOSE, fd);
} }
int int
SystemStat(const char *path, struct stat *sb) OSStat(const char *path, struct stat *sb)
{ {
return syscall(SYSCALL_STAT, path, sb); return syscall(SYSCALL_STAT, path, sb);
} }
int int
SystemReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset) OSReadDir(uint64_t fd, char *buf, size_t length, uint64_t *offset)
{ {
return syscall(SYSCALL_READDIR, fd, buf, length, offset); return syscall(SYSCALL_READDIR, fd, buf, length, offset);
} }
int int
SystemThreadSleep(uint64_t time) OSThreadSleep(uint64_t time)
{ {
return syscall(SYSCALL_THREADSLEEP, time); return syscall(SYSCALL_THREADSLEEP, time);
} }

View File

@ -17,7 +17,7 @@ static const char *months[12] = {
time_t time_t
time(time_t *t) time(time_t *t)
{ {
uint64_t nsec = SystemTime(); uint64_t nsec = OSTime();
time_t sec = nsec / 1000000000; time_t sec = nsec / 1000000000;
printf("%ld\n", nsec); printf("%ld\n", nsec);
@ -31,7 +31,7 @@ time(time_t *t)
int int
gettimeofday(struct timeval *tv, struct timezone *tz) gettimeofday(struct timeval *tv, struct timezone *tz)
{ {
uint64_t nsec = SystemTime(); uint64_t nsec = OSTime();
tv->tv_sec = nsec / 1000000000; tv->tv_sec = nsec / 1000000000;
tv->tv_usec = (nsec % 1000000000) / 1000; tv->tv_usec = (nsec % 1000000000) / 1000;

View File

@ -6,10 +6,10 @@ main(int argc, const char *argv[])
{ {
fputs("Init spawning shell\n", stdout); fputs("Init spawning shell\n", stdout);
SystemSpawn("/bin/shell"); OSSpawn("/bin/shell");
while (1) { while (1) {
SystemThreadSleep(0); OSThreadSleep(0);
} }
} }