rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Macros
******************************************************/
#ifndef WEAK
#ifndef __MINGW32__
#define WEAK __attribute__((weak))
#else
/* MinGW doesn't support weak */
#define WEAK
#endif
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef MAY_BE_UNUSED
#define MAY_BE_UNUSED __attribute__((unused))
#endif
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif
#ifndef ALIGNED
#define ALIGNED(size) __attribute__((aligned(size)))
#endif
#ifndef SECTION
#define SECTION(name) __attribute__((section(name)))
#endif
#ifndef NEVER_INLINE
#define NEVER_INLINE __attribute__((noinline))
#endif
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE __attribute__((always_inline))
#endif
/******************************************************
* Constants
******************************************************/
/******************************************************
* Enumerations
******************************************************/
/******************************************************
* Type Definitions
******************************************************/
/******************************************************
* Structures
******************************************************/
/******************************************************
* Global Variables
******************************************************/
/******************************************************
* Function Declarations
******************************************************/
void *memrchr( const void *s, int c, size_t n );
/* Windows doesn't come with support for strlcpy */
#ifdef WIN32
size_t strlcpy (char *dest, const char *src, size_t size);
#endif /* WIN32 */
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -0,0 +1,128 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#include "k_config.h"
int errno;
#if defined (__CC_ARM) && defined(__MICROLIB)
void __aeabi_assert(const char *expr, const char *file, int line)
{
while (1);
}
extern long long krhino_sys_time_get(void);
int gettimeofday(struct timeval *tv, void *tzp)
{
uint64_t t = krhino_sys_time_get();
tv->tv_sec = t / 1000;
tv->tv_usec = (t % 1000) * 1000;
return 0;
}
#if (RHINO_CONFIG_MM_TLF > 0)
#define AOS_UNSIGNED_INT_MSB (1u << (sizeof(unsigned int) * 8 - 1))
extern void *aos_malloc(unsigned int size);
extern void aos_alloc_trace(void *addr, size_t allocator);
extern void aos_free(void *mem);
extern void *aos_realloc(void *mem, unsigned int size);
extern int32_t aos_uart_send(void *data, uint32_t size, uint32_t timeout);
void *malloc(size_t size)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(size);
#endif
return mem;
}
void free(void *mem)
{
aos_free(mem);
}
void *realloc(void *old, size_t newlen)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_realloc(old, newlen);
#endif
return mem;
}
void *calloc(size_t len, size_t elsize)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc((elsize * len) | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(elsize * len);
#endif
if (mem) {
memset(mem, 0, elsize * len);
}
return mem;
}
char * strdup(const char *s)
{
size_t len = strlen(s) +1;
void *dup_str = aos_malloc(len);
if (dup_str == NULL)
return NULL;
return (char *)memcpy(dup_str, s, len);
}
#pragma weak fputc
int fputc(int ch, FILE *f)
{
/* Send data. */
return aos_uart_send((uint8_t *)(&ch), 1, 1000);
}
#endif
//referred from ota_socket.o
void bzero()
{
}
//referred from ssl_cli.o
time_t time(time_t *t)
{
return 0;
}
//referred from aos_network.o
int accept(int sock, long *addr, long *addrlen)
{
return 0;
}
int listen(int sock, int backlog)
{
return 0;
}
//referred from timing.o
unsigned int alarm(unsigned int seconds)
{
return 0;
}
#endif

View file

@ -0,0 +1,5 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "sys/fcntl.h"

View file

@ -0,0 +1,157 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_ERRNO_H__
#define _SYS_ERRNO_H__
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ENSROK 0 /* DNS server returned answer with no data */
#define ENSRNODATA 160 /* DNS server returned answer with no data */
#define ENSRFORMERR 161 /* DNS server claims query was misformatted */
#define ENSRSERVFAIL 162 /* DNS server returned general failure */
#define ENSRNOTFOUND 163 /* Domain name not found */
#define ENSRNOTIMP 164 /* DNS server does not implement requested operation */
#define ENSRREFUSED 165 /* DNS server refused query */
#define ENSRBADQUERY 166 /* Misformatted DNS query */
#define ENSRBADNAME 167 /* Misformatted domain name */
#define ENSRBADFAMILY 168 /* Unsupported address family */
#define ENSRBADRESP 169 /* Misformatted DNS reply */
#define ENSRCONNREFUSED 170 /* Could not contact DNS servers */
#define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */
#define ENSROF 172 /* End of file */
#define ENSRFILE 173 /* Error reading file */
#define ENSRNOMEM 174 /* Out of memory */
#define ENSRDESTRUCTION 175 /* Application terminated lookup */
#define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */
#define ENSRCNAMELOOP 177 /* Domain name is too long */
#endif /* _SYS_ERROR_H */

