lib: General Linux RISC-V64 syscall support.

* include/linux/riscv32/kernel-stat.h,
include/linux/riscv64/kernel-stat.h: New files.
* include/fcntl.h (AT_FDCWD, AT_SYMLINK_NOFOLLOW, AT_REMOVEDIR): Add
necessary constants.
* include/stdint.h: Integer size defines for RISC-V.
* include/sys/stat.h: "stat" struct for RISC-V.
* lib/linux/_open3.c (_open3)[!SYS_open]: Use SYS_openat.
* lib/linux/access.c (access)[!SYS_access]: Use SYS_faccessat.
* lib/linux/chmod.c (chmod)[!SYS_chmod]: Use SYS_fchmodat.
* lib/linux/dup2.c (dup2)[!SYS_dup2]: Use if SYS_dup3.
* lib/linux/fork.c (fork)[!SYS_fork]: Use SYS_clone.
* lib/linux/getdents.c (getdents)[!SYS_getdents]: Use SYS_getdents64.
* lib/linux/link.c (link)[!SYS_link]: Use SYS_linkat.
* lib/linux/lstat.c (lstat)[!SYS_lstat]: Use SYS_newfstatat.
* lib/linux/mkdir.c (mkdir)[!SYS_mkdir]: Use SYS_mkdirat.
* lib/linux/mknod.c (mknod)[!SYS_mknod]: Use SYS_mknodat.
* lib/linux/pipe.c (pipe)[!SYS_pipe]: Use SYS_pipe2.
* lib/linux/readlink.c (readlink)[!SYS_readlinkat]: Use SYS_readlinkat.
* lib/linux/rename.c (rename)[!SYS_rename]: Use SYS_renameat2.
* lib/linux/rmdir.c (rmdir)[!SYS_rmdir]: Use SYS_unlinkat.
* lib/linux/signal.c (_restorer_for_siginfo): Remove unused function
that causes compilation issue.
* lib/linux/stat.c (stat)[!SYS_stat]: Use SYS_newfstatat.
* lib/linux/symlink.c (symlink)[!SYS_symlinkat]: Use SYS_symlink.
* lib/linux/unlink.c (unlink)[!SYS_unlink]: Use SYS_unlinkat.
This commit is contained in:
W. J. van der Laan 2021-04-04 07:24:37 +00:00 committed by Janneke Nieuwenhuizen
parent 9ce2b56743
commit f24b1e467c
23 changed files with 240 additions and 7 deletions

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2017 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
* Copyright © 2023 Emily Trau <emily@downunderctf.com>
*
* 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

View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -0,0 +1,46 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#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

View File

@ -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

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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)
{

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -21,11 +22,18 @@
#include <mes/lib.h>
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -22,11 +23,18 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <sys/stat.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,9 +21,17 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <signal.h>
#include <unistd.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* 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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,9 +21,16 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,10 +21,18 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
#include <sys/stat.h>
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;
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,10 +21,17 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
#include <sys/stat.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -21,9 +22,16 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <sys/stat.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -21,9 +22,16 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <unistd.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,10 +21,17 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
#include <sys/stat.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -21,9 +22,16 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <unistd.h>
#include <fcntl.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,9 +21,16 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
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
}

View File

@ -23,8 +23,7 @@
#include <unistd.h>
#include <signal.h>
#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
}

View File

@ -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);

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,10 +21,17 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
#include <sys/stat.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -20,10 +21,17 @@
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
#include <unistd.h>
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
}

View File

@ -1,6 +1,7 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019,2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
* Copyright © 2021 W. J. van der Laan <laanwj@protonmail.com>
*
* This file is part of GNU Mes.
*
@ -21,10 +22,17 @@
#include <mes/lib.h>
#include <linux/syscall.h>
#include <arch/syscall.h>
#include <fcntl.h>
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
}