diff --git a/include/mes/builtins.h b/include/mes/builtins.h index 8b473dbd..07609ddf 100644 --- a/include/mes/builtins.h +++ b/include/mes/builtins.h @@ -102,6 +102,7 @@ struct scm *module_variable (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); /* src/posix.c */ +struct scm *abort_ (); struct scm *exit_ (struct scm *x); struct scm *peek_byte (); struct scm *read_byte (); diff --git a/kaem.run b/kaem.run index 7255f1d4..f7a554d0 100644 --- a/kaem.run +++ b/kaem.run @@ -33,6 +33,7 @@ M2-Planet \ -f lib/mes/mini-write.c \ -f lib/linux/x86-mes-m2/syscall.c \ -f include/linux/x86/syscall.h \ + -f lib/stub/__raise.c \ -f lib/linux/brk.c \ -f lib/stdlib/malloc.c \ -f lib/string/memset.c \ diff --git a/lib/mes/div.c b/lib/mes/div.c index a192a96c..4ea0ce32 100644 --- a/lib/mes/div.c +++ b/lib/mes/div.c @@ -33,7 +33,7 @@ struct ldiv_t int __raise (int); -#if __TINYC__ +#if __TINYC__ || SYSTEM_LIBC #define __raise(x) -1 #endif diff --git a/lib/stdlib/abort.c b/lib/stdlib/abort.c index e496561d..7c55da9c 100644 --- a/lib/stdlib/abort.c +++ b/lib/stdlib/abort.c @@ -23,9 +23,10 @@ void abort (void) { - if (raise (SIGABRT) < 0) { /* could not raise SIGABRT */ - /* Fail in any way possible */ - unsigned char* x = (unsigned char*) 0; - *x = 2; - } + if (raise (SIGABRT) < 0) /* could not raise SIGABRT */ + { + /* Fail in any way possible */ + unsigned char* x = (unsigned char*) 0; + *x = 2; + } } diff --git a/lib/stub/__raise.c b/lib/stub/__raise.c new file mode 100644 index 00000000..9467513c --- /dev/null +++ b/lib/stub/__raise.c @@ -0,0 +1,27 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2020 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 . + */ + +// CONSTANT SIGABRT 0 + +int +__raise (int signum) +{ + return -1; +} diff --git a/src/builtins.c b/src/builtins.c index f86e696a..be5c1fb1 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -212,6 +212,7 @@ mes_builtins (struct scm *a) /*:((internal)) */ a = init_builtin (builtin_type, "module-ref", 2, &module_ref, a); a = init_builtin (builtin_type, "module-define!", 3, &module_define_x, a); /* 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, "peek-byte", 0, &peek_byte, a); a = init_builtin (builtin_type, "read-byte", 0, &read_byte, a); diff --git a/src/posix.c b/src/posix.c index ed887f11..3f240c61 100644 --- a/src/posix.c +++ b/src/posix.c @@ -33,6 +33,24 @@ #include #include +#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 * exit_ (struct scm *x) /*:((name . "exit")) */ {