View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef LIBC_FCNTL_H__
#define LIBC_FCNTL_H__
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define O_CREAT 0100
#define O_EXCL 0200
#define O_NOCTTY 0400
#define O_TRUNC 01000
#define O_APPEND 02000
#define O_NONBLOCK 04000
#define O_DSYNC 010000
#define O_SYNC 04010000
#define O_RSYNC 04010000
#define O_BINARY 0100000
#define O_DIRECTORY 0200000
#define O_NOFOLLOW 0400000
#define O_CLOEXEC 02000000
#define O_ASYNC 020000
#define O_DIRECT 040000
#define O_LARGEFILE 0100000
#define O_NOATIME 01000000
#define O_PATH 010000000
#define O_TMPFILE 020200000
#define O_NDELAY O_NONBLOCK
#define O_SEARCH O_PATH
#define O_EXEC O_PATH
#define O_ACCMODE (03|O_SEARCH)
#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
#define F_SETOWN 8
#define F_GETOWN 9
#define F_SETSIG 10
#define F_GETSIG 11
#define F_GETLK 12
#define F_SETLK 13
#define F_SETLKW 14
#define F_SETOWN_EX 15
#define F_GETOWN_EX 16
#define F_GETOWNER_UIDS 17
#endif

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_SELECT_H__
#define _SYS_SELECT_H__
#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif
#define NBBY 8 /* number of bits in a byte */
typedef long fd_mask;
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
#endif
/* We use a macro for fd_set so that including Sockets.h afterwards
can work. */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
#define fd_set _types_fd_set
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
#endif

View file

@ -0,0 +1,52 @@
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
typedef void (*SIG_FUNC)(int);
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGEMT 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGBUS 10
#define SIGSEGV 11
#define SIGSYS 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGURG 16
#define SIGSTOP 17
#define SIGTSTP 18
#define SIGCONT 19
#define SIGCHLD 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGIO 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGINFO 29
#define SIGUSR1 30
#define SIGUSR2 31
#define SIGSCAN 32
#define SIGASSOC 33
#define SIGDISASSOC 34
#define SIGDEAUTH 35
#define SIGPOLL SIGIO
#define SIGPWR SIGINFO
#define SIGIOT SIGABRT
extern void signal(int sig_num, SIG_FUNC func);
extern unsigned int alarm(unsigned int seconds);
#endif
// eof

View file

@ -0,0 +1,57 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_STAT_H__
#define _SYS_STAT_H__
#define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
/* stat structure */
#include <stdint.h>
#include <time.h>
struct stat
{
struct rt_device* st_dev;
uint16_t st_mode;
uint32_t st_size;
time_t st_mtime;
uint32_t st_blksize;
};
#endif

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_TIME_H_
#define _SYS_TIME_H_
#include <time.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
/*
* Structure returned by gettimeofday(2) system call,
* and used in other calls.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif /* _TIMEVAL_DEFINED */
#ifndef _TIMESPEC_DEFINED
#define _TIMESPEC_DEFINED
/*
* Structure defined by POSIX.1b to be like a timeval.
*/
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
};
#endif /* _TIMESPEC_DEFINED */
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tp, void *ignore);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIME_H_ */

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
#include <stdint.h>
typedef uint32_t clockid_t;
typedef uint32_t key_t; /* Used for interprocess communication. */
typedef uint32_t pid_t; /* Used for process IDs and process group IDs. */
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
typedef long long off_t;
typedef long suseconds_t;
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#if __BSD_VISIBLE
#include <sys/select.h>
#endif
#endif /* _SYS_TYPES_H */

View file

@ -0,0 +1,9 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_UNISTD_H
#define _SYS_UNISTD_H
#endif /* _SYS_UNISTD_H */

View file

@ -0,0 +1,5 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "sys/unistd.h"

