From e894942e52480af63c2fe0551247bcf01f7e7279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Thu, 28 Dec 2023 18:40:35 +0000 Subject: [PATCH] Add sys_lseek. --- posix-runner/posix-runner.c | 2 +- posix-runner/syscalls.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/posix-runner/posix-runner.c b/posix-runner/posix-runner.c index 9cff02d..1a9aab8 100644 --- a/posix-runner/posix-runner.c +++ b/posix-runner/posix-runner.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) /* Load binary into memory */ int file_size = fseek(file_in, 0, SEEK_END); - char *file_data = malloc(file_size); + char *file_data = calloc(file_size + 0x1000); /* Allocate extra space in case application tries to use it */ rewind(file_in); fread(file_data, 1, file_size, file_in); fclose(file_in); diff --git a/posix-runner/syscalls.c b/posix-runner/syscalls.c index 7ffa587..b2080d1 100644 --- a/posix-runner/syscalls.c +++ b/posix-runner/syscalls.c @@ -13,7 +13,6 @@ int sys_read(int fd, char* buf, unsigned count, void, void, void) int sys_write(int fd, char* buf, unsigned count, void, void, void) { - fputs("write\n", stderr); return write(fd, buf, count); } @@ -22,6 +21,11 @@ int sys_open(char* name, int flag, int mode, void, void, void) return open(name, flag, mode); } +int sys_lseek(int fd, int offset, int whence, void, void, void) +{ + return lseek(fd, offset, whence); +} + void sys_exit(unsigned value, void, void, void, void, void) { exit(value); @@ -33,5 +37,6 @@ void init_syscalls() syscall_table[0] = sys_read; syscall_table[1] = sys_write; syscall_table[2] = sys_open; + syscall_table[8] = sys_lseek; syscall_table[60] = sys_exit; }