From 3a12301a25559aafa8497286ff067a292f638ef9 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 12 May 2019 00:33:33 +0200 Subject: [PATCH] mescc: Mes C Library: Explode linux/gnu.c. * lib/linux/chdir.c: New file. * lib/linux/fcntl.c: New file. * lib/linux/fstat.c: New file. * lib/linux/getdents.c: New file. * lib/linux/getegid.c: New file. * lib/linux/geteuid.c: New file. * lib/linux/getgid.c: New file. * lib/linux/getpid.c: New file. * lib/linux/getppid.c: New file. * lib/linux/getrusage.c: New file. * lib/linux/getuid.c: New file. * lib/linux/kill.c: New file. * lib/linux/link.c: New file. * lib/linux/lstat.c: New file. * lib/linux/mkdir.c: New file. * lib/linux/nanosleep.c: New file. * lib/linux/pipe.c: New file. * lib/linux/rename.c: New file. * lib/linux/setgid.c: New file. * lib/linux/settimer.c: New file. * lib/linux/setuid.c: New file. * lib/linux/signal.c: New file. * lib/linux/sigprogmask.c: New file. * lib/linux/gnu.c: Include them. (chdir, fcntl, fstat, getdents, getegid, geteuid, getgid, getpid, getppid, getrusage, getuid, kill, link, lstat, mkdir, munmap, nanosleep, pipe, rename, setgid, settimer, setuid, signal, sigprogmask): Remove. --- lib/libc+gnu.c | 2 +- lib/linux/chdir.c | 25 +++++ lib/linux/fcntl.c | 30 ++++++ lib/linux/fstat.c | 25 +++++ lib/linux/getdents.c | 25 +++++ lib/linux/getegid.c | 25 +++++ lib/linux/geteuid.c | 25 +++++ lib/linux/getgid.c | 25 +++++ lib/linux/getpid.c | 25 +++++ lib/linux/getppid.c | 25 +++++ lib/linux/getrusage.c | 25 +++++ lib/linux/getuid.c | 25 +++++ lib/linux/gnu.c | 202 +++++----------------------------------- lib/linux/kill.c | 25 +++++ lib/linux/link.c | 25 +++++ lib/linux/lstat.c | 25 +++++ lib/linux/mkdir.c | 25 +++++ lib/linux/nanosleep.c | 26 ++++++ lib/linux/pipe.c | 25 +++++ lib/linux/rename.c | 25 +++++ lib/linux/setgid.c | 25 +++++ lib/linux/settimer.c | 26 ++++++ lib/linux/setuid.c | 25 +++++ lib/linux/signal.c | 51 ++++++++++ lib/linux/sigprogmask.c | 29 ++++++ 25 files changed, 636 insertions(+), 180 deletions(-) create mode 100644 lib/linux/chdir.c create mode 100644 lib/linux/fcntl.c create mode 100644 lib/linux/fstat.c create mode 100644 lib/linux/getdents.c create mode 100644 lib/linux/getegid.c create mode 100644 lib/linux/geteuid.c create mode 100644 lib/linux/getgid.c create mode 100644 lib/linux/getpid.c create mode 100644 lib/linux/getppid.c create mode 100644 lib/linux/getrusage.c create mode 100644 lib/linux/getuid.c create mode 100644 lib/linux/kill.c create mode 100644 lib/linux/link.c create mode 100644 lib/linux/lstat.c create mode 100644 lib/linux/mkdir.c create mode 100644 lib/linux/nanosleep.c create mode 100644 lib/linux/pipe.c create mode 100644 lib/linux/rename.c create mode 100644 lib/linux/setgid.c create mode 100644 lib/linux/settimer.c create mode 100644 lib/linux/setuid.c create mode 100644 lib/linux/signal.c create mode 100644 lib/linux/sigprogmask.c diff --git a/lib/libc+gnu.c b/lib/libc+gnu.c index e9095a19..9f533e17 100644 --- a/lib/libc+gnu.c +++ b/lib/libc+gnu.c @@ -21,7 +21,7 @@ #include #if __GNU__ -#include +#error TODO, see wip-hurd #elif __linux__ #include #else diff --git a/lib/linux/chdir.c b/lib/linux/chdir.c new file mode 100644 index 00000000..43d522cf --- /dev/null +++ b/lib/linux/chdir.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +chdir (char const *file_name) +{ + return _sys_call1 (SYS_chdir, (long)file_name); +} diff --git a/lib/linux/fcntl.c b/lib/linux/fcntl.c new file mode 100644 index 00000000..3fb291b7 --- /dev/null +++ b/lib/linux/fcntl.c @@ -0,0 +1,30 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +fcntl (int filedes, int command, ...) +{ + va_list ap; + va_start (ap, command); + int data = va_arg (ap, int); + int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data); + va_end (ap); + return r; +} diff --git a/lib/linux/fstat.c b/lib/linux/fstat.c new file mode 100644 index 00000000..48aabcab --- /dev/null +++ b/lib/linux/fstat.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +fstat (int filedes, struct stat *statbuf) +{ + return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf); +} diff --git a/lib/linux/getdents.c b/lib/linux/getdents.c new file mode 100644 index 00000000..e4b1dda4 --- /dev/null +++ b/lib/linux/getdents.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +getdents (int filedes, char *buffer, size_t nbytes) +{ + return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes); +} diff --git a/lib/linux/getegid.c b/lib/linux/getegid.c new file mode 100644 index 00000000..a813c0a0 --- /dev/null +++ b/lib/linux/getegid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +gid_t +getegid () +{ + return _sys_call (SYS_getegid); +} diff --git a/lib/linux/geteuid.c b/lib/linux/geteuid.c new file mode 100644 index 00000000..e4d198be --- /dev/null +++ b/lib/linux/geteuid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +uid_t +geteuid () +{ + return _sys_call (SYS_geteuid); +} diff --git a/lib/linux/getgid.c b/lib/linux/getgid.c new file mode 100644 index 00000000..c8b61838 --- /dev/null +++ b/lib/linux/getgid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +gid_t +getgid () +{ + return _sys_call (SYS_getgid); +} diff --git a/lib/linux/getpid.c b/lib/linux/getpid.c new file mode 100644 index 00000000..3b30a4ee --- /dev/null +++ b/lib/linux/getpid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +pid_t +getpid () +{ + return _sys_call (SYS_getpid); +} diff --git a/lib/linux/getppid.c b/lib/linux/getppid.c new file mode 100644 index 00000000..82b0febe --- /dev/null +++ b/lib/linux/getppid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +pid_t +getppid () +{ + return _sys_call (SYS_getppid); +} diff --git a/lib/linux/getrusage.c b/lib/linux/getrusage.c new file mode 100644 index 00000000..56aaf208 --- /dev/null +++ b/lib/linux/getrusage.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +getrusage (int processes, struct rusage *rusage) +{ + return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage); +} diff --git a/lib/linux/getuid.c b/lib/linux/getuid.c new file mode 100644 index 00000000..5bbe5ed7 --- /dev/null +++ b/lib/linux/getuid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +uid_t +getuid () +{ + return _sys_call (SYS_getuid); +} diff --git a/lib/linux/gnu.c b/lib/linux/gnu.c index 325eb247..9cd01695 100644 --- a/lib/linux/gnu.c +++ b/lib/linux/gnu.c @@ -18,182 +18,26 @@ * along with GNU Mes. If not, see . */ -#include -#include - -int -link (char const *old_name, char const *new_name) -{ - return _sys_call2 (SYS_link, (long)old_name, (long)new_name); -} - -pid_t -getpid () -{ - return _sys_call (SYS_getpid); -} - -uid_t -getuid () -{ - return _sys_call (SYS_getuid); -} - -int -kill (pid_t pid, int signum) -{ - return _sys_call2 (SYS_kill, (long)pid, (long)signum); -} - -int -rename (char const *old_name, char const *new_name) -{ - return _sys_call2 (SYS_rename, (long)old_name, (long)new_name); -} - -int -mkdir (char const *file_name, mode_t mode) -{ - return _sys_call2 (SYS_mkdir, (long)file_name, (long)mode); -} - -gid_t -getgid () -{ - return _sys_call (SYS_getgid); -} - -#if __x86_64__ -void -_restorer (void) -{ - _sys_call (SYS_rt_sigreturn); -} -#endif - -# define __sigmask(sig) \ - (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int)))) - -sighandler_t -signal (int signum, sighandler_t action) -{ -#if __i386__ - return _sys_call2 (SYS_signal, signum, action); -#else - static struct sigaction setup_action = {-1}; - static struct sigaction old = {0}; - - setup_action.sa_handler = action; - setup_action.sa_restorer = _restorer; - setup_action.sa_mask = __sigmask (signum); - old.sa_handler = SIG_DFL; - setup_action.sa_flags = SA_RESTORER | SA_RESTART; - int r = _sys_call4 (SYS_rt_sigaction, signum, &setup_action, &old, sizeof (sigset_t)); - if (r) - return 0; - return old.sa_handler; -#endif -} - -int -fcntl (int filedes, int command, ...) -{ - va_list ap; - va_start (ap, command); - int data = va_arg (ap, int); - int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data); - va_end (ap); - return r; -} - -int -pipe (int filedes[2]) -{ - return _sys_call1 (SYS_pipe, (long)filedes); -} - -int -getrusage (int processes, struct rusage *rusage) -{ - return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage); -} - -int -lstat (char const *file_name, struct stat *statbuf) -{ - return _sys_call2 (SYS_lstat, (long)file_name, (long)statbuf); -} - -int -nanosleep (const struct timespec *requested_time, - struct timespec *remaining) -{ - return _sys_call2 (SYS_nanosleep, (long)requested_time, (long)remaining); -} - -int -setitimer (int which, struct itimerval const *new, - struct itimerval *old) -{ - return _sys_call3 (SYS_setitimer, (long)which, (long)new, (long)old); -} - -int -fstat (int filedes, struct stat *statbuf) -{ - return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf); -} - -int -getdents (int filedes, char *buffer, size_t nbytes) -{ - return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes); -} - -int -chdir (char const *file_name) -{ - return _sys_call1 (SYS_chdir, (long)file_name); -} - -// bash -uid_t -geteuid () -{ - return _sys_call (SYS_geteuid); -} - -gid_t -getegid () -{ - return _sys_call (SYS_getegid); -} - -pid_t -getppid () -{ - return _sys_call (SYS_getppid); -} - -int -setuid (uid_t newuid) -{ - return _sys_call1 (SYS_setuid, (long)newuid); -} - -int -setgid (gid_t newgid) -{ - return _sys_call1 (SYS_setgid, (long)newgid); -} - -// make+POSIX -int -sigprocmask (int how, sigset_t const *set, sigset_t *oldset) -{ -#if __i386__ - return _sys_call3 (SYS_sigprocmask, (long)how, (long)set, (long)oldset); -#else - return _sys_call3 (SYS_rt_sigprocmask, (long)how, (long)set, (long)oldset); -#endif -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/lib/linux/kill.c b/lib/linux/kill.c new file mode 100644 index 00000000..4aeeeeb3 --- /dev/null +++ b/lib/linux/kill.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +kill (pid_t pid, int signum) +{ + return _sys_call2 (SYS_kill, (long)pid, (long)signum); +} diff --git a/lib/linux/link.c b/lib/linux/link.c new file mode 100644 index 00000000..7d9893b7 --- /dev/null +++ b/lib/linux/link.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +link (char const *old_name, char const *new_name) +{ + return _sys_call2 (SYS_link, (long)old_name, (long)new_name); +} diff --git a/lib/linux/lstat.c b/lib/linux/lstat.c new file mode 100644 index 00000000..c3ca9cbf --- /dev/null +++ b/lib/linux/lstat.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +lstat (char const *file_name, struct stat *statbuf) +{ + return _sys_call2 (SYS_lstat, (long)file_name, (long)statbuf); +} diff --git a/lib/linux/mkdir.c b/lib/linux/mkdir.c new file mode 100644 index 00000000..1f5a1af1 --- /dev/null +++ b/lib/linux/mkdir.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +mkdir (char const *file_name, mode_t mode) +{ + return _sys_call2 (SYS_mkdir, (long)file_name, (long)mode); +} diff --git a/lib/linux/nanosleep.c b/lib/linux/nanosleep.c new file mode 100644 index 00000000..f5c02b45 --- /dev/null +++ b/lib/linux/nanosleep.c @@ -0,0 +1,26 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +nanosleep (const struct timespec *requested_time, + struct timespec *remaining) +{ + return _sys_call2 (SYS_nanosleep, (long)requested_time, (long)remaining); +} diff --git a/lib/linux/pipe.c b/lib/linux/pipe.c new file mode 100644 index 00000000..ba510660 --- /dev/null +++ b/lib/linux/pipe.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +pipe (int filedes[2]) +{ + return _sys_call1 (SYS_pipe, (long)filedes); +} diff --git a/lib/linux/rename.c b/lib/linux/rename.c new file mode 100644 index 00000000..56a8a5b9 --- /dev/null +++ b/lib/linux/rename.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +rename (char const *old_name, char const *new_name) +{ + return _sys_call2 (SYS_rename, (long)old_name, (long)new_name); +} diff --git a/lib/linux/setgid.c b/lib/linux/setgid.c new file mode 100644 index 00000000..9b11e0a9 --- /dev/null +++ b/lib/linux/setgid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +setgid (gid_t newgid) +{ + return _sys_call1 (SYS_setgid, (long)newgid); +} diff --git a/lib/linux/settimer.c b/lib/linux/settimer.c new file mode 100644 index 00000000..28fd3c9e --- /dev/null +++ b/lib/linux/settimer.c @@ -0,0 +1,26 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +setitimer (int which, struct itimerval const *new, + struct itimerval *old) +{ + return _sys_call3 (SYS_setitimer, (long)which, (long)new, (long)old); +} diff --git a/lib/linux/setuid.c b/lib/linux/setuid.c new file mode 100644 index 00000000..33a73303 --- /dev/null +++ b/lib/linux/setuid.c @@ -0,0 +1,25 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +setuid (uid_t newuid) +{ + return _sys_call1 (SYS_setuid, (long)newuid); +} diff --git a/lib/linux/signal.c b/lib/linux/signal.c new file mode 100644 index 00000000..72b66512 --- /dev/null +++ b/lib/linux/signal.c @@ -0,0 +1,51 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#if __x86_64__ +void +_restorer (void) +{ + _sys_call (SYS_rt_sigreturn); +} +#endif + +# define __sigmask(sig) \ + (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int)))) + +sighandler_t +signal (int signum, sighandler_t action) +{ +#if __i386__ + return _sys_call2 (SYS_signal, signum, action); +#else + static struct sigaction setup_action = {-1}; + static struct sigaction old = {0}; + + setup_action.sa_handler = action; + setup_action.sa_restorer = _restorer; + setup_action.sa_mask = __sigmask (signum); + old.sa_handler = SIG_DFL; + setup_action.sa_flags = SA_RESTORER | SA_RESTART; + int r = _sys_call4 (SYS_rt_sigaction, signum, &setup_action, &old, sizeof (sigset_t)); + if (r) + return 0; + return old.sa_handler; +#endif +} diff --git a/lib/linux/sigprogmask.c b/lib/linux/sigprogmask.c new file mode 100644 index 00000000..13ae60cf --- /dev/null +++ b/lib/linux/sigprogmask.c @@ -0,0 +1,29 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2018,2019 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +int +sigprocmask (int how, sigset_t const *set, sigset_t *oldset) +{ +#if __i386__ + return _sys_call3 (SYS_sigprocmask, (long)how, (long)set, (long)oldset); +#else + return _sys_call3 (SYS_rt_sigprocmask, (long)how, (long)set, (long)oldset); +#endif +}