View file

@ -0,0 +1,90 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#pragma once
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************
* Macros
******************************************************/
#ifndef WEAK
#ifndef __MINGW32__
#define WEAK __attribute__((weak))
#else
/* MinGW doesn't support weak */
#define WEAK
#endif
#endif
#ifndef USED
#define USED __attribute__((used))
#endif
#ifndef MAY_BE_UNUSED
#define MAY_BE_UNUSED __attribute__((unused))
#endif
#ifndef NORETURN
#define NORETURN __attribute__((noreturn))
#endif
#ifndef ALIGNED
#define ALIGNED(size) __attribute__((aligned(size)))
#endif
#ifndef SECTION
#define SECTION(name) __attribute__((section(name)))
#endif
#ifndef NEVER_INLINE
#define NEVER_INLINE __attribute__((noinline))
#endif
#ifndef ALWAYS_INLINE
#define ALWAYS_INLINE __attribute__((always_inline))
#endif
/******************************************************
* Constants
******************************************************/
/******************************************************
* Enumerations
******************************************************/
/******************************************************
* Type Definitions
******************************************************/
/******************************************************
* Structures
******************************************************/
/******************************************************
* Global Variables
******************************************************/
/******************************************************
* Function Declarations
******************************************************/
void *memrchr( const void *s, int c, size_t n );
/* Windows doesn't come with support for strlcpy */
#ifdef WIN32
size_t strlcpy (char *dest, const char *src, size_t size);
#endif /* WIN32 */
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -0,0 +1,5 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "sys/fcntl.h"

View file

@ -0,0 +1,143 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifdef __ICCARM__
#include <stdarg.h>
#include <sys/types.h>
#include <time.h>
#include <stdio.h>
int errno;
extern void *aos_malloc(unsigned int size);
extern void aos_alloc_trace(void *addr, size_t allocator);
extern void aos_free(void *mem);
extern void *aos_realloc(void *mem, unsigned int size);
extern long long aos_now_ms(void);
__ATTRIBUTES void *malloc(unsigned int size)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(size);
#endif
return mem;
}
__ATTRIBUTES void *realloc(void *old, unsigned int newlen)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_realloc(old, newlen);
#endif
return mem;
}
__ATTRIBUTES void *calloc(size_t len, size_t elsize)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc((elsize * len) | AOS_UNSIGNED_INT_MSB);
#else
mem = aos_malloc(elsize * len);
#endif
if (mem) {
memset(mem, 0, elsize * len);
}
return mem;
}
__ATTRIBUTES void free(void *mem)
{
aos_free(mem);
}
__ATTRIBUTES time_t time(time_t *tod)
{
uint64_t t = aos_now_ms();
return (time_t)(t / 1000);
}
int *__errno _PARAMS ((void))
{
return 0;
}
void __assert_func(const char * a, int b, const char * c, const char *d)
{
while (1);
}
/*TO DO*/
#pragma weak __write
size_t __write(int handle, const unsigned char *buffer, size_t size)
{
if (buffer == 0)
{
/*
* This means that we should flush internal buffers. Since we don't we just return.
* (Remember, "handle" == -1 means that all handles should be flushed.)
*/
return 0;
}
/* This function only writes to "standard out" and "standard err" for all other file handles it returns failure. */
if ((handle != 1) && (handle != 2))
{
return ((size_t)-1);
}
/* Send data. */
aos_uart_send(buffer, size, 1000);
return size;
}
void bzero()
{
}
void __lseek()
{
}
void __close()
{
}
int remove(char const *p)
{
return 0;
}
void gettimeofday()
{
}
void getopt()
{
}
void optarg()
{
}
#endif

View file

