core: Add abort.

* lib/stub/__raise.c: New file.
* kaem.run: Use it.
* src/posix.c (__raise)[SYSTEM_LIBC]: New macro.
 (abort_): New function: possibly use it.
* include/mes/builtins.h: Declare it.
* src/builtins.c (mes_builtins): Register it.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2019-11-10 16:04:25 +01:00
parent 94643f8361
commit 96e6ecaf7d
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
9 changed files with 58 additions and 6 deletions

View file

@ -107,6 +107,7 @@ lib/mes/ntoab.c
lib/mes/oputc.c lib/mes/oputc.c
lib/mes/ultoa.c lib/mes/ultoa.c
lib/mes/utoa.c lib/mes/utoa.c
lib/stub/__raise.c
" "
if test $mes_libc = mes; then if test $mes_libc = mes; then

View file

@ -103,6 +103,7 @@ struct scm *module_variable (struct scm *module, struct scm *name);
struct scm *module_ref (struct scm *module, struct scm *name); struct scm *module_ref (struct scm *module, struct scm *name);
struct scm *module_define_x (struct scm *module, struct scm *name, struct scm *value); struct scm *module_define_x (struct scm *module, struct scm *name, struct scm *value);
/* src/posix.c */ /* src/posix.c */
struct scm *abort_ ();
struct scm *exit_ (struct scm *x); struct scm *exit_ (struct scm *x);
struct scm *peek_byte (); struct scm *peek_byte ();
struct scm *read_byte (); struct scm *read_byte ();

View file

@ -84,5 +84,6 @@ unsigned long __mesabi_uldiv (unsigned long a, unsigned long b,
void *__memcpy (void *dest, void const *src, size_t n); void *__memcpy (void *dest, void const *src, size_t n);
void *__memmove (void *dest, void const *src, size_t n); void *__memmove (void *dest, void const *src, size_t n);
void *__memset (void *s, int c, size_t n); void *__memset (void *s, int c, size_t n);
int __raise (int signal);
#endif //__MES_LIB_H #endif //__MES_LIB_H

View file

@ -37,6 +37,7 @@ M2-Planet \
-f lib/mes/mini-write.c \ -f lib/mes/mini-write.c \
-f lib/linux/${mes_cpu}-mes-m2/syscall.c \ -f lib/linux/${mes_cpu}-mes-m2/syscall.c \
-f include/linux/${mes_cpu}/syscall.h \ -f include/linux/${mes_cpu}/syscall.h \
-f lib/stub/__raise.c \
-f lib/linux/brk.c \ -f lib/linux/brk.c \
-f lib/m2/malloc.c \ -f lib/m2/malloc.c \
-f lib/string/memset.c \ -f lib/string/memset.c \

View file

@ -33,7 +33,7 @@ struct ldiv_t
int __raise (int); int __raise (int);
#if __TINYC__ #if __TINYC__ || SYSTEM_LIBC
#define __raise(x) -1 #define __raise(x) -1
#endif #endif

View file

@ -23,7 +23,8 @@
void void
abort (void) abort (void)
{ {
if (raise (SIGABRT) < 0) { /* could not raise SIGABRT */ if (raise (SIGABRT) < 0) /* could not raise SIGABRT */
{
/* Fail in any way possible */ /* Fail in any way possible */
unsigned char* x = (unsigned char*) 0; unsigned char* x = (unsigned char*) 0;
*x = 2; *x = 2;

27
lib/stub/__raise.c Normal file
View file

@ -0,0 +1,27 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* 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/>.
*/
// CONSTANT SIGABRT 0
int
__raise (int signum)
{
return -1;
}

View file

@ -213,6 +213,7 @@ mes_builtins (struct scm *a) /*:((internal)) */
a = init_builtin (builtin_type, "module-ref", 2, &module_ref, a); a = init_builtin (builtin_type, "module-ref", 2, &module_ref, a);
a = init_builtin (builtin_type, "module-define!", 3, &module_define_x, a); a = init_builtin (builtin_type, "module-define!", 3, &module_define_x, a);
/* src/posix.c */ /* src/posix.c */
a = init_builtin (builtin_type, "abort", 0, &abort_, a);
a = init_builtin (builtin_type, "exit", 1, &exit_, a); a = init_builtin (builtin_type, "exit", 1, &exit_, a);
a = init_builtin (builtin_type, "peek-byte", 0, &peek_byte, a); a = init_builtin (builtin_type, "peek-byte", 0, &peek_byte, a);
a = init_builtin (builtin_type, "read-byte", 0, &read_byte, a); a = init_builtin (builtin_type, "read-byte", 0, &read_byte, a);

View file

@ -23,6 +23,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <limits.h> #include <limits.h>
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -33,6 +34,24 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#if SYSTEM_LIBC
#define __raise(x) -1
#endif
struct scm *
abort_ () /*:((name . "abort")) */
{
if (g_debug > 0)
eputs ("abort!\n");
if (__raise (SIGABRT) < 0) /* could not raise SIGABRT */
{
/* Fail in any way possible */
char* x = 0;
x[0] = 2;
}
return cell_unspecified;
}
struct scm * struct scm *
exit_ (struct scm *x) /*:((name . "exit")) */ exit_ (struct scm *x) /*:((name . "exit")) */
{ {