|
1 | 1 | /* |
2 | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
3 | 3 | * All rights reserved. |
| 4 | + * Copyright 2026 Arm Limited and/or its affiliates. |
4 | 5 | * |
5 | 6 | * This source code is licensed under the BSD-style license found in the |
6 | 7 | * LICENSE file in the root directory of this source tree. |
|
15 | 16 | #include <executorch/runtime/platform/runtime.h> |
16 | 17 | #include <stdio.h> |
17 | 18 |
|
| 19 | +#if defined(EXECUTORCH_SIZE_TEST_NO_OS_LINK) |
| 20 | +#include <errno.h> |
| 21 | +#include <stddef.h> |
| 22 | +#include <sys/stat.h> |
| 23 | +#include <sys/types.h> |
| 24 | +#endif |
| 25 | + |
18 | 26 | using namespace torch::executor; |
19 | 27 | using torch::executor::util::FileDataLoader; |
20 | 28 |
|
21 | 29 | static uint8_t method_allocator_pool[1024]; |
22 | 30 | static uint8_t activation_pool[512]; |
23 | 31 |
|
| 32 | +#if defined(EXECUTORCH_SIZE_TEST_NO_OS_LINK) |
| 33 | +#define ET_WEAK_SYSCALL __attribute__((weak)) |
| 34 | + |
| 35 | +extern "C" { |
| 36 | + |
| 37 | +// The Zephyr size test links directly with arm-zephyr-eabi, outside Zephyr's |
| 38 | +// normal application link flow. This binary is link/size-only and is never run; |
| 39 | +// these stubs only satisfy libc hooks pulled in by FileDataLoader and |
| 40 | +// profiling. |
| 41 | +#ifdef stderr |
| 42 | +#undef stderr |
| 43 | +#endif |
| 44 | +#if !defined(__GLIBC__) |
| 45 | +extern FILE* const stderr ET_WEAK_SYSCALL = nullptr; |
| 46 | +#endif |
| 47 | + |
| 48 | +ET_WEAK_SYSCALL int close(int fd) { |
| 49 | + (void)fd; |
| 50 | + errno = ENOSYS; |
| 51 | + return -1; |
| 52 | +} |
| 53 | + |
| 54 | +ET_WEAK_SYSCALL int _close(int fd) { |
| 55 | + return close(fd); |
| 56 | +} |
| 57 | + |
| 58 | +ET_WEAK_SYSCALL int fstat(int fd, struct stat* st) { |
| 59 | + (void)fd; |
| 60 | + st->st_mode = S_IFCHR; |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +ET_WEAK_SYSCALL int _fstat(int fd, struct stat* st) { |
| 65 | + return fstat(fd, st); |
| 66 | +} |
| 67 | + |
| 68 | +ET_WEAK_SYSCALL int gettimeofday(void* tv, void* tz) { |
| 69 | + (void)tv; |
| 70 | + (void)tz; |
| 71 | + errno = ENOSYS; |
| 72 | + return -1; |
| 73 | +} |
| 74 | + |
| 75 | +ET_WEAK_SYSCALL int getentropy(void* buffer, size_t length) { |
| 76 | + (void)buffer; |
| 77 | + (void)length; |
| 78 | + errno = ENOSYS; |
| 79 | + return -1; |
| 80 | +} |
| 81 | + |
| 82 | +ET_WEAK_SYSCALL int _getentropy(void* buffer, size_t length) { |
| 83 | + return getentropy(buffer, length); |
| 84 | +} |
| 85 | + |
| 86 | +ET_WEAK_SYSCALL int isatty(int fd) { |
| 87 | + (void)fd; |
| 88 | + return 1; |
| 89 | +} |
| 90 | + |
| 91 | +ET_WEAK_SYSCALL int _isatty(int fd) { |
| 92 | + return isatty(fd); |
| 93 | +} |
| 94 | + |
| 95 | +ET_WEAK_SYSCALL off_t lseek(int fd, off_t offset, int whence) { |
| 96 | + (void)fd; |
| 97 | + (void)offset; |
| 98 | + (void)whence; |
| 99 | + errno = ENOSYS; |
| 100 | + return -1; |
| 101 | +} |
| 102 | + |
| 103 | +ET_WEAK_SYSCALL off_t _lseek(int fd, off_t offset, int whence) { |
| 104 | + return lseek(fd, offset, whence); |
| 105 | +} |
| 106 | + |
| 107 | +ET_WEAK_SYSCALL int open(const char* path, int flags, ...) { |
| 108 | + (void)path; |
| 109 | + (void)flags; |
| 110 | + errno = ENOSYS; |
| 111 | + return -1; |
| 112 | +} |
| 113 | + |
| 114 | +ET_WEAK_SYSCALL int _open(const char* path, int flags, ...) { |
| 115 | + (void)path; |
| 116 | + (void)flags; |
| 117 | + errno = ENOSYS; |
| 118 | + return -1; |
| 119 | +} |
| 120 | + |
| 121 | +ET_WEAK_SYSCALL ssize_t read(int fd, void* buf, size_t count) { |
| 122 | + (void)fd; |
| 123 | + (void)buf; |
| 124 | + (void)count; |
| 125 | + errno = ENOSYS; |
| 126 | + return -1; |
| 127 | +} |
| 128 | + |
| 129 | +ET_WEAK_SYSCALL ssize_t _read(int fd, void* buf, size_t count) { |
| 130 | + return read(fd, buf, count); |
| 131 | +} |
| 132 | + |
| 133 | +ET_WEAK_SYSCALL ssize_t write(int fd, const void* buf, size_t count) { |
| 134 | + (void)fd; |
| 135 | + (void)buf; |
| 136 | + (void)count; |
| 137 | + errno = ENOSYS; |
| 138 | + return -1; |
| 139 | +} |
| 140 | + |
| 141 | +ET_WEAK_SYSCALL ssize_t _write(int fd, const void* buf, size_t count) { |
| 142 | + return write(fd, buf, count); |
| 143 | +} |
| 144 | + |
| 145 | +ET_WEAK_SYSCALL void* _sbrk(ptrdiff_t increment) { |
| 146 | + (void)increment; |
| 147 | + errno = ENOMEM; |
| 148 | + return (void*)-1; |
| 149 | +} |
| 150 | + |
| 151 | +ET_WEAK_SYSCALL void* sbrk(ptrdiff_t increment) { |
| 152 | + return _sbrk(increment); |
| 153 | +} |
| 154 | + |
| 155 | +ET_WEAK_SYSCALL int getpid(void) { |
| 156 | + return 1; |
| 157 | +} |
| 158 | + |
| 159 | +ET_WEAK_SYSCALL int _getpid(void) { |
| 160 | + return getpid(); |
| 161 | +} |
| 162 | + |
| 163 | +ET_WEAK_SYSCALL int kill(int pid, int sig) { |
| 164 | + (void)pid; |
| 165 | + (void)sig; |
| 166 | + errno = ENOSYS; |
| 167 | + return -1; |
| 168 | +} |
| 169 | + |
| 170 | +ET_WEAK_SYSCALL int _kill(int pid, int sig) { |
| 171 | + return kill(pid, sig); |
| 172 | +} |
| 173 | + |
| 174 | +ET_WEAK_SYSCALL void _exit(int status) { |
| 175 | + (void)status; |
| 176 | + __builtin_trap(); |
| 177 | + for (;;) { |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +} // extern "C" |
| 182 | + |
| 183 | +#undef ET_WEAK_SYSCALL |
| 184 | +#endif |
| 185 | + |
24 | 186 | int main(int argc, char** argv) { |
25 | 187 | runtime_init(); |
26 | 188 |
|
|
0 commit comments