@ -0,0 +1,102 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
/* This header file provides the reentrancy. */
/* The reentrant system calls here serve two purposes:
1) Provide reentrant versions of the system calls the ANSI C library
requires.
2) Provide these system calls in a namespace clean way.
It is intended that *all* system calls that the ANSI C library needs
be declared here. It documents them all in one place. All library access
to the system is via some form of these functions.
The target may provide the needed syscalls by any of the following:
1) Define the reentrant versions of the syscalls directly.
(eg: _open_r, _close_r, etc.). Please keep the namespace clean.
When you do this, set "syscall_dir" to "syscalls" and add
-DREENTRANT_SYSCALLS_PROVIDED to newlib_cflags in configure.host.
2) Define namespace clean versions of the system calls by prefixing
them with '_' (eg: _open, _close, etc.). Technically, there won't be
true reentrancy at the syscall level, but the library will be namespace
clean.
When you do this, set "syscall_dir" to "syscalls" in configure.host.
3) Define or otherwise provide the regular versions of the syscalls
(eg: open, close, etc.). The library won't be reentrant nor namespace
clean, but at least it will work.
When you do this, add -DMISSING_SYSCALL_NAMES to newlib_cflags in
configure.host.
4) Define or otherwise provide the regular versions of the syscalls,
and do not supply functional interfaces for any of the reentrant
calls. With this method, the reentrant syscalls are redefined to
directly call the regular system call without the reentrancy argument.
When you do this, specify both -DREENTRANT_SYSCALLS_PROVIDED and
-DMISSING_SYSCALL_NAMES via newlib_cflags in configure.host and do
not specify "syscall_dir".
Stubs of the reentrant versions of the syscalls exist in the libc/reent
source directory and are provided if REENTRANT_SYSCALLS_PROVIDED isn't
defined. These stubs call the native system calls: _open, _close, etc.
if MISSING_SYSCALL_NAMES is *not* defined, otherwise they call the
non-underscored versions: open, close, etc. when MISSING_SYSCALL_NAMES
*is* defined.
By default, newlib functions call the reentrant syscalls internally,
passing a reentrancy structure as an argument. This reentrancy structure
contains data that is thread-specific. For example, the errno value is
kept in the reentrancy structure. If multiple threads exist, each will
keep a separate errno value which is intuitive since the application flow
cannot check for failure reliably otherwise.
The reentrant syscalls are either provided by the platform, by the
libc/reent stubs, or in the case of both MISSING_SYSCALL_NAMES and
REENTRANT_SYSCALLS_PROVIDED being defined, the calls are redefined to
simply call the regular syscalls with no reentrancy struct argument.
A single-threaded application does not need to worry about the reentrancy
structure. It is used internally.
A multi-threaded application needs either to manually manage reentrancy
structures or use dynamic reentrancy.
Manually managing reentrancy structures entails calling special reentrant
versions of newlib functions that have an additional reentrancy argument.
For example, _printf_r. By convention, the first argument is the
reentrancy structure. By default, the normal version of the function
uses the default reentrancy structure: _REENT. The reentrancy structure
is passed internally, eventually to the reentrant syscalls themselves.
How the structures are stored and accessed in this model is up to the
application.
Dynamic reentrancy is specified by the __DYNAMIC_REENT__ flag. This
flag denotes setting up a macro to replace _REENT with a function call
to __getreent(). This function needs to be implemented by the platform
and it is meant to return the reentrancy structure for the current
thread. When the regular C functions (e.g. printf) go to call internal
routines with the default _REENT structure, they end up calling with
the reentrancy structure for the thread. Thus, application code does not
need to call the _r routines nor worry about reentrancy structures. */
/* WARNING: All identifiers here must begin with an underscore. This file is
included by stdio.h and others and we therefore must only use identifiers
in the namespace allotted to us. */
#ifndef _REENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _REENT_H_
#include <sys/reent.h>
#ifdef __cplusplus
}
#endif
#endif /* _REENT_H_ */

View file

