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 4200e3f472
commit 9d6ab2de67
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/ultoa.c
lib/mes/utoa.c
lib/stub/__raise.c
"
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_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 ();

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 *__memmove (void *dest, void const *src, size_t n);
void *__memset (void *s, int c, size_t n);
int __raise (int signal);
#endif //__MES_LIB_H

View File

@ -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 \

View File

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

View File

@ -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;
}
}

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-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);

View File

@ -23,6 +23,7 @@
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -33,6 +34,24 @@
#include <sys/wait.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 *
exit_ (struct scm *x) /*:((name . "exit")) */
{