1 /* -*-comment-start: "//";comment-end:""-*-
2 * GNU Mes --- Maxwell Equations of Software
3 * Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
5 * This file is part of GNU Mes.
7 * GNU Mes is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or (at
10 * your option) any later version.
12 * GNU Mes is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/resource.h>
25 link (char const *old_name, char const *new_name)
27 return _sys_call2 (SYS_link, (long)old_name, (long)new_name);
33 return _sys_call (SYS_getpid);
39 return _sys_call (SYS_getuid);
43 kill (pid_t pid, int signum)
45 return _sys_call2 (SYS_kill, (long)pid, (long)signum);
49 rename (char const *old_name, char const *new_name)
51 return _sys_call2 (SYS_rename, (long)old_name, (long)new_name);
55 mkdir (char const *file_name, mode_t mode)
57 return _sys_call2 (SYS_mkdir, (long)file_name, (long)mode);
63 return _sys_call (SYS_getgid);
66 // long _sys_call (long sys_call);
67 // long _sys_call4 (long sys_call, long one, long two, long three, long four);
70 #define SA_RESTORER 0x04000000
72 #define SYS_rt_sigreturn 15
77 _sys_call (SYS_rt_sigreturn);
80 # define __sigmask(sig) \
81 (((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
84 signal (int signum, sighandler_t action)
87 return _sys_call2 (SYS_signal, signum, action);
89 static struct sigaction setup_action = {-1};
90 static struct sigaction old = {0};
92 setup_action.sa_handler = action;
93 setup_action.sa_restorer = _restorer;
94 setup_action.sa_mask = __sigmask (signum);
95 old.sa_handler = SIG_DFL;
96 setup_action.sa_flags = SA_RESTORER | SA_RESTART;
97 int r = _sys_call4 (SYS_rt_sigaction, signum, &setup_action, &old, sizeof (sigset_t));
100 return old.sa_handler;
105 fcntl (int filedes, int command, ...)
108 va_start (ap, command);
109 int data = va_arg (ap, int);
110 int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data);
116 pipe (int filedes[2])
118 return _sys_call1 (SYS_pipe, (long)filedes);
122 getrusage (int processes, struct rusage *rusage)
124 return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage);
128 lstat (char const *file_name, struct stat *statbuf)
130 return _sys_call2 (SYS_lstat, (long)file_name, (long)statbuf);
134 nanosleep (const struct timespec *requested_time,
135 struct timespec *remaining)
137 return _sys_call2 (SYS_nanosleep, (long)requested_time, (long)remaining);
141 setitimer (int which, struct itimerval const *new,
142 struct itimerval *old)
144 return _sys_call3 (SYS_setitimer, (long)which, (long)new, (long)old);
148 fstat (int filedes, struct stat *statbuf)
150 return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf);
154 getdents (int filedes, char *buffer, size_t nbytes)
156 return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes);
160 chdir (char const *file_name)
162 return _sys_call1 (SYS_chdir, (long)file_name);
169 return _sys_call (SYS_geteuid);
175 return _sys_call (SYS_getegid);
179 setuid (uid_t newuid)
181 return _sys_call1 (SYS_setuid, (long)newuid);
185 setgid (gid_t newgid)
187 return _sys_call1 (SYS_setgid, (long)newgid);
192 sigprocmask (int how, sigset_t const *set, sigset_t *oldset)
195 return _sys_call3 (SYS_sigprocmask, (long)how, (long)set, (long)oldset);
197 return _sys_call3 (SYS_rt_sigprocmask, (long)how, (long)set, (long)oldset);