@ -0,0 +1,158 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_ERRNO_H__
#define _SYS_ERRNO_H__
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Arg list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#define EDEADLK 35 /* Resource deadlock would occur */
#define ENAMETOOLONG 36 /* File name too long */
#define ENOLCK 37 /* No record locks available */
#define ENOSYS 38 /* Function not implemented */
#define ENOTEMPTY 39 /* Directory not empty */
#define ELOOP 40 /* Too many symbolic links encountered */
#define EWOULDBLOCK EAGAIN /* Operation would block */
#define ENOMSG 42 /* No message of desired type */
#define EIDRM 43 /* Identifier removed */
#define ECHRNG 44 /* Channel number out of range */
#define EL2NSYNC 45 /* Level 2 not synchronized */
#define EL3HLT 46 /* Level 3 halted */
#define EL3RST 47 /* Level 3 reset */
#define ELNRNG 48 /* Link number out of range */
#define EUNATCH 49 /* Protocol driver not attached */
#define ENOCSI 50 /* No CSI structure available */
#define EL2HLT 51 /* Level 2 halted */
#define EBADE 52 /* Invalid exchange */
#define EBADR 53 /* Invalid request descriptor */
#define EXFULL 54 /* Exchange full */
#define ENOANO 55 /* No anode */
#define EBADRQC 56 /* Invalid request code */
#define EBADSLT 57 /* Invalid slot */
#define EDEADLOCK EDEADLK
#define EBFONT 59 /* Bad font file format */
#define ENOSTR 60 /* Device not a stream */
#define ENODATA 61 /* No data available */
#define ETIME 62 /* Timer expired */
#define ENOSR 63 /* Out of streams resources */
#define ENONET 64 /* Machine is not on the network */
#define ENOPKG 65 /* Package not installed */
#define EREMOTE 66 /* Object is remote */
#define ENOLINK 67 /* Link has been severed */
#define EADV 68 /* Advertise error */
#define ESRMNT 69 /* Srmount error */
#define ECOMM 70 /* Communication error on send */
#define EPROTO 71 /* Protocol error */
#define EMULTIHOP 72 /* Multihop attempted */
#define EDOTDOT 73 /* RFS specific error */
#define EBADMSG 74 /* Not a data message */
#define EOVERFLOW 75 /* Value too large for defined data type */
#define ENOTUNIQ 76 /* Name not unique on network */
#define EBADFD 77 /* File descriptor in bad state */
#define EREMCHG 78 /* Remote address changed */
#define ELIBACC 79 /* Can not access a needed shared library */
#define ELIBBAD 80 /* Accessing a corrupted shared library */
#define ELIBSCN 81 /* .lib section in a.out corrupted */
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
#define EILSEQ 84 /* Illegal byte sequence */
#define ERESTART 85 /* Interrupted system call should be restarted */
#define ESTRPIPE 86 /* Streams pipe error */
#define EUSERS 87 /* Too many users */
#define ENOTSOCK 88 /* Socket operation on non-socket */
#define EDESTADDRREQ 89 /* Destination address required */
#define EMSGSIZE 90 /* Message too long */
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
#define ENOPROTOOPT 92 /* Protocol not available */
#define EPROTONOSUPPORT 93 /* Protocol not supported */
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
#define EADDRINUSE 98 /* Address already in use */
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
#define ENETDOWN 100 /* Network is down */
#define ENETUNREACH 101 /* Network is unreachable */
#define ENETRESET 102 /* Network dropped connection because of reset */
#define ECONNABORTED 103 /* Software caused connection abort */
#define ECONNRESET 104 /* Connection reset by peer */
#define ENOBUFS 105 /* No buffer space available */
#define EISCONN 106 /* Transport endpoint is already connected */
#define ENOTCONN 107 /* Transport endpoint is not connected */
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
#define ETIMEDOUT 110 /* Connection timed out */
#define ECONNREFUSED 111 /* Connection refused */
#define EHOSTDOWN 112 /* Host is down */
#define EHOSTUNREACH 113 /* No route to host */
#define EALREADY 114 /* Operation already in progress */
#define EINPROGRESS 115 /* Operation now in progress */
#define ESTALE 116 /* Stale NFS file handle */
#define EUCLEAN 117 /* Structure needs cleaning */
#define ENOTNAM 118 /* Not a XENIX named type file */
#define ENAVAIL 119 /* No XENIX semaphores available */
#define EISNAM 120 /* Is a named type file */
#define EREMOTEIO 121 /* Remote I/O error */
#define EDQUOT 122 /* Quota exceeded */
#define ENOMEDIUM 123 /* No medium found */
#define EMEDIUMTYPE 124 /* Wrong medium type */
#define ENSROK 0 /* DNS server returned answer with no data */
#define ENOTSUP 134 /* Not supported */
#define ENSRNODATA 160 /* DNS server returned answer with no data */
#define ENSRFORMERR 161 /* DNS server claims query was misformatted */
#define ENSRSERVFAIL 162 /* DNS server returned general failure */
#define ENSRNOTFOUND 163 /* Domain name not found */
#define ENSRNOTIMP 164 /* DNS server does not implement requested operation */
#define ENSRREFUSED 165 /* DNS server refused query */
#define ENSRBADQUERY 166 /* Misformatted DNS query */
#define ENSRBADNAME 167 /* Misformatted domain name */
#define ENSRBADFAMILY 168 /* Unsupported address family */
#define ENSRBADRESP 169 /* Misformatted DNS reply */
#define ENSRCONNREFUSED 170 /* Could not contact DNS servers */
#define ENSRTIMEOUT 171 /* Timeout while contacting DNS servers */
#define ENSROF 172 /* End of file */
#define ENSRFILE 173 /* Error reading file */
#define ENSRNOMEM 174 /* Out of memory */
#define ENSRDESTRUCTION 175 /* Application terminated lookup */
#define ENSRQUERYDOMAINTOOLONG 176 /* Domain name is too long */
#define ENSRCNAMELOOP 177 /* Domain name is too long */
#endif /* _SYS_ERROR_H */

