initial commit
This commit is contained in:
		
							
								
								
									
										17
									
								
								fw/bsp/libwrap/sys/_exit.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								fw/bsp/libwrap/sys/_exit.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <unistd.h> | ||||
| #include "platform.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| void __wrap_exit(int code) | ||||
| { | ||||
|   const char message[] = "\nProgam has exited with code:"; | ||||
|  | ||||
|   write(STDERR_FILENO, message, sizeof(message) - 1); | ||||
|   write_hex(STDERR_FILENO, code); | ||||
|   write(STDERR_FILENO, "\n", 1); | ||||
|  | ||||
|   for (;;); | ||||
| } | ||||
| weak_under_alias(exit); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/close.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/close.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_close(int fd) | ||||
| { | ||||
|   return _stub(EBADF); | ||||
| } | ||||
| weak_under_alias(close); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/execve.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/execve.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_execve(const char* name, char* const argv[], char* const env[]) | ||||
| { | ||||
|   return _stub(ENOMEM); | ||||
| } | ||||
| weak_under_alias(execve); | ||||
							
								
								
									
										9
									
								
								fw/bsp/libwrap/sys/fork.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								fw/bsp/libwrap/sys/fork.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
|  | ||||
| int fork(void) | ||||
| { | ||||
|   return _stub(EAGAIN); | ||||
| } | ||||
							
								
								
									
										18
									
								
								fw/bsp/libwrap/sys/fstat.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								fw/bsp/libwrap/sys/fstat.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/stat.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_fstat(int fd, struct stat* st) | ||||
| { | ||||
|   if (isatty(fd)) { | ||||
|     st->st_mode = S_IFCHR; | ||||
|     return 0; | ||||
|   } | ||||
|  | ||||
|   return _stub(EBADF); | ||||
| } | ||||
| weak_under_alias(fstat); | ||||
							
								
								
									
										8
									
								
								fw/bsp/libwrap/sys/getpid.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								fw/bsp/libwrap/sys/getpid.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,8 @@ | ||||
| /* See LICENSE of license details. */ | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_getpid(void) | ||||
| { | ||||
|   return 1; | ||||
| } | ||||
| weak_under_alias(getpid); | ||||
							
								
								
									
										13
									
								
								fw/bsp/libwrap/sys/isatty.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								fw/bsp/libwrap/sys/isatty.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <unistd.h> | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_isatty(int fd) | ||||
