2018-06-03 16:54:26 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes --- Maxwell Equations of Software
|
2018-06-03 16:54:26 +00:00
|
|
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* This file is part of GNU Mes.
|
2018-06-03 16:54:26 +00:00
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is free software; you can redistribute it and/or modify it
|
2018-06-03 16:54:26 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2018-07-22 12:24:36 +00:00
|
|
|
* GNU Mes is distributed in the hope that it will be useful, but
|
2018-06-03 16:54:26 +00:00
|
|
|
* 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
|
2018-07-22 12:24:36 +00:00
|
|
|
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
|
2018-06-03 16:54:26 +00:00
|
|
|
*/
|
|
|
|
|
2018-07-21 09:15:48 +00:00
|
|
|
#include <sys/resource.h>
|
2018-08-26 22:34:13 +00:00
|
|
|
#include <time.h>
|
2018-08-26 20:41:52 +00:00
|
|
|
|
2018-06-03 16:54:26 +00:00
|
|
|
int
|
|
|
|
link (char const *old_name, char const *new_name)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_link, (long)old_name, (long)new_name);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-06 20:14:35 +00:00
|
|
|
pid_t
|
|
|
|
getpid ()
|
|
|
|
{
|
|
|
|
return _sys_call (SYS_getpid);
|
|
|
|
}
|
|
|
|
|
2018-06-07 05:19:01 +00:00
|
|
|
uid_t
|
|
|
|
getuid ()
|
|
|
|
{
|
|
|
|
return _sys_call (SYS_getuid);
|
|
|
|
}
|
|
|
|
|
2018-06-03 16:54:26 +00:00
|
|
|
int
|
|
|
|
kill (pid_t pid, int signum)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_kill, (long)pid, (long)signum);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rename (char const *old_name, char const *new_name)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_rename, (long)old_name, (long)new_name);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
mkdir (char const *file_name, mode_t mode)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_mkdir, (long)file_name, (long)mode);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
dup (int old)
|
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
return _sys_call1 (SYS_dup, (int)old);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 05:19:01 +00:00
|
|
|
gid_t
|
|
|
|
getgid ()
|
|
|
|
{
|
|
|
|
return _sys_call (SYS_getgid);
|
|
|
|
}
|
|
|
|
|
2018-08-15 16:26:55 +00:00
|
|
|
// long _sys_call (long sys_call);
|
|
|
|
// long _sys_call4 (long sys_call, long one, long two, long three, long four);
|
|
|
|
|
|
|
|
#define SA_SIGINFO 4
|
|
|
|
#define SA_RESTORER 0x04000000
|
|
|
|
|
|
|
|
#define SYS_rt_sigreturn 15
|
|
|
|
|
|
|
|
void
|
|
|
|
_restorer (void)
|
2018-06-06 20:14:35 +00:00
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
_sys_call (SYS_rt_sigreturn);
|
2018-06-06 20:14:35 +00:00
|
|
|
}
|
2018-08-15 16:26:55 +00:00
|
|
|
|
|
|
|
# define __sigmask(sig) \
|
|
|
|
(((unsigned long int) 1) << (((sig) - 1) % (8 * sizeof (unsigned long int))))
|
|
|
|
|
2018-08-11 17:04:01 +00:00
|
|
|
sighandler_t
|
|
|
|
signal (int signum, sighandler_t action)
|
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
#if __i386__
|
|
|
|
return _sys_call2 (SYS_signal, signum, action);
|
2018-08-11 17:04:01 +00:00
|
|
|
#else
|
2018-08-15 16:26:55 +00:00
|
|
|
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;
|
2018-08-11 17:04:01 +00:00
|
|
|
#endif
|
2018-08-15 16:26:55 +00:00
|
|
|
}
|
2018-06-06 20:14:35 +00:00
|
|
|
|
2018-06-07 06:02:32 +00:00
|
|
|
int
|
|
|
|
fcntl (int filedes, int command, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
va_start (ap, command);
|
|
|
|
int data = va_arg (ap, int);
|
2018-08-15 16:26:55 +00:00
|
|
|
int r = _sys_call3 (SYS_fcntl, (int)filedes, (int)command, (int)data);
|
2018-06-07 06:02:32 +00:00
|
|
|
va_end (ap);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-06-03 16:54:26 +00:00
|
|
|
int
|
|
|
|
pipe (int filedes[2])
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call1 (SYS_pipe, (long)filedes);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 06:02:32 +00:00
|
|
|
int
|
|
|
|
dup2 (int old, int new)
|
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
return _sys_call2 (SYS_dup2, (int)old, (int)new);
|
2018-06-07 06:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
getrusage (int processes, struct rusage *rusage)
|
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
return _sys_call2 (SYS_getrusage, (int)processes, (long)rusage);
|
2018-06-07 06:02:32 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 16:54:26 +00:00
|
|
|
int
|
|
|
|
lstat (char const *file_name, struct stat *statbuf)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_lstat, (long)file_name, (long)statbuf);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nanosleep (const struct timespec *requested_time,
|
|
|
|
struct timespec *remaining)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call2 (SYS_nanosleep, (long)requested_time, (long)remaining);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
|
|
|
|
2018-06-07 16:03:51 +00:00
|
|
|
int
|
|
|
|
setitimer (int which, struct itimerval const *new,
|
|
|
|
struct itimerval *old)
|
|
|
|
{
|
2018-08-11 09:42:30 +00:00
|
|
|
return _sys_call3 (SYS_setitimer, (long)which, (long)new, (long)old);
|
2018-06-07 16:03:51 +00:00
|
|
|
}
|
|
|
|
|
2018-06-03 16:54:26 +00:00
|
|
|
int
|
2018-08-15 16:26:55 +00:00
|
|
|
fstat (int filedes, struct stat *statbuf)
|
2018-06-03 16:54:26 +00:00
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
return _sys_call2 (SYS_fstat, (int)filedes, (long)statbuf);
|
2018-06-03 16:54:26 +00:00
|
|
|
}
|
2018-08-26 16:34:53 +00:00
|
|
|
|
|
|
|
int
|
2018-08-15 16:26:55 +00:00
|
|
|
getdents (int filedes, char *buffer, size_t nbytes)
|
2018-08-26 16:34:53 +00:00
|
|
|
{
|
2018-08-15 16:26:55 +00:00
|
|
|
return _sys_call3 (SYS_getdents, (int)filedes, (long)buffer, (long)nbytes);
|
2018-08-26 16:34:53 +00:00
|
|
|
}
|
2018-08-26 22:34:13 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
chdir (char const *file_name)
|
|
|
|
{
|
|
|
|
return _sys_call1 (SYS_chdir, (long)file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
clock_gettime (clockid_t clk_id, struct timespec *tp)
|
|
|
|
{
|
|
|
|
return _sys_call2 (SYS_clock_gettime, (long)clk_id, (long)tp);
|
|
|
|
}
|