View file

@ -0,0 +1,60 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef LIBC_FCNTL_H__
#define LIBC_FCNTL_H__
#define O_RDONLY 00
#define O_WRONLY 01
#define O_RDWR 02
#define O_CREAT 0100
#define O_EXCL 0200
#define O_NOCTTY 0400
#define O_TRUNC 01000
#define O_APPEND 02000
#define O_NONBLOCK 04000
#define O_DSYNC 010000
#define O_SYNC 04010000
#define O_RSYNC 04010000
#define O_BINARY 0100000
#define O_DIRECTORY 0200000
#define O_NOFOLLOW 0400000
#define O_CLOEXEC 02000000
#define O_ASYNC 020000
#define O_DIRECT 040000
#define O_LARGEFILE 0100000
#define O_NOATIME 01000000
#define O_PATH 010000000
#define O_TMPFILE 020200000
#define O_NDELAY O_NONBLOCK
#define O_SEARCH O_PATH
#define O_EXEC O_PATH
#define O_ACCMODE (03|O_SEARCH)
#define F_DUPFD 0
#define F_GETFD 1
#define F_SETFD 2
#define F_GETFL 3
#define F_SETFL 4
#define F_SETOWN 8
#define F_GETOWN 9
#define F_SETSIG 10
#define F_GETSIG 11
#define F_GETLK 12
#define F_SETLK 13
#define F_SETLKW 14
#define F_SETOWN_EX 15
#define F_GETOWN_EX 16
#define F_GETOWNER_UIDS 17
#endif

View file

@ -0,0 +1,31 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
/* This header file provides the reentrancy. */
/* WARNING: All identifiers here must begin with an underscore. This file is
included by stdio.h and others and we therefore must only use identifiers
in the namespace allotted to us. */
#ifndef _SYS_REENT_H_
#ifdef __cplusplus
extern "C" {
#endif
#define _SYS_REENT_H_
#include <errno.h>
/* This version of _reent is laid out with "int"s in pairs, to help
* ports with 16-bit int's but 32-bit pointers, align nicely. */
struct _reent
{
/* As an exception to the above put _errno first for binary
compatibility with non _REENT_SMALL targets. */
int _errno; /* local copy of errno */
};
#ifdef __cplusplus
}
#endif
#endif /* _SYS_REENT_H_ */

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_SELECT_H__
#define _SYS_SELECT_H__
#ifndef FD_SETSIZE
#define FD_SETSIZE 32
#endif
#define NBBY 8 /* number of bits in a byte */
typedef long fd_mask;
#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x,y) (((x)+((y)-1))/(y))
#endif
/* We use a macro for fd_set so that including Sockets.h afterwards
can work. */
typedef struct _types_fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} _types_fd_set;
#define fd_set _types_fd_set
#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
#endif

View file