| { | ||||
|   if (fd == STDOUT_FILENO || fd == STDERR_FILENO) | ||||
|     return 1; | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
| weak_under_alias(isatty); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/kill.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/kill.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_kill(int pid, int sig) | ||||
| { | ||||
|   return _stub(EINVAL); | ||||
| } | ||||
| weak_under_alias(kill); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/link.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/link.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_link(const char *old_name, const char *new_name) | ||||
| { | ||||
|   return _stub(EMLINK); | ||||
| } | ||||
| weak_under_alias(link); | ||||
							
								
								
									
										16
									
								
								fw/bsp/libwrap/sys/lseek.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								fw/bsp/libwrap/sys/lseek.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/types.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| off_t __wrap_lseek(int fd, off_t ptr, int dir) | ||||
| { | ||||
|   if (isatty(fd)) | ||||
|     return 0; | ||||
|  | ||||
|   return _stub(EBADF); | ||||
| } | ||||
| weak_under_alias(lseek); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/open.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/open.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_open(const char* name, int flags, int mode) | ||||
| { | ||||
|   return _stub(ENOENT); | ||||
| } | ||||
| weak_under_alias(open); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/openat.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/openat.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_openat(int dirfd, const char* name, int flags, int mode) | ||||
| { | ||||
|   return _stub(ENOENT); | ||||
| } | ||||
| weak_under_alias(openat); | ||||
							
								
								
									
										271
									
								
								fw/bsp/libwrap/sys/printf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										271
									
								
								fw/bsp/libwrap/sys/printf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,271 @@ | ||||
| /* The functions in this file are only meant to support Dhrystone on an | ||||
|  * embedded RV32 system and are obviously incorrect in general. */ | ||||
|  | ||||
| #include <stdarg.h> | ||||
| #include <stddef.h> | ||||
| #include <stdio.h> | ||||
| #include <stdint.h> | ||||
| #include <string.h> | ||||
| #include <unistd.h> | ||||
|  | ||||
| #undef putchar | ||||
| int putchar(int ch) | ||||
| { | ||||
|   return write(STDOUT_FILENO, &ch, 1) == 1 ? ch : -1; | ||||
| } | ||||
|  | ||||
| static void sprintf_putch(int ch, void** data) | ||||
| { | ||||
|   char** pstr = (char**)data; | ||||
|   **pstr = ch; | ||||
|   (*pstr)++; | ||||
| } | ||||
|  | ||||
| static unsigned long getuint(va_list *ap, int lflag) | ||||
| { | ||||
|   if (lflag) | ||||
|     return va_arg(*ap, unsigned long); | ||||
|   else | ||||
|     return va_arg(*ap, unsigned int); | ||||
| } | ||||
|  | ||||
| static long getint(va_list *ap, int lflag) | ||||
| { | ||||
|   if (lflag) | ||||
|     return va_arg(*ap, long); | ||||
|   else | ||||
|     return va_arg(*ap, int); | ||||
| } | ||||
|  | ||||
| static inline void printnum(void (*putch)(int, void**), void **putdat, | ||||
|                     unsigned long num, unsigned base, int width, int padc) | ||||
| { | ||||
|   unsigned digs[sizeof(num)*8]; | ||||
|   int pos = 0; | ||||
|  | ||||
|   while (1) | ||||
|   { | ||||
|     digs[pos++] = num % base; | ||||
|     if (num < base) | ||||
|       break; | ||||
|     num /= base; | ||||
|   } | ||||
|  | ||||
|   while (width-- > pos) | ||||
|     putch(padc, putdat); | ||||
|  | ||||
|   while (pos-- > 0) | ||||
|     putch(digs[pos] + (digs[pos] >= 10 ? 'a' - 10 : '0'), putdat); | ||||
| } | ||||
| /* | ||||
| static inline void print_double(void (*putch)(int, void**), void **putdat, | ||||
|                                 double num, int width, int prec) | ||||
| { | ||||
|   union { | ||||
|     double d; | ||||
|     uint64_t u; | ||||
|   } u; | ||||
|   u.d = num; | ||||
|  | ||||
|   if (u.u & (1ULL << 63)) { | ||||
|     putch('-', putdat); | ||||
|     u.u &= ~(1ULL << 63); | ||||
|   } | ||||
|  | ||||
|   for (int i = 0; i < prec; i++) | ||||
|     u.d *= 10; | ||||
|  | ||||
|   char buf[32], *pbuf = buf; | ||||
|   printnum(sprintf_putch, (void**)&pbuf, (unsigned long)u.d, 10, 0, 0); | ||||
|   if (prec > 0) { | ||||
|     for (int i = 0; i < prec; i++) { | ||||
|       pbuf[-i] = pbuf[-i-1]; | ||||
|     } | ||||
|     pbuf[-prec] = '.'; | ||||
|     pbuf++; | ||||
|   } | ||||
|  | ||||
|   for (char* p = buf; p < pbuf; p++) | ||||
|     putch(*p, putdat); | ||||
| } | ||||
| */ | ||||
| static void vprintfmt(void (*putch)(int, void**), void **putdat, const char *fmt, va_list ap) | ||||
| { | ||||
|   register const char* p; | ||||
|   const char* last_fmt; | ||||
|   register int ch, err; | ||||
|   unsigned long num; | ||||
|   int base, lflag, width, precision, altflag; | ||||
|   char padc; | ||||
|  | ||||
|   while (1) { | ||||
|     while ((ch = *(unsigned char *) fmt) != '%') { | ||||
|       if (ch == '\0') | ||||
|         return; | ||||
|       fmt++; | ||||
|       putch(ch, putdat); | ||||
|     } | ||||
|     fmt++; | ||||
|  | ||||
|     // Process a %-escape sequence | ||||
|     last_fmt = fmt; | ||||
|     padc = ' '; | ||||
|     width = -1; | ||||
|     precision = -1; | ||||
|     lflag = 0; | ||||
|     altflag = 0; | ||||
|   reswitch: | ||||
|     switch (ch = *(unsigned char *) fmt++) { | ||||
|  | ||||
|     // flag to pad on the right | ||||
|     case '-': | ||||
|       padc = '-'; | ||||
|       goto reswitch; | ||||
|        | ||||
|     // flag to pad with 0's instead of spaces | ||||
|     case '0': | ||||
|       padc = '0'; | ||||
|       goto reswitch; | ||||
|  | ||||
|     // width field | ||||
|     case '1': | ||||
|     case '2': | ||||
|     case '3': | ||||
|     case '4': | ||||
|     case '5': | ||||
|     case '6': | ||||
|     case '7': | ||||
|     case '8': | ||||
|     case '9': | ||||
|       for (precision = 0; ; ++fmt) { | ||||
|         precision = precision * 10 + ch - '0'; | ||||
|         ch = *fmt; | ||||
|         if (ch < '0' || ch > '9') | ||||
|           break; | ||||
|       } | ||||
|       goto process_precision; | ||||
|  | ||||
|     case '*': | ||||
|       precision = va_arg(ap, int); | ||||
|       goto process_precision; | ||||
|  | ||||
|     case '.': | ||||
|       if (width < 0) | ||||
|         width = 0; | ||||
|       goto reswitch; | ||||
|  | ||||
|     case '#': | ||||
|       altflag = 1; | ||||
|       goto reswitch; | ||||
|  | ||||
|     process_precision: | ||||
|       if (width < 0) | ||||
|         width = precision, precision = -1; | ||||
|       goto reswitch; | ||||
|  | ||||
|     // long flag | ||||
|     case 'l': | ||||
|       if (lflag) | ||||
|         goto bad; | ||||
|       goto reswitch; | ||||
|  | ||||
|     // character | ||||
|     case 'c': | ||||
|       putch(va_arg(ap, int), putdat); | ||||
|       break; | ||||
|  | ||||
|     // double | ||||
|     case 'f': | ||||
|       //print_double(putch, putdat, va_arg(ap, double), width, precision); | ||||
|       break; | ||||
|  | ||||
|     // string | ||||
|     case 's': | ||||
|       if ((p = va_arg(ap, char *)) == NULL) | ||||
|         p = "(null)"; | ||||
|       if (width > 0 && padc != '-') | ||||
|         for (width -= strnlen(p, precision); width > 0; width--) | ||||
|           putch(padc, putdat); | ||||
|       for (; (ch = *p) != '\0' && (precision < 0 || --precision >= 0); width--) { | ||||
|         putch(ch, putdat); | ||||
|         p++; | ||||
|       } | ||||
|       for (; width > 0; width--) | ||||
|         putch(' ', putdat); | ||||
|       break; | ||||
|  | ||||
|     // (signed) decimal | ||||
|     case 'd': | ||||
|       num = getint(&ap, lflag); | ||||
|       if ((long) num < 0) { | ||||
|         putch('-', putdat); | ||||
|         num = -(long) num; | ||||
|       } | ||||
|       base = 10; | ||||
|       goto signed_number; | ||||
|  | ||||
|     // unsigned decimal | ||||
|     case 'u': | ||||
|       base = 10; | ||||
|       goto unsigned_number; | ||||
|  | ||||
|     // (unsigned) octal | ||||
|     case 'o': | ||||
|       // should do something with padding so it's always 3 octits | ||||
|       base = 8; | ||||
|       goto unsigned_number; | ||||
|  | ||||
|     // pointer | ||||
|     case 'p': | ||||
|       lflag = 1; | ||||
|       putch('0', putdat); | ||||
|       putch('x', putdat); | ||||
|       /* fall through to 'x' */ | ||||
|  | ||||
|     // (unsigned) hexadecimal | ||||
|     case 'x': | ||||
|       base = 16; | ||||
|     unsigned_number: | ||||
|       num = getuint(&ap, lflag); | ||||
|     signed_number: | ||||
|       printnum(putch, putdat, num, base, width, padc); | ||||
|       break; | ||||
|  | ||||
|     // escaped '%' character | ||||
|     case '%': | ||||
|       putch(ch, putdat); | ||||
|       break; | ||||
|        | ||||
|     // unrecognized escape sequence - just print it literally | ||||
|     default: | ||||
|     bad: | ||||
|       putch('%', putdat); | ||||
|       fmt = last_fmt; | ||||
|       break; | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| int __wrap_printf(const char* fmt, ...) | ||||
| { | ||||
|   va_list ap; | ||||
|   va_start(ap, fmt); | ||||
|  | ||||
|   vprintfmt((void*)putchar, 0, fmt, ap); | ||||
|  | ||||
|   va_end(ap); | ||||
|   return 0; // incorrect return value, but who cares, anyway? | ||||
| } | ||||
|  | ||||
| int __wrap_sprintf(char* str, const char* fmt, ...) | ||||
| { | ||||
|   va_list ap; | ||||
|   char* str0 = str; | ||||
|   va_start(ap, fmt); | ||||
|  | ||||
|   vprintfmt(sprintf_putch, (void**)&str, fmt, ap); | ||||
|   *str = 0; | ||||
|  | ||||
|   va_end(ap); | ||||
|   return str - str0; | ||||
| } | ||||
							
								
								
									
										28
									
								
								fw/bsp/libwrap/sys/puts.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								fw/bsp/libwrap/sys/puts.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <errno.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/types.h> | ||||
|  | ||||
| #include "platform.h" | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_puts(const char *s) | ||||
| { | ||||
|   while (*s != '\0') { | ||||
|     while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; | ||||
|     UART0_REG(UART_REG_TXFIFO) = *s; | ||||
|  | ||||
|     if (*s == '\n') { | ||||
|       while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; | ||||
|       UART0_REG(UART_REG_TXFIFO) = '\r'; | ||||
|     } | ||||
|  | ||||
|     ++s; | ||||
|   } | ||||
|  | ||||
|   return 0; | ||||
| } | ||||
| weak_under_alias(puts); | ||||
							
								
								
									
										32
									
								
								fw/bsp/libwrap/sys/read.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								fw/bsp/libwrap/sys/read.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <errno.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/types.h> | ||||
|  | ||||
| #include "platform.h" | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| ssize_t __wrap_read(int fd, void* ptr, size_t len) | ||||
| { | ||||
|   uint8_t * current = (uint8_t *)ptr; | ||||
|   volatile uint32_t * uart_rx = (uint32_t *)(UART0_CTRL_ADDR + UART_REG_RXFIFO); | ||||
|   volatile uint8_t * uart_rx_cnt = (uint8_t *)(UART0_CTRL_ADDR + UART_REG_RXCTRL + 2); | ||||
|  | ||||
|   ssize_t result = 0; | ||||
|  | ||||
|   if (isatty(fd)) { | ||||
|     for (current = (uint8_t *)ptr; | ||||
|         (current < ((uint8_t *)ptr) + len) && (*uart_rx_cnt > 0); | ||||
|         current ++) { | ||||
|       *current = *uart_rx; | ||||
|       result++; | ||||
|     } | ||||
|     return result; | ||||
|   } | ||||
|  | ||||
|   return _stub(EBADF); | ||||
| } | ||||
| weak_under_alias(read); | ||||
							
								
								
									
										18
									
								
								fw/bsp/libwrap/sys/sbrk.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								fw/bsp/libwrap/sys/sbrk.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,18 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <stddef.h> | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| void *__wrap_sbrk(ptrdiff_t incr) | ||||
| { | ||||
|   extern char _end[]; | ||||
|   extern char _heap_end[]; | ||||
|   static char *curbrk = _end; | ||||
|  | ||||
|   if ((curbrk + incr < _end) || (curbrk + incr > _heap_end)) | ||||
|     return NULL - 1; | ||||
|  | ||||
|   curbrk += incr; | ||||
|   return curbrk - incr; | ||||
| } | ||||
| weak_under_alias(sbrk); | ||||
							
								
								
									
										12
									
								
								fw/bsp/libwrap/sys/stat.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								fw/bsp/libwrap/sys/stat.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <sys/stat.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_stat(const char* file, struct stat* st) | ||||
| { | ||||
|   return _stub(EACCES); | ||||
| } | ||||
| weak_under_alias(stat); | ||||
							
								
								
									
										10
									
								
								fw/bsp/libwrap/sys/stub.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								fw/bsp/libwrap/sys/stub.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| /* See LICENSE of license details. */ | ||||
| #ifndef _SIFIVE_SYS_STUB_H | ||||
| #define _SIFIVE_SYS_STUB_H | ||||
|  | ||||
| static inline int _stub(int err) | ||||
| { | ||||
|   return -1; | ||||
| } | ||||
|  | ||||
| #endif /* _SIFIVE_SYS_STUB_H */ | ||||
							
								
								
									
										12
									
								
								fw/bsp/libwrap/sys/times.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								fw/bsp/libwrap/sys/times.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include <sys/times.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| clock_t __wrap_times(struct tms* buf) | ||||
| { | ||||
|   return _stub(EACCES); | ||||
| } | ||||
| weak_under_alias(times); | ||||
							
								
								
									
										11
									
								
								fw/bsp/libwrap/sys/unlink.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								fw/bsp/libwrap/sys/unlink.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| int __wrap_unlink(const char* name) | ||||
| { | ||||
|   return _stub(ENOENT); | ||||
| } | ||||
| weak_under_alias(unlink); | ||||
							
								
								
									
										9
									
								
								fw/bsp/libwrap/sys/wait.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								fw/bsp/libwrap/sys/wait.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <errno.h> | ||||
| #include "stub.h" | ||||
|  | ||||
| int wait(int* status) | ||||
| { | ||||
|   return _stub(ECHILD); | ||||
| } | ||||
							
								
								
									
										7
									
								
								fw/bsp/libwrap/sys/weak_under_alias.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								fw/bsp/libwrap/sys/weak_under_alias.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | ||||
| #ifndef _BSP_LIBWRAP_WEAK_UNDER_ALIAS_H | ||||
| #define _BSP_LIBWRAP_WEAK_UNDER_ALIAS_H | ||||
|  | ||||
| #define weak_under_alias(name) \ | ||||
|   extern __typeof (__wrap_##name) __wrap__##name __attribute__ ((weak, alias ("__wrap_"#name))) | ||||
|  | ||||
| #endif | ||||
							
								
								
									
										31
									
								
								fw/bsp/libwrap/sys/write.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								fw/bsp/libwrap/sys/write.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | ||||
| /* See LICENSE of license details. */ | ||||
|  | ||||
| #include <stdint.h> | ||||
| #include <errno.h> | ||||
| #include <unistd.h> | ||||
| #include <sys/types.h> | ||||
|  | ||||
| #include "platform.h" | ||||
| #include "stub.h" | ||||
| #include "weak_under_alias.h" | ||||
|  | ||||
| ssize_t __wrap_write(int fd, const void* ptr, size_t len) | ||||
| { | ||||
|   const uint8_t * current = (const char *)ptr; | ||||
|  | ||||
|   if (isatty(fd)) { | ||||
|     for (size_t jj = 0; jj < len; jj++) { | ||||
|       while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; | ||||
|       UART0_REG(UART_REG_TXFIFO) = current[jj]; | ||||
|  | ||||
|       if (current[jj] == '\n') { | ||||
|         while (UART0_REG(UART_REG_TXFIFO) & 0x80000000) ; | ||||
|         UART0_REG(UART_REG_TXFIFO) = '\r'; | ||||
|       } | ||||
|     } | ||||
|     return len; | ||||
|   } | ||||
|  | ||||
|   return _stub(EBADF); | ||||
| } | ||||
| weak_under_alias(write); | ||||
		Reference in New Issue
	
	Block a user