Merge pull request #1 from EOSIO/musl-cleanup

Musl cleanup
This commit is contained in:
wanderingbort
2018-02-12 13:32:21 -05:00
committed by GitHub
52 changed files with 110 additions and 7598 deletions
-25
View File
@@ -1,25 +0,0 @@
#ifndef _AR_H
#define _AR_H
#ifdef __cplusplus
extern "C" {
#endif
#define ARMAG "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"
struct ar_hdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6], ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
#ifdef __cplusplus
}
#endif
#endif
-29
View File
@@ -1,29 +0,0 @@
#ifndef _CPIO_H
#define _CPIO_H
#define MAGIC "070707"
#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001
#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000
#define C_ISBLK 060000
#define C_ISCHR 020000
#define C_ISDIR 040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK 0120000
#define C_ISCTG 0110000
#define C_ISREG 0100000
#endif
-3121
View File
File diff suppressed because it is too large Load Diff
-24
View File
@@ -1,24 +0,0 @@
#ifndef _FNMATCH_H
#define _FNMATCH_H
#ifdef __cplusplus
extern "C" {
#endif
#define FNM_PATHNAME 0x1
#define FNM_NOESCAPE 0x2
#define FNM_PERIOD 0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD 0x10
#define FNM_FILE_NAME FNM_PATHNAME
#define FNM_NOMATCH 1
#define FNM_NOSYS (-1)
int fnmatch(const char *, const char *, int);
#ifdef __cplusplus
}
#endif
#endif
-24
View File
@@ -1,24 +0,0 @@
#ifndef _ICONV_H
#define _ICONV_H
#ifdef __cplusplus
extern "C" {
#endif
#include <features.h>
#define __NEED_size_t
#include <bits/alltypes.h>
typedef void *iconv_t;
iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict);
int iconv_close(iconv_t);
#ifdef __cplusplus
}
#endif
#endif
+1 -4
View File
@@ -13,12 +13,9 @@ void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
void free (void *);
/*
void *valloc (size_t);
void *memalign(size_t, size_t);
size_t malloc_usable_size(void *);
*/
#ifdef __cplusplus
}
#endif
-36
View File
@@ -1,36 +0,0 @@
#ifndef _MQUEUE_H
#define _MQUEUE_H
#ifdef __cplusplus
extern "C" {
#endif
#include <features.h>
#define __NEED_size_t
#define __NEED_ssize_t
#define __NEED_pthread_attr_t
#define __NEED_time_t
#define __NEED_struct_timespec
#include <bits/alltypes.h>
typedef int mqd_t;
struct mq_attr {
long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4];
};
struct sigevent;
int mq_close(mqd_t);
int mq_getattr(mqd_t, struct mq_attr *);
int mq_notify(mqd_t, const struct sigevent *);
mqd_t mq_open(const char *, int, ...);
ssize_t mq_receive(mqd_t, char *, size_t, unsigned *);
int mq_send(mqd_t, const char *, size_t, unsigned);
int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict);
ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict);
int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *);
int mq_unlink(const char *);
#ifdef __cplusplus
}
#endif
#endif
-62
View File
@@ -1,62 +0,0 @@
#ifndef _REGEX_H
#define _REGEX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <features.h>
#define __NEED_regoff_t
#define __NEED_size_t
#include <bits/alltypes.h>
typedef struct re_pattern_buffer {
size_t re_nsub;
void *__opaque, *__padding[4];
size_t __nsub2;
char __padding2;
} regex_t;
typedef struct {
regoff_t rm_so;
regoff_t rm_eo;
} regmatch_t;
#define REG_EXTENDED 1
#define REG_ICASE 2
#define REG_NEWLINE 4
#define REG_NOSUB 8
#define REG_NOTBOL 1
#define REG_NOTEOL 2
#define REG_OK 0
#define REG_NOMATCH 1
#define REG_BADPAT 2
#define REG_ECOLLATE 3
#define REG_ECTYPE 4
#define REG_EESCAPE 5
#define REG_ESUBREG 6
#define REG_EBRACK 7
#define REG_EPAREN 8
#define REG_EBRACE 9
#define REG_BADBR 10
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
#define REG_ENOSYS -1
int regcomp(regex_t *__restrict, const char *__restrict, int);
int regexec(const regex_t *__restrict, const char *__restrict, size_t, regmatch_t *__restrict, int);
void regfree(regex_t *);
size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t);
#ifdef __cplusplus
}
#endif
#endif
-30
View File
@@ -60,13 +60,6 @@ extern FILE *const stderr;
#define stdout (stdout)
#define stderr (stderr)
//FILE *fopen(const char *__restrict, const char *__restrict);
//FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict);
int fclose(FILE *);
int remove(const char *);
int rename(const char *, const char *);
int feof(FILE *);
int ferror(FILE *);
int fflush(FILE *);
@@ -121,46 +114,25 @@ void perror(const char *);
int setvbuf(FILE *__restrict, char *__restrict, int, size_t);
void setbuf(FILE *__restrict, char *__restrict);
char *tmpnam(char *);
FILE *tmpfile(void);
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
FILE *fmemopen(void *__restrict, size_t, const char *__restrict);
FILE *open_memstream(char **, size_t *);
FILE *fdopen(int, const char *);
//FILE *popen(const char *, const char *);
//int pclose(FILE *);
int fileno(FILE *);
int fseeko(FILE *, off_t, int);
off_t ftello(FILE *);
int dprintf(int, const char *__restrict, ...);
int vdprintf(int, const char *__restrict, __isoc_va_list);
void flockfile(FILE *);
int ftrylockfile(FILE *);
void funlockfile(FILE *);
int getc_unlocked(FILE *);
int getchar_unlocked(void);
int putc_unlocked(int, FILE *);
int putchar_unlocked(int);
ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict);
ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict);
int renameat(int, const char *, int, const char *);
char *ctermid(char *);
#define L_ctermid 20
#endif
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
#define P_tmpdir "/tmp"
char *tempnam(const char *, const char *);
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define L_cuserid 20
char *cuserid(char *);
void setlinebuf(FILE *);
void setbuffer(FILE *, char *, size_t);
int fgetc_unlocked(FILE *);
@@ -200,8 +172,6 @@ FILE *fopencookie(void *, const char *, cookie_io_functions_t);
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define tmpfile64 tmpfile
#define fopen64 fopen
#define freopen64 freopen
#define fseeko64 fseeko
#define ftello64 ftello
#define fgetpos64 fgetpos
-56
View File
@@ -32,9 +32,6 @@ unsigned long strtoul (const char *__restrict, char **__restrict, int);
long long strtoll (const char *__restrict, char **__restrict, int);
unsigned long long strtoull (const char *__restrict, char **__restrict, int);
int rand (void);
void srand (unsigned);
void *malloc (size_t);
void *calloc (size_t, size_t);
void *realloc (void *, size_t);
@@ -86,65 +83,21 @@ size_t __ctype_get_mb_cur_max(void);
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
#define WNOHANG 1
#define WUNTRACED 2
#define WEXITSTATUS(s) (((s) & 0xff00) >> 8)
#define WTERMSIG(s) ((s) & 0x7f)
#define WSTOPSIG(s) WEXITSTATUS(s)
#define WIFEXITED(s) (!WTERMSIG(s))
#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
int posix_memalign (void **, size_t, size_t);
int setenv (const char *, const char *, int);
int unsetenv (const char *);
int mkstemp (char *);
int mkostemp (char *, int);
char *mkdtemp (char *);
int getsubopt (char **, char *const *, char **);
int rand_r (unsigned *);
#endif
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
char *realpath (const char *__restrict, char *__restrict);
long int random (void);
void srandom (unsigned int);
char *initstate (unsigned int, char *, size_t);
char *setstate (char *);
int putenv (char *);
int posix_openpt (int);
int grantpt (int);
int unlockpt (int);
char *ptsname (int);
char *l64a (long);
long a64l (const char *);
void setkey (const char *);
double drand48 (void);
double erand48 (unsigned short [3]);
long int lrand48 (void);
long int nrand48 (unsigned short [3]);
long mrand48 (void);
long jrand48 (unsigned short [3]);
void srand48 (long);
unsigned short *seed48 (unsigned short [3]);
void lcong48 (unsigned short [7]);
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#include <alloca.h>
char *mktemp (char *);
int mkstemps (char *, int);
int mkostemps (char *, int, int);
void *valloc (size_t);
void *memalign(size_t, size_t);
int getloadavg(double *, int);
int clearenv(void);
#define WCOREDUMP(s) ((s) & 0x80)
#define WIFCONTINUED(s) ((s) == 0xffff)
#endif
#ifdef _GNU_SOURCE
@@ -158,15 +111,6 @@ struct __locale_struct;
//long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *);
#endif
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define mkstemp64 mkstemp
#define mkostemp64 mkostemp
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define mkstemps64 mkstemps
#define mkostemps64 mkostemps
#endif
#endif
#ifdef __cplusplus
}
#endif
-1
View File
@@ -93,7 +93,6 @@ void *memmem(const void *, size_t, const void *, size_t);
void *memrchr(const void *, int, size_t);
void *mempcpy(void *, const void *, size_t);
#ifndef __cplusplus
char *basename();
#endif
#endif
-139
View File
@@ -1,139 +0,0 @@
#ifndef _STROPTS_H
#define _STROPTS_H
#ifdef __cplusplus
extern "C" {
#endif
#define __SID ('S' << 8)
#define I_NREAD (__SID | 1)
#define I_PUSH (__SID | 2)
#define I_POP (__SID | 3)
#define I_LOOK (__SID | 4)
#define I_FLUSH (__SID | 5)
#define I_SRDOPT (__SID | 6)
#define I_GRDOPT (__SID | 7)
#define I_STR (__SID | 8)
#define I_SETSIG (__SID | 9)
#define I_GETSIG (__SID |10)
#define I_FIND (__SID |11)
#define I_LINK (__SID |12)
#define I_UNLINK (__SID |13)
#define I_PEEK (__SID |15)
#define I_FDINSERT (__SID |16)
#define I_SENDFD (__SID |17)
#define I_RECVFD (__SID |14)
#define I_SWROPT (__SID |19)
#define I_GWROPT (__SID |20)
#define I_LIST (__SID |21)
#define I_PLINK (__SID |22)
#define I_PUNLINK (__SID |23)
#define I_FLUSHBAND (__SID |28)
#define I_CKBAND (__SID |29)
#define I_GETBAND (__SID |30)
#define I_ATMARK (__SID |31)
#define I_SETCLTIME (__SID |32)
#define I_GETCLTIME (__SID |33)
#define I_CANPUT (__SID |34)
#define FMNAMESZ 8
#define FLUSHR 0x01
#define FLUSHW 0x02
#define FLUSHRW 0x03
#define FLUSHBAND 0x04
#define S_INPUT 0x0001
#define S_HIPRI 0x0002
#define S_OUTPUT 0x0004
#define S_MSG 0x0008
#define S_ERROR 0x0010
#define S_HANGUP 0x0020
#define S_RDNORM 0x0040
#define S_WRNORM S_OUTPUT
#define S_RDBAND 0x0080
#define S_WRBAND 0x0100
#define S_BANDURG 0x0200
#define RS_HIPRI 0x01
#define RNORM 0x0000
#define RMSGD 0x0001
#define RMSGN 0x0002
#define RPROTDAT 0x0004
#define RPROTDIS 0x0008
#define RPROTNORM 0x0010
#define RPROTMASK 0x001C
#define SNDZERO 0x001
#define SNDPIPE 0x002
#define ANYMARK 0x01
#define LASTMARK 0x02
#define MUXID_ALL (-1)
#define MSG_HIPRI 0x01
#define MSG_ANY 0x02
#define MSG_BAND 0x04
#define MORECTL 1
#define MOREDATA 2
struct bandinfo {
unsigned char bi_pri;
int bi_flag;
};
struct strbuf {
int maxlen;
int len;
char *buf;
};
struct strpeek {
struct strbuf ctlbuf;
struct strbuf databuf;
unsigned flags;
};
struct strfdinsert {
struct strbuf ctlbuf;
struct strbuf databuf;
unsigned flags;
int fildes;
int offset;
};
struct strioctl {
int ic_cmd;
int ic_timout;
int ic_len;
char *ic_dp;
};
struct strrecvfd {
int fd;
int uid;
int gid;
char __fill[8];
};
struct str_mlist {
char l_name[FMNAMESZ + 1];
};
struct str_list {
int sl_nmods;
struct str_mlist *sl_modlist;
};
int isastream(int);
int ioctl(int, int, ...);
#ifdef __cplusplus
}
#endif
#endif
-21
View File
@@ -1,21 +0,0 @@
#ifndef _SYSEXITS_H
#define _SYSEXITS_H
#define EX_OK 0
#define EX__BASE 64
#define EX_USAGE 64
#define EX_DATAERR 65
#define EX_NOINPUT 66
#define EX_NOUSER 67
#define EX_NOHOST 68
#define EX_UNAVAILABLE 69
#define EX_SOFTWARE 70
#define EX_OSERR 71
#define EX_OSFILE 72
#define EX_CANTCREAT 73
#define EX_IOERR 74
#define EX_TEMPFAIL 75
#define EX_PROTOCOL 76
#define EX_NOPERM 77
#define EX_CONFIG 78
#define EX__MAX 78
#endif
-33
View File
@@ -1,33 +0,0 @@
#ifndef _TAR_H
#define _TAR_H
#define TSUID 04000
#define TSGID 02000
#define TSVTX 01000
#define TUREAD 00400
#define TUWRITE 00200
#define TUEXEC 00100
#define TGREAD 00040
#define TGWRITE 00020
#define TGEXEC 00010
#define TOREAD 00004
#define TOWRITE 00002
#define TOEXEC 00001
#define REGTYPE '0'
#define AREGTYPE '\0'
#define LNKTYPE '1'
#define SYMTYPE '2'
#define CHRTYPE '3'
#define BLKTYPE '4'
#define DIRTYPE '5'
#define FIFOTYPE '6'
#define CONTTYPE '7'
#define TMAGIC "ustar"
#define TMAGLEN 6
#define TVERSION "00"
#define TVERSLEN 2
#endif
+1 -56
View File
@@ -48,18 +48,11 @@ struct tm {
long __tm_gmtoff;
const char *__tm_zone;
};
/*
clock_t clock (void);
time_t time (time_t *);
*/
double difftime (time_t, time_t);
time_t mktime (struct tm *);
size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict);
struct tm *gmtime (const time_t *);
struct tm *localtime (const time_t *);
char *asctime (const struct tm *);
char *ctime (const time_t *);
int timespec_get(struct timespec *, int);
#define CLOCKS_PER_SEC 1000000L
@@ -72,68 +65,20 @@ int timespec_get(struct timespec *, int);
size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t);
struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict);
struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict);
char *asctime_r (const struct tm *__restrict, char *__restrict);
char *ctime_r (const time_t *, char *);
/*
void tzset (void);
*/
struct itimerspec {
struct timespec it_interval;
struct timespec it_value;
};
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 1
#define CLOCK_PROCESS_CPUTIME_ID 2
#define CLOCK_THREAD_CPUTIME_ID 3
#define CLOCK_MONOTONIC_RAW 4
#define CLOCK_REALTIME_COARSE 5
#define CLOCK_MONOTONIC_COARSE 6
#define CLOCK_BOOTTIME 7
#define CLOCK_REALTIME_ALARM 8
#define CLOCK_BOOTTIME_ALARM 9
#define CLOCK_SGI_CYCLE 10
#define CLOCK_TAI 11
#define TIMER_ABSTIME 1
/*
int nanosleep (const struct timespec *, struct timespec *);
int clock_getres (clockid_t, struct timespec *);
int clock_gettime (clockid_t, struct timespec *);
int clock_settime (clockid_t, const struct timespec *);
int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *);
int clock_getcpuclockid (pid_t, clockid_t *);
struct sigevent;
int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict);
int timer_delete (timer_t);
int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict);
int timer_gettime (timer_t, struct itimerspec *);
int timer_getoverrun (timer_t);
extern char *tzname[2];
*/
#endif
#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict);
/*
extern int daylight;
extern long timezone;
extern int getdate_err;
struct tm *getdate (const char *);
*/
#endif
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
/*
int stime(const time_t *);
time_t timegm(struct tm *);
*/
#endif
#ifdef __cplusplus
+3 -1
View File
@@ -87,10 +87,12 @@ size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict);
size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict);
size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict);
/* waiting for soft float*/
float wcstof (const wchar_t *__restrict, wchar_t **__restrict);
double wcstod (const wchar_t *__restrict, wchar_t **__restrict);
long double wcstold (const wchar_t *__restrict, wchar_t **__restrict);
/**/
long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int);
unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int);
-41
View File
@@ -1,41 +0,0 @@
#ifndef _WORDEXP_H
#define _WORDEXP_H
#ifdef __cplusplus
extern "C" {
#endif
#include <features.h>
#define __NEED_size_t
#include <bits/alltypes.h>
#define WRDE_DOOFFS 1
#define WRDE_APPEND 2
#define WRDE_NOCMD 4
#define WRDE_REUSE 8
#define WRDE_SHOWERR 16
#define WRDE_UNDEF 32
typedef struct {
size_t we_wordc;
char **we_wordv;
size_t we_offs;
} wordexp_t;
#define WRDE_NOSYS -1
#define WRDE_NOSPACE 1
#define WRDE_BADCHAR 2
#define WRDE_BADVAL 3
#define WRDE_CMDSUB 4
#define WRDE_SYNTAX 5
int wordexp (const char *__restrict, wordexp_t *__restrict, int);
void wordfree (wordexp_t *);
#ifdef __cplusplus
}
#endif
#endif
-148
View File
@@ -1,148 +0,0 @@
#include <stddef.h>
#include "dynlink.h"
#ifndef START
#define START "_dlstart"
#endif
#define SHARED
#include "crt_arch.h"
#ifndef GETFUNCSYM
#define GETFUNCSYM(fp, sym, got) do { \
__attribute__((__visibility__("hidden"))) void sym(); \
static void (*static_func_ptr)() = sym; \
__asm__ __volatile__ ( "" : "+m"(static_func_ptr) : : "memory"); \
*(fp) = static_func_ptr; } while(0)
#endif
__attribute__((__visibility__("hidden")))
void _dlstart_c(size_t *sp, size_t *dynv)
{
size_t i, aux[AUX_CNT], dyn[DYN_CNT];
size_t *rel, rel_size, base;
int argc = *sp;
char **argv = (void *)(sp+1);
for (i=argc+1; argv[i]; i++);
size_t *auxv = (void *)(argv+i+1);
for (i=0; i<AUX_CNT; i++) aux[i] = 0;
for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT)
aux[auxv[i]] = auxv[i+1];
#if DL_FDPIC
struct fdpic_loadseg *segs, fakeseg;
size_t j;
if (dynv) {
/* crt_arch.h entry point asm is responsible for reserving
* space and moving the extra fdpic arguments to the stack
* vector where they are easily accessible from C. */
segs = ((struct fdpic_loadmap *)(sp[-1] ? sp[-1] : sp[-2]))->segs;
} else {
/* If dynv is null, the entry point was started from loader
* that is not fdpic-aware. We can assume normal fixed-
* displacement ELF loading was performed, but when ldso was
* run as a command, finding the Ehdr is a heursitic: we
* have to assume Phdrs start in the first 4k of the file. */
base = aux[AT_BASE];
if (!base) base = aux[AT_PHDR] & -4096;
segs = &fakeseg;
segs[0].addr = base;
segs[0].p_vaddr = 0;
segs[0].p_memsz = -1;
Ehdr *eh = (void *)base;
Phdr *ph = (void *)(base + eh->e_phoff);
size_t phnum = eh->e_phnum;
size_t phent = eh->e_phentsize;
while (phnum-- && ph->p_type != PT_DYNAMIC)
ph = (void *)((size_t)ph + phent);
dynv = (void *)(base + ph->p_vaddr);
}
#endif
for (i=0; i<DYN_CNT; i++) dyn[i] = 0;
for (i=0; dynv[i]; i+=2) if (dynv[i]<DYN_CNT)
dyn[dynv[i]] = dynv[i+1];
#if DL_FDPIC
for (i=0; i<DYN_CNT; i++) {
if (i==DT_RELASZ || i==DT_RELSZ) continue;
if (!dyn[i]) continue;
for (j=0; dyn[i]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
dyn[i] += segs[j].addr - segs[j].p_vaddr;
}
base = 0;
const Sym *syms = (void *)dyn[DT_SYMTAB];
rel = (void *)dyn[DT_RELA];
rel_size = dyn[DT_RELASZ];
for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
if (!IS_RELATIVE(rel[1], syms)) continue;
for (j=0; rel[0]-segs[j].p_vaddr >= segs[j].p_memsz; j++);
size_t *rel_addr = (void *)
(rel[0] + segs[j].addr - segs[j].p_vaddr);
if (R_TYPE(rel[1]) == REL_FUNCDESC_VAL) {
*rel_addr += segs[rel_addr[1]].addr
- segs[rel_addr[1]].p_vaddr
+ syms[R_SYM(rel[1])].st_value;
rel_addr[1] = dyn[DT_PLTGOT];
} else {
size_t val = syms[R_SYM(rel[1])].st_value;
for (j=0; val-segs[j].p_vaddr >= segs[j].p_memsz; j++);
*rel_addr = rel[2] + segs[j].addr - segs[j].p_vaddr + val;
}
}
#else
/* If the dynamic linker is invoked as a command, its load
* address is not available in the aux vector. Instead, compute
* the load address as the difference between &_DYNAMIC and the
* virtual address in the PT_DYNAMIC program header. */
base = aux[AT_BASE];
if (!base) {
size_t phnum = aux[AT_PHNUM];
size_t phentsize = aux[AT_PHENT];
Phdr *ph = (void *)aux[AT_PHDR];
for (i=phnum; i--; ph = (void *)((char *)ph + phentsize)) {
if (ph->p_type == PT_DYNAMIC) {
base = (size_t)dynv - ph->p_vaddr;
break;
}
}
}
/* MIPS uses an ugly packed form for GOT relocations. Since we
* can't make function calls yet and the code is tiny anyway,
* it's simply inlined here. */
if (NEED_MIPS_GOT_RELOCS) {
size_t local_cnt = 0;
size_t *got = (void *)(base + dyn[DT_PLTGOT]);
for (i=0; dynv[i]; i+=2) if (dynv[i]==DT_MIPS_LOCAL_GOTNO)
local_cnt = dynv[i+1];
for (i=0; i<local_cnt; i++) got[i] += base;
}
rel = (void *)(base+dyn[DT_REL]);
rel_size = dyn[DT_RELSZ];
for (; rel_size; rel+=2, rel_size-=2*sizeof(size_t)) {
if (!IS_RELATIVE(rel[1], 0)) continue;
size_t *rel_addr = (void *)(base + rel[0]);
*rel_addr += base;
}
rel = (void *)(base+dyn[DT_RELA]);
rel_size = dyn[DT_RELASZ];
for (; rel_size; rel+=3, rel_size-=3*sizeof(size_t)) {
if (!IS_RELATIVE(rel[1], 0)) continue;
size_t *rel_addr = (void *)(base + rel[0]);
*rel_addr = base + rel[2];
}
#endif
stage2_func dls2;
GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]);
dls2((void *)base, sp);
}
-2023
View File
File diff suppressed because it is too large Load Diff
-34
View File
@@ -1,34 +0,0 @@
#include <stdlib.h>
#include <stdint.h>
#include "libc.h"
static void dummy()
{
}
/* atexit.c and __stdio_exit.c override these. the latter is linked
* as a consequence of linking either __toread.c or __towrite.c. */
weak_alias(dummy, __funcs_on_exit);
weak_alias(dummy, __stdio_exit);
weak_alias(dummy, _fini);
__attribute__((__weak__, __visibility__("hidden")))
extern void (*const __fini_array_start)(void), (*const __fini_array_end)(void);
static void libc_exit_fini(void)
{
uintptr_t a = (uintptr_t)&__fini_array_end;
for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)()))
(*(void (**)())(a-sizeof(void(*)())))();
_fini();
}
weak_alias(libc_exit_fini, __libc_exit_fini);
_Noreturn void exit(int code)
{
__funcs_on_exit();
__libc_exit_fini();
__stdio_exit();
_Exit(code);
}
-98
View File
@@ -1,98 +0,0 @@
#ifndef _INTERNAL_RELOC_H
#define _INTERNAL_RELOC_H
#include <features.h>
#include <elf.h>
#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
typedef Elf32_Ehdr Ehdr;
typedef Elf32_Phdr Phdr;
typedef Elf32_Sym Sym;
#define R_TYPE(x) ((x)&255)
#define R_SYM(x) ((x)>>8)
#define R_INFO ELF32_R_INFO
#else
typedef Elf64_Ehdr Ehdr;
typedef Elf64_Phdr Phdr;
typedef Elf64_Sym Sym;
#define R_TYPE(x) ((x)&0x7fffffff)
#define R_SYM(x) ((x)>>32)
#define R_INFO ELF64_R_INFO
#endif
/* These enum constants provide unmatchable default values for
* any relocation type the arch does not use. */
enum {
REL_NONE = 0,
REL_SYMBOLIC = -100,
REL_GOT,
REL_PLT,
REL_RELATIVE,
REL_OFFSET,
REL_OFFSET32,
REL_COPY,
REL_SYM_OR_REL,
REL_DTPMOD,
REL_DTPOFF,
REL_TPOFF,
REL_TPOFF_NEG,
REL_TLSDESC,
REL_FUNCDESC,
REL_FUNCDESC_VAL,
};
struct fdpic_loadseg {
uintptr_t addr, p_vaddr, p_memsz;
};
struct fdpic_loadmap {
unsigned short version, nsegs;
struct fdpic_loadseg segs[];
};
struct fdpic_dummy_loadmap {
unsigned short version, nsegs;
struct fdpic_loadseg segs[1];
};
#include "reloc.h"
#ifndef FDPIC_CONSTDISP_FLAG
#define FDPIC_CONSTDISP_FLAG 0
#endif
#ifndef DL_FDPIC
#define DL_FDPIC 0
#endif
#ifndef DL_NOMMU_SUPPORT
#define DL_NOMMU_SUPPORT 0
#endif
#if !DL_FDPIC
#define IS_RELATIVE(x,s) ( \
(R_TYPE(x) == REL_RELATIVE) || \
(R_TYPE(x) == REL_SYM_OR_REL && !R_SYM(x)) )
#else
#define IS_RELATIVE(x,s) ( ( \
(R_TYPE(x) == REL_FUNCDESC_VAL) || \
(R_TYPE(x) == REL_SYMBOLIC) ) \
&& (((s)[R_SYM(x)].st_info & 0xf) == STT_SECTION) )
#endif
#ifndef NEED_MIPS_GOT_RELOCS
#define NEED_MIPS_GOT_RELOCS 0
#endif
#ifndef DT_DEBUG_INDIRECT
#define DT_DEBUG_INDIRECT 0
#endif
#define AUX_CNT 32
#define DYN_CNT 32
typedef void (*stage2_func)(unsigned char *, size_t *);
typedef _Noreturn void (*stage3_func)(size_t *);
#endif
-28
View File
@@ -1,28 +0,0 @@
#include <stdint.h>
__attribute__((__visibility__("hidden")))
void *__fdpic_fixup(void *map, uintptr_t *a, uintptr_t *z)
{
/* If map is a null pointer, the program was loaded by a
* non-FDPIC-aware ELF loader, and fixups are not needed,
* but the value for the GOT pointer is. */
if (!map) return (void *)z[-1];
struct {
unsigned short version, nsegs;
struct fdpic_loadseg {
uintptr_t addr, p_vaddr, p_memsz;
} segs[];
} *lm = map;
int nsegs = lm->nsegs, rseg = 0, vseg = 0;
for (;;) {
while (*a-lm->segs[rseg].p_vaddr >= lm->segs[rseg].p_memsz)
if (++rseg == nsegs) rseg = 0;
uintptr_t *r = (uintptr_t *)
(*a + lm->segs[rseg].addr - lm->segs[rseg].p_vaddr);
if (++a == z) return r;
while (*r-lm->segs[vseg].p_vaddr >= lm->segs[vseg].p_memsz)
if (++vseg == nsegs) vseg = 0;
*r += lm->segs[vseg].addr - lm->segs[vseg].p_vaddr;
}
}
-21
View File
@@ -1,21 +0,0 @@
#ifndef _INTERNAL_FUTEX_H
#define _INTERNAL_FUTEX_H
#define FUTEX_WAIT 0
#define FUTEX_WAKE 1
#define FUTEX_FD 2
#define FUTEX_REQUEUE 3
#define FUTEX_CMP_REQUEUE 4
#define FUTEX_WAKE_OP 5
#define FUTEX_LOCK_PI 6
#define FUTEX_UNLOCK_PI 7
#define FUTEX_TRYLOCK_PI 8
#define FUTEX_WAIT_BITSET 9
#define FUTEX_PRIVATE 128
#define FUTEX_CLOCK_REALTIME 256
int __futex(volatile int *, int, int, void *);
#endif
-11
View File
@@ -1,11 +0,0 @@
/* This is the structure used for the rt_sigaction syscall on most archs,
* but it can be overridden by a file with the same name in the top-level
* arch dir for a given arch, if necessary. */
struct k_sigaction {
void (*handler)(int);
unsigned long flags;
void (*restorer)(void);
unsigned mask[2];
};
void __restore(), __restore_rt();
-13
View File
@@ -1,13 +0,0 @@
void __procfdname(char *buf, unsigned fd)
{
unsigned i, j;
for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++);
if (!fd) {
buf[i] = '0';
buf[i+1] = 0;
return;
}
for (j=fd; j; j/=10, i++);
buf[i] = 0;
for (; fd; fd/=10) buf[--i] = '0' + fd%10;
}
-5
View File
@@ -1,5 +0,0 @@
__attribute__((__visibility__("hidden")))
int __shcall(void *arg, int (*func)(void *))
{
return func(arg);
}
View File
-247
View File
@@ -1,247 +0,0 @@
#ifndef _INTERNAL_SYSCALL_H
#define _INTERNAL_SYSCALL_H
#include <sys/syscall.h>
#include "syscall_arch.h"
#ifndef SYSCALL_RLIM_INFINITY
#define SYSCALL_RLIM_INFINITY (~0ULL)
#endif
#ifndef SYSCALL_MMAP2_UNIT
#define SYSCALL_MMAP2_UNIT 4096ULL
#endif
#ifndef __SYSCALL_LL_PRW
#define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x)
#endif
#ifndef __scc
#define __scc(X) ((long) (X))
typedef long syscall_arg_t;
#endif
__attribute__((visibility("hidden")))
long __syscall_ret(unsigned long), __syscall(syscall_arg_t, ...),
__syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t,
syscall_arg_t, syscall_arg_t, syscall_arg_t);
#ifdef SYSCALL_NO_INLINE
#define __syscall0(n) (__syscall)(n)
#define __syscall1(n,a) (__syscall)(n,__scc(a))
#define __syscall2(n,a,b) (__syscall)(n,__scc(a),__scc(b))
#define __syscall3(n,a,b,c) (__syscall)(n,__scc(a),__scc(b),__scc(c))
#define __syscall4(n,a,b,c,d) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d))
#define __syscall5(n,a,b,c,d,e) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
#define __syscall6(n,a,b,c,d,e,f) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
#else
#define __syscall1(n,a) __syscall1(n,__scc(a))
#define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b))
#define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c))
#define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d))
#define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e))
#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
#endif
#define __syscall7(n,a,b,c,d,e,f,g) (__syscall)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g))
#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n
#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,)
#define __SYSCALL_CONCAT_X(a,b) a##b
#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b)
#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__)
#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__)
#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__))
#define socketcall __socketcall
#define socketcall_cp __socketcall_cp
#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0)
#define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0)
#define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0)
#define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0)
#define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0)
#define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0)
#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f))
#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
#ifndef SYSCALL_USE_SOCKETCALL
#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_##nm, a, b, c, d, e, f)
#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_##nm, a, b, c, d, e, f)
#else
#define __socketcall(nm,a,b,c,d,e,f) syscall(SYS_socketcall, __SC_##nm, \
((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f }))
#define __socketcall_cp(nm,a,b,c,d,e,f) syscall_cp(SYS_socketcall, __SC_##nm, \
((long [6]){ (long)a, (long)b, (long)c, (long)d, (long)e, (long)f }))
#endif
/* fixup legacy 16-bit junk */
#ifdef SYS_getuid32
#undef SYS_lchown
#undef SYS_getuid
#undef SYS_getgid
#undef SYS_geteuid
#undef SYS_getegid
#undef SYS_setreuid
#undef SYS_setregid
#undef SYS_getgroups
#undef SYS_setgroups
#undef SYS_fchown
#undef SYS_setresuid
#undef SYS_getresuid
#undef SYS_setresgid
#undef SYS_getresgid
#undef SYS_chown
#undef SYS_setuid
#undef SYS_setgid
#undef SYS_setfsuid
#undef SYS_setfsgid
#define SYS_lchown SYS_lchown32
#define SYS_getuid SYS_getuid32
#define SYS_getgid SYS_getgid32
#define SYS_geteuid SYS_geteuid32
#define SYS_getegid SYS_getegid32
#define SYS_setreuid SYS_setreuid32
#define SYS_setregid SYS_setregid32
#define SYS_getgroups SYS_getgroups32
#define SYS_setgroups SYS_setgroups32
#define SYS_fchown SYS_fchown32
#define SYS_setresuid SYS_setresuid32
#define SYS_getresuid SYS_getresuid32
#define SYS_setresgid SYS_setresgid32
#define SYS_getresgid SYS_getresgid32
#define SYS_chown SYS_chown32
#define SYS_setuid SYS_setuid32
#define SYS_setgid SYS_setgid32
#define SYS_setfsuid SYS_setfsuid32
#define SYS_setfsgid SYS_setfsgid32
#endif
/* fixup legacy 32-bit-vs-lfs64 junk */
#ifdef SYS_fcntl64
#undef SYS_fcntl
#define SYS_fcntl SYS_fcntl64
#endif
#ifdef SYS_getdents64
#undef SYS_getdents
#define SYS_getdents SYS_getdents64
#endif
#ifdef SYS_ftruncate64
#undef SYS_ftruncate
#undef SYS_truncate
#define SYS_ftruncate SYS_ftruncate64
#define SYS_truncate SYS_truncate64
#endif
#ifdef SYS_stat64
#undef SYS_stat
#define SYS_stat SYS_stat64
#endif
#ifdef SYS_fstat64
#undef SYS_fstat
#define SYS_fstat SYS_fstat64
#endif
#ifdef SYS_lstat64
#undef SYS_lstat
#define SYS_lstat SYS_lstat64
#endif
#ifdef SYS_statfs64
#undef SYS_statfs
#define SYS_statfs SYS_statfs64
#endif
#ifdef SYS_fstatfs64
#undef SYS_fstatfs
#define SYS_fstatfs SYS_fstatfs64
#endif
#if defined(SYS_newfstatat)
#undef SYS_fstatat
#define SYS_fstatat SYS_newfstatat
#elif defined(SYS_fstatat64)
#undef SYS_fstatat
#define SYS_fstatat SYS_fstatat64
#endif
#ifdef SYS_ugetrlimit
#undef SYS_getrlimit
#define SYS_getrlimit SYS_ugetrlimit
#endif
#ifdef SYS__newselect
#undef SYS_select
#define SYS_select SYS__newselect
#endif
#ifdef SYS_pread64
#undef SYS_pread
#undef SYS_pwrite
#define SYS_pread SYS_pread64
#define SYS_pwrite SYS_pwrite64
#endif
#ifdef SYS_fadvise64_64
#undef SYS_fadvise
#define SYS_fadvise SYS_fadvise64_64
#elif defined(SYS_fadvise64)
#undef SYS_fadvise
#define SYS_fadvise SYS_fadvise64
#endif
#ifdef SYS_sendfile64
#undef SYS_sendfile
#define SYS_sendfile SYS_sendfile64
#endif
/* socketcall calls */
#define __SC_socket 1
#define __SC_bind 2
#define __SC_connect 3
#define __SC_listen 4
#define __SC_accept 5
#define __SC_getsockname 6
#define __SC_getpeername 7
#define __SC_socketpair 8
#define __SC_send 9
#define __SC_recv 10
#define __SC_sendto 11
#define __SC_recvfrom 12
#define __SC_shutdown 13
#define __SC_setsockopt 14
#define __SC_getsockopt 15
#define __SC_sendmsg 16
#define __SC_recvmsg 17
#define __SC_accept4 18
#define __SC_recvmmsg 19
#define __SC_sendmmsg 20
#ifdef SYS_open
#define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE)
#define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
#define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE)
#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo)
#else
#define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
#define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
#define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE)
#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo)
#endif
#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__)
#define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__))
#define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__)
#define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__))
#endif
-11
View File
@@ -1,11 +0,0 @@
#include <errno.h>
#include "syscall.h"
long __syscall_ret(unsigned long r)
{
if (r > -4096UL) {
errno = -r;
return -1;
}
return r;
}
-93
View File
@@ -1,93 +0,0 @@
#include <elf.h>
#include <link.h>
#include <limits.h>
#include <stdint.h>
#include <string.h>
#include "libc.h"
#include "syscall.h"
#ifdef VDSO_USEFUL
#if ULONG_MAX == 0xffffffff
typedef Elf32_Ehdr Ehdr;
typedef Elf32_Phdr Phdr;
typedef Elf32_Sym Sym;
typedef Elf32_Verdef Verdef;
typedef Elf32_Verdaux Verdaux;
#else
typedef Elf64_Ehdr Ehdr;
typedef Elf64_Phdr Phdr;
typedef Elf64_Sym Sym;
typedef Elf64_Verdef Verdef;
typedef Elf64_Verdaux Verdaux;
#endif
static int checkver(Verdef *def, int vsym, const char *vername, char *strings)
{
vsym &= 0x7fff;
for (;;) {
if (!(def->vd_flags & VER_FLG_BASE)
&& (def->vd_ndx & 0x7fff) == vsym)
break;
if (def->vd_next == 0)
return 0;
def = (Verdef *)((char *)def + def->vd_next);
}
Verdaux *aux = (Verdaux *)((char *)def + def->vd_aux);
return !strcmp(vername, strings + aux->vda_name);
}
#define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON)
#define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE)
void *__vdsosym(const char *vername, const char *name)
{
size_t i;
for (i=0; libc.auxv[i] != AT_SYSINFO_EHDR; i+=2)
if (!libc.auxv[i]) return 0;
if (!libc.auxv[i+1]) return 0;
Ehdr *eh = (void *)libc.auxv[i+1];
Phdr *ph = (void *)((char *)eh + eh->e_phoff);
size_t *dynv=0, base=-1;
for (i=0; i<eh->e_phnum; i++, ph=(void *)((char *)ph+eh->e_phentsize)) {
if (ph->p_type == PT_LOAD)
base = (size_t)eh + ph->p_offset - ph->p_vaddr;
else if (ph->p_type == PT_DYNAMIC)
dynv = (void *)((char *)eh + ph->p_offset);
}
if (!dynv || base==(size_t)-1) return 0;
char *strings = 0;
Sym *syms = 0;
Elf_Symndx *hashtab = 0;
uint16_t *versym = 0;
Verdef *verdef = 0;
for (i=0; dynv[i]; i+=2) {
void *p = (void *)(base + dynv[i+1]);
switch(dynv[i]) {
case DT_STRTAB: strings = p; break;
case DT_SYMTAB: syms = p; break;
case DT_HASH: hashtab = p; break;
case DT_VERSYM: versym = p; break;
case DT_VERDEF: verdef = p; break;
}
}
if (!strings || !syms || !hashtab) return 0;
if (!verdef) versym = 0;
for (i=0; i<hashtab[1]; i++) {
if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue;
if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue;
if (!syms[i].st_shndx) continue;
if (strcmp(name, strings+syms[i].st_name)) continue;
if (versym && !checkver(verdef, versym[i], vername, strings))
continue;
return (void *)(base + syms[i].st_value);
}
return 0;
}
#endif
-9
View File
@@ -1,9 +0,0 @@
#include "version.h"
static const char version[] = VERSION;
__attribute__((__visibility__("hidden")))
const char *__libc_get_version()
{
return version;
}
-674
View File
@@ -1,674 +0,0 @@
#include <iconv.h>
#include <errno.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <stdint.h>
#include "locale_impl.h"
#define UTF_32BE 0300
#define UTF_16LE 0301
#define UTF_16BE 0302
#define UTF_32LE 0303
#define UCS2BE 0304
#define UCS2LE 0305
#define WCHAR_T 0306
#define US_ASCII 0307
#define UTF_8 0310
#define UTF_16 0312
#define UTF_32 0313
#define UCS2 0314
#define EUC_JP 0320
#define SHIFT_JIS 0321
#define ISO2022_JP 0322
#define GB18030 0330
#define GBK 0331
#define GB2312 0332
#define BIG5 0340
#define EUC_KR 0350
/* Definitions of charmaps. Each charmap consists of:
* 1. Empty-string-terminated list of null-terminated aliases.
* 2. Special type code or number of elided quads of entries.
* 3. Character table (size determined by field 2), consisting
* of 5 bytes for every 4 characters, interpreted as 10-bit
* indices into the legacy_chars table. */
static const unsigned char charmaps[] =
"utf8\0char\0\0\310"
"wchart\0\0\306"
"ucs2be\0\0\304"
"ucs2le\0\0\305"
"utf16be\0\0\302"
"utf16le\0\0\301"
"ucs4be\0utf32be\0\0\300"
"ucs4le\0utf32le\0\0\303"
"ascii\0usascii\0iso646\0iso646us\0\0\307"
"utf16\0\0\312"
"ucs4\0utf32\0\0\313"
"ucs2\0\0\314"
"eucjp\0\0\320"
"shiftjis\0sjis\0\0\321"
"iso2022jp\0\0\322"
"gb18030\0\0\330"
"gbk\0\0\331"
"gb2312\0\0\332"
"big5\0bigfive\0cp950\0big5hkscs\0\0\340"
"euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
#include "codepages.h"
;
/* Table of characters that appear in legacy 8-bit codepages,
* limited to 1024 slots (10 bit indices). The first 256 entries
* are elided since those characters are obviously all included. */
static const unsigned short legacy_chars[] = {
#include "legacychars.h"
};
static const unsigned short jis0208[84][94] = {
#include "jis0208.h"
};
static const unsigned short gb18030[126][190] = {
#include "gb18030.h"
};
static const unsigned short big5[89][157] = {
#include "big5.h"
};
static const unsigned short hkscs[] = {
#include "hkscs.h"
};
static const unsigned short ksc[93][94] = {
#include "ksc.h"
};
static const unsigned short rev_jis[] = {
#include "revjis.h"
};
static int fuzzycmp(const unsigned char *a, const unsigned char *b)
{
for (; *a && *b; a++, b++) {
while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++;
if ((*a|32U) != *b) return 1;
}
return *a != *b;
}
static size_t find_charmap(const void *name)
{
const unsigned char *s;
if (!*(char *)name) name=charmaps; /* "utf8" */
for (s=charmaps; *s; ) {
if (!fuzzycmp(name, s)) {
for (; *s; s+=strlen((void *)s)+1);
return s+1-charmaps;
}
s += strlen((void *)s)+1;
if (!*s) {
if (s[1] > 0200) s+=2;
else s+=2+(64U-s[1])*5;
}
}
return -1;
}
struct stateful_cd {
iconv_t base_cd;
unsigned state;
};
static iconv_t combine_to_from(size_t t, size_t f)
{
return (void *)(f<<16 | t<<1 | 1);
}
static size_t extract_from(iconv_t cd)
{
return (size_t)cd >> 16;
}
static size_t extract_to(iconv_t cd)
{
return (size_t)cd >> 1 & 0x7fff;
}
iconv_t iconv_open(const char *to, const char *from)
{
size_t f, t;
struct stateful_cd *scd;
if ((t = find_charmap(to))==-1
|| (f = find_charmap(from))==-1
|| (charmaps[t] >= 0330)) {
errno = EINVAL;
return (iconv_t)-1;
}
iconv_t cd = combine_to_from(t, f);
switch (charmaps[f]) {
case UTF_16:
case UTF_32:
case UCS2:
case ISO2022_JP:
scd = malloc(sizeof *scd);
if (!scd) return (iconv_t)-1;
scd->base_cd = cd;
scd->state = 0;
cd = (iconv_t)scd;
}
return cd;
}
static unsigned get_16(const unsigned char *s, int e)
{
e &= 1;
return s[e]<<8 | s[1-e];
}
static void put_16(unsigned char *s, unsigned c, int e)
{
e &= 1;
s[e] = c>>8;
s[1-e] = c;
}
static unsigned get_32(const unsigned char *s, int e)
{
e &= 3;
return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3];
}
static void put_32(unsigned char *s, unsigned c, int e)
{
e &= 3;
s[e^0] = c>>24;
s[e^1] = c>>16;
s[e^2] = c>>8;
s[e^3] = c;
}
/* Adapt as needed */
#define mbrtowc_utf8 mbrtowc
#define wctomb_utf8 wctomb
static unsigned legacy_map(const unsigned char *map, unsigned c)
{
if (c < 4*map[-1]) return c;
unsigned x = c - 4*map[-1];
x = map[x*5/4]>>2*x%8 | map[x*5/4+1]<<8-2*x%8 & 1023;
return x < 256 ? x : legacy_chars[x-256];
}
static unsigned uni_to_jis(unsigned c)
{
unsigned nel = sizeof rev_jis / sizeof *rev_jis;
unsigned d, j, i, b = 0;
for (;;) {
i = nel/2;
j = rev_jis[b+i];
d = jis0208[j/256][j%256];
if (d==c) return j + 0x2121;
else if (nel == 1) return 0;
else if (c < d)
nel /= 2;
else {
b += i;
nel -= nel/2;
}
}
}
size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb)
{
size_t x=0;
struct stateful_cd *scd=0;
if (!((size_t)cd & 1)) {
scd = (void *)cd;
cd = scd->base_cd;
}
unsigned to = extract_to(cd);
unsigned from = extract_from(cd);
const unsigned char *map = charmaps+from+1;
const unsigned char *tomap = charmaps+to+1;
mbstate_t st = {0};
wchar_t wc;
unsigned c, d;
size_t k, l;
int err;
unsigned char type = map[-1];
unsigned char totype = tomap[-1];
locale_t *ploc = &CURRENT_LOCALE, loc = *ploc;
if (!in || !*in || !*inb) return 0;
*ploc = UTF8_LOCALE;
for (; *inb; *in+=l, *inb-=l) {
c = *(unsigned char *)*in;
l = 1;
switch (type) {
case UTF_8:
if (c < 128) break;
l = mbrtowc_utf8(&wc, *in, *inb, &st);
if (l == (size_t)-1) goto ilseq;
if (l == (size_t)-2) goto starved;
c = wc;
break;
case US_ASCII:
if (c >= 128) goto ilseq;
break;
case WCHAR_T:
l = sizeof(wchar_t);
if (*inb < l) goto starved;
c = *(wchar_t *)*in;
if (0) {
case UTF_32BE:
case UTF_32LE:
l = 4;
if (*inb < 4) goto starved;
c = get_32((void *)*in, type);
}
if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq;
break;
case UCS2BE:
case UCS2LE:
case UTF_16BE:
case UTF_16LE:
l = 2;
if (*inb < 2) goto starved;
c = get_16((void *)*in, type);
if ((unsigned)(c-0xdc00) < 0x400) goto ilseq;
if ((unsigned)(c-0xd800) < 0x400) {
if (type-UCS2BE < 2U) goto ilseq;
l = 4;
if (*inb < 4) goto starved;
d = get_16((void *)(*in + 2), type);
if ((unsigned)(d-0xdc00) >= 0x400) goto ilseq;
c = ((c-0xd7c0)<<10) + (d-0xdc00);
}
break;
case UCS2:
case UTF_16:
l = 0;
if (!scd->state) {
if (*inb < 2) goto starved;
c = get_16((void *)*in, 0);
scd->state = type==UCS2
? c==0xfffe ? UCS2LE : UCS2BE
: c==0xfffe ? UTF_16LE : UTF_16BE;
if (c == 0xfffe || c == 0xfeff)
l = 2;
}
type = scd->state;
continue;
case UTF_32:
l = 0;
if (!scd->state) {
if (*inb < 4) goto starved;
c = get_32((void *)*in, 0);
scd->state = c==0xfffe0000 ? UTF_32LE : UTF_32BE;
if (c == 0xfffe0000 || c == 0xfeff)
l = 4;
}
type = scd->state;
continue;
case SHIFT_JIS:
if (c < 128) break;
if (c-0xa1 <= 0xdf-0xa1) {
c += 0xff61-0xa1;
break;
}
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (c-129 <= 159-129) c -= 129;
else if (c-224 <= 239-224) c -= 193;
else goto ilseq;
c *= 2;
if (d-64 <= 158-64) {
if (d==127) goto ilseq;
if (d>127) d--;
d -= 64;
} else if (d-159 <= 252-159) {
c++;
d -= 159;
}
c = jis0208[c][d];
if (!c) goto ilseq;
break;
case EUC_JP:
if (c < 128) break;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (c==0x8e) {
c = d;
if (c-0xa1 > 0xdf-0xa1) goto ilseq;
c += 0xff61 - 0xa1;
break;
}
c -= 0xa1;
d -= 0xa1;
if (c >= 84 || d >= 94) goto ilseq;
c = jis0208[c][d];
if (!c) goto ilseq;
break;
case ISO2022_JP:
if (c >= 128) goto ilseq;
if (c == '\033') {
l = 3;
if (*inb < 3) goto starved;
c = *((unsigned char *)*in + 1);
d = *((unsigned char *)*in + 2);
if (c != '(' && c != '$') goto ilseq;
switch (128*(c=='$') + d) {
case 'B': scd->state=0; continue;
case 'J': scd->state=1; continue;
case 'I': scd->state=4; continue;
case 128+'@': scd->state=2; continue;
case 128+'B': scd->state=3; continue;
}
goto ilseq;
}
switch (scd->state) {
case 1:
if (c=='\\') c = 0xa5;
if (c=='~') c = 0x203e;
break;
case 2:
case 3:
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
c -= 0x21;
d -= 0x21;
if (c >= 84 || d >= 94) goto ilseq;
c = jis0208[c][d];
if (!c) goto ilseq;
break;
case 4:
if (c-0x60 < 0x1f) goto ilseq;
if (c-0x21 < 0x5e) c += 0xff61-0x21;
break;
}
break;
case GB2312:
if (c < 128) break;
if (c < 0xa1) goto ilseq;
case GBK:
case GB18030:
if (c < 128) break;
c -= 0x81;
if (c >= 126) goto ilseq;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (d < 0xa1 && type == GB2312) goto ilseq;
if (d-0x40>=191 || d==127) {
if (d-'0'>9 || type != GB18030)
goto ilseq;
l = 4;
if (*inb < 4) goto starved;
c = (10*c + d-'0') * 1260;
d = *((unsigned char *)*in + 2);
if (d-0x81>126) goto ilseq;
c += 10*(d-0x81);
d = *((unsigned char *)*in + 3);
if (d-'0'>9) goto ilseq;
c += d-'0';
c += 128;
for (d=0; d<=c; ) {
k = 0;
for (int i=0; i<126; i++)
for (int j=0; j<190; j++)
if (gb18030[i][j]-d <= c-d)
k++;
d = c+1;
c += k;
}
break;
}
d -= 0x40;
if (d>63) d--;
c = gb18030[c][d];
break;
case BIG5:
if (c < 128) break;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
if (d-0x40>=0xff-0x40 || d-0x7f<0xa1-0x7f) goto ilseq;
d -= 0x40;
if (d > 0x3e) d -= 0x22;
if (c-0xa1>=0xfa-0xa1) {
if (c-0x87>=0xff-0x87) goto ilseq;
if (c < 0xa1) c -= 0x87;
else c -= 0x87 + (0xfa-0xa1);
c = (hkscs[4867+(c*157+d)/16]>>(c*157+d)%16)%2<<17
| hkscs[c*157+d];
/* A few HKSCS characters map to pairs of UCS
* characters. These are mapped to surrogate
* range in the hkscs table then hard-coded
* here. Ugly, yes. */
if (c/256 == 0xdc) {
if (totype-0300U > 8) k = 2;
else k = "\10\4\4\10\4\4\10\2\4"[totype-0300];
if (k > *outb) goto toobig;
x += iconv(combine_to_from(to, 0),
&(char *){"\303\212\314\204"
"\303\212\314\214"
"\303\252\314\204"
"\303\252\314\214"
+c%256}, &(size_t){4},
out, outb);
continue;
}
if (!c) goto ilseq;
break;
}
c -= 0xa1;
c = big5[c][d]|(c==0x27&&(d==0x3a||d==0x3c||d==0x42))<<17;
if (!c) goto ilseq;
break;
case EUC_KR:
if (c < 128) break;
l = 2;
if (*inb < 2) goto starved;
d = *((unsigned char *)*in + 1);
c -= 0xa1;
d -= 0xa1;
if (c >= 93 || d >= 94) {
c += (0xa1-0x81);
d += 0xa1;
if (c >= 93 || c>=0xc6-0x81 && d>0x52)
goto ilseq;
if (d-'A'<26) d = d-'A';
else if (d-'a'<26) d = d-'a'+26;
else if (d-0x81<0xff-0x81) d = d-0x81+52;
else goto ilseq;
if (c < 0x20) c = 178*c + d;
else c = 178*0x20 + 84*(c-0x20) + d;
c += 0xac00;
for (d=0xac00; d<=c; ) {
k = 0;
for (int i=0; i<93; i++)
for (int j=0; j<94; j++)
if (ksc[i][j]-d <= c-d)
k++;
d = c+1;
c += k;
}
break;
}
c = ksc[c][d];
if (!c) goto ilseq;
break;
default:
if (!c) break;
c = legacy_map(map, c);
if (!c) goto ilseq;
}
switch (totype) {
case WCHAR_T:
if (*outb < sizeof(wchar_t)) goto toobig;
*(wchar_t *)*out = c;
*out += sizeof(wchar_t);
*outb -= sizeof(wchar_t);
break;
case UTF_8:
if (*outb < 4) {
char tmp[4];
k = wctomb_utf8(tmp, c);
if (*outb < k) goto toobig;
memcpy(*out, tmp, k);
} else k = wctomb_utf8(*out, c);
*out += k;
*outb -= k;
break;
case US_ASCII:
if (c > 0x7f) subst: x++, c='*';
default:
if (*outb < 1) goto toobig;
if (c<256 && c==legacy_map(tomap, c)) {
revout:
*(*out)++ = c;
*outb -= 1;
break;
}
d = c;
for (c=4*totype; c<256; c++) {
if (d == legacy_map(tomap, c)) {
goto revout;
}
}
goto subst;
case SHIFT_JIS:
if (c < 128) goto revout;
if (c == 0xa5) {
x++;
c = '\\';
goto revout;
}
if (c == 0x203e) {
x++;
c = '~';
goto revout;
}
if (c-0xff61 <= 0xdf-0xa1) {
c += 0xa1 - 0xff61;
goto revout;
}
c = uni_to_jis(c);
if (!c) goto subst;
if (*outb < 2) goto toobig;
d = c%256;
c = c/256;
*(*out)++ = (c+1)/2 + (c<95 ? 112 : 176);
*(*out)++ = c%2 ? d + 31 + d/96 : d + 126;
*outb -= 2;
break;
case EUC_JP:
if (c < 128) goto revout;
if (c-0xff61 <= 0xdf-0xa1) {
c += 0x0e00 + 0x21 - 0xff61;
} else {
c = uni_to_jis(c);
}
if (!c) goto subst;
if (*outb < 2) goto toobig;
*(*out)++ = c/256 + 0x80;
*(*out)++ = c%256 + 0x80;
*outb -= 2;
break;
case ISO2022_JP:
if (c < 128) goto revout;
if (c-0xff61 <= 0xdf-0xa1 || c==0xa5 || c==0x203e) {
if (*outb < 7) goto toobig;
*(*out)++ = '\033';
*(*out)++ = '(';
if (c==0xa5) {
*(*out)++ = 'J';
*(*out)++ = '\\';
} else if (c==0x203e) {
*(*out)++ = 'J';
*(*out)++ = '~';
} else {
*(*out)++ = 'I';
*(*out)++ = c-0xff61+0x21;
}
*(*out)++ = '\033';
*(*out)++ = '(';
*(*out)++ = 'B';
*outb -= 7;
break;
}
c = uni_to_jis(c);
if (!c) goto subst;
if (*outb < 8) goto toobig;
*(*out)++ = '\033';
*(*out)++ = '$';
*(*out)++ = 'B';
*(*out)++ = c/256;
*(*out)++ = c%256;
*(*out)++ = '\033';
*(*out)++ = '(';
*(*out)++ = 'B';
*outb -= 8;
break;
case UCS2:
totype = UCS2BE;
case UCS2BE:
case UCS2LE:
case UTF_16:
case UTF_16BE:
case UTF_16LE:
if (c < 0x10000 || totype-UCS2BE < 2U) {
if (c >= 0x10000) c = 0xFFFD;
if (*outb < 2) goto toobig;
put_16((void *)*out, c, totype);
*out += 2;
*outb -= 2;
break;
}
if (*outb < 4) goto toobig;
c -= 0x10000;
put_16((void *)*out, (c>>10)|0xd800, totype);
put_16((void *)(*out + 2), (c&0x3ff)|0xdc00, totype);
*out += 4;
*outb -= 4;
break;
case UTF_32BE:
case UTF_32LE:
if (*outb < 4) goto toobig;
put_32((void *)*out, c, totype);
*out += 4;
*outb -= 4;
break;
}
}
*ploc = loc;
return x;
ilseq:
err = EILSEQ;
x = -1;
goto end;
toobig:
err = E2BIG;
x = -1;
goto end;
starved:
err = EINVAL;
x = -1;
end:
errno = err;
*ploc = loc;
return x;
}
-8
View File
@@ -1,8 +0,0 @@
#include <iconv.h>
#include <stdlib.h>
int iconv_close(iconv_t cd)
{
if (!((size_t)cd & 1)) free((void *)cd);
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
#include <stdlib.h>
void *__memalign(size_t, size_t);
void *aligned_alloc(size_t align, size_t len)
{
return __memalign(align, len);
}
+57
View File
@@ -0,0 +1,57 @@
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include "libc.h"
/* This function should work with most dlmalloc-like chunk bookkeeping
* systems, but it's only guaranteed to work with the native implementation
* used in this library. */
void *__memalign(size_t align, size_t len)
{
unsigned char *mem, *new, *end;
size_t header, footer;
if ((align & -align) != align) {
errno = EINVAL;
return NULL;
}
if (len > SIZE_MAX - align) {
errno = ENOMEM;
return NULL;
}
if (align <= 4*sizeof(size_t)) {
if (!(mem = malloc(len)))
return NULL;
return mem;
}
if (!(mem = malloc(len + align-1)))
return NULL;
new = (void *)((uintptr_t)mem + align-1 & -align);
if (new == mem) return mem;
header = ((size_t *)mem)[-1];
if (!(header & 7)) {
((size_t *)new)[-2] = ((size_t *)mem)[-2] + (new-mem);
((size_t *)new)[-1] = ((size_t *)mem)[-1] - (new-mem);
return new;
}
end = mem + (header & -8);
footer = ((size_t *)end)[-2];
((size_t *)mem)[-1] = header&7 | new-mem;
((size_t *)new)[-2] = footer&7 | new-mem;
((size_t *)new)[-1] = header&7 | end-new;
((size_t *)end)[-2] = footer&7 | end-new;
free(mem);
return new;
}
weak_alias(__memalign, memalign);
+13
View File
@@ -0,0 +1,13 @@
#include <stdlib.h>
#include <errno.h>
void *__memalign(size_t, size_t);
int posix_memalign(void **res, size_t align, size_t len)
{
if (align < sizeof(void *)) return EINVAL;
void *mem = __memalign(align, len);
if (!mem) return errno;
*res = mem;
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <strings.h>
#include "atomic.h"
int ffs(int i)
{
return i ? a_ctz_l(i)+1 : 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <strings.h>
#include "atomic.h"
int ffsl(long i)
{
return i ? a_ctz_l(i)+1 : 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <strings.h>
#include "atomic.h"
int ffsll(long long i)
{
return i ? a_ctz_64(i)+1 : 0;
}
+2 -32
View File
@@ -4,37 +4,7 @@
size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
{
prints_l(f->wbase, f->wpos-f->wbase);
prints_l((void *)buf, len);
prints_l((char*)(f->wbase), f->wpos-f->wbase);
prints_l((void*)buf, len);
return f->wpos-f->wbase + len;
/*
struct iovec iovs[2] = {
{ .iov_base = f->wbase, .iov_len = f->wpos-f->wbase },
{ .iov_base = (void *)buf, .iov_len = len }
};
struct iovec *iov = iovs;
size_t rem = iov[0].iov_len + iov[1].iov_len;
int iovcnt = 2;
ssize_t cnt;
for (;;) {
cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
if (cnt == rem) {
f->wend = f->buf + f->buf_size;
f->wpos = f->wbase = f->buf;
return len;
}
if (cnt < 0) {
f->wpos = f->wbase = f->wend = 0;
f->flags |= F_ERR;
return iovcnt == 2 ? 0 : len-iov[0].iov_len;
}
rem -= cnt;
if (cnt > iov[0].iov_len) {
cnt -= iov[0].iov_len;
iov++; iovcnt--;
}
iov[0].iov_base = (char *)iov[0].iov_base + cnt;
iov[0].iov_len -= cnt;
}
*/
}
+1 -7
View File
@@ -3,11 +3,5 @@
size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
{
/*
struct winsize wsz;
f->write = __stdio_write;
if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz))
f->lbf = -1;
return __stdio_write(f, buf, len);
*/
return __stdio_write(f, buf, len);
}
-15
View File
@@ -1,15 +0,0 @@
#include "stdio_impl.h"
#include "pthread_impl.h"
void __unlist_locked_file(FILE *);
void funlockfile(FILE *f)
{
if (f->lockcount == 1) {
__unlist_locked_file(f);
f->lockcount = 0;
__unlockfile(f);
} else {
f->lockcount--;
}
}
-124
View File
@@ -1,124 +0,0 @@
#include <string.h>
#include <stdint.h>
#include <endian.h>
void *memcpy(void *restrict dest, const void *restrict src, size_t n)
{
unsigned char *d = dest;
const unsigned char *s = src;
#ifdef __GNUC__
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define LS >>
#define RS <<
#else
#define LS <<
#define RS >>
#endif
typedef uint32_t __attribute__((__may_alias__)) u32;
uint32_t w, x;
for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++;
if ((uintptr_t)d % 4 == 0) {
for (; n>=16; s+=16, d+=16, n-=16) {
*(u32 *)(d+0) = *(u32 *)(s+0);
*(u32 *)(d+4) = *(u32 *)(s+4);
*(u32 *)(d+8) = *(u32 *)(s+8);
*(u32 *)(d+12) = *(u32 *)(s+12);
}
if (n&8) {
*(u32 *)(d+0) = *(u32 *)(s+0);
*(u32 *)(d+4) = *(u32 *)(s+4);
d += 8; s += 8;
}
if (n&4) {
*(u32 *)(d+0) = *(u32 *)(s+0);
d += 4; s += 4;
}
if (n&2) {
*d++ = *s++; *d++ = *s++;
}
if (n&1) {
*d = *s;
}
return dest;
}
if (n >= 32) switch ((uintptr_t)d % 4) {
case 1:
w = *(u32 *)s;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
n -= 3;
for (; n>=17; s+=16, d+=16, n-=16) {
x = *(u32 *)(s+1);
*(u32 *)(d+0) = (w LS 24) | (x RS 8);
w = *(u32 *)(s+5);
*(u32 *)(d+4) = (x LS 24) | (w RS 8);
x = *(u32 *)(s+9);
*(u32 *)(d+8) = (w LS 24) | (x RS 8);
w = *(u32 *)(s+13);
*(u32 *)(d+12) = (x LS 24) | (w RS 8);
}
break;
case 2:
w = *(u32 *)s;
*d++ = *s++;
*d++ = *s++;
n -= 2;
for (; n>=18; s+=16, d+=16, n-=16) {
x = *(u32 *)(s+2);
*(u32 *)(d+0) = (w LS 16) | (x RS 16);
w = *(u32 *)(s+6);
*(u32 *)(d+4) = (x LS 16) | (w RS 16);
x = *(u32 *)(s+10);
*(u32 *)(d+8) = (w LS 16) | (x RS 16);
w = *(u32 *)(s+14);
*(u32 *)(d+12) = (x LS 16) | (w RS 16);
}
break;
case 3:
w = *(u32 *)s;
*d++ = *s++;
n -= 1;
for (; n>=19; s+=16, d+=16, n-=16) {
x = *(u32 *)(s+3);
*(u32 *)(d+0) = (w LS 8) | (x RS 24);
w = *(u32 *)(s+7);
*(u32 *)(d+4) = (x LS 8) | (w RS 24);
x = *(u32 *)(s+11);
*(u32 *)(d+8) = (w LS 8) | (x RS 24);
w = *(u32 *)(s+15);
*(u32 *)(d+12) = (x LS 8) | (w RS 24);
}
break;
}
if (n&16) {
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
}
if (n&8) {
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
}
if (n&4) {
*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
}
if (n&2) {
*d++ = *s++; *d++ = *s++;
}
if (n&1) {
*d = *s;
}
return dest;
#endif
for (; n; n--) *d++ = *s++;
return dest;
}
-36
View File
@@ -1,36 +0,0 @@
#include <string.h>
#include <stdint.h>
#define WT size_t
#define WS (sizeof(WT))
void *memmove(void *dest, const void *src, size_t n)
{
char *d = dest;
const char *s = src;
if (d==s) return d;
if (s+n <= d || d+n <= s) return memcpy(d, s, n);
if (d<s) {
if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
while ((uintptr_t)d % WS) {
if (!n--) return dest;
*d++ = *s++;
}
for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s;
}
for (; n; n--) *d++ = *s++;
} else {
if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
while ((uintptr_t)(d+n) % WS) {
if (!n--) return dest;
d[n] = s[n];
}
while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n);
}
while (n) n--, d[n] = s[n];
}
return dest;
}
-90
View File
@@ -1,90 +0,0 @@
#include <string.h>
#include <stdint.h>
void *memset(void *dest, int c, size_t n)
{
unsigned char *s = dest;
size_t k;
/* Fill head and tail with minimal branching. Each
* conditional ensures that all the subsequently used
* offsets are well-defined and in the dest region. */
if (!n) return dest;
s[0] = c;
s[n-1] = c;
if (n <= 2) return dest;
s[1] = c;
s[2] = c;
s[n-2] = c;
s[n-3] = c;
if (n <= 6) return dest;
s[3] = c;
s[n-4] = c;
if (n <= 8) return dest;
/* Advance pointer to align it at a 4-byte boundary,
* and truncate n to a multiple of 4. The previous code
* already took care of any head/tail that get cut off
* by the alignment. */
k = -(uintptr_t)s & 3;
s += k;
n -= k;
n &= -4;
#ifdef __GNUC__
typedef uint32_t __attribute__((__may_alias__)) u32;
typedef uint64_t __attribute__((__may_alias__)) u64;
u32 c32 = ((u32)-1)/255 * (unsigned char)c;
/* In preparation to copy 32 bytes at a time, aligned on
* an 8-byte bounary, fill head/tail up to 28 bytes each.
* As in the initial byte-based head/tail fill, each
* conditional below ensures that the subsequent offsets
* are valid (e.g. !(n<=24) implies n>=28). */
*(u32 *)(s+0) = c32;
*(u32 *)(s+n-4) = c32;
if (n <= 8) return dest;
*(u32 *)(s+4) = c32;
*(u32 *)(s+8) = c32;
*(u32 *)(s+n-12) = c32;
*(u32 *)(s+n-8) = c32;
if (n <= 24) return dest;
*(u32 *)(s+12) = c32;
*(u32 *)(s+16) = c32;
*(u32 *)(s+20) = c32;
*(u32 *)(s+24) = c32;
*(u32 *)(s+n-28) = c32;
*(u32 *)(s+n-24) = c32;
*(u32 *)(s+n-20) = c32;
*(u32 *)(s+n-16) = c32;
/* Align to a multiple of 8 so we can fill 64 bits at a time,
* and avoid writing the same bytes twice as much as is
* practical without introducing additional branching. */
k = 24 + ((uintptr_t)s & 4);
s += k;
n -= k;
/* If this loop is reached, 28 tail bytes have already been
* filled, so any remainder when n drops below 32 can be
* safely ignored. */
u64 c64 = c32 | ((u64)c32 << 32);
for (; n >= 32; n-=32, s+=32) {
*(u64 *)(s+0) = c64;
*(u64 *)(s+8) = c64;
*(u64 *)(s+16) = c64;
*(u64 *)(s+24) = c64;
}
#else
/* Pure C fallback with no aliasing violations. */
for (; n; n--, s++) *s = c;
#endif
return dest;
}
-89
View File
@@ -113,12 +113,6 @@ static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t
return y;
}
int __munmap(void *, size_t);
static void do_tzset()
{
}
/* Search zoneinfo rules to find the one that applies to the given time,
* and determine alternate opposite-DST-status rule that may be needed. */
@@ -218,86 +212,3 @@ static long long rule_to_secs(const int *rule, int year)
t += rule[4];
return t;
}
/* Determine the time zone in effect for a given time in seconds since the
* epoch. It can be given in local or universal time. The results will
* indicate whether DST is in effect at the queried time, and will give both
* the GMT offset for the active zone/DST rule and the opposite DST. This
* enables a caller to efficiently adjust for the case where an explicit
* DST specification mismatches what would be in effect at the time. */
void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename)
{
LOCK(lock);
do_tzset();
if (zi) {
size_t alt, i = scan_trans(t, local, &alt);
if (i != -1) {
*isdst = types[6*i+4];
*offset = (int32_t)zi_read32(types+6*i);
*zonename = (const char *)abbrevs + types[6*i+5];
if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt);
UNLOCK(lock);
return;
}
}
if (!__daylight) goto std;
/* FIXME: may be broken if DST changes right at year boundary?
* Also, this could be more efficient.*/
long long y = t / 31556952 + 70;
while (__year_to_secs(y, 0) > t) y--;
while (__year_to_secs(y+1, 0) < t) y++;
long long t0 = rule_to_secs(r0, y);
long long t1 = rule_to_secs(r1, y);
if (!local) {
t0 += __timezone;
t1 += dst_off;
}
if (t0 < t1) {
if (t >= t0 && t < t1) goto dst;
goto std;
} else {
if (t >= t1 && t < t0) goto std;
goto dst;
}
std:
*isdst = 0;
*offset = -__timezone;
if (oppoff) *oppoff = -dst_off;
*zonename = __tzname[0];
UNLOCK(lock);
return;
dst:
*isdst = 1;
*offset = -dst_off;
if (oppoff) *oppoff = -__timezone;
*zonename = __tzname[1];
UNLOCK(lock);
}
void __tzset()
{
LOCK(lock);
do_tzset();
UNLOCK(lock);
}
weak_alias(__tzset, tzset);
const char *__tm_to_tzname(const struct tm *tm)
{
const void *p = tm->__tm_zone;
LOCK(lock);
do_tzset();
if (p != __utc && p != __tzname[0] && p != __tzname[1] &&
(!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs))
p = "";
UNLOCK(lock);
return p;
}
-8
View File
@@ -1,8 +0,0 @@
#include <time.h>
char *ctime(const time_t *t)
{
struct tm *tm = localtime(t);
if (!tm) return 0;
return asctime(tm);
}
-7
View File
@@ -1,7 +0,0 @@
#include <time.h>
char *ctime_r(const time_t *t, char *buf)
{
struct tm tm, *tm_p = localtime_r(t, &tm);
return tm_p ? asctime_r(tm_p, buf) : 0;
}
-9
View File
@@ -1,9 +0,0 @@
#include "time_impl.h"
struct tm *__localtime_r(const time_t *restrict, struct tm *restrict);
struct tm *localtime(const time_t *t)
{
static struct tm tm;
return __localtime_r(t, &tm);
}
-21
View File
@@ -1,21 +0,0 @@
#include "time_impl.h"
#include <errno.h>
#include "libc.h"
struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm)
{
/* Reject time_t values whose year would overflow int because
* __secs_to_zone cannot safely handle them. */
if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
errno = EOVERFLOW;
return 0;
}
__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
if (__secs_to_tm((long long)*t + tm->__tm_gmtoff, tm) < 0) {
errno = EOVERFLOW;
return 0;
}
return tm;
}
weak_alias(__localtime_r, localtime_r);
-28
View File
@@ -1,28 +0,0 @@
#include "time_impl.h"
#include <errno.h>
time_t mktime(struct tm *tm)
{
struct tm new;
long opp;
long long t = __tm_to_secs(tm);
__secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst)
t -= opp - new.__tm_gmtoff;
t -= new.__tm_gmtoff;
if ((time_t)t != t) goto error;
__secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone);
if (__secs_to_tm(t + new.__tm_gmtoff, &new) < 0) goto error;
*tm = new;
return t;
error:
errno = EOVERFLOW;
return -1;
}
+3 -6
View File
@@ -9,6 +9,8 @@
#include "libc.h"
#include "time_impl.h"
#include <assert.h>
const char *__nl_langinfo_l(nl_item, locale_t);
static int is_leap(int y)
@@ -45,7 +47,6 @@ static int week_num(const struct tm *tm)
return val;
}
const char *__tm_to_tzname(const struct tm *);
size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t);
const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad)
@@ -186,11 +187,7 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *
abs(tm->__tm_gmtoff%3600)/60);
return *s;
case 'Z':
if (tm->tm_isdst < 0) {
*l = 0;
return "";
}
fmt = __tm_to_tzname(tm);
__assert_fail("strftime %Z not supported.", __FILE__, __LINE__, __func__);
goto string;
case '%':
*l = 1;