@ -0,0 +1,52 @@
#ifndef _SIGNAL_H_
#define _SIGNAL_H_
typedef void (*SIG_FUNC)(int);
#define SIGHUP 1
#define SIGINT 2
#define SIGQUIT 3
#define SIGILL 4
#define SIGTRAP 5
#define SIGABRT 6
#define SIGEMT 7
#define SIGFPE 8
#define SIGKILL 9
#define SIGBUS 10
#define SIGSEGV 11
#define SIGSYS 12
#define SIGPIPE 13
#define SIGALRM 14
#define SIGTERM 15
#define SIGURG 16
#define SIGSTOP 17
#define SIGTSTP 18
#define SIGCONT 19
#define SIGCHLD 20
#define SIGTTIN 21
#define SIGTTOU 22
#define SIGIO 23
#define SIGXCPU 24
#define SIGXFSZ 25
#define SIGVTALRM 26
#define SIGPROF 27
#define SIGWINCH 28
#define SIGINFO 29
#define SIGUSR1 30
#define SIGUSR2 31
#define SIGSCAN 32
#define SIGASSOC 33
#define SIGDISASSOC 34
#define SIGDEAUTH 35
#define SIGPOLL SIGIO
#define SIGPWR SIGINFO
#define SIGIOT SIGABRT
extern void signal(int sig_num, SIG_FUNC func);
extern unsigned int alarm(unsigned int seconds);
#endif
// eof

View file

@ -0,0 +1,57 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_STAT_H__
#define _SYS_STAT_H__
#define S_IFMT 00170000
#define S_IFSOCK 0140000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFBLK 0060000
#define S_IFDIR 0040000
#define S_IFCHR 0020000
#define S_IFIFO 0010000
#define S_ISUID 0004000
#define S_ISGID 0002000
#define S_ISVTX 0001000
#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
/* stat structure */
#include <stdint.h>
#include <time.h>
struct stat
{
struct rt_device* st_dev;
uint16_t st_mode;
uint32_t st_size;
time_t st_mtime;
uint32_t st_blksize;
};
#endif

View file

@ -0,0 +1,49 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_TIME_H_
#define _SYS_TIME_H_
#include <time.h>
#include <sys/types.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
/*
* Structure returned by gettimeofday(2) system call,
* and used in other calls.
*/
struct timeval {
long tv_sec; /* seconds */
long tv_usec; /* and microseconds */
};
#endif /* _TIMEVAL_DEFINED */
#ifndef _TIMESPEC_DEFINED
#define _TIMESPEC_DEFINED
/*
* Structure defined by POSIX.1b to be like a timeval.
*/
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* and nanoseconds */
};
#endif /* _TIMESPEC_DEFINED */
struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tp, void *ignore);
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIME_H_ */

View file

@ -0,0 +1,33 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
#include <stdint.h>
#ifndef _PARAMS
#define _PARAMS(paramlist) paramlist
#endif
#define _CLOCK_T_ uint32_t
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
typedef uint32_t clockid_t;
typedef uint32_t key_t; /* Used for interprocess communication. */
typedef uint32_t pid_t; /* Used for process IDs and process group IDs. */
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
typedef long long off_t;
typedef long suseconds_t;
typedef uint32_t _off_t;
typedef uint32_t _ssize_t;
#ifndef PATH_MAX
#define PATH_MAX 1024
#endif
#if __BSD_VISIBLE
#include <sys/select.h>
#endif
#endif /* _SYS_TYPES_H */

View file

@ -0,0 +1,9 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _SYS_UNISTD_H
#define _SYS_UNISTD_H
#endif /* _SYS_UNISTD_H */

View file

@ -0,0 +1,5 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "sys/unistd.h"

View file

@ -0,0 +1,15 @@
NAME := newlib_stub
ifeq ($(COMPILER),armcc)
$(NAME)_TYPE := share
$(NAME)_SOURCES := compilers/armlibc/armcc_libc.c
GLOBAL_INCLUDES += compilers/armlibc
else ifeq ($(COMPILER),iar)
$(NAME)_TYPE := share
GLOBAL_INCLUDES += compilers/iar
$(NAME)_SOURCES := compilers/iar/iar_libc.c
else ifneq ($(HOST_MCU_FAMILY),linux)
$(NAME)_TYPE := share
$(NAME)_MBINS_TYPE := share
$(NAME)_SOURCES := newlib_stub.c
endif

View file

