From 86107a467c76166157a19508f33bf8ecac5e021f Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 22 Sep 2012 00:44:41 +0200 Subject: [PATCH] Use instead of . --- libmaxsi/_exit.cpp | 6 +- libmaxsi/access.cpp | 7 +- libmaxsi/chdir.cpp | 8 +- libmaxsi/chmod.cpp | 7 +- libmaxsi/close.cpp | 7 +- libmaxsi/dup.cpp | 7 +- libmaxsi/error.cpp | 1 - libmaxsi/fchmod.cpp | 7 +- libmaxsi/fcntl.cpp | 14 +- libmaxsi/fstat.cpp | 7 +- libmaxsi/ftruncate.cpp | 8 +- libmaxsi/getcwd.cpp | 8 +- libmaxsi/gettermmode.cpp | 7 +- libmaxsi/include/libmaxsi/syscall.h | 311 --------------------------- libmaxsi/include/sys/syscall.h | 313 ++++++++++++++++++++++++++++ libmaxsi/include/termios.h | 1 + libmaxsi/isatty.cpp | 7 +- libmaxsi/kernelinfo.cpp | 8 +- libmaxsi/lseek.cpp | 7 +- libmaxsi/memory.cpp | 2 +- libmaxsi/mkdir.cpp | 8 +- libmaxsi/open.cpp | 18 +- libmaxsi/pipe.cpp | 7 +- libmaxsi/process.cpp | 2 +- libmaxsi/read.cpp | 7 +- libmaxsi/readdirents.cpp | 7 +- libmaxsi/rmdir.cpp | 8 +- libmaxsi/settermmode.cpp | 7 +- libmaxsi/signal.cpp | 2 +- libmaxsi/sortix-sound.cpp | 2 +- libmaxsi/stat.cpp | 7 +- libmaxsi/thread.cpp | 2 +- libmaxsi/time.cpp | 2 +- libmaxsi/truncate.cpp | 8 +- libmaxsi/umask.cpp | 9 +- libmaxsi/unlink.cpp | 8 +- libmaxsi/winsize.cpp | 7 +- libmaxsi/write.cpp | 7 +- 38 files changed, 372 insertions(+), 489 deletions(-) delete mode 100644 libmaxsi/include/libmaxsi/syscall.h create mode 100644 libmaxsi/include/sys/syscall.h diff --git a/libmaxsi/_exit.cpp b/libmaxsi/_exit.cpp index 070130d1..b629d837 100644 --- a/libmaxsi/_exit.cpp +++ b/libmaxsi/_exit.cpp @@ -22,14 +22,10 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { DEFN_SYSCALL1_VOID(sys_exit, SYSCALL_EXIT, int); -} // namespace Maxsi -using namespace Maxsi; extern "C" void _exit(int status) { diff --git a/libmaxsi/access.cpp b/libmaxsi/access.cpp index 54957b60..6a5b810a 100644 --- a/libmaxsi/access.cpp +++ b/libmaxsi/access.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL2(int, SysAccess, SYSCALL_ACCESS, const char*, int); extern "C" int access(const char* pathname, int mode) { return SysAccess(pathname, mode); } - -} // namespace Maxsi diff --git a/libmaxsi/chdir.cpp b/libmaxsi/chdir.cpp index ea514ec8..41b5b934 100644 --- a/libmaxsi/chdir.cpp +++ b/libmaxsi/chdir.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL1(int, SysChDir, SYSCALL_CHDIR, const char*); @@ -33,5 +31,3 @@ extern "C" int chdir(const char* path) { return SysChDir(path); } - -} // namespace Maxsi diff --git a/libmaxsi/chmod.cpp b/libmaxsi/chmod.cpp index e13b33d2..53c208b8 100644 --- a/libmaxsi/chmod.cpp +++ b/libmaxsi/chmod.cpp @@ -22,18 +22,13 @@ *******************************************************************************/ -#include -#include #include +#include #include -namespace Maxsi { - // TODO: Implement this in the kernel. extern "C" int chmod(const char* path, mode_t mode) { errno = ENOSYS; return -1; } - -} // namespace Maxsi diff --git a/libmaxsi/close.cpp b/libmaxsi/close.cpp index d18bbdf7..82a41b35 100644 --- a/libmaxsi/close.cpp +++ b/libmaxsi/close.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL1(int, SysClose, SYSCALL_CLOSE, int); extern "C" int close(int fd) { return SysClose(fd); } - -} // namespace Maxsi diff --git a/libmaxsi/dup.cpp b/libmaxsi/dup.cpp index 65484a16..c85448a1 100644 --- a/libmaxsi/dup.cpp +++ b/libmaxsi/dup.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL1(int, SysDup, SYSCALL_DUP, int); extern "C" int dup(int fd) { return SysDup(fd); } - -} // namespace Maxsi diff --git a/libmaxsi/error.cpp b/libmaxsi/error.cpp index aee70cf7..101435de 100644 --- a/libmaxsi/error.cpp +++ b/libmaxsi/error.cpp @@ -26,7 +26,6 @@ #include #include #ifndef SORTIX_KERNEL -#include #include #endif diff --git a/libmaxsi/fchmod.cpp b/libmaxsi/fchmod.cpp index 7319d8f0..f941afce 100644 --- a/libmaxsi/fchmod.cpp +++ b/libmaxsi/fchmod.cpp @@ -22,18 +22,13 @@ *******************************************************************************/ -#include -#include #include +#include #include -namespace Maxsi { - // TODO: Implement this in the kernel. extern "C" int fchmod(int fd, mode_t mode) { errno = ENOSYS; return -1; } - -} // namespace Maxsi diff --git a/libmaxsi/fcntl.cpp b/libmaxsi/fcntl.cpp index b5cb8fa3..a9264174 100644 --- a/libmaxsi/fcntl.cpp +++ b/libmaxsi/fcntl.cpp @@ -22,17 +22,17 @@ *******************************************************************************/ -#include -#include +#include #include - -namespace Maxsi { +#include DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long); -extern "C" int fcntl(int fd, int cmd, unsigned long arg) +extern "C" int fcntl(int fd, int cmd, ...) { + va_list ap; + va_start(ap, cmd); + unsigned long arg = va_arg(ap, unsigned long); + va_end(ap); return SysFCntl(fd, cmd, arg); } - -} // namespace Maxsi diff --git a/libmaxsi/fstat.cpp b/libmaxsi/fstat.cpp index 54f62d0e..7678d673 100644 --- a/libmaxsi/fstat.cpp +++ b/libmaxsi/fstat.cpp @@ -22,11 +22,8 @@ *******************************************************************************/ -#include -#include #include - -namespace Maxsi { +#include DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*); @@ -34,5 +31,3 @@ extern "C" int fstat(int fd, struct stat* st) { return SysFStat(fd, st); } - -} // namespace Maxsi diff --git a/libmaxsi/ftruncate.cpp b/libmaxsi/ftruncate.cpp index 8aa2f6d6..66e55e8c 100644 --- a/libmaxsi/ftruncate.cpp +++ b/libmaxsi/ftruncate.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t); @@ -33,5 +31,3 @@ extern "C" int ftruncate(int fd, off_t length) { return SysFTruncate(fd, length); } - -} // namespace Maxsi diff --git a/libmaxsi/getcwd.cpp b/libmaxsi/getcwd.cpp index e5616ecb..e25e9143 100644 --- a/libmaxsi/getcwd.cpp +++ b/libmaxsi/getcwd.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL2(char*, SysGetCWD, SYSCALL_GETCWD, char*, size_t); @@ -33,5 +31,3 @@ extern "C" char* getcwd(char* buf, size_t size) { return SysGetCWD(buf, size); } - -} // namespace Maxsi diff --git a/libmaxsi/gettermmode.cpp b/libmaxsi/gettermmode.cpp index 4558a7a4..697b6291 100644 --- a/libmaxsi/gettermmode.cpp +++ b/libmaxsi/gettermmode.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL2(int, sys_gettermmode, SYSCALL_GETTERMMODE, int, unsigned*); extern "C" int gettermmode(int fd, unsigned* mode) { return sys_gettermmode(fd, mode); } - -} // namespace Maxsi diff --git a/libmaxsi/include/libmaxsi/syscall.h b/libmaxsi/include/libmaxsi/syscall.h deleted file mode 100644 index 71c4eeed..00000000 --- a/libmaxsi/include/libmaxsi/syscall.h +++ /dev/null @@ -1,311 +0,0 @@ -/******************************************************************************* - - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. - - This file is part of LibMaxsi. - - LibMaxsi is free software: you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more - details. - - You should have received a copy of the GNU Lesser General Public License - along with LibMaxsi. If not, see . - - syscall.h - Assembly stubs for declaring system calls in libmaxsi. - -*******************************************************************************/ - -#ifdef SORTIX_KERNEL -#warning === -#warning Sortix does not support syscalls from within the kernel, building this part of LibMaxsi should not be needed, and should not be used in kernel mode -#warning === -#else - -#ifndef LIBMAXSI_SYSCALL_H -#define LIBMAXSI_SYSCALL_H - -#include -#include - -namespace Maxsi -{ - #define DECL_SYSCALL0(type,fn) type fn(); - #define DECL_SYSCALL1(type,fn,p1) type fn(p1); - #define DECL_SYSCALL2(type,fn,p1,p2) type fn(p1,p2); - #define DECL_SYSCALL3(type,fn,p1,p2,p3) type fn(p1,p2,p3); - #define DECL_SYSCALL4(type,fn,p1,p2,p3,p4) type fn(p1,p2,p3,p4); - #define DECL_SYSCALL5(type,fn,p1,p2,p3,p4,p5) type fn(p1,p2,p3,p4,p5); - -#ifdef PLATFORM_X86 - - #define DEFN_SYSCALL0(type, fn, num) \ - inline type fn() \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL1(type, fn, num, P1) \ - inline type fn(P1 p1) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL2(type, fn, num, P1, P2) \ - inline type fn(P1 p1, P2 p2) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \ - inline type fn(P1 p1, P2 p2, P3 p3) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \ - inline type fn(P1 p1, P2 p2, P3 p3, P4 p4) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \ - inline type fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4), "S" ((size_t)p5)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL0_VOID(fn, num) \ - inline void fn() \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL1_VOID(fn, num, P1) \ - inline void fn(P1 p1) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \ - inline void fn(P1 p1, P2 p2) \ - { \ - size_t a; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \ - inline void fn(P1 p1, P2 p2, P3 p3) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \ - inline void fn(P1 p1, P2 p2, P3 p3, P4 p4) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \ - inline void fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((size_t)p1), "c" ((size_t)p2), "d" ((size_t)p3), "D" ((size_t)p4), "S" ((size_t)p5)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - -#else - - // TODO: Make these inline - though that requires a move advanced inline - // assembly stub to force parameters into the right registers. - - #define DEFN_SYSCALL0(type, fn, num) \ - type fn() \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL1(type, fn, num, P1) \ - type fn(P1) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL2(type, fn, num, P1, P2) \ - type fn(P1, P2) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \ - type fn(P1, P2, P3) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \ - type fn(P1, P2, P3, P4) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \ - type fn(P1, P2, P3, P4, P5) \ - { \ - type a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - return a; \ - } - - #define DEFN_SYSCALL0_VOID(fn, num) \ - void fn() \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL1_VOID(fn, num, P1) \ - void fn(P1) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \ - void fn(P1, P2) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \ - void fn(P1, P2, P3) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \ - void fn(P1, P2, P3, P4) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - - #define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \ - void fn(P1, P2, P3, P4, P5) \ - { \ - size_t a; \ - int reterrno; \ - asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ - asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ - if ( reterrno ) { errno = reterrno; } \ - } - -#endif - -} - -#endif - -#endif - diff --git a/libmaxsi/include/sys/syscall.h b/libmaxsi/include/sys/syscall.h new file mode 100644 index 00000000..28145777 --- /dev/null +++ b/libmaxsi/include/sys/syscall.h @@ -0,0 +1,313 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + + This file is part of LibMaxsi. + + LibMaxsi is free software: you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + LibMaxsi is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + + You should have received a copy of the GNU Lesser General Public License + along with LibMaxsi. If not, see . + + sys/syscall.h + Functions and macros for declaring system call stubs. + +*******************************************************************************/ + +#if defined(SORTIX_KERNEL) +#error This part of libc should not be built in kernel mode +#endif + +#ifndef _SYS_SYSCALL_H +#define _SYS_SYSCALL_H 1 + +#include +#include +#include /* Should not be exposed here; use an eventual __errno.h. */ + +__BEGIN_DECLS + +#define DECL_SYSCALL0(type,fn) type fn(); +#define DECL_SYSCALL1(type,fn,p1) type fn(p1); +#define DECL_SYSCALL2(type,fn,p1,p2) type fn(p1,p2); +#define DECL_SYSCALL3(type,fn,p1,p2,p3) type fn(p1,p2,p3); +#define DECL_SYSCALL4(type,fn,p1,p2,p3,p4) type fn(p1,p2,p3,p4); +#define DECL_SYSCALL5(type,fn,p1,p2,p3,p4,p5) type fn(p1,p2,p3,p4,p5); + +// System call functions for i386. (IA-32) +#if defined(__i386__) + +#define DEFN_SYSCALL0(type, fn, num) \ +inline type fn() \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL1(type, fn, num, P1) \ +inline type fn(P1 p1) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL2(type, fn, num, P1, P2) \ +inline type fn(P1 p1, P2 p2) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \ +inline type fn(P1 p1, P2 p2, P3 p3) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \ +inline type fn(P1 p1, P2 p2, P3 p3, P4 p4) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \ +inline type fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4), "S" ((unsigned long)p5)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL0_VOID(fn, num) \ +inline void fn() \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL1_VOID(fn, num, P1) \ +inline void fn(P1 p1) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \ +inline void fn(P1 p1, P2 p2) \ +{ \ + unsigned long a; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \ +inline void fn(P1 p1, P2 p2, P3 p3) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \ +inline void fn(P1 p1, P2 p2, P3 p3, P4 p4) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \ +inline void fn(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num), "b" ((unsigned long)p1), "c" ((unsigned long)p2), "d" ((unsigned long)p3), "D" ((unsigned long)p4), "S" ((unsigned long)p5)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +// System call functions for x86_64. (amd64) +#elif defined(__x86_64__) + +// TODO: Make these inline - though that requires a move advanced inline +// assembly stub to force parameters into the right registers. + +#define DEFN_SYSCALL0(type, fn, num) \ +type fn() \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL1(type, fn, num, P1) \ +type fn(P1) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL2(type, fn, num, P1, P2) \ +type fn(P1, P2) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL3(type, fn, num, P1, P2, P3) \ +type fn(P1, P2, P3) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL4(type, fn, num, P1, P2, P3, P4) \ +type fn(P1, P2, P3, P4) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL5(type, fn, num, P1, P2, P3, P4, P5) \ +type fn(P1, P2, P3, P4, P5) \ +{ \ + type a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ + return a; \ +} + +#define DEFN_SYSCALL0_VOID(fn, num) \ +void fn() \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL1_VOID(fn, num, P1) \ +void fn(P1) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL2_VOID(fn, num, P1, P2) \ +void fn(P1, P2) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL3_VOID(fn, num, P1, P2, P3) \ +void fn(P1, P2, P3) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL4_VOID(fn, num, P1, P2, P3, P4) \ +void fn(P1, P2, P3, P4) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +#define DEFN_SYSCALL5_VOID(fn, num, P1, P2, P3, P4, P5) \ +void fn(P1, P2, P3, P4, P5) \ +{ \ + unsigned long a; \ + int reterrno; \ + asm volatile("int $0x80" : "=a" (a) : "0" (num)); \ + asm volatile("movl %%edx, %0" : "=r"(reterrno)); \ + if ( reterrno ) { errno = reterrno; } \ +} + +// Unknown platform with no implementation available. +#else +#error System call interface is not declared for host system. + +#endif + +__END_DECLS + +#endif diff --git a/libmaxsi/include/termios.h b/libmaxsi/include/termios.h index 14109238..7585f758 100644 --- a/libmaxsi/include/termios.h +++ b/libmaxsi/include/termios.h @@ -28,6 +28,7 @@ #define _TERMIOS_H 1 #include +#include #include __BEGIN_DECLS diff --git a/libmaxsi/isatty.cpp b/libmaxsi/isatty.cpp index e743aa98..23788468 100644 --- a/libmaxsi/isatty.cpp +++ b/libmaxsi/isatty.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL1(int, sys_isatty, SYSCALL_ISATTY, int); extern "C" int isatty(int fd) { return sys_isatty(fd); } - -} // namespace Maxsi diff --git a/libmaxsi/kernelinfo.cpp b/libmaxsi/kernelinfo.cpp index 163dc1bd..ccfe5c09 100644 --- a/libmaxsi/kernelinfo.cpp +++ b/libmaxsi/kernelinfo.cpp @@ -22,11 +22,8 @@ *******************************************************************************/ -#include -#include #include - -namespace Maxsi { +#include DEFN_SYSCALL3(ssize_t, SysKernelInfo, SYSCALL_KERNELINFO, const char*, char*, size_t); @@ -34,6 +31,3 @@ extern "C" ssize_t kernelinfo(const char* req, char* resp, size_t resplen) { return SysKernelInfo(req, resp, resplen); } - -} // namespace Maxsi - diff --git a/libmaxsi/lseek.cpp b/libmaxsi/lseek.cpp index 025fc5c4..b6cd6b4b 100644 --- a/libmaxsi/lseek.cpp +++ b/libmaxsi/lseek.cpp @@ -22,12 +22,9 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL3_VOID(SysSeek, SYSCALL_SEEK, int, off_t*, int); extern "C" off_t lseek(int fd, off_t offset, int whence) @@ -35,5 +32,3 @@ extern "C" off_t lseek(int fd, off_t offset, int whence) SysSeek(fd, &offset, whence); return offset; } - -} // namespace Maxsi diff --git a/libmaxsi/memory.cpp b/libmaxsi/memory.cpp index 63de0c13..ffb2b2e5 100644 --- a/libmaxsi/memory.cpp +++ b/libmaxsi/memory.cpp @@ -26,7 +26,7 @@ #include #include #ifndef SORTIX_KERNEL -#include +#include #endif namespace Maxsi diff --git a/libmaxsi/mkdir.cpp b/libmaxsi/mkdir.cpp index c56eaff9..25be6157 100644 --- a/libmaxsi/mkdir.cpp +++ b/libmaxsi/mkdir.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL2(int, SysMkDir, SYSCALL_MKDIR, const char*, mode_t); @@ -33,5 +31,3 @@ extern "C" int mkdir(const char* pathname, mode_t mode) { return SysMkDir(pathname, mode); } - -} // namespace Maxsi diff --git a/libmaxsi/open.cpp b/libmaxsi/open.cpp index 6b224e9c..930a5b76 100644 --- a/libmaxsi/open.cpp +++ b/libmaxsi/open.cpp @@ -22,17 +22,21 @@ *******************************************************************************/ -#include -#include +#include #include - -namespace Maxsi { +#include DEFN_SYSCALL3(int, SysOpen, SYSCALL_OPEN, const char*, int, mode_t); -extern "C" int open(const char* path, int flags, mode_t mode) +extern "C" int open(const char* path, int flags, ...) { + int mode = 0; + if ( flags & O_CREAT ) + { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } return SysOpen(path, flags, mode); } - -} // namespace Maxsi diff --git a/libmaxsi/pipe.cpp b/libmaxsi/pipe.cpp index 80733e14..deeaf56f 100644 --- a/libmaxsi/pipe.cpp +++ b/libmaxsi/pipe.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL1(int, SysPipe, SYSCALL_PIPE, int*); extern "C" int pipe(int pipefd[2]) { return SysPipe(pipefd); } - -} // namespace Maxsi diff --git a/libmaxsi/process.cpp b/libmaxsi/process.cpp index 7fc90e32..7d8c49bb 100644 --- a/libmaxsi/process.cpp +++ b/libmaxsi/process.cpp @@ -24,8 +24,8 @@ #define _WANT_ENVIRON #include -#include #include +#include #include #include #include diff --git a/libmaxsi/read.cpp b/libmaxsi/read.cpp index a138282d..0cba59ba 100644 --- a/libmaxsi/read.cpp +++ b/libmaxsi/read.cpp @@ -22,13 +22,10 @@ *******************************************************************************/ -#include -#include +#include #include #include -namespace Maxsi { - DEFN_SYSCALL3(ssize_t, SysRead, SYSCALL_READ, int, void*, size_t); extern "C" ssize_t read(int fd, void* buf, size_t count) @@ -44,5 +41,3 @@ extern "C" ssize_t pread(int, void*, size_t, off_t) errno = ENOSYS; return -1; } - -} // namespace Maxsi diff --git a/libmaxsi/readdirents.cpp b/libmaxsi/readdirents.cpp index 6ef29882..bb6c1118 100644 --- a/libmaxsi/readdirents.cpp +++ b/libmaxsi/readdirents.cpp @@ -22,11 +22,8 @@ *******************************************************************************/ -#include -#include #include - -namespace Maxsi { +#include DEFN_SYSCALL3(int, SysReadDirEnts, SYSCALL_READDIRENTS, int, struct sortix_dirent*, size_t); @@ -34,5 +31,3 @@ extern "C" int readdirents(int fd, struct sortix_dirent* dirent, size_t size) { return SysReadDirEnts(fd, dirent, size); } - -} // namespace Maxsi diff --git a/libmaxsi/rmdir.cpp b/libmaxsi/rmdir.cpp index a9cbdc63..90163185 100644 --- a/libmaxsi/rmdir.cpp +++ b/libmaxsi/rmdir.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL1(int, SysRmDir, SYSCALL_RMDIR, const char*); @@ -33,5 +31,3 @@ extern "C" int rmdir(const char* pathname) { return SysRmDir(pathname); } - -} // namespace Maxsi diff --git a/libmaxsi/settermmode.cpp b/libmaxsi/settermmode.cpp index 580f1f13..80b2d2e0 100644 --- a/libmaxsi/settermmode.cpp +++ b/libmaxsi/settermmode.cpp @@ -22,17 +22,12 @@ *******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL2(int, sys_settermmode, SYSCALL_SETTERMMODE, int, unsigned); extern "C" int settermmode(int fd, unsigned mode) { return sys_settermmode(fd, mode); } - -} // namespace Maxsi diff --git a/libmaxsi/signal.cpp b/libmaxsi/signal.cpp index 2aa7598e..859b332b 100644 --- a/libmaxsi/signal.cpp +++ b/libmaxsi/signal.cpp @@ -24,8 +24,8 @@ #include #include -#include #include +#include #include #include #include diff --git a/libmaxsi/sortix-sound.cpp b/libmaxsi/sortix-sound.cpp index d8716bbe..1f6c8bae 100644 --- a/libmaxsi/sortix-sound.cpp +++ b/libmaxsi/sortix-sound.cpp @@ -24,8 +24,8 @@ ******************************************************************************/ #include -#include #include +#include namespace System { diff --git a/libmaxsi/stat.cpp b/libmaxsi/stat.cpp index 67ba8b03..a372f244 100644 --- a/libmaxsi/stat.cpp +++ b/libmaxsi/stat.cpp @@ -22,11 +22,8 @@ *******************************************************************************/ -#include -#include #include - -namespace Maxsi { +#include DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*); @@ -40,5 +37,3 @@ extern "C" int lstat(const char* path, struct stat* st) { return SysStat(path, st); } - -} // namespace Maxsi diff --git a/libmaxsi/thread.cpp b/libmaxsi/thread.cpp index f70c77ac..68e2c519 100644 --- a/libmaxsi/thread.cpp +++ b/libmaxsi/thread.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #ifdef SORTIX_KERNEL diff --git a/libmaxsi/time.cpp b/libmaxsi/time.cpp index 94e82b0f..815adf26 100644 --- a/libmaxsi/time.cpp +++ b/libmaxsi/time.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/libmaxsi/truncate.cpp b/libmaxsi/truncate.cpp index 11dadcd7..7fd4fb84 100644 --- a/libmaxsi/truncate.cpp +++ b/libmaxsi/truncate.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL2(int, SysTruncate, SYSCALL_TRUNCATE, const char*, off_t); @@ -33,5 +31,3 @@ extern "C" int truncate(const char* pathname, off_t length) { return SysTruncate(pathname, length); } - -} // namespace Maxsi diff --git a/libmaxsi/umask.cpp b/libmaxsi/umask.cpp index 2d87a5e8..d9c401ab 100644 --- a/libmaxsi/umask.cpp +++ b/libmaxsi/umask.cpp @@ -22,18 +22,13 @@ *******************************************************************************/ -#include -#include -#include #include +#include +#include #include -namespace Maxsi { - // TODO: Implement this in the kernel. extern "C" mode_t umask(mode_t mask) { return 0; } - -} // namespace Maxsi diff --git a/libmaxsi/unlink.cpp b/libmaxsi/unlink.cpp index 3e911fb7..17667064 100644 --- a/libmaxsi/unlink.cpp +++ b/libmaxsi/unlink.cpp @@ -22,10 +22,8 @@ *******************************************************************************/ -#include -#include - -namespace Maxsi { +#include +#include DEFN_SYSCALL1(int, SysUnlink, SYSCALL_UNLINK, const char*); @@ -33,5 +31,3 @@ extern "C" int unlink(const char* pathname) { return SysUnlink(pathname); } - -} // namespace Maxsi diff --git a/libmaxsi/winsize.cpp b/libmaxsi/winsize.cpp index 63379e85..3a5081ad 100644 --- a/libmaxsi/winsize.cpp +++ b/libmaxsi/winsize.cpp @@ -22,17 +22,12 @@ ******************************************************************************/ -#include -#include +#include #include -namespace Maxsi { - DEFN_SYSCALL2(int, SysTCGetWinSize, SYSCALL_TCGETWINSIZE, int, struct winsize*); extern "C" int tcgetwinsize(int fd, struct winsize* ws) { return SysTCGetWinSize(fd, ws); } - -} // namespace Maxsi diff --git a/libmaxsi/write.cpp b/libmaxsi/write.cpp index c46c3f71..740e187a 100644 --- a/libmaxsi/write.cpp +++ b/libmaxsi/write.cpp @@ -22,13 +22,10 @@ *******************************************************************************/ -#include -#include +#include #include #include -namespace Maxsi { - DEFN_SYSCALL3(ssize_t, SysWrite, SYSCALL_WRITE, int, const void*, size_t); extern "C" ssize_t write(int fd, const void* buf, size_t count) @@ -44,5 +41,3 @@ extern "C" ssize_t pwrite(int, const void*, size_t, off_t) errno = ENOSYS; return -1; } - -} // namespace Maxsi