diff --git a/src/omv/Makefile b/src/omv/Makefile index 5f3f5a978..5a60bb667 100644 --- a/src/omv/Makefile +++ b/src/omv/Makefile @@ -28,6 +28,7 @@ SRCS += $(addprefix common/, \ file_utils.c \ mp_utils.c \ sensor_utils.c \ + nosys_stubs.c \ ) SRCS += $(addprefix sensors/, \ diff --git a/src/omv/common/nosys_stubs.c b/src/omv/common/nosys_stubs.c new file mode 100644 index 000000000..5e4710f07 --- /dev/null +++ b/src/omv/common/nosys_stubs.c @@ -0,0 +1,81 @@ +/* + * This file is part of the OpenMV project. + * + * Copyright (c) 2024 Ibrahim Abdelkader + * Copyright (c) 2024 Kwabena W. Agyeman + * + * This work is licensed under the MIT license, see the file LICENSE for details. + * + * stub functions for use when linking with nosys. + */ +#if OMV_NOSYS_STUBS_ENABLE +#include +#include +#include +#include CMSIS_MCU_H + +void _exit(int fd) { + while (1) { + __WFI(); + } +} + +int _write(int handle, char *buffer, int size) { + errno = ENOSYS; + return -1; +} + +int _read(int handle, char *buffer, int size) { + errno = ENOSYS; + return -1; +} + +int _close(int f) { + errno = ENOSYS; + return -1; +} + +int _lseek(int f, int ptr, int dir) { + errno = ENOSYS; + return -1; +} + +int _fstat(int fs, struct stat *st) { + errno = ENOSYS; + return -1; +} + +int _isatty(int f) { + errno = ENOSYS; + return 0; +} + +int _stat(const char *f, struct stat *st) { + errno = ENOSYS; + return -1; +} + +void *_sbrk(ptrdiff_t increment) { + extern char __end__; + static char *heap_end; + + extern char _heap_limit; + static char *heap_limit = &_heap_limit; + + if (heap_end == 0) { + heap_end = &__end__; + } + + char *prev_heap_end = heap_end; + + // Check if the new break is within the limits + if (heap_end + increment > heap_limit) { + // Out of memory + errno = ENOMEM; + return (void *) -1; + } + + heap_end += increment; + return (void *) prev_heap_end; +} +#endif // OMV_NOSYS_STUBS_ENABLE