@ -0,0 +1,246 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include <reent.h>
#include <sys/errno.h>
#include <sys/unistd.h>
#include <sys/time.h>
#include <k_api.h>
#include <aos/aos.h>
#include "hal/soc/soc.h"
#ifdef AOS_BINS
extern uart_dev_t uart_0;
#endif
int _execve_r(struct _reent *ptr, const char *name, char *const *argv, char *const *env)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _fcntl_r(struct _reent *ptr, int fd, int cmd, int arg)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _fork_r(struct _reent *ptr)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _getpid_r(struct _reent *ptr)
{
ptr->_errno = ENOTSUP;
return 0;
}
int _isatty_r(struct _reent *ptr, int fd)
{
if (fd >= 0 && fd < 3) {
return 1;
}
ptr->_errno = ENOTSUP;
return -1;
}
int _kill_r(struct _reent *ptr, int pid, int sig)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _link_r(struct _reent *ptr, const char *old, const char *new)
{
ptr->_errno = ENOTSUP;
return -1;
}
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
{
ptr->_errno = ENOTSUP;
return 0;
}
int _mkdir_r(struct _reent *ptr, const char *name, int mode)
{
ptr->_errno = ENOTSUP;
return 0;
}
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
{
ptr->_errno = ENOTSUP;
return 0;
}
int _close_r(struct _reent *ptr, int fd)
{
ptr->_errno = ENOTSUP;
return 0;
}
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
ptr->_errno = ENOTSUP;
return 0;
}
/*
* implement _write_r here
*/
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
const char *tmp = buf;
int i;
switch (fd) {
case STDOUT_FILENO: /*stdout*/
case STDERR_FILENO: /* stderr */
break;
default:
set_errno(EBADF);
return -1;
}
for (i = 0; i < nbytes; i++) {
if (*tmp == '\n') {
#ifdef AOS_BINS
hal_uart_send(&uart_0, (void *)"\r", 1, 0);
#else
aos_uart_send((void *)"\r", 1, 0);
#endif
}
#ifdef AOS_BINS
hal_uart_send(&uart_0, (void *)tmp, 1, 0);
#else
aos_uart_send((void *)tmp, 1, 0);
#endif
tmp ++;
}
return nbytes;
}
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _rename_r(struct _reent *ptr, const char *old, const char *new)
{
ptr->_errno = ENOTSUP;
return 0;
}
void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
{
ptr->_errno = ENOTSUP;
return NULL;
}
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
{
ptr->_errno = ENOTSUP;
return 0;
}
_CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _unlink_r(struct _reent *ptr, const char *file)
{
ptr->_errno = ENOTSUP;
return 0;
}
int _wait_r(struct _reent *ptr, int *status)
{
ptr->_errno = ENOTSUP;
return -1;
}
int _gettimeofday_r(struct _reent *ptr, struct timeval *tv, void *__tzp)
{
uint64_t t = aos_now_ms();
tv->tv_sec = t / 1000;
tv->tv_usec = (t % 1000) * 1000;
return 0;
}
void *_malloc_r(struct _reent *ptr, size_t size)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc(size | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_malloc(size);
#endif
return mem;
}
void *_realloc_r(struct _reent *ptr, void *old, size_t newlen)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_realloc(old, newlen | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_realloc(old, newlen);
#endif
return mem;
}
void *_calloc_r(struct _reent *ptr, size_t size, size_t len)
{
void *mem;
#if (RHINO_CONFIG_MM_DEBUG > 0u && RHINO_CONFIG_GCC_RETADDR > 0u)
mem = aos_malloc((size * len) | AOS_UNSIGNED_INT_MSB);
aos_alloc_trace(mem, (size_t)__builtin_return_address(0));
#else
mem = aos_malloc(size * len);
#endif
if (mem) {
bzero(mem, size * len);
}
return mem;
}
void _free_r(struct _reent *ptr, void *addr)
{
aos_free(addr);
}
void _exit(int status)
{
while (1);
}
void _system(const char *s)
{
return;
}
void abort(void)
{
while (1);
}

View file

@ -0,0 +1,25 @@
src = []
include_tmp = []
if aos_global_config.compiler == 'armcc':
src = Split('''
compilers/armlibc/armcc_libc.c
''')
include_tmp = Split('''
compilers/armlibc
''')
elif aos_global_config.compiler == 'iar':
src = Split('''
compilers/iar/iar_libc.c
''')
include_tmp = Split('''
compilers/iar
''')
elif aos_global_config.board != 'linuxhost':
src = Split('''
newlib_stub.c
''')
component = aos_component('newlib_stub', src)
for i in include_tmp:
component.add_global_includes(i)