summaryrefslogtreecommitdiff
path: root/05/musl-0.6.0/src
diff options
context:
space:
mode:
Diffstat (limited to '05/musl-0.6.0/src')
-rw-r--r--05/musl-0.6.0/src/malloc/malloc.c2
-rw-r--r--05/musl-0.6.0/src/mman/madvise.c5
-rw-r--r--05/musl-0.6.0/src/mman/mmap.c12
-rw-r--r--05/musl-0.6.0/src/mman/munmap.c5
-rw-r--r--05/musl-0.6.0/src/signal/sigaction.c10
-rw-r--r--05/musl-0.6.0/src/signal/sigprocmask.c25
-rw-r--r--05/musl-0.6.0/src/stdio/clearerr.c8
-rw-r--r--05/musl-0.6.0/src/stdio/feof.c5
-rw-r--r--05/musl-0.6.0/src/stdio/ferror.c5
-rw-r--r--05/musl-0.6.0/src/stdio/fgetc.c9
-rw-r--r--05/musl-0.6.0/src/stdio/fgets.c5
-rw-r--r--05/musl-0.6.0/src/stdio/fileno.c5
-rw-r--r--05/musl-0.6.0/src/stdio/fputc.c9
-rw-r--r--05/musl-0.6.0/src/stdio/fputs.c7
-rw-r--r--05/musl-0.6.0/src/stdio/fread.c4
-rw-r--r--05/musl-0.6.0/src/stdio/fwrite.c10
-rw-r--r--05/musl-0.6.0/src/string/strdup.c8
-rw-r--r--05/musl-0.6.0/src/syscall.s (renamed from 05/musl-0.6.0/src/syscall56.s)14
-rw-r--r--05/musl-0.6.0/src/time/clock_gettime.c5
19 files changed, 137 insertions, 16 deletions
diff --git a/05/musl-0.6.0/src/malloc/malloc.c b/05/musl-0.6.0/src/malloc/malloc.c
index d9a30fe..29f9760 100644
--- a/05/musl-0.6.0/src/malloc/malloc.c
+++ b/05/musl-0.6.0/src/malloc/malloc.c
@@ -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) {
diff --git a/05/musl-0.6.0/src/mman/madvise.c b/05/musl-0.6.0/src/mman/madvise.c
index f03647c..c4ef799 100644
--- a/05/musl-0.6.0/src/mman/madvise.c
+++ b/05/musl-0.6.0/src/mman/madvise.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/mman/mmap.c b/05/musl-0.6.0/src/mman/mmap.c
index 5be6e12..665e2ec 100644
--- a/05/musl-0.6.0/src/mman/mmap.c
+++ b/05/musl-0.6.0/src/mman/mmap.c
@@ -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);
diff --git a/05/musl-0.6.0/src/mman/munmap.c b/05/musl-0.6.0/src/mman/munmap.c
index c9661cd..d1777e3 100644
--- a/05/musl-0.6.0/src/mman/munmap.c
+++ b/05/musl-0.6.0/src/mman/munmap.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/signal/sigaction.c b/05/musl-0.6.0/src/signal/sigaction.c
index b1603b9..1c35e34 100644
--- a/05/musl-0.6.0/src/signal/sigaction.c
+++ b/05/musl-0.6.0/src/signal/sigaction.c
@@ -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);
+}
+
diff --git a/05/musl-0.6.0/src/signal/sigprocmask.c b/05/musl-0.6.0/src/signal/sigprocmask.c
index e89f876..a8a4a87 100644
--- a/05/musl-0.6.0/src/signal/sigprocmask.c
+++ b/05/musl-0.6.0/src/signal/sigprocmask.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/stdio/clearerr.c b/05/musl-0.6.0/src/stdio/clearerr.c
index 3bf94d3..a409120 100644
--- a/05/musl-0.6.0/src/stdio/clearerr.c
+++ b/05/musl-0.6.0/src/stdio/clearerr.c
@@ -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);
+}
+
diff --git a/05/musl-0.6.0/src/stdio/feof.c b/05/musl-0.6.0/src/stdio/feof.c
index f2b739b..9038a7c 100644
--- a/05/musl-0.6.0/src/stdio/feof.c
+++ b/05/musl-0.6.0/src/stdio/feof.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/stdio/ferror.c b/05/musl-0.6.0/src/stdio/ferror.c
index f535fbe..2c59172 100644
--- a/05/musl-0.6.0/src/stdio/ferror.c
+++ b/05/musl-0.6.0/src/stdio/ferror.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/stdio/fgetc.c b/05/musl-0.6.0/src/stdio/fgetc.c
index 3a7f1e3..8810f35 100644
--- a/05/musl-0.6.0/src/stdio/fgetc.c
+++ b/05/musl-0.6.0/src/stdio/fgetc.c
@@ -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;
+}
diff --git a/05/musl-0.6.0/src/stdio/fgets.c b/05/musl-0.6.0/src/stdio/fgets.c
index 7939303..22dab95 100644
--- a/05/musl-0.6.0/src/stdio/fgets.c
+++ b/05/musl-0.6.0/src/stdio/fgets.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);
+}
diff --git a/05/musl-0.6.0/src/stdio/fileno.c b/05/musl-0.6.0/src/stdio/fileno.c
index 9ffb26d..38bc8e8 100644
--- a/05/musl-0.6.0/src/stdio/fileno.c
+++ b/05/musl-0.6.0/src/stdio/fileno.c
@@ -5,4 +5,7 @@ int fileno(FILE *f)
return f->fd;
}
-weak_alias(fileno, fileno_unlocked);
+int fileno_unlocked(FILE *f)
+{
+ return f->fd;
+}
diff --git a/05/musl-0.6.0/src/stdio/fputc.c b/05/musl-0.6.0/src/stdio/fputc.c
index ec85938..3e0f738 100644
--- a/05/musl-0.6.0/src/stdio/fputc.c
+++ b/05/musl-0.6.0/src/stdio/fputc.c
@@ -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;
+}
diff --git a/05/musl-0.6.0/src/stdio/fputs.c b/05/musl-0.6.0/src/stdio/fputs.c
index e6bdb20..5f78ca7 100644
--- a/05/musl-0.6.0/src/stdio/fputs.c
+++ b/05/musl-0.6.0/src/stdio/fputs.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;
+}
diff --git a/05/musl-0.6.0/src/stdio/fread.c b/05/musl-0.6.0/src/stdio/fread.c
index 0fa0b2a..8b9ca55 100644
--- a/05/musl-0.6.0/src/stdio/fread.c
+++ b/05/musl-0.6.0/src/stdio/fread.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/stdio/fwrite.c b/05/musl-0.6.0/src/stdio/fwrite.c
index 23974fe..d6bf314 100644
--- a/05/musl-0.6.0/src/stdio/fwrite.c
+++ b/05/musl-0.6.0/src/stdio/fwrite.c
@@ -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;
+}
diff --git a/05/musl-0.6.0/src/string/strdup.c b/05/musl-0.6.0/src/string/strdup.c
index dd5f80c..defd559 100644
--- a/05/musl-0.6.0/src/string/strdup.c
+++ b/05/musl-0.6.0/src/string/strdup.c
@@ -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);
+}
diff --git a/05/musl-0.6.0/src/syscall56.s b/05/musl-0.6.0/src/syscall.s
index dc81733..67af412 100644
--- a/05/musl-0.6.0/src/syscall56.s
+++ b/05/musl-0.6.0/src/syscall.s
@@ -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
diff --git a/05/musl-0.6.0/src/time/clock_gettime.c b/05/musl-0.6.0/src/time/clock_gettime.c
index dab09d5..67a05ba 100644
--- a/05/musl-0.6.0/src/time/clock_gettime.c
+++ b/05/musl-0.6.0/src/time/clock_gettime.c
@@ -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);
+}