Newlib: implement locks

* Dynamically allocate arc4random data. Saves about 1k off the bss.
This commit is contained in:
Our Air Quality 2017-12-09 00:45:57 +11:00
parent 89c6c410ff
commit e9d9201527
24 changed files with 3442 additions and 44 deletions

View file

@ -52,17 +52,29 @@ extern "C" {
#define _FNOFOLLOW 0x100000
#define _FDIRECTORY 0x200000
#define _FEXECSRCH 0x400000
#define _FTMPFILE 0x800000
#define _FNOATIME 0x1000000
#define O_BINARY _FBINARY
#define O_TEXT _FTEXT
#define O_CLOEXEC _FNOINHERIT
#define O_DIRECT _FDIRECT
#define O_NOFOLLOW _FNOFOLLOW
#define O_DSYNC _FSYNC
#define O_RSYNC _FSYNC
#define O_DIRECTORY _FDIRECTORY
#define O_EXEC _FEXECSRCH
#define O_SEARCH _FEXECSRCH
/* POSIX-1.2008 specific flags */
#if __POSIX_VISIBLE >= 200809
#define O_CLOEXEC _FNOINHERIT
#define O_NOFOLLOW _FNOFOLLOW
#define O_DIRECTORY _FDIRECTORY
#endif
/* Linux-specific flags */
#if __GNU_VISIBLE
#define O_DIRECT _FDIRECT
#define O_TMPFILE _FTMPFILE
#define O_NOATIME _FNOATIME
#endif
#endif
#if __MISC_VISIBLE

View file

@ -397,7 +397,7 @@
#endif
#if __GNUC_PREREQ__(3, 3)
#define __nonnull(x) __attribute__((__nonnull__(x)))
#define __nonnull(x) __attribute__((__nonnull__ x))
#define __nonnull_all __attribute__((__nonnull__))
#else
#define __nonnull(x)

View file

@ -100,6 +100,9 @@ extern "C" {
* _SVID_SOURCE (deprecated by _DEFAULT_SOURCE)
* _DEFAULT_SOURCE (or none of the above)
* POSIX-1.2008 with BSD and SVr4 extensions
*
* _FORTIFY_SOURCE = 1 or 2
* Object Size Checking function wrappers
*/
#ifdef _GNU_SOURCE
@ -233,9 +236,11 @@ extern "C" {
* __GNU_VISIBLE
* GNU extensions; enabled with _GNU_SOURCE.
*
* __SSP_FORTIFY_LEVEL
* Object Size Checking; defined to 0 (off), 1, or 2.
*
* In all cases above, "enabled by default" means either by defining
* _DEFAULT_SOURCE, or by not defining any of the public feature test macros.
* Defining _GNU_SOURCE makes all of the above avaliable.
*/
#ifdef _ATFILE_SOURCE
@ -314,6 +319,17 @@ extern "C" {
#define __XSI_VISIBLE 0
#endif
#if _FORTIFY_SOURCE > 0 && !defined(__cplusplus) && !defined(__lint__) && \
(__OPTIMIZE__ > 0 || defined(__clang__)) && __GNUC_PREREQ__(4, 1)
# if _FORTIFY_SOURCE > 1
# define __SSP_FORTIFY_LEVEL 2
# else
# define __SSP_FORTIFY_LEVEL 1
# endif
#else
# define __SSP_FORTIFY_LEVEL 0
#endif
/* RTEMS adheres to POSIX -- 1003.1b with some features from annexes. */
#ifdef __rtems__
@ -448,7 +464,7 @@ extern "C" {
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
/* #define _POSIX_THREAD_SPORADIC_SERVER -1 */
#define _POSIX_THREADS 200809L
/* #define _POSIX_TIMEOUTS -1 */
#define _POSIX_TIMEOUTS 200809L
#define _POSIX_TIMERS 200809L
/* #define _POSIX_TRACE -1 */
/* #define _POSIX_TRACE_EVENT_FILTER -1 */

View file

@ -22,8 +22,17 @@ typedef _lock_t _LOCK_T;
Lock functions all take a pointer to the _lock_t entry, so the
value stored there can be manipulated.
*/
#if 0
#define __LOCK_INIT(CLASS,NAME) CLASS _lock_t NAME = 0;
#define __LOCK_INIT_RECURSIVE(CLASS,NAME) CLASS _lock_t NAME = 0;
#else
/*
* Skip a 'static' class definition, so they are all visible and can
* be initialize at startup.
*/
#define __LOCK_INIT(CLASS,NAME) _lock_t NAME = 0;
#define __LOCK_INIT_RECURSIVE(CLASS,NAME) _lock_t NAME = 0;
#endif
void _lock_init(_lock_t *lock);
void _lock_init_recursive(_lock_t *lock);

View file

@ -73,13 +73,17 @@ int _EXFUN(execvpe, (const char *__file, char * const __argv[], char * const
#if __ATFILE_VISIBLE
int _EXFUN(faccessat, (int __dirfd, const char *__path, int __mode, int __flags));
#endif
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
int _EXFUN(fchdir, (int __fildes));
#endif
#if __POSIX_VISIBLE >= 199309
int _EXFUN(fchmod, (int __fildes, mode_t __mode ));
#endif
#if !defined(__INSIDE_CYGWIN__)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
int _EXFUN(fchown, (int __fildes, uid_t __owner, gid_t __group ));
#endif
#endif
#if __ATFILE_VISIBLE
int _EXFUN(fchownat, (int __dirfd, const char *__path, uid_t __owner, gid_t __group, int __flags));
#endif
@ -89,7 +93,9 @@ int _EXFUN(fexecve, (int __fd, char * const __argv[], char * const __envp[] ));
pid_t _EXFUN(fork, (void ));
long _EXFUN(fpathconf, (int __fd, int __name ));
int _EXFUN(fsync, (int __fd));
#if __POSIX_VISIBLE >= 199309
int _EXFUN(fdatasync, (int __fd));
#endif
#if __GNU_VISIBLE
char * _EXFUN(get_current_dir_name, (void));
#endif
@ -113,12 +119,16 @@ char * _EXFUN(getlogin, (void ));
#if defined(_POSIX_THREAD_SAFE_FUNCTIONS)
int _EXFUN(getlogin_r, (char *name, size_t namesize) );
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
char * _EXFUN(getpass, (const char *__prompt));
int _EXFUN(getpagesize, (void));
#endif
#if __BSD_VISIBLE
int _EXFUN(getpeereid, (int, uid_t *, gid_t *));
#endif
#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 4
pid_t _EXFUN(getpgid, (pid_t));
#endif
pid_t _EXFUN(getpgrp, (void ));
pid_t _EXFUN(getpid, (void ));
pid_t _EXFUN(getppid, (void ));
@ -142,13 +152,17 @@ int _EXFUN(isatty, (int __fildes ));
int _EXFUN(issetugid, (void));
#endif
#if !defined(__INSIDE_CYGWIN__)
#if __BSD_VISIBLE || __XSI_VISIBLE >= 4 || __POSIX_VISIBLE >= 200809
int _EXFUN(lchown, (const char *__path, uid_t __owner, gid_t __group ));
#endif
#endif
int _EXFUN(link, (const char *__path1, const char *__path2 ));
#if __ATFILE_VISIBLE
int _EXFUN(linkat, (int __dirfd1, const char *__path1, int __dirfd2, const char *__path2, int __flags ));
#endif
#if __MISC_VISIBLE || __XSI_VISIBLE
int _EXFUN(nice, (int __nice_value ));
#endif
#if !defined(__INSIDE_CYGWIN__)
off_t _EXFUN(lseek, (int __fildes, off_t __offset, int __whence ));
#endif
@ -168,8 +182,10 @@ int _EXFUN(pipe, (int __fildes[2] ));
#if __GNU_VISIBLE
int _EXFUN(pipe2, (int __fildes[2], int flags));
#endif
#if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE >= 500
ssize_t _EXFUN(pread, (int __fd, void *__buf, size_t __nbytes, off_t __offset));
ssize_t _EXFUN(pwrite, (int __fd, const void *__buf, size_t __nbytes, off_t __offset));
#endif
_READ_WRITE_RETURN_TYPE _EXFUN(read, (int __fd, void *__buf, size_t __nbyte ));
#if __BSD_VISIBLE
int _EXFUN(rresvport, (int *__alport));
@ -179,7 +195,9 @@ int _EXFUN(rmdir, (const char *__path ));
#if __BSD_VISIBLE
int _EXFUN(ruserok, (const char *rhost, int superuser, const char *ruser, const char *luser));
#endif
#if __BSD_VISIBLE || (__XSI_VISIBLE >= 4 && __POSIX_VISIBLE < 200112)
void * _EXFUN(sbrk, (ptrdiff_t __incr));
#endif
#if !defined(__INSIDE_CYGWIN__)
#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112
int _EXFUN(setegid, (gid_t __gid ));
@ -194,7 +212,9 @@ int _EXFUN(setgroups, (int ngroups, const gid_t *grouplist ));
int _EXFUN(sethostname, (const char *, size_t));
#endif
int _EXFUN(setpgid, (pid_t __pid, pid_t __pgid ));
#if __SVID_VISIBLE || __XSI_VISIBLE >= 500
int _EXFUN(setpgrp, (void ));
#endif
#if (__BSD_VISIBLE || __XSI_VISIBLE >= 4) && !defined(__INSIDE_CYGWIN__)
int _EXFUN(setregid, (gid_t __rgid, gid_t __egid));
int _EXFUN(setreuid, (uid_t __ruid, uid_t __euid));
@ -567,4 +587,9 @@ int _EXFUN(unlinkat, (int, const char *, int));
#ifdef __cplusplus
}
#endif
#if __SSP_FORTIFY_LEVEL > 0
#include <ssp/unistd.h>
#endif
#endif /* _SYS_UNISTD_H */