coda
This commit is contained in:
parent
9bc8a11afe
commit
c75af0c8e5
28 changed files with 711 additions and 64 deletions
|
@ -324,7 +324,7 @@ void *malloc(size_t n)
|
|||
{
|
||||
struct chunk *c;
|
||||
int i, j;
|
||||
|
||||
if (n == 0) n = 1;/* everyone depends on this behavior for some fucking reason */
|
||||
if (!n || adjust_size(&n) < 0) return 0;
|
||||
|
||||
if (n > MMAP_THRESHOLD) {
|
||||
|
|
|
@ -7,4 +7,7 @@ int __madvise(void *addr, size_t len, int advice)
|
|||
return syscall3(__NR_madvise, (long)addr, len, advice);
|
||||
}
|
||||
|
||||
weak_alias(__madvise, madvise);
|
||||
int madvise(void *addr, size_t len, int advice)
|
||||
{
|
||||
return syscall3(__NR_madvise, (long)addr, len, advice);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,16 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
|
|||
#endif
|
||||
}
|
||||
|
||||
weak_alias(__mmap, mmap);
|
||||
void *mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
|
||||
{
|
||||
if (sizeof(off_t) > sizeof(long))
|
||||
if (((long)off & 0xfff) | ((long)((unsigned long long)off>>(12 + 8*(sizeof(off_t)-sizeof(long))))))
|
||||
start = (void *)-1;
|
||||
#ifdef __NR_mmap2
|
||||
return (void *)syscall6(__NR_mmap2, (long)start, len, prot, flags, fd, off>>12);
|
||||
#else
|
||||
return (void *)syscall6(__NR_mmap, (long)start, len, prot, flags, fd, off);
|
||||
#endif
|
||||
}
|
||||
|
||||
LFS64(mmap);
|
||||
|
|
|
@ -8,4 +8,7 @@ int __munmap(void *start, size_t len)
|
|||
return syscall2(__NR_munmap, (long)start, len);
|
||||
}
|
||||
|
||||
weak_alias(__munmap, munmap);
|
||||
int munmap(void *start, size_t len)
|
||||
{
|
||||
return syscall2(__NR_munmap, (long)start, len);
|
||||
}
|
||||
|
|
|
@ -42,4 +42,12 @@ int __sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
|
|||
return __libc_sigaction(sig, sa, old);
|
||||
}
|
||||
|
||||
weak_alias(__sigaction, sigaction);
|
||||
int sigaction(int sig, const struct sigaction *sa, struct sigaction *old)
|
||||
{
|
||||
if (sig == SIGCANCEL || sig == SIGSYSCALL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return __libc_sigaction(sig, sa, old);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,5 +19,26 @@ int __sigprocmask(int how, const sigset_t *set, sigset_t *old)
|
|||
return __libc_sigprocmask(how, set, old);
|
||||
}
|
||||
|
||||
weak_alias(__sigprocmask, sigprocmask);
|
||||
weak_alias(__sigprocmask, pthread_sigmask);
|
||||
int sigprocmask(int how, const sigset_t *set, sigset_t *old)
|
||||
{
|
||||
sigset_t tmp;
|
||||
/* Quickly mask out bits 32 and 33 (thread control signals) */
|
||||
if (0 && how != SIG_UNBLOCK && (set->__bits[4/sizeof *set->__bits] & 3UL<<(32&8*sizeof *set->__bits-1))) {
|
||||
tmp = *set;
|
||||
set = &tmp;
|
||||
tmp.__bits[4/sizeof *set->__bits] &= ~(3UL<<(32&8*sizeof *set->__bits-1));
|
||||
}
|
||||
return __libc_sigprocmask(how, set, old);
|
||||
}
|
||||
|
||||
int pthread_sigmask(int how, const sigset_t *set, sigset_t *old)
|
||||
{
|
||||
sigset_t tmp;
|
||||
/* Quickly mask out bits 32 and 33 (thread control signals) */
|
||||
if (0 && how != SIG_UNBLOCK && (set->__bits[4/sizeof *set->__bits] & 3UL<<(32&8*sizeof *set->__bits-1))) {
|
||||
tmp = *set;
|
||||
set = &tmp;
|
||||
tmp.__bits[4/sizeof *set->__bits] &= ~(3UL<<(32&8*sizeof *set->__bits-1));
|
||||
}
|
||||
return __libc_sigprocmask(how, set, old);
|
||||
}
|
||||
|
|
|
@ -7,4 +7,10 @@ void clearerr(FILE *f)
|
|||
FUNLOCK(f);
|
||||
}
|
||||
|
||||
weak_alias(clearerr, clearerr_unlocked);
|
||||
void clearerr_unlocked(FILE *f)
|
||||
{
|
||||
FLOCK(f);
|
||||
f->flags &= ~(F_EOF|F_ERR);
|
||||
FUNLOCK(f);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,4 +7,7 @@ int feof(FILE *f)
|
|||
return !!(f->flags & F_EOF);
|
||||
}
|
||||
|
||||
weak_alias(feof, feof_unlocked);
|
||||
int feof_unlocked(FILE *f)
|
||||
{
|
||||
return !!(f->flags & F_EOF);
|
||||
}
|
||||
|
|
|
@ -7,4 +7,7 @@ int ferror(FILE *f)
|
|||
return !!(f->flags & F_ERR);
|
||||
}
|
||||
|
||||
weak_alias(ferror, ferror_unlocked);
|
||||
int ferror_unlocked(FILE *f)
|
||||
{
|
||||
return !!(f->flags & F_ERR);
|
||||
}
|
||||
|
|
|
@ -8,3 +8,12 @@ int fgetc(FILE *f)
|
|||
FUNLOCK(f);
|
||||
return c;
|
||||
}
|
||||
|
||||
int fgetc_unlocked(FILE *f)
|
||||
{
|
||||
int c;
|
||||
FLOCK(f);
|
||||
c = f->rpos < f->rstop ? *f->rpos++ : __uflow(f);
|
||||
FUNLOCK(f);
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -31,4 +31,7 @@ char *fgets(char *s, int n, FILE *f)
|
|||
return (p == s) ? 0 : s;
|
||||
}
|
||||
|
||||
weak_alias(fgets, fgets_unlocked);
|
||||
|
||||
char *fgets_unlocked(char *s, int n, FILE *f) {
|
||||
return fgets(s, n, f);
|
||||
}
|
||||
|
|
|
@ -5,4 +5,7 @@ int fileno(FILE *f)
|
|||
return f->fd;
|
||||
}
|
||||
|
||||
weak_alias(fileno, fileno_unlocked);
|
||||
int fileno_unlocked(FILE *f)
|
||||
{
|
||||
return f->fd;
|
||||
}
|
||||
|
|
|
@ -8,3 +8,12 @@ int fputc(int c, FILE *f)
|
|||
FUNLOCK(f);
|
||||
return c;
|
||||
}
|
||||
|
||||
int fputc_unlocked(int c, FILE *f)
|
||||
{
|
||||
FLOCK(f);
|
||||
if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c;
|
||||
else c = __overflow(f, c);
|
||||
FUNLOCK(f);
|
||||
return c;
|
||||
}
|
||||
|
|
|
@ -7,4 +7,9 @@ int fputs(const char *s, FILE *f)
|
|||
return (int)fwrite(s, l, 1, f) - 1;
|
||||
}
|
||||
|
||||
weak_alias(fputs, fputs_unlocked);
|
||||
int fputs_unlocked(const char *s, FILE *f)
|
||||
{
|
||||
size_t l = strlen(s);
|
||||
if (!l) return 0;
|
||||
return (int)fwrite(s, l, 1, f) - 1;
|
||||
}
|
||||
|
|
|
@ -46,4 +46,6 @@ eof:
|
|||
return (len-l)/size;
|
||||
}
|
||||
|
||||
weak_alias(fread, fread_unlocked);
|
||||
size_t fread_unlocked(void *destv, size_t size, size_t nmemb, FILE *f) {
|
||||
return fread(destv, size, nmemb, f);
|
||||
}
|
||||
|
|
|
@ -48,4 +48,12 @@ size_t fwrite(const void *src, size_t size, size_t nmemb, FILE *f)
|
|||
return l/size;
|
||||
}
|
||||
|
||||
weak_alias(fwrite, fwrite_unlocked);
|
||||
size_t fwrite_unlocked(const void *src, size_t size, size_t nmemb, FILE *f)
|
||||
{
|
||||
size_t l = size*nmemb;
|
||||
if (!l) return l;
|
||||
FLOCK(f);
|
||||
l = __fwritex(src, l, f);
|
||||
FUNLOCK(f);
|
||||
return l/size;
|
||||
}
|
||||
|
|
|
@ -10,4 +10,10 @@ char *__strdup(const char *s)
|
|||
return memcpy(d, s, l+1);
|
||||
}
|
||||
|
||||
weak_alias(__strdup, strdup);
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
size_t l = strlen(s);
|
||||
char *d = malloc(l+1);
|
||||
if (!d) return NULL;
|
||||
return memcpy(d, s, l+1);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
# this file is necessary because tcc doesn't like musl's inline-assembly implementation
|
||||
# of syscall
|
||||
.global syscall0
|
||||
.global syscall1
|
||||
.global syscall2
|
||||
.global syscall3
|
||||
.global syscall4
|
||||
.global syscall5
|
||||
.global syscall6
|
||||
|
||||
syscall0:
|
||||
syscall1:
|
||||
syscall2:
|
||||
syscall3:
|
||||
syscall4:
|
||||
syscall5:
|
||||
syscall6:
|
||||
# SysV calling convention: RDI, RSI, RDX, RCX, R8, R9, 8(%rsp)
|
||||
|
@ -13,4 +25,6 @@ syscall6:
|
|||
mov %r9, %r8
|
||||
mov 8(%rsp), %r9
|
||||
syscall
|
||||
mov %rax, %rdi
|
||||
call __syscall_ret
|
||||
ret
|
|
@ -5,3 +5,8 @@ int clock_gettime(clockid_t clk, struct timespec *ts)
|
|||
{
|
||||
return syscall2(__NR_clock_gettime, clk, (long)ts);
|
||||
}
|
||||
|
||||
int clock_settime(clockid_t clk, const struct timespec *ts)
|
||||
{
|
||||
return syscall2(__NR_clock_settime, clk, (long)ts);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue