mescc: Support gcc-3.2: Add getpid, signal.
* lib/linux+gnu.c (getpid, signal): New function. * include/signal.h: Declare signal. * include/unistd.h: Declare getpid. * scaffold/tests/95-signal.c: Test it. * build-aux/check-mescc.sh (tests): Run it.
This commit is contained in:
parent
7c4a6a88ed
commit
04302b3fe4
|
@ -139,6 +139,7 @@ t
|
||||||
92-stat
|
92-stat
|
||||||
93-fread-fwrite
|
93-fread-fwrite
|
||||||
94-unsetenv
|
94-unsetenv
|
||||||
|
95-signal
|
||||||
"
|
"
|
||||||
|
|
||||||
# 90: needs GNU, fails for mescc, passes for tcc
|
# 90: needs GNU, fails for mescc, passes for tcc
|
||||||
|
|
127
include/signal.h
127
include/signal.h
|
@ -51,57 +51,57 @@ typedef int sigval_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define NSIG 30
|
#define NSIG 30
|
||||||
#define SIGHUP 1
|
#define SIGHUP 1
|
||||||
#define SIGINT 2
|
#define SIGINT 2
|
||||||
#define SIGQUIT 3
|
#define SIGQUIT 3
|
||||||
#define SIGILL 4
|
#define SIGILL 4
|
||||||
#define SIGTRAP 5
|
#define SIGTRAP 5
|
||||||
#define SIGABRT 6
|
#define SIGABRT 6
|
||||||
#define SIGIOT 6
|
#define SIGIOT 6
|
||||||
#define SIGBUS 7
|
#define SIGBUS 7
|
||||||
#define SIGFPE 8
|
#define SIGFPE 8
|
||||||
#define SIGKILL 9
|
#define SIGKILL 9
|
||||||
#define SIGUSR1 10
|
#define SIGUSR1 10
|
||||||
#define SIGSEGV 11
|
#define SIGSEGV 11
|
||||||
#define SIGUSR2 12
|
#define SIGUSR2 12
|
||||||
#define SIGPIPE 13
|
#define SIGPIPE 13
|
||||||
#define SIGALRM 14
|
#define SIGALRM 14
|
||||||
#define SIGTERM 15
|
#define SIGTERM 15
|
||||||
#define SIGSTKFLT 16
|
#define SIGSTKFLT 16
|
||||||
#define SIGCHLD 17
|
#define SIGCHLD 17
|
||||||
#define SIGCONT 18
|
#define SIGCONT 18
|
||||||
#define SIGSTOP 19
|
#define SIGSTOP 19
|
||||||
#define SIGTSTP 20
|
#define SIGTSTP 20
|
||||||
#define SIGTTIN 21
|
#define SIGTTIN 21
|
||||||
#define SIGTTOU 22
|
#define SIGTTOU 22
|
||||||
#define SIGURG 23
|
#define SIGURG 23
|
||||||
#define SIGXCPU 24
|
#define SIGXCPU 24
|
||||||
#define SIGXFSZ 25
|
#define SIGXFSZ 25
|
||||||
#define SIGVTALRM 26
|
#define SIGVTALRM 26
|
||||||
#define SIGPROF 27
|
#define SIGPROF 27
|
||||||
#define SIGWINCH 28
|
#define SIGWINCH 28
|
||||||
#define SIGIO 29
|
#define SIGIO 29
|
||||||
#define SIGPOLL SIGIO
|
#define SIGPOLL SIGIO
|
||||||
|
|
||||||
#define FPE_INTDIV 1
|
#define FPE_INTDIV 1
|
||||||
#define FPE_INTOVF 2
|
#define FPE_INTOVF 2
|
||||||
#define FPE_FLTDIV 3
|
#define FPE_FLTDIV 3
|
||||||
#define FPE_FLTOVF 4
|
#define FPE_FLTOVF 4
|
||||||
#define FPE_FLTUND 5
|
#define FPE_FLTUND 5
|
||||||
#define FPE_FLTRES 6
|
#define FPE_FLTRES 6
|
||||||
#define FPE_FLTINV 7
|
#define FPE_FLTINV 7
|
||||||
#define FPE_FLTSUB 8
|
#define FPE_FLTSUB 8
|
||||||
|
|
||||||
#define SA_NOCLDSTOP 0x00000001
|
#define SA_NOCLDSTOP 0x00000001
|
||||||
#define SA_NOCLDWAIT 0x00000002
|
#define SA_NOCLDWAIT 0x00000002
|
||||||
#define SA_SIGINFO 0x00000004
|
#define SA_SIGINFO 0x00000004
|
||||||
#define SA_ONSTACK 0x08000000
|
#define SA_ONSTACK 0x08000000
|
||||||
#define SA_RESTART 0x10000000
|
#define SA_RESTART 0x10000000
|
||||||
#define SA_NODEFER 0x40000000
|
#define SA_NODEFER 0x40000000
|
||||||
#define SA_RESETHAND 0x80000000
|
#define SA_RESETHAND 0x80000000
|
||||||
|
|
||||||
#define SA_NOMASK SA_NODEFER
|
#define SA_NOMASK SA_NODEFER
|
||||||
#define SA_ONESHOT SA_RESETHAND
|
#define SA_ONESHOT SA_RESETHAND
|
||||||
|
|
||||||
|
|
||||||
typedef struct siginfo_t {
|
typedef struct siginfo_t {
|
||||||
|
@ -132,22 +132,25 @@ typedef struct siginfo_t {
|
||||||
} siginfo_t;
|
} siginfo_t;
|
||||||
|
|
||||||
|
|
||||||
// typedef void __signalfn_t(int);
|
typedef void (*sighandler_t)(int);
|
||||||
// typedef __signalfn_t *__sighandler_t;
|
|
||||||
// typedef __signalfn_t *__sighandler_t;
|
|
||||||
typedef void __sighandler_t(int);
|
|
||||||
|
|
||||||
struct sigaction {
|
struct sigaction {
|
||||||
void (*sa_sigaction) (int, siginfo_t *, void *);
|
union {
|
||||||
//__sighandler_t sa_handler;
|
void (*sa_sigaction) (int signum, siginfo_t *, void *);
|
||||||
void (*sa_handler) (int);
|
#if __MESC__
|
||||||
|
void (*sa_handler) (int);
|
||||||
|
#else
|
||||||
|
sighandler_t sa_handler;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
unsigned long sa_flags;
|
unsigned long sa_flags;
|
||||||
sigset_t sa_mask;
|
sigset_t sa_mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SIG_DFL ((__sighandler_t)0) /* default signal handling */
|
|
||||||
#define SIG_IGN ((__sighandler_t)1) /* ignore signal */
|
#define SIG_DFL ((sighandler_t)0)
|
||||||
#define SIG_ERR ((__sighandler_t)-1) /* error return from signal */
|
#define SIG_IGN ((sighandler_t)1)
|
||||||
|
#define SIG_ERR ((sighandler_t)-1)
|
||||||
|
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
|
|
||||||
|
@ -174,7 +177,7 @@ struct sigaction {
|
||||||
typedef int greg_t;
|
typedef int greg_t;
|
||||||
|
|
||||||
/* Number of general registers. */
|
/* Number of general registers. */
|
||||||
#define NGREG 19
|
#define NGREG 19
|
||||||
|
|
||||||
/* Container for all general registers. */
|
/* Container for all general registers. */
|
||||||
typedef greg_t gregset_t[NGREG];
|
typedef greg_t gregset_t[NGREG];
|
||||||
|
@ -224,7 +227,13 @@ typedef struct ucontext
|
||||||
} ucontext_t;
|
} ucontext_t;
|
||||||
#endif // !__i386__
|
#endif // !__i386__
|
||||||
|
|
||||||
|
int kill (pid_t pid, int signum);
|
||||||
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
|
int sigaction (int signum, struct sigaction const *act, struct sigaction *oldact);
|
||||||
|
#if __MESC__
|
||||||
|
void* signal (int signum, void * action);
|
||||||
|
#else
|
||||||
|
sighandler_t signal (int signum, sighandler_t action);
|
||||||
|
#endif
|
||||||
int sigemptyset (sigset_t *set);
|
int sigemptyset (sigset_t *set);
|
||||||
|
|
||||||
#endif //! WITH_GLIBC
|
#endif //! WITH_GLIBC
|
||||||
|
|
|
@ -59,6 +59,7 @@ int chmod (char const *file_name, mode_t mode);
|
||||||
int mkdir (char const *file_name, mode_t mode);
|
int mkdir (char const *file_name, mode_t mode);
|
||||||
int chown (char const *file_name, uid_t owner, gid_t group);
|
int chown (char const *file_name, uid_t owner, gid_t group);
|
||||||
int rmdir (char const *file_name);
|
int rmdir (char const *file_name);
|
||||||
|
int stat (char const *file_name, struct stat *buf);
|
||||||
|
|
||||||
#define S_IFCHR 0020000
|
#define S_IFCHR 0020000
|
||||||
#define S_IFDIR 0040000
|
#define S_IFDIR 0040000
|
||||||
|
|
|
@ -39,6 +39,12 @@
|
||||||
#define STDERR_FILENO 2
|
#define STDERR_FILENO 2
|
||||||
#endif // STDIN_FILENO
|
#endif // STDIN_FILENO
|
||||||
|
|
||||||
|
#ifndef STDIN_FILE_NO
|
||||||
|
#define STDIN_FILE_NO 0
|
||||||
|
#define STDOUT_FILE_NO 1
|
||||||
|
#define STDERR_FILE_NO 2
|
||||||
|
#endif // STDIN_FILE_NO
|
||||||
|
|
||||||
#ifndef __MES_OFF_T
|
#ifndef __MES_OFF_T
|
||||||
#define __MES_OFF_T
|
#define __MES_OFF_T
|
||||||
#undef off_t
|
#undef off_t
|
||||||
|
@ -69,6 +75,12 @@ typedef long intptr_t;
|
||||||
typedef long ptrdiff_t;
|
typedef long ptrdiff_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MES_PID_T
|
||||||
|
#define __MES_PID_T
|
||||||
|
#undef pid_t
|
||||||
|
typedef int pid_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef R_OK
|
#ifndef R_OK
|
||||||
#define F_OK 0
|
#define F_OK 0
|
||||||
#define X_OK 1
|
#define X_OK 1
|
||||||
|
@ -98,6 +110,8 @@ void * sbrk (intptr_t delta);
|
||||||
#endif
|
#endif
|
||||||
int unlink (char const *file_name);
|
int unlink (char const *file_name);
|
||||||
ssize_t write (int filedes, void const *buffer, size_t size);
|
ssize_t write (int filedes, void const *buffer, size_t size);
|
||||||
|
pid_t getpid (void);
|
||||||
|
|
||||||
#endif // ! WITH_GLIBC
|
#endif // ! WITH_GLIBC
|
||||||
|
|
||||||
#endif // __MES_UNISTD_H
|
#endif // __MES_UNISTD_H
|
||||||
|
|
|
@ -98,13 +98,6 @@ getgid (int x)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
getpid (int x)
|
|
||||||
{
|
|
||||||
eputs ("getpid stub\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
getuid (int x)
|
getuid (int x)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,11 +19,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_link 0x09
|
#define SYS_link 0x09
|
||||||
|
#define SYS_getpid 0x14
|
||||||
#define SYS_kill 0x25
|
#define SYS_kill 0x25
|
||||||
#define SYS_rename 0x26
|
#define SYS_rename 0x26
|
||||||
#define SYS_mkdir 0x27
|
#define SYS_mkdir 0x27
|
||||||
#define SYS_dup 0x29
|
#define SYS_dup 0x29
|
||||||
#define SYS_pipe 0x2a
|
#define SYS_pipe 0x2a
|
||||||
|
#define SYS_signal 0x30
|
||||||
#define SYS_lstat 0x6b
|
#define SYS_lstat 0x6b
|
||||||
#define SYS_fstat 0x6c
|
#define SYS_fstat 0x6c
|
||||||
#define SYS_nanosleep 0xa2
|
#define SYS_nanosleep 0xa2
|
||||||
|
@ -34,6 +36,12 @@ link (char const *old_name, char const *new_name)
|
||||||
return _sys_call2 (SYS_link, (int)old_name, (int)new_name);
|
return _sys_call2 (SYS_link, (int)old_name, (int)new_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t
|
||||||
|
getpid ()
|
||||||
|
{
|
||||||
|
return _sys_call (SYS_getpid);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
kill (pid_t pid, int signum)
|
kill (pid_t pid, int signum)
|
||||||
{
|
{
|
||||||
|
@ -58,6 +66,17 @@ dup (int old)
|
||||||
return _sys_call1 (SYS_dup, (int)old);
|
return _sys_call1 (SYS_dup, (int)old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __MESC__
|
||||||
|
void *
|
||||||
|
signal (int signum, void * action)
|
||||||
|
#else
|
||||||
|
sighandler_t
|
||||||
|
signal (int signum, sighandler_t action)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
return _sys_call2 (SYS_signal, signum, action);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
pipe (int filedes[2])
|
pipe (int filedes[2])
|
||||||
{
|
{
|
||||||
|
|
7
lib/m4.c
7
lib/m4.c
|
@ -160,13 +160,6 @@ setbuf (int x)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
signal (int x)
|
|
||||||
{
|
|
||||||
eputs ("signal stub\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
system (int x)
|
system (int x)
|
||||||
{
|
{
|
||||||
|
|
46
scaffold/tests/95-signal.c
Normal file
46
scaffold/tests/95-signal.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* -*-comment-start: "//";comment-end:""-*-
|
||||||
|
* Mes --- Maxwell Equations of Software
|
||||||
|
* Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
|
*
|
||||||
|
* This file is part of Mes.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libmes.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
int g_alarm_handled_p = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
handler (int signum)
|
||||||
|
{
|
||||||
|
eputs ("handle:"); eputs (itoa (signum)); eputs ("\n");
|
||||||
|
if (signum != SIGALRM)
|
||||||
|
exit (1);
|
||||||
|
g_alarm_handled_p = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
signal (SIGALRM, handler);
|
||||||
|
kill (getpid (), SIGALRM);
|
||||||
|
if (!g_alarm_handled_p)
|
||||||
|
return 2;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue