Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,50 @@ endif
ifneq (,$(filter newlib,$(USEMODULE)))
# allow custom newlib syscalls implementations by adding
# newlib_syscalls_XXX to USEMODULE
ifeq (,$(filter newlib_syscalls_%,$(USEMODULE)))
# Once all syscall are split into "real" implementations and stubs, this
# module should go away
ifeq (,$(filter-out newlib_syscalls_riot_%,$(filter newlib_syscalls_%,$(USEMODULE))))
USEMODULE += newlib_syscalls_default
endif
ifeq (,$(filter stdio_rtt,$(USEMODULE)))
# If xtimer is available, use it to provide the clock function, but only if
# the stub module was not explicitly selected
ifeq (,$(filter newlib_stubs_clock,$(USEMODULE)))
ifneq (,$(filter xtimer,$(USEMODULE)))
USEMODULE += newlib_syscalls_riot_clock
endif
endif
ifeq (,$(filter newlib_stubs_time,$(USEMODULE)))
ifneq (,$(filter periph_rtc,$(USEMODULE)))
USEMODULE += newlib_syscalls_riot_time
endif
endif
ifeq (,$(filter newlib_stubs_rw newlib_stubs_fs,$(USEMODULE)))
ifneq (,$(filter vfs,$(USEMODULE)))
USEMODULE += newlib_syscalls_riot_vfs
endif
endif
ifeq (,$(filter newlib_stubs_rw vfs,$(USEMODULE)))
USEMODULE += newlib_syscalls_riot_serial_rw
endif
ifeq (,$(filter newlib_stubs_rw stdio_rtt,$(USEMODULE)))
USEMODULE += stdio_uart
endif
ifeq (,$(filter vfs newlib_syscalls_riot_vfs,$(USEMODULE)))
USEMODULE += newlib_stubs_fs
endif
USEMODULE += newlib_syscalls_riot_sbrk
endif

ifneq (,$(filter newlib_syscalls_riot_serial_rw,$(USEMODULE)))
USEMODULE += stdio_uart
endif

ifneq (,$(filter newlib_syscalls_riot_%,$(USEMODULE)))
USEMODULE += newlib_syscalls_riot
endif

ifneq (,$(filter newlib_stubs_%,$(USEMODULE)))
USEMODULE += newlib_stubs
endif

ifneq (,$(filter posix_sockets,$(USEMODULE)))
Expand Down
4 changes: 4 additions & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,8 @@ PSEUDOMODULES += crypto_aes_precalculated
# This pseudomodule causes a loop in AES to be unrolled (more flash, less CPU)
PSEUDOMODULES += crypto_aes_unroll

# Newlib system call implementation and stubs are submodules
PSEUDOMODULES += newlib_syscalls_riot_%
PSEUDOMODULES += newlib_stubs_%

# Packages may also add modules to PSEUDOMODULES in their `Makefile.include`.
8 changes: 8 additions & 0 deletions sys/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ ifneq (,$(filter newlib_syscalls_default,$(USEMODULE)))
include $(RIOTBASE)/sys/newlib_syscalls_default/Makefile.include
endif

ifneq (,$(filter newlib_stubs_%,$(USEMODULE)))
include $(RIOTBASE)/sys/newlib_stubs/Makefile.include
endif

ifneq (,$(filter newlib_syscalls_riot_%,$(USEMODULE)))
include $(RIOTBASE)/sys/newlib_syscalls_riot/Makefile.include
endif

ifneq (,$(filter arduino,$(USEMODULE)))
include $(RIOTBASE)/sys/arduino/Makefile.include
endif
Expand Down
3 changes: 3 additions & 0 deletions sys/newlib_stubs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SUBMODULES = 1

include $(RIOTBASE)/Makefile.base
15 changes: 15 additions & 0 deletions sys/newlib_stubs/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ifneq (,$(filter newlib_stubs_clock,$(USEMODULE)))
UNDEF += $(BINDIR)/newlib_stubs/clock.o
endif

ifneq (,$(filter newlib_stubs_time,$(USEMODULE)))
UNDEF += $(BINDIR)/newlib_stubs/time.o
endif

ifneq (,$(filter newlib_stubs_fs,$(USEMODULE)))
UNDEF += $(BINDIR)/newlib_stubs/fs.o
endif

