diff --git a/include/fcntl.h b/include/fcntl.h index 09877471..ff66fa40 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * Copyright © 2023 Emily Trau * * This file is part of GNU Mes. @@ -48,6 +49,10 @@ #define O_TMPFILE 0x410000 #endif +#define AT_FDCWD -100 +#define AT_SYMLINK_NOFOLLOW 0x100 +#define AT_REMOVEDIR 0x200 + #elif __GNU__ #define O_RDONLY 1 #define O_WRONLY 2 diff --git a/include/linux/riscv32/kernel-stat.h b/include/linux/riscv32/kernel-stat.h new file mode 100644 index 00000000..9ac404f4 --- /dev/null +++ b/include/linux/riscv32/kernel-stat.h @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2021 W. J. van der Laan + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ +#ifndef __MES_LINUX_RISCV32_KERNEL_STAT_H +#define __MES_LINUX_RISCV32_KERNEL_STAT_H 1 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned long st_rdev; + long st_size; /* Linux: unsigned long; glibc: off_t (i.e. signed) */ + unsigned long st_blksize; + unsigned long st_blocks; + time_t st_atime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_atime_usec; + time_t st_mtime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_mtime_usec; + time_t st_ctime; /* Linux: unsigned long; glibc: time_t */ + unsigned long st_ctime_usec; + unsigned long __foo0; + unsigned long __foo1; +}; + +#endif // __MES_LINUX_RISCV32_KERNEL_STAT_H diff --git a/include/linux/riscv64/kernel-stat.h b/include/linux/riscv64/kernel-stat.h new file mode 100644 index 00000000..9519ef39 --- /dev/null +++ b/include/linux/riscv64/kernel-stat.h @@ -0,0 +1,46 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2021 W. J. van der Laan + * + * This file is part of GNU Mes. + * + * GNU Mes is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or (at + * your option) any later version. + * + * GNU Mes 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Mes. If not, see . + */ +#ifndef __MES_LINUX_RISCV64_KERNEL_STAT_H +#define __MES_LINUX_RISCV64_KERNEL_STAT_H 1 + +// *INDENT-OFF* +struct stat +{ + unsigned long st_dev; + unsigned long st_ino; + unsigned int st_mode; + unsigned int st_nlink; + unsigned int st_uid; + unsigned int st_gid; + unsigned long st_rdev; + long st_size; + unsigned long st_blksize; + unsigned long st_blocks; + time_t st_atime; + unsigned long st_atime_usec; + time_t st_mtime; + unsigned long st_mtime_usec; + time_t st_ctime; + unsigned long st_ctime_usec; + unsigned long __foo0; + unsigned long __foo1; +}; + +#endif // __MES_LINUX_RISCV64_KERNEL_STAT_H diff --git a/include/stdint.h b/include/stdint.h index 0f85d6b0..080d1029 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -87,7 +87,7 @@ typedef unsigned uintmax_t; #define INT_MIN -2147483648 #define INT_MAX 2147483647 -#if __i386__ || __arm__ +#if __i386__ || __arm__ || __riscv_xlen == 32 #define LONG_MIN INT_MIN #define LONG_MAX INT_MAX #define UINT_MAX UINT32_MAX @@ -95,7 +95,7 @@ typedef unsigned uintmax_t; #define LLONG_MIN INT64_MIN #define LLONG_MAX INT64_MAX #define SIZE_MAX UINT32_MAX -#elif __x86_64__ +#elif __x86_64__ || __riscv_xlen == 64 #define LONG_MIN INT64_MIN #define LONG_MAX INT64_MAX #define UINT_MAX UINT32_MAX diff --git a/lib/linux/_open3.c b/lib/linux/_open3.c index b67da57a..26e5dc89 100644 --- a/lib/linux/_open3.c +++ b/lib/linux/_open3.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -27,7 +28,13 @@ int _open3 (char const *file_name, int flags, int mask) { long long_file_name = cast_charp_to_long (file_name); +#if defined (SYS_open) int r = _sys_call3 (SYS_open, long_file_name, flags, mask); +#elif defined (SYS_openat) + int r = _sys_call4 (SYS_openat, AT_FDCWD, long_file_name, flags, mask); +#else +#error No usable open syscall +#endif __ungetc_init (); if (r > 2) { diff --git a/lib/linux/access.c b/lib/linux/access.c index ceb18595..84e71139 100644 --- a/lib/linux/access.c +++ b/lib/linux/access.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -21,11 +22,18 @@ #include #include #include +#include int access (char const *file_name, int how) { long long_file_name = cast_charp_to_long (file_name); long long_how = cast_int_to_long (how); +#if defined (SYS_access) return _sys_call2 (SYS_access, long_file_name, long_how); +#elif defined (SYS_faccessat) + return _sys_call3 (SYS_faccessat, AT_FDCWD, long_file_name, long_how); +#else +#error No usable access sysall +#endif } diff --git a/lib/linux/chmod.c b/lib/linux/chmod.c index a6d74a43..615d13c5 100644 --- a/lib/linux/chmod.c +++ b/lib/linux/chmod.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -22,11 +23,18 @@ #include #include #include +#include int chmod (char const *file_name, mode_t mask) { long long_file_name = cast_charp_to_long (file_name); long long_mask = cast_int_to_long (mask); +#if defined (SYS_chmod) return _sys_call2 (SYS_chmod, long_file_name, long_mask); +#elif defined (SYS_fchmodat) + return _sys_call3 (SYS_fchmodat, AT_FDCWD, long_file_name, long_mask); +#else +#error No usable chmod syscall +#endif } diff --git a/lib/linux/dup2.c b/lib/linux/dup2.c index 9a0752e3..70a62d08 100644 --- a/lib/linux/dup2.c +++ b/lib/linux/dup2.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -26,5 +27,11 @@ dup2 (int old, int new) { long long_old = old; long long_new = new; +#if defined (SYS_dup2) return _sys_call2 (SYS_dup2, long_old, long_new); +#elif defined (SYS_dup3) + return _sys_call3 (SYS_dup3, long_old, long_new, 0); +#else +#error No usable dup2 syscall +#endif } diff --git a/lib/linux/fork.c b/lib/linux/fork.c index d07050bf..bb2c29f2 100644 --- a/lib/linux/fork.c +++ b/lib/linux/fork.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,9 +21,17 @@ #include #include +#include +#include int fork () { +#if defined (SYS_fork) return _sys_call (SYS_fork); +#elif defined (SYS_clone) + return _sys_call4 (SYS_clone, SIGCHLD, 0, NULL, 0); +#else +#error No usable clone syscall found +#endif } diff --git a/lib/linux/getdents.c b/lib/linux/getdents.c index 03717710..16563b42 100644 --- a/lib/linux/getdents.c +++ b/lib/linux/getdents.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -25,5 +26,11 @@ int getdents (int filedes, char *buffer, size_t nbytes) { +#if defined (SYS_getdents) return _sys_call3 (SYS_getdents, (int) filedes, (long) buffer, (long) nbytes); +#elif defined (SYS_getdents64) + return _sys_call3 (SYS_getdents64, (int) filedes, (long) buffer, (long) nbytes); +#else +#error No usable getdents syscall +#endif } diff --git a/lib/linux/link.c b/lib/linux/link.c index e2d66912..b89b181f 100644 --- a/lib/linux/link.c +++ b/lib/linux/link.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,9 +21,16 @@ #include #include +#include int link (char const *old_name, char const *new_name) { +#if defined (SYS_link) return _sys_call2 (SYS_link, (long) old_name, (long) new_name); +#elif defined (SYS_linkat) + return _sys_call4 (SYS_linkat, AT_FDCWD, (long) old_name, AT_FDCWD, (long) new_name); +#else +#error No usable link syscall +#endif } diff --git a/lib/linux/lstat.c b/lib/linux/lstat.c index feebc6cb..0cdaa037 100644 --- a/lib/linux/lstat.c +++ b/lib/linux/lstat.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,10 +21,18 @@ #include #include +#include #include int lstat (char const *file_name, struct stat *statbuf) { +#if defined (SYS_lstat) return _sys_call2 (SYS_lstat, (long) file_name, (long) statbuf); +#elif defined (SYS_newfstatat) + return _sys_call4 (SYS_newfstatat, AT_FDCWD, (long) file_name, (long) statbuf, 0); +#else +#error No usable stat syscall +#endif + return 0; } diff --git a/lib/linux/mkdir.c b/lib/linux/mkdir.c index 59319329..e1ad59b4 100644 --- a/lib/linux/mkdir.c +++ b/lib/linux/mkdir.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,10 +21,17 @@ #include #include +#include #include int mkdir (char const *file_name, mode_t mode) { +#if defined (SYS_mkdir) return _sys_call2 (SYS_mkdir, (long) file_name, (long) mode); +#elif defined (SYS_mkdirat) + return _sys_call3 (SYS_mkdirat, AT_FDCWD, (long) file_name, (long) mode); +#else +#error No usable mkdir syscall +#endif } diff --git a/lib/linux/mknod.c b/lib/linux/mknod.c index 24a9b0c7..a410ca67 100644 --- a/lib/linux/mknod.c +++ b/lib/linux/mknod.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -21,9 +22,16 @@ #include #include #include +#include int mknod (char const *file_name, mode_t mode, dev_t dev) { +#if defined (SYS_mknod) return _sys_call3 (SYS_mknod, (long) file_name, (long) mode, (long) dev); +#elif defined (SYS_mknodat) + return _sys_call4 (SYS_mknodat, AT_FDCWD, (long) file_name, (long) mode, (long) dev); +#else +#error No usable mknod syscall +#endif } diff --git a/lib/linux/pipe.c b/lib/linux/pipe.c index f6b3689a..ac916105 100644 --- a/lib/linux/pipe.c +++ b/lib/linux/pipe.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -21,9 +22,16 @@ #include #include #include +#include int pipe (int filedes[2]) { +#if defined (SYS_pipe) return _sys_call1 (SYS_pipe, (long) filedes); +#elif defined (SYS_pipe2) + return _sys_call2 (SYS_pipe2, (long) filedes, 0); +#else +#error No usable pipe syscall found +#endif } diff --git a/lib/linux/readlink.c b/lib/linux/readlink.c index 96443273..61125290 100644 --- a/lib/linux/readlink.c +++ b/lib/linux/readlink.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,10 +21,17 @@ #include #include +#include #include ssize_t readlink (char const *file_name, char *buffer, size_t size) { +#if defined (SYS_readlink) return _sys_call3 (SYS_readlink, (long) file_name, (long) buffer, (long) size); +#elif defined (SYS_readlinkat) + return _sys_call4 (SYS_readlinkat, AT_FDCWD, (long) file_name, (long) buffer, (long) size); +#else +#error No usable readlink syscall +#endif } diff --git a/lib/linux/rename.c b/lib/linux/rename.c index 762c3093..7fb4191e 100644 --- a/lib/linux/rename.c +++ b/lib/linux/rename.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -21,9 +22,16 @@ #include #include #include +#include int rename (char const *old_name, char const *new_name) { +#if defined (SYS_rename) return _sys_call2 (SYS_rename, (long) old_name, (long) new_name); +#elif defined (SYS_renameat2) + return _sys_call5 (SYS_renameat2, AT_FDCWD, (long) old_name, AT_FDCWD, (long) new_name, 0); +#else +#error No usable rename syscall +#endif } diff --git a/lib/linux/rmdir.c b/lib/linux/rmdir.c index 5d4c0f49..9eb75902 100644 --- a/lib/linux/rmdir.c +++ b/lib/linux/rmdir.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,9 +21,16 @@ #include #include +#include int rmdir (char const *file_name) { +#if defined (SYS_rmdir) return _sys_call1 (SYS_rmdir, (long) file_name); +#elif defined (SYS_unlinkat) + return _sys_call3 (SYS_unlinkat, AT_FDCWD, (long) file_name, AT_REMOVEDIR); +#else +#error No usable rmdir syscall +#endif } diff --git a/lib/linux/signal.c b/lib/linux/signal.c index 1950f767..1289ce54 100644 --- a/lib/linux/signal.c +++ b/lib/linux/signal.c @@ -23,8 +23,7 @@ #include #include -#if __i386__ -#else +#if defined (SYS_rt_sigreturn) void _restorer_for_siginfo (void) { @@ -36,8 +35,8 @@ sighandler_t signal (int signum, sighandler_t action) { #if __i386__ - return (sighandler_t) _sys_call2 (SYS_signal, signum, (long) action); -#else + return _sys_call2 (SYS_signal, signum, (long) action); +#elif defined (SYS_rt_sigaction) static struct sigaction setup_action = { 0 }; static struct sigaction old = { 0 }; unsigned short bitindex; @@ -68,5 +67,7 @@ signal (int signum, sighandler_t action) if (r) return 0; return old.sa_handler; +#else +#error no signal #endif } diff --git a/lib/linux/sigprogmask.c b/lib/linux/sigprogmask.c index 4b0bb8eb..562b84a1 100644 --- a/lib/linux/sigprogmask.c +++ b/lib/linux/sigprogmask.c @@ -26,7 +26,7 @@ int sigprocmask (int how, sigset_t const *set, sigset_t * oldset) { -#if __i386__ +#if SYS_sigprocmask return _sys_call3 (SYS_sigprocmask, (long) how, (long) set, (long) oldset); #else return _sys_call3 (SYS_rt_sigprocmask, (long) how, (long) set, (long) oldset); diff --git a/lib/linux/stat.c b/lib/linux/stat.c index df0022aa..565d40f9 100644 --- a/lib/linux/stat.c +++ b/lib/linux/stat.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,10 +21,17 @@ #include #include +#include #include int stat (char const *file_name, struct stat *statbuf) { +#if defined (SYS_stat) return _sys_call2 (SYS_stat, (long) file_name, (long) statbuf); +#elif defined (SYS_newfstatat) + return _sys_call4 (SYS_newfstatat, AT_FDCWD, (long) file_name, (long) statbuf, AT_SYMLINK_NOFOLLOW); +#else +#error No usable stat syscall +#endif } diff --git a/lib/linux/symlink.c b/lib/linux/symlink.c index 4e4084d2..e521791d 100644 --- a/lib/linux/symlink.c +++ b/lib/linux/symlink.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -20,10 +21,17 @@ #include #include +#include #include int symlink (char const *old_name, char const *new_name) { +#if defined (SYS_symlink) return _sys_call2 (SYS_symlink, (long) old_name, (long) new_name); +#elif defined (SYS_symlinkat) + return _sys_call3 (SYS_symlinkat, (long) old_name, AT_FDCWD, (long) new_name); +#else +#error No usable symlink syscall +#endif } diff --git a/lib/linux/unlink.c b/lib/linux/unlink.c index 9f204b5f..5699c004 100644 --- a/lib/linux/unlink.c +++ b/lib/linux/unlink.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * GNU Mes --- Maxwell Equations of Software * Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen + * Copyright © 2021 W. J. van der Laan * * This file is part of GNU Mes. * @@ -21,10 +22,17 @@ #include #include #include +#include int unlink (char const *file_name) { long long_file_name = cast_charp_to_long (file_name); +#if defined (SYS_unlink) return _sys_call1 (SYS_unlink, long_file_name); +#elif defined (SYS_unlinkat) + return _sys_call3 (SYS_unlinkat, AT_FDCWD, long_file_name, 0); +#else +#error No usable unlink syscall +#endif }