From 17b855aac959b3e8cea64d7b4e887ef3b8aa584e Mon Sep 17 00:00:00 2001 From: Michael LeMay Date: Thu, 23 Jul 2015 14:17:55 -0700 Subject: [PATCH] galileo: Replace non-halting core implementation of assert with the halting one from newlib This patch modifies the include order to include headers from newlib ahead of those from the core of Contiki. The only header file names that are common between Contiki and newlib are assert.h and config.h, but the config.h files in Contiki are only located in ports for other CPUs so they are irrelevant to this patch. The motivation for this patch is to cause files that include assert.h to include the one from newlib that halts when an assertion fails. The assert implementation in the core of Contiki does not halt when an assertion fails. This patch also adds newlib syscall stubs that are required by the newlib assert implementation and the _exit syscall function that halts the system. Finally, this patch updates some other newlib syscall stubs to properly indicate their status as unsupported syscalls. --- platform/galileo/Makefile.galileo | 2 +- platform/galileo/newlib-syscalls.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/platform/galileo/Makefile.galileo b/platform/galileo/Makefile.galileo index 9aca3d0a8..a1429b398 100644 --- a/platform/galileo/Makefile.galileo +++ b/platform/galileo/Makefile.galileo @@ -12,7 +12,7 @@ PROJECT_SOURCEFILES += newlib-syscalls.c CONTIKI_CPU=$(CONTIKI)/cpu/x86 include $(CONTIKI)/cpu/x86/Makefile.x86_quarkX1000 -CFLAGS += -fno-stack-protector -nostdinc -isystem $(LIBC)/include -isystem $(LIBGCC_PATH)/include -isystem $(LIBGCC_PATH)/include-fixed +CFLAGS += -fno-stack-protector -nostdinc -I$(LIBC)/include -isystem $(LIBGCC_PATH)/include -isystem $(LIBGCC_PATH)/include-fixed LDFLAGS += -nostdlib -L$(LIBC)/lib -L$(LIBGCC_PATH)/32 TARGET_LIBFILES += -lm -lc -lgcc diff --git a/platform/galileo/newlib-syscalls.c b/platform/galileo/newlib-syscalls.c index 8032e6da8..fa098c6eb 100644 --- a/platform/galileo/newlib-syscalls.c +++ b/platform/galileo/newlib-syscalls.c @@ -32,6 +32,7 @@ #include #include "uart.h" +#include "helpers.h" #define CONSOLE_OUTPUT_DEV QUARK_X1000_UART_1 @@ -48,19 +49,42 @@ _close_r(struct _reent *ptr, int file) return -1; } /*---------------------------------------------------------------------------*/ +void +_exit(int status) +{ + halt(); +} +/*---------------------------------------------------------------------------*/ +int +_getpid_r(struct _reent *ptr) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return -1; +} +/*---------------------------------------------------------------------------*/ int _isatty_r(struct _reent *ptr, int file) { /* Stubbed function */ + ptr->_errno = ENOTSUP; return 0; } /*---------------------------------------------------------------------------*/ int +_kill_r(struct _reent *ptr, int pid, int signal) +{ + /* Stubbed function */ + ptr->_errno = ENOTSUP; + return -1; +} +/*---------------------------------------------------------------------------*/ +int _read_r(struct _reent *ptr, int file, char *buf, int len) { /* Stubbed function */ ptr->_errno = ENOTSUP; - return 0; + return -1; } /*---------------------------------------------------------------------------*/ int @@ -107,7 +131,7 @@ _lseek_r(struct _reent *ptr, int file, int p, int dir) { /* Stubbed function */ ptr->_errno = ENOTSUP; - return 0; + return -1; } /*---------------------------------------------------------------------------*/ int