ifneq (,$(filter newlib_stubs_rw,$(USEMODULE)))
UNDEF += $(BINDIR)/newlib_stubs/rw.o
endif
41 changes: 41 additions & 0 deletions sys/newlib_stubs/clock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2018 FU Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_newlib_stubs
* @{
*
* @file
* @brief Provide stub for _times_r (process' CPU time).
*
* By providing _times_r this module indirectly provides a stub for clock().
* If a real implementation is needed, see the newlib_syscalls_clock module.
*
* @author Juan Carrano <j.carrano@fu-berlin.de>
*
* @}
*/

#include <reent.h>
#include <errno.h>
#include <sys/times.h>

/**
* Current process times (not implemented).
*
* @param[out] ptms Not modified.
*
* @return -1, this function always fails. errno is set to ENOSYS.
*/
clock_t _times_r(struct _reent *ptr, struct tms *ptms)
{
(void)ptms;
ptr->_errno = ENOSYS;

return (-1);
}
22 changes: 22 additions & 0 deletions sys/newlib_stubs/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @ingroup sys
* @defgroup sys_newlib_stubs Newlib system call stubs
*
*
* These module provide stubs (functions that always return an error) for the
* system calls required by newlib:
*
* - File handling: _open_r, _close_r, _lseek_r, _read_r, _write_r, _stat_r,
* _fstat_r, _link_r, _unlink_r, _fcntl_r
* - Process control: _execve_r, _wait_r, _fork_r, _getpid_r
* - Memory management: _sbrk_r
* - Timekeeping: _gettimeofday_r, _times_r
*
* Stubs for these functions can be found in the newlib source, under newlib/libc/reent/.
*
* Stubs may be needed if an external module uses a standard library function
* that depends on a syscall, but it is not desired to pull in the code needed
* to support it (for example, there is no point in having VFS if there is no
* storage support.) In many of these cases it is perfectly acceptable if those
* functions do nothing but fail.
*/
91 changes: 91 additions & 0 deletions sys/newlib_stubs/fs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright (C) 2018 Freie Universität Berlin
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @ingroup sys_newlib_stubs
* @{
*
* @file
* @brief Stubs for filesystem routines.
*
* @author Michael Baar <michael.baar@fu-berlin.de>
* @author Stefan Pfeiffer <pfeiffer@inf.fu-berlin.de>
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @author Juan I Carrano <j.carrano@fu-berlin.de>
*
* @}
*/

#include <reent.h>
#include <errno.h>

/* Stubs to avoid linking errors, these functions do not have any effect */
int _open_r(struct _reent *r, const char *name, int flags, int mode)
{
(void) name;
(void) flags;
(void) mode;
r->_errno = ENODEV;
return -1;
}

int _close_r(struct _reent *r, int fd)
{
(void) fd;
r->_errno = ENODEV;
return -1;
}

_off_t _lseek_r(struct _reent *r, int fd, _off_t pos, int dir)
{
(void) fd;
(void) pos;
(void) dir;
r->_errno = ENODEV;
return -1;
}

int _fstat_r(struct _reent *r, int fd, struct stat *st)
{
(void) fd;
(void) st;
r->_errno = ENODEV;
return -1;
}

int _stat_r(struct _reent *r, const char *name, struct stat *st)
{
(void) name;
(void) st;
r->_errno = ENODEV;
return -1;
}

int _unlink_r(struct _reent *r, const char *path)
{
(void) path;
r->_errno = ENODEV;
return -1;
}

/*
* Riot does not support hard links (that's why the error is ENOSYS instead
* of ENODEV.
*/
int _link_r(struct _reent *ptr, const char *old_name, const char *new_name)
{
(void)old_name;
(void)new_name;

ptr->_errno = ENOSYS;

return -1;
}
56 changes: 56 additions & 0 deletions sys/newlib_stubs/rw.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2018 Freie Universität Berlin
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
* 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/

/**
* @ingroup sys_newlib_stubs
* @{
*
* @file
* @brief Stubs for read() and write()
*
* This modules makes reads and write to any file descriptor fail with EBADF.
*
* @author Juan I Carrano <j.carrano@fu-berlin.de>
*
* @}
*/

#include <reent.h>
#include <errno.h>

/**
* Stub for read().
*
* Always fails with errno = EBADF.
*/
_ssize_t _read_r(struct _reent *r, int fd, void *buffer, size_t count)
{
(void)r;
(void)fd;
(void)buffer;
(void)count;
r->_errno = EBADF;
return -1;
}

/**
* Stub for write().
*
* Always fails with errno = EBADF.
*/
_ssize_t _write_r(struct _reent *r, int fd, const void *data, size_t count)
{
(void)r;
(void)fd;
(void)data;
(void)count;
r->_errno = EBADF;
return -1;
}
43 changes: 43 additions & 0 deletions sys/newlib_stubs/time.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2018 FU Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup sys_newlib_stubs
* @{
*
* @file
* @brief Provide stub for _gettimeofday_r (wall time).
*
* @author Juan Carrano <j.carrano@fu-berlin.de>
*
* @}
*/

#include <reent.h>
#include <errno.h>
#include <sys/time.h>

/**
* Get wall time in milliseconds since the epoch (not implemented).
*
* This is a stub that always fails for systems without RTC.
*
* @param[out] r Reentrant structure.
* @param[out] tp Not modified.
* @param tpz Not used.
*
* @return -1, this function always fails. errno is set to ENOSYS.
*/
int _gettimeofday_r(struct _reent *r, struct timeval *restrict tp,
void *restrict tzp)
{
(void) tp;
(void) tzp;
r->_errno = ENOSYS;
return -1;
}
Loading