diff --git a/kernel/include/sys/Syscall.h b/kernel/include/sys/Syscall.h index b5dfb2bd..594a3071 100644 --- a/kernel/include/sys/Syscall.h +++ b/kernel/include/sys/Syscall.h @@ -1,6 +1,7 @@ #pragma once #include "interrupts/Context.h" #include +#include #define SYS_exit 0 #define SYS_yield 1 @@ -45,7 +46,7 @@ void sys_paint(Context* context, uint64_t x, uint64_t y, uint64_t w, uint64_t h, void sys_getprocid(Context* context, int field); void sys_mmap(Context* context, void* address, size_t size, int prot); void sys_munmap(Context* context, void* address, size_t size); -void sys_open(Context* context, const char* filename, int flags); +void sys_open(Context* context, const char* filename, int flags, mode_t mode); void sys_read(Context* context, int fd, size_t size, char* buffer); void sys_close(Context* context, int fd); void sys_seek(Context* context, int fd, long offset, int whence); diff --git a/kernel/src/sys/Syscall.cpp b/kernel/src/sys/Syscall.cpp index ac1e9a04..0773a06f 100644 --- a/kernel/src/sys/Syscall.cpp +++ b/kernel/src/sys/Syscall.cpp @@ -19,7 +19,7 @@ void Syscall::entry(Context* context) case SYS_getprocid: sys_getprocid(context, (int)context->rdi); break; case SYS_mmap: sys_mmap(context, (void*)context->rdi, context->rsi, (int)context->rdx); break; case SYS_munmap: sys_munmap(context, (void*)context->rdi, context->rsi); break; - case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi); break; + case SYS_open: sys_open(context, (const char*)context->rdi, (int)context->rsi, (mode_t)context->rdx); break; case SYS_read: sys_read(context, (int)context->rdi, context->rsi, (char*)context->rdx); break; case SYS_close: sys_close(context, (int)context->rdi); break; case SYS_seek: sys_seek(context, (int)context->rdi, (long)context->rsi, (int)context->rdx); break; diff --git a/kernel/src/sys/stdio.cpp b/kernel/src/sys/stdio.cpp index b4ed6d44..d0cca5f6 100644 --- a/kernel/src/sys/stdio.cpp +++ b/kernel/src/sys/stdio.cpp @@ -11,6 +11,7 @@ #include "sys/UserMemory.h" #include "thread/Scheduler.h" #include "thread/Task.h" +#include #define OPEN_READ 1 #define OPEN_WRITE 2 @@ -137,7 +138,7 @@ void sys_write(Context* context, int fd, size_t size, const char* addr) return; } -void sys_open(Context* context, const char* filename, int flags) +void sys_open(Context* context, const char* filename, int flags, mode_t) // FIXME: mode is not used. { Task* current_task = Scheduler::current_task(); int fd = current_task->alloc_fd(); diff --git a/libs/libc/include/fcntl.h b/libs/libc/include/fcntl.h index 6e801bd6..0b709fa3 100644 --- a/libs/libc/include/fcntl.h +++ b/libs/libc/include/fcntl.h @@ -31,7 +31,7 @@ extern "C" #endif /* Opens the file specified by pathname. Returns a file descriptor on success, or -1 on error. */ - int open(const char* pathname, int flags); + int open(const char* pathname, int flags, ...); /* Performs an operation on the file descriptor fd determined by cmd. */ int fcntl(int fd, int cmd, ...); diff --git a/libs/libc/src/fcntl.cpp b/libs/libc/src/fcntl.cpp index 1c5bb063..5c623d43 100644 --- a/libs/libc/src/fcntl.cpp +++ b/libs/libc/src/fcntl.cpp @@ -6,9 +6,13 @@ extern "C" { - int open(const char* pathname, int flags) + int open(const char* pathname, int flags, ...) { - return (int)syscall(SYS_open, pathname, flags); + va_list ap; + va_start(ap, flags); + long result = syscall(SYS_open, pathname, flags, va_arg(ap, unsigned int)); + va_end(ap); + return (int)result; } int fcntl(int fd, int cmd, ...) diff --git a/libs/libc/src/syscall.cpp b/libs/libc/src/syscall.cpp index 9b655704..b5ae5667 100644 --- a/libs/libc/src/syscall.cpp +++ b/libs/libc/src/syscall.cpp @@ -26,13 +26,13 @@ extern "C" long syscall(long number, ...) case SYS_fstat: case SYS_stat: case SYS_dup2: - case SYS_pstat: - case SYS_open: { + case SYS_pstat: { arg arg0 = va_arg(ap, arg); arg arg1 = va_arg(ap, arg); result = __luna_syscall2(number, arg0, arg1); break; } + case SYS_open: case SYS_getdents: case SYS_fcntl: case SYS_seek: