Merge remote-tracking branch 'ppc-port/ppc-squashed'
authorRich Felker <dalias@aerifal.cx>
Wed, 14 Nov 2012 19:01:39 +0000 (14:01 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 14 Nov 2012 19:01:39 +0000 (14:01 -0500)
98 files changed:
configure
include/pthread.h
include/sched.h
include/spawn.h
include/unistd.h
src/aio/aio_readwrite.c
src/aio/lio_listio.c
src/conf/sysconf.c
src/env/__init_tls.c
src/internal/floatscan.c
src/internal/i386/syscall.s
src/internal/intscan.c
src/internal/pthread_impl.h
src/internal/stdio_impl.h
src/ldso/dynlink.c
src/process/fork.c
src/process/posix_spawnattr_sched.c [new file with mode: 0644]
src/sched/sched_get_priority_max.c
src/sched/sched_getparam.c
src/sched/sched_getscheduler.c
src/sched/sched_rr_get_interval.c
src/sched/sched_setparam.c
src/sched/sched_setscheduler.c
src/signal/sigaction.c
src/stdio/__fdopen.c
src/stdio/__fopen_rb_ca.c
src/stdio/__stdio_read.c
src/stdio/__stdio_write.c
src/stdio/__stdout_write.c
src/stdio/__string_read.c
src/stdio/fgetln.c
src/stdio/fgets.c
src/stdio/fgetwc.c
src/stdio/fgetws.c
src/stdio/fmemopen.c
src/stdio/fopen.c
src/stdio/fputs.c
src/stdio/fputwc.c
src/stdio/fputws.c
src/stdio/fread.c
src/stdio/freopen.c
src/stdio/ftell.c
src/stdio/ftrylockfile.c
src/stdio/fwrite.c
src/stdio/getdelim.c
src/stdio/gets.c
src/stdio/getwc.c
src/stdio/getwchar.c
src/stdio/open_memstream.c
src/stdio/open_wmemstream.c
src/stdio/pclose.c
src/stdio/popen.c
src/stdio/putwc.c
src/stdio/putwchar.c
src/stdio/ungetwc.c
src/stdio/vfprintf.c
src/stdio/vfscanf.c
src/stdio/vfwprintf.c
src/stdio/vsnprintf.c
src/stdio/vswprintf.c
src/stdio/vswscanf.c
src/stdlib/strtol.c
src/stdlib/wcstod.c
src/stdlib/wcstol.c
src/thread/__wake.c
src/thread/pthread_attr_get.c [new file with mode: 0644]
src/thread/pthread_attr_getdetachstate.c [deleted file]
src/thread/pthread_attr_getguardsize.c [deleted file]
src/thread/pthread_attr_getschedparam.c [deleted file]
src/thread/pthread_attr_getscope.c [deleted file]
src/thread/pthread_attr_getstack.c [deleted file]
src/thread/pthread_attr_getstacksize.c [deleted file]
src/thread/pthread_attr_init.c
src/thread/pthread_attr_setinheritsched.c [new file with mode: 0644]
src/thread/pthread_attr_setschedparam.c
src/thread/pthread_attr_setschedpolicy.c [new file with mode: 0644]
src/thread/pthread_attr_setscope.c
src/thread/pthread_barrierattr_getpshared.c [deleted file]
src/thread/pthread_barrierattr_init.c
src/thread/pthread_cond_init.c
src/thread/pthread_condattr_getclock.c [deleted file]
src/thread/pthread_condattr_getpshared.c [deleted file]
src/thread/pthread_condattr_init.c
src/thread/pthread_create.c
src/thread/pthread_getschedparam.c [new file with mode: 0644]
src/thread/pthread_join.c
src/thread/pthread_mutex_init.c
src/thread/pthread_mutexattr_getpshared.c [deleted file]
src/thread/pthread_mutexattr_getrobust.c [deleted file]
src/thread/pthread_mutexattr_gettype.c [deleted file]
src/thread/pthread_mutexattr_init.c
src/thread/pthread_rwlock_init.c
src/thread/pthread_rwlockattr_getpshared.c [deleted file]
src/thread/pthread_rwlockattr_init.c
src/thread/pthread_setschedparam.c [new file with mode: 0644]
src/thread/pthread_setschedprio.c [new file with mode: 0644]
src/thread/synccall.c
src/time/timer_create.c

index 288d65d..08ef19a 100755 (executable)
--- a/configure
+++ b/configure
@@ -50,9 +50,8 @@ fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
 cmdexists () { type "$1" >/dev/null 2>&1 ; }
 trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; }
 
-setdir () {
-if eval "test -z \"\${$1}\"" ; then eval "$1=\$2"
-else eval "fnmatch '*/' \"\${$1}\"" && eval "$1=\${$1%/}" ; fi
+stripdir () {
+while eval "fnmatch '*/' \"\${$1}\"" ; do eval "$1=\${$1%/}" ; done
 }
 
 tryflag () {
@@ -90,15 +89,15 @@ fi
 CFLAGS_C99FSE=
 CFLAGS_AUTO=
 LDFLAGS_AUTO=
-prefix=
-exec_prefix=
-bindir=
-libdir=
-includedir=
-syslibdir=
+prefix=/usr/local/musl
+exec_prefix='$(prefix)'
+bindir='$(exec_prefix)/bin'
+libdir='$(prefix)/lib'
+includedir='$(prefix)/include'
+syslibdir='/lib'
 target=
 debug=no
-warnings=
+warnings=no
 shared=yes
 static=yes
 
@@ -135,12 +134,9 @@ LIBCC=*) LIBCC=${arg#*=} ;;
 esac
 done
 
-setdir prefix /usr/local/musl
-setdir exec_prefix '$(prefix)'
-setdir bindir '$(exec_prefix)/bin'
-setdir libdir '$(prefix)/lib'
-setdir includedir '$(prefix)/include'
-setdir syslibdir '/lib'
+for i in prefix exec_prefix bindir libdir includedir syslibdir ; do
+stripdir $i
+done
 
 #
 # Get a temp filename we can use
index 74d8600..660a64d 100644 (file)
@@ -91,6 +91,10 @@ int pthread_setcanceltype(int, int *);
 void pthread_testcancel(void);
 int pthread_cancel(pthread_t);
 
+int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict);
+int pthread_setschedparam(pthread_t, int, const struct sched_param *);
+int pthread_setschedprio(pthread_t, int);
+
 int pthread_once(pthread_once_t *, void (*)(void));
 
 int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict);
index 3df4c7b..994260d 100644 (file)
@@ -32,6 +32,9 @@ int     sched_yield(void);
 #define SCHED_OTHER 0
 #define SCHED_FIFO 1
 #define SCHED_RR 2
+#define SCHED_BATCH 3
+#define SCHED_IDLE 5
+#define SCHED_RESET_ON_FORK 0x40000000
 
 #ifdef _GNU_SOURCE
 #define CSIGNAL                0x000000ff
index a28ae69..92b77f7 100644 (file)
@@ -55,6 +55,11 @@ int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict, sigset_t *__
 int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict, const sigset_t *__restrict);
 int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict, sigset_t *__restrict);
 
+int posix_spawnattr_setschedparam(posix_spawnattr_t *__restrict, const struct sched_param *__restrict);
+int posix_spawnattr_getschedparam(const posix_spawnattr_t *__restrict, struct sched_param *__restrict);
+int posix_spawnattr_setschedpolicy(posix_spawnattr_t *__restrict, int);
+int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *__restrict, int *);
+
 int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
 int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
 
index bb741e4..2791c3d 100644 (file)
@@ -225,6 +225,7 @@ void syncfs(int);
 #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
 #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
 #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
+#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
 #define _POSIX_TIMERS           _POSIX_VERSION
 #define _POSIX_TIMEOUTS         _POSIX_VERSION
 #define _POSIX_MONOTONIC_CLOCK  _POSIX_VERSION
index 584ccb3..e4c95aa 100644 (file)
@@ -1,5 +1,8 @@
 #include <aio.h>
 #include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <limits.h>
 #include "pthread_impl.h"
 
 static void dummy(void)
index 30f7cc0..53f9f50 100644 (file)
@@ -1,5 +1,8 @@
 #include <aio.h>
 #include <errno.h>
+#include <limits.h>
+#include <unistd.h>
+#include <string.h>
 #include "pthread_impl.h"
 
 struct lio_state {
index d6691df..9f0d97b 100644 (file)
@@ -89,9 +89,9 @@ long sysconf(int name)
                [_SC_THREAD_KEYS_MAX] = PTHREAD_KEYS_MAX,
                [_SC_THREAD_STACK_MIN] = PTHREAD_STACK_MIN,
                [_SC_THREAD_THREADS_MAX] = -1,
-               [_SC_THREAD_ATTR_STACKADDR] = -1,
+               [_SC_THREAD_ATTR_STACKADDR] = VER,
                [_SC_THREAD_ATTR_STACKSIZE] = VER,
-               [_SC_THREAD_PRIORITY_SCHEDULING] = -1,
+               [_SC_THREAD_PRIORITY_SCHEDULING] = VER,
                [_SC_THREAD_PRIO_INHERIT] = -1,
                [_SC_THREAD_PRIO_PROTECT] = -1,
                [_SC_THREAD_PROCESS_SHARED] = VER,
index c71f49c..3a1b1f5 100644 (file)
@@ -1,5 +1,7 @@
 #include <elf.h>
 #include <limits.h>
+#include <sys/mman.h>
+#include <string.h>
 #include "pthread_impl.h"
 #include "libc.h"
 #include "atomic.h"
index 0825121..f6e331d 100644 (file)
@@ -4,6 +4,7 @@
 #include <float.h>
 #include <limits.h>
 #include <errno.h>
+#include <ctype.h>
 
 #include "shgetc.h"
 #include "floatscan.h"
index 291168c..2914ace 100644 (file)
@@ -16,7 +16,8 @@ __vsyscall:
        mov 12(%esp),%edi
        push %eax
        call 1f
-2:     pop %ebx
+2:     mov %ebx,%edx
+       pop %ebx
        pop %ebx
        pop %edi
        ret
index 178cdf0..69350ef 100644 (file)
@@ -1,5 +1,6 @@
 #include <limits.h>
 #include <errno.h>
+#include <ctype.h>
 #include "shgetc.h"
 
 /* Lookup table for digit values. -1==255>=36 -> invalid */
index 0f10cc4..4215e67 100644 (file)
@@ -2,17 +2,9 @@
 #define _PTHREAD_IMPL_H
 
 #include <pthread.h>
-#include <sched.h>
 #include <signal.h>
-#include <unistd.h>
-#include <sys/mman.h>
 #include <errno.h>
 #include <limits.h>
-#include <inttypes.h>
-#include <setjmp.h>
-#include <string.h>
-#include <time.h>
-#include <locale.h>
 #include "libc.h"
 #include "syscall.h"
 #include "atomic.h"
@@ -48,6 +40,8 @@ struct pthread {
        locale_t locale;
        int killlock[2];
        int exitlock[2];
+       int startlock[2];
+       unsigned long sigmask[__SYSCALL_SSLEN/sizeof(long)];
 };
 
 struct __timer {
@@ -61,6 +55,9 @@ struct __timer {
 #define _a_guardsize __u.__s[1]
 #define _a_stackaddr __u.__s[2]
 #define _a_detach __u.__i[3*__SU+0]
+#define _a_sched __u.__i[3*__SU+1]
+#define _a_policy __u.__i[3*__SU+2]
+#define _a_prio __u.__i[3*__SU+3]
 #define _m_type __u.__i[0]
 #define _m_lock __u.__i[1]
 #define _m_waiters __u.__i[2]
index e9045f2..c9d20fa 100644 (file)
@@ -2,23 +2,6 @@
 #define _STDIO_IMPL_H
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <stdarg.h>
-#include <string.h>
-#include <inttypes.h>
-#include <wchar.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>
-#include <termios.h>
-#include <sys/ioctl.h>
-#include <ctype.h>
-#include <sys/wait.h>
-#include <math.h>
-#include <float.h>
-#include <sys/uio.h>
 #include "syscall.h"
 #include "libc.h"
 
index 625f80c..ba2f612 100644 (file)
@@ -478,13 +478,16 @@ static struct dso *load_library(const char *name)
                        if (!sys_path) {
                                FILE *f = fopen(ETC_LDSO_PATH, "rbe");
                                if (f) {
-                                       if (getline(&sys_path, (size_t[1]){0}, f) > 0)
-                                               sys_path[strlen(sys_path)-1]=0;
+                                       if (getline(&sys_path, (size_t[1]){0}, f) > 0) {
+                                               size_t l = strlen(sys_path);
+                                               if (l && sys_path[l-1]=='\n')
+                                                       sys_path[-1] = 0;
+                                       }
                                        fclose(f);
                                }
                        }
-                       if (sys_path) fd = path_open(name, sys_path, buf, sizeof buf);
-                       else fd = path_open(name, "/lib:/usr/local/lib:/usr/lib", buf, sizeof buf);
+                       if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
+                       fd = path_open(name, sys_path, buf, sizeof buf);
                }
                pathname = buf;
        }
index a8bdbe0..fb8a430 100644 (file)
@@ -1,4 +1,5 @@
 #include <unistd.h>
+#include <string.h>
 #include "syscall.h"
 #include "libc.h"
 #include "pthread_impl.h"
diff --git a/src/process/posix_spawnattr_sched.c b/src/process/posix_spawnattr_sched.c
new file mode 100644 (file)
index 0000000..e2ba0d1
--- /dev/null
@@ -0,0 +1,25 @@
+#include <spawn.h>
+#include <sched.h>
+#include <errno.h>
+
+int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict attr,
+       struct sched_param *restrict schedparam)
+{
+       return ENOSYS;
+}
+
+int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict attr,
+       const struct sched_param *restrict schedparam)
+{
+       return ENOSYS;
+}
+
+int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *policy)
+{
+       return ENOSYS;
+}
+
+int posix_spawnattr_setschedpolicy(posix_spawnattr_t *restrict attr, int policy)
+{
+       return ENOSYS;
+}
index 64cbca9..30ae510 100644 (file)
@@ -1,11 +1,12 @@
 #include <sched.h>
+#include "syscall.h"
 
 int sched_get_priority_max(int policy)
 {
-       return 0;
+       return syscall(SYS_sched_get_priority_max, policy);
 }
 
 int sched_get_priority_min(int policy)
 {
-       return 0;
+       return syscall(SYS_sched_get_priority_min, policy);
 }
index 65be107..76f10e4 100644 (file)
@@ -1,7 +1,8 @@
 #include <sched.h>
+#include <errno.h>
 #include "syscall.h"
 
 int sched_getparam(pid_t pid, struct sched_param *param)
 {
-       return syscall(SYS_sched_getparam, pid, param);
+       return __syscall_ret(-ENOSYS);
 }
index 4c922f6..394e508 100644 (file)
@@ -1,7 +1,8 @@
 #include <sched.h>
+#include <errno.h>
 #include "syscall.h"
 
 int sched_getscheduler(pid_t pid)
 {
-       return syscall(SYS_sched_getscheduler, pid);
+       return __syscall_ret(-ENOSYS);
 }
index 43bc490..4b01028 100644 (file)
@@ -5,4 +5,3 @@ int sched_rr_get_interval(pid_t pid, struct timespec *ts)
 {
        return syscall(SYS_sched_rr_get_interval, pid, ts);
 }
-
index 07d61ae..18623ee 100644 (file)
@@ -1,8 +1,8 @@
 #include <sched.h>
+#include <errno.h>
 #include "syscall.h"
 
 int sched_setparam(pid_t pid, const struct sched_param *param)
 {
-       static const struct sched_param def;
-       return syscall(SYS_sched_setparam, pid, &def);
+       return __syscall_ret(-ENOSYS);
 }
index 1958066..4435f21 100644 (file)
@@ -1,8 +1,8 @@
 #include <sched.h>
+#include <errno.h>
 #include "syscall.h"
 
 int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param)
 {
-       static const struct sched_param def;
-       return syscall(SYS_sched_setscheduler, pid, 0, &def);
+       return __syscall_ret(-ENOSYS);
 }
index d953503..7a72a44 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <errno.h>
+#include <string.h>
 #include "syscall.h"
 #include "pthread_impl.h"
 #include "libc.h"
index df6ed71..59690f6 100644 (file)
@@ -1,4 +1,10 @@
 #include "stdio_impl.h"
+#include <stdlib.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
 
 FILE *__fdopen(int fd, const char *mode)
 {
index a1b1b3b..9202c8c 100644 (file)
@@ -1,4 +1,6 @@
 #include "stdio_impl.h"
+#include <fcntl.h>
+#include <string.h>
 
 FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len)
 {
index c99ca9a..05e56f9 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <sys/uio.h>
 #include <pthread.h>
 
 static void cleanup(void *p)
index cef7bbd..e52e91a 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <sys/uio.h>
 #include <pthread.h>
 
 static void cleanup(void *p)
index 0cf7123..200fe2c 100644 (file)
@@ -1,4 +1,6 @@
 #include "stdio_impl.h"
+#include <termios.h>
+#include <sys/ioctl.h>
 
 size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len)
 {
index de002fc..7b50a7e 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 size_t __string_read(FILE *f, unsigned char *buf, size_t len)
 {
index 06b8883..a2e4bd3 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 char *fgetln(FILE *f, size_t *plen)
 {
index ee0ac30..b01a418 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 #define MIN(a,b) ((a)<(b) ? (a) : (b))
 
index 6f9f9ec..8626d54 100644 (file)
@@ -1,4 +1,6 @@
 #include "stdio_impl.h"
+#include <wchar.h>
+#include <errno.h>
 
 wint_t __fgetwc_unlocked(FILE *f)
 {
index fab9bd0..195cb43 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 wint_t __fgetwc_unlocked(FILE *);
 
index 770fd99..d784960 100644 (file)
@@ -1,4 +1,7 @@
 #include "stdio_impl.h"
+#include <errno.h>
+#include <string.h>
+#include <inttypes.h>
 
 struct cookie {
        size_t pos, len, size;
@@ -105,12 +108,13 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode)
        f->seek = mseek;
        f->close = mclose;
 
-       if (!libc.threaded) {
-               f->lock = -1;
-               f->next = libc.ofl_head;
-               if (libc.ofl_head) libc.ofl_head->prev = f;
-               libc.ofl_head = f;
-       }
+       if (!libc.threaded) f->lock = -1;
+
+       OFLLOCK();
+       f->next = libc.ofl_head;
+       if (libc.ofl_head) libc.ofl_head->prev = f;
+       libc.ofl_head = f;
+       OFLUNLOCK();
 
        return f;
 }
index c741aed..da17ce8 100644 (file)
@@ -1,4 +1,7 @@
 #include "stdio_impl.h"
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
 
 FILE *fopen(const char *restrict filename, const char *restrict mode)
 {
index b41bc8c..1112b19 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 int fputs(const char *restrict s, FILE *restrict f)
 {
index 45ea8c2..7b621dd 100644 (file)
@@ -1,4 +1,7 @@
 #include "stdio_impl.h"
+#include <wchar.h>
+#include <limits.h>
+#include <ctype.h>
 
 wint_t __fputwc_unlocked(wchar_t c, FILE *f)
 {
index 0b593c0..5723cbc 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 int fputws(const wchar_t *restrict ws, FILE *restrict f)
 {
index 3f31af8..c461256 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 #define MIN(a,b) ((a)<(b) ? (a) : (b))
 
index 7ae116d..6c1b575 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <fcntl.h>
 
 /* The basic idea of this implementation is to open a new FILE,
  * hack the necessary parts of the new FILE into the old one, then
index 3904a1d..82371e3 100644 (file)
@@ -1,4 +1,6 @@
 #include "stdio_impl.h"
+#include <limits.h>
+#include <errno.h>
 
 off_t __ftello_unlocked(FILE *f)
 {
index 725c4c3..eef4e25 100644 (file)
@@ -1,5 +1,6 @@
 #include "stdio_impl.h"
 #include "pthread_impl.h"
+#include <limits.h>
 
 int ftrylockfile(FILE *f)
 {
index 8027b30..d5f6542 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <string.h>
 
 size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f)
 {
index 5015c3a..26093a6 100644 (file)
@@ -1,4 +1,7 @@
 #include "stdio_impl.h"
+#include <string.h>
+#include <inttypes.h>
+#include <errno.h>
 
 #define MIN(a,b) ((a)<(b) ? (a) : (b))
 
index 24319eb..6c4645e 100644 (file)
@@ -1,4 +1,6 @@
 #include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
 
 char *gets(char *s)
 {
index a2818bc..a5008f0 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 wint_t getwc(FILE *f)
 {
index 2295bd4..bd89e0e 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 wint_t getwchar(void)
 {
index 687e818..9eafdfb 100644 (file)
@@ -1,4 +1,7 @@
 #include "stdio_impl.h"
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
 
 struct cookie {
        char **bufp;
@@ -74,12 +77,13 @@ FILE *open_memstream(char **bufp, size_t *sizep)
        f->seek = ms_seek;
        f->close = ms_close;
 
-       if (!libc.threaded) {
-               f->lock = -1;
-               f->next = libc.ofl_head;
-               if (libc.ofl_head) libc.ofl_head->prev = f;
-               libc.ofl_head = f;
-       }
+       if (!libc.threaded) f->lock = -1;
+
+       OFLLOCK();
+       f->next = libc.ofl_head;
+       if (libc.ofl_head) libc.ofl_head->prev = f;
+       libc.ofl_head = f;
+       OFLUNLOCK();
 
        return f;
 }
index a830b14..3537030 100644 (file)
@@ -1,4 +1,8 @@
 #include "stdio_impl.h"
+#include <wchar.h>
+#include <errno.h>
+#include <limits.h>
+#include <string.h>
 
 struct cookie {
        wchar_t **bufp;
@@ -75,12 +79,13 @@ FILE *open_wmemstream(wchar_t **bufp, size_t *sizep)
        f->seek = wms_seek;
        f->close = wms_close;
 
-       if (!libc.threaded) {
-               f->lock = -1;
-               f->next = libc.ofl_head;
-               if (libc.ofl_head) libc.ofl_head->prev = f;
-               libc.ofl_head = f;
-       }
+       if (!libc.threaded) f->lock = -1;
+
+       OFLLOCK();
+       f->next = libc.ofl_head;
+       if (libc.ofl_head) libc.ofl_head->prev = f;
+       libc.ofl_head = f;
+       OFLUNLOCK();
 
        return f;
 }
index 7fb76ed..080a426 100644 (file)
@@ -1,5 +1,6 @@
 #include "stdio_impl.h"
-#include "syscall.h"
+#include <errno.h>
+#include <unistd.h>
 
 int pclose(FILE *f)
 {
index ca3cdf9..ed20f5a 100644 (file)
@@ -1,4 +1,7 @@
 #include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
 #include "stdio_impl.h"
 #include "pthread_impl.h"
 #include "syscall.h"
index 80b54a4..4bb7473 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 wint_t putwc(wchar_t c, FILE *f)
 {
index 3aacc1c..b249c4a 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 wint_t putwchar(wchar_t c)
 {
index 5282fee..8cc85a6 100644 (file)
@@ -1,4 +1,8 @@
 #include "stdio_impl.h"
+#include <wchar.h>
+#include <limits.h>
+#include <ctype.h>
+#include <string.h>
 
 wint_t ungetwc(wint_t c, FILE *f)
 {
index 4a2752b..1e7e6a4 100644 (file)
@@ -1,4 +1,13 @@
 #include "stdio_impl.h"
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <inttypes.h>
+#include <math.h>
+#include <float.h>
 
 /* Some useful macros */
 
index 54d0849..fe071e9 100644 (file)
@@ -1,4 +1,3 @@
-#include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <ctype.h>
@@ -9,6 +8,7 @@
 #include <errno.h>
 #include <math.h>
 #include <float.h>
+#include <inttypes.h>
 
 #include "stdio_impl.h"
 #include "shgetc.h"
index a42ba19..eb07931 100644 (file)
@@ -1,4 +1,11 @@
 #include "stdio_impl.h"
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdarg.h>
+#include <wchar.h>
+#include <inttypes.h>
 
 /* Convenient bit representation for modifier flags, which all fall
  * within 31 codepoints of the space character. */
index 6f19b02..be2c44e 100644 (file)
@@ -1,4 +1,8 @@
 #include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
 
 static size_t sn_write(FILE *f, const unsigned char *s, size_t l)
 {
index f3d4fec..7d237ba 100644 (file)
@@ -1,4 +1,9 @@
 #include "stdio_impl.h"
+#include <limits.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <wchar.h>
 
 struct cookie {
        wchar_t *ws;
index a205200..7a2f7c7 100644 (file)
@@ -1,4 +1,5 @@
 #include "stdio_impl.h"
+#include <wchar.h>
 
 static size_t wstring_read(FILE *f, unsigned char *buf, size_t len)
 {
index 23a2f3b..7ee8879 100644 (file)
@@ -1,6 +1,9 @@
 #include "stdio_impl.h"
 #include "intscan.h"
 #include "shgetc.h"
+#include <inttypes.h>
+#include <limits.h>
+#include <ctype.h>
 
 static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim)
 {
index 03670b0..83f308d 100644 (file)
@@ -1,6 +1,7 @@
 #include "shgetc.h"
 #include "floatscan.h"
 #include "stdio_impl.h"
+#include <wctype.h>
 
 /* This read function heavily cheats. It knows:
  *  (1) len will always be 1
index 3d7c97d..4443f57 100644 (file)
@@ -1,6 +1,10 @@
 #include "stdio_impl.h"
 #include "intscan.h"
 #include "shgetc.h"
+#include <inttypes.h>
+#include <limits.h>
+#include <wctype.h>
+#include <wchar.h>
 
 /* This read function heavily cheats. It knows:
  *  (1) len will always be 1
index 8fd0599..d8bf70f 100644 (file)
@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include <limits.h>
 
 void __wake(volatile int *addr, int cnt, int priv)
 {
diff --git a/src/thread/pthread_attr_get.c b/src/thread/pthread_attr_get.c
new file mode 100644 (file)
index 0000000..f81103d
--- /dev/null
@@ -0,0 +1,93 @@
+#include "pthread_impl.h"
+
+int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
+{
+       *state = a->_a_detach;
+       return 0;
+}
+int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
+{
+       *size = a->_a_guardsize + DEFAULT_GUARD_SIZE;
+       return 0;
+}
+
+int pthread_attr_getinheritsched(const pthread_attr_t *a, int *inherit)
+{
+       *inherit = a->_a_sched;
+       return 0;
+}
+
+int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
+{
+       param->sched_priority = a->_a_prio;
+       return 0;
+}
+
+int pthread_attr_getschedpolicy(const pthread_attr_t *a, int *policy)
+{
+       *policy = a->_a_policy;
+       return 0;
+}
+
+int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
+{
+       *scope = PTHREAD_SCOPE_SYSTEM;
+       return 0;
+}
+
+int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
+{
+       if (!a->_a_stackaddr)
+               return EINVAL;
+       *size = a->_a_stacksize + DEFAULT_STACK_SIZE;
+       *addr = (void *)(a->_a_stackaddr - *size);
+       return 0;
+}
+
+int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
+{
+       *size = a->_a_stacksize + DEFAULT_STACK_SIZE;
+       return 0;
+}
+
+int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
+{
+       *pshared = !!*a;
+       return 0;
+}
+
+int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
+{
+       *clk = *a & 0x7fffffff;
+       return 0;
+}
+
+int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
+{
+       *pshared = *a>>31;
+       return 0;
+}
+
+int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
+{
+       *pshared = *a>>31;
+       return 0;
+}
+
+int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
+{
+       *robust = *a / 4U % 2;
+       return 0;
+}
+
+int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
+{
+       *type = *a & 3;
+       return 0;
+}
+
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
+{
+       *pshared = *(int *)a;
+       return 0;
+}
diff --git a/src/thread/pthread_attr_getdetachstate.c b/src/thread/pthread_attr_getdetachstate.c
deleted file mode 100644 (file)
index 47c4c02..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state)
-{
-       *state = a->_a_detach;
-       return 0;
-}
diff --git a/src/thread/pthread_attr_getguardsize.c b/src/thread/pthread_attr_getguardsize.c
deleted file mode 100644 (file)
index 93ba05d..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
-{
-       *size = a->_a_guardsize + DEFAULT_GUARD_SIZE;
-       return 0;
-}
diff --git a/src/thread/pthread_attr_getschedparam.c b/src/thread/pthread_attr_getschedparam.c
deleted file mode 100644 (file)
index 5806bdf..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
-{
-       param->sched_priority = 0;
-       return 0;
-}
diff --git a/src/thread/pthread_attr_getscope.c b/src/thread/pthread_attr_getscope.c
deleted file mode 100644 (file)
index c0167b6..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
-{
-       return 0;
-}
diff --git a/src/thread/pthread_attr_getstack.c b/src/thread/pthread_attr_getstack.c
deleted file mode 100644 (file)
index 70adbb0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
-{
-       if (!a->_a_stackaddr)
-               return EINVAL;
-       *size = a->_a_stacksize + DEFAULT_STACK_SIZE;
-       *addr = (void *)(a->_a_stackaddr - *size);
-       return 0;
-}
diff --git a/src/thread/pthread_attr_getstacksize.c b/src/thread/pthread_attr_getstacksize.c
deleted file mode 100644 (file)
index f69cc1e..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
-{
-       *size = a->_a_stacksize + DEFAULT_STACK_SIZE;
-       return 0;
-}
index d91bf15..6693488 100644 (file)
@@ -1,7 +1,8 @@
 #include "pthread_impl.h"
+#include <string.h>
 
 int pthread_attr_init(pthread_attr_t *a)
 {
-       memset(a, 0, sizeof *a);
+       *a = (pthread_attr_t){0};
        return 0;
 }
diff --git a/src/thread/pthread_attr_setinheritsched.c b/src/thread/pthread_attr_setinheritsched.c
new file mode 100644 (file)
index 0000000..c91d8f8
--- /dev/null
@@ -0,0 +1,8 @@
+#include "pthread_impl.h"
+
+int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit)
+{
+       if (inherit > 1U) return EINVAL;
+       a->_a_sched = inherit;
+       return 0;
+}
index 77ce9c9..d4c1204 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
 {
-       if (param->sched_priority) return ENOTSUP;
+       a->_a_prio = param->sched_priority;
        return 0;
 }
diff --git a/src/thread/pthread_attr_setschedpolicy.c b/src/thread/pthread_attr_setschedpolicy.c
new file mode 100644 (file)
index 0000000..bb71f39
--- /dev/null
@@ -0,0 +1,7 @@
+#include "pthread_impl.h"
+
+int pthread_attr_setschedpolicy(pthread_attr_t *a, int policy)
+{
+       a->_a_policy = policy;
+       return 0;
+}
index d56ee39..46b520c 100644 (file)
@@ -2,6 +2,12 @@
 
 int pthread_attr_setscope(pthread_attr_t *a, int scope)
 {
-       if (scope > 1U) return EINVAL;
-       return 0;
+       switch (scope) {
+       case PTHREAD_SCOPE_SYSTEM:
+               return 0;
+       case PTHREAD_SCOPE_PROCESS:
+               return ENOTSUP;
+       default:
+               return EINVAL;
+       }
 }
diff --git a/src/thread/pthread_barrierattr_getpshared.c b/src/thread/pthread_barrierattr_getpshared.c
deleted file mode 100644 (file)
index df337c2..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
-{
-       *pshared = !!*a;
-       return 0;
-}
index f269827..fa742bb 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_barrierattr_init(pthread_barrierattr_t *a)
 {
-       memset(a, 0, sizeof *a);
+       *a = (pthread_barrierattr_t){0};
        return 0;
 }
index 2eac30f..71489bc 100644 (file)
@@ -2,7 +2,7 @@
 
 int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a)
 {
-       memset(c, 0, sizeof *c);
+       *c = (pthread_cond_t){0};
        if (a) {
                c->_c_clock = *a & 0x7fffffff;
                if (*a>>31) c->_c_mutex = (void *)-1;
diff --git a/src/thread/pthread_condattr_getclock.c b/src/thread/pthread_condattr_getclock.c
deleted file mode 100644 (file)
index d293384..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
-{
-       *clk = *a & 0x7fffffff;
-       return 0;
-}
diff --git a/src/thread/pthread_condattr_getpshared.c b/src/thread/pthread_condattr_getpshared.c
deleted file mode 100644 (file)
index 4991e49..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
-{
-       *pshared = *a>>31;
-       return 0;
-}
index 6d09ac1..a41741b 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_condattr_init(pthread_condattr_t *a)
 {
-       memset(a, 0, sizeof *a);
+       *a = (pthread_condattr_t){0};
        return 0;
 }
index e67616e..a65e88e 100644 (file)
@@ -1,5 +1,6 @@
 #include "pthread_impl.h"
 #include "stdio_impl.h"
+#include <sys/mman.h>
 
 static void dummy_0()
 {
@@ -61,6 +62,15 @@ void __do_cleanup_pop(struct __ptcb *cb)
 static int start(void *p)
 {
        pthread_t self = p;
+       if (self->startlock[0]) {
+               __wait(self->startlock, 0, 1, 1);
+               if (self->startlock[0]) {
+                       self->detached = 2;
+                       pthread_exit(0);
+               }
+               __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
+                       self->sigmask, 0, __SYSCALL_SSLEN);
+       }
        if (self->unblock_cancel)
                __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
                        SIGPT_SET, 0, __SYSCALL_SSLEN);
@@ -94,6 +104,7 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attr,
        struct pthread *self = pthread_self(), *new;
        unsigned char *map, *stack, *tsd;
        unsigned flags = 0x7d8f00;
+       int do_sched = 0;
 
        if (!self) return ENOSYS;
        if (!libc.threaded) {
@@ -143,6 +154,11 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attr,
                new->detached = 1;
                flags -= 0x200000;
        }
+       if (attr && attr->_a_sched) {
+               do_sched = new->startlock[0] = 1;
+               __syscall(SYS_rt_sigprocmask, SIG_BLOCK,
+                       SIGALL_SET, self->sigmask, __SYSCALL_SSLEN);
+       }
        new->unblock_cancel = self->cancel;
        new->canary = self->canary;
 
@@ -151,11 +167,25 @@ int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attr,
 
        __release_ptc();
 
+       if (do_sched) {
+               __syscall(SYS_rt_sigprocmask, SIG_SETMASK,
+                       new->sigmask, 0, __SYSCALL_SSLEN);
+       }
+
        if (ret < 0) {
                a_dec(&libc.threads_minus_1);
                munmap(map, size);
                return EAGAIN;
        }
+
+       if (do_sched) {
+               ret = __syscall(SYS_sched_setscheduler, new->tid,
+                       attr->_a_policy, &attr->_a_prio);
+               a_store(new->startlock, ret<0 ? 2 : 0);
+               __wake(new->startlock, 1, 1);
+               if (ret < 0) return -ret;
+       }
+
        *res = new;
        return 0;
 }
diff --git a/src/thread/pthread_getschedparam.c b/src/thread/pthread_getschedparam.c
new file mode 100644 (file)
index 0000000..7b6a95f
--- /dev/null
@@ -0,0 +1,17 @@
+#include "pthread_impl.h"
+
+int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param)
+{
+       int r;
+       __lock(t->killlock);
+       if (t->dead) {
+               r = ESRCH;
+       } else {
+               r = -__syscall(SYS_sched_getparam, t->tid, &param);
+               if (!r) {
+                       *policy = __syscall(SYS_sched_getscheduler, t->tid);
+               }
+       }
+       __unlock(t->killlock);
+       return r;
+}
index 86191f2..719c91c 100644 (file)
@@ -1,4 +1,5 @@
 #include "pthread_impl.h"
+#include <sys/mman.h>
 
 static void dummy(void *p)
 {
index fb68927..a7ba39b 100644 (file)
@@ -2,7 +2,7 @@
 
 int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a)
 {
-       memset(m, 0, sizeof *m);
+       *m = (pthread_mutex_t){0};
        if (a) m->_m_type = *a & 7;
        return 0;
 }
diff --git a/src/thread/pthread_mutexattr_getpshared.c b/src/thread/pthread_mutexattr_getpshared.c
deleted file mode 100644 (file)
index e7340b1..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
-{
-       *pshared = *a>>31;
-       return 0;
-}
diff --git a/src/thread/pthread_mutexattr_getrobust.c b/src/thread/pthread_mutexattr_getrobust.c
deleted file mode 100644 (file)
index 4d176f2..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
-{
-       *robust = *a / 4U % 2;
-       return 0;
-}
diff --git a/src/thread/pthread_mutexattr_gettype.c b/src/thread/pthread_mutexattr_gettype.c
deleted file mode 100644 (file)
index 7688b06..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
-{
-       *type = *a & 3;
-       return 0;
-}
index ea63106..0b72c1b 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_mutexattr_init(pthread_mutexattr_t *a)
 {
-       memset(a, 0, sizeof *a);
+       *a = (pthread_mutexattr_t){0};
        return 0;
 }
index 29003bc..82df52e 100644 (file)
@@ -2,7 +2,7 @@
 
 int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a)
 {
-       memset(rw, 0, sizeof *rw);
+       *rw = (pthread_rwlock_t){0};
        if (a) {
        }
        return 0;
diff --git a/src/thread/pthread_rwlockattr_getpshared.c b/src/thread/pthread_rwlockattr_getpshared.c
deleted file mode 100644 (file)
index 02fd8c8..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "pthread_impl.h"
-
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
-{
-       *pshared = *(int *)a;
-       return 0;
-}
index e0893d6..e742069 100644 (file)
@@ -2,6 +2,6 @@
 
 int pthread_rwlockattr_init(pthread_rwlockattr_t *a)
 {
-       memset(a, 0, sizeof *a);
+       *a = (pthread_rwlockattr_t){0};
        return 0;
 }
diff --git a/src/thread/pthread_setschedparam.c b/src/thread/pthread_setschedparam.c
new file mode 100644 (file)
index 0000000..8e8b5a1
--- /dev/null
@@ -0,0 +1,10 @@
+#include "pthread_impl.h"
+
+int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param)
+{
+       int r;
+       __lock(t->killlock);
+       r = t->dead ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, &param);
+       __unlock(t->killlock);
+       return r;
+}
diff --git a/src/thread/pthread_setschedprio.c b/src/thread/pthread_setschedprio.c
new file mode 100644 (file)
index 0000000..e0bdc03
--- /dev/null
@@ -0,0 +1,10 @@
+#include "pthread_impl.h"
+
+int pthread_setschedprio(pthread_t t, int prio)
+{
+       int r;
+       __lock(t->killlock);
+       r = t->dead ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio);
+       __unlock(t->killlock);
+       return r;
+}
index 2b7eac2..dc59863 100644 (file)
@@ -1,5 +1,6 @@
 #include "pthread_impl.h"
 #include <semaphore.h>
+#include <string.h>
 
 static struct chain {
        struct chain *next;
index 560f1a8..60a18c7 100644 (file)
@@ -1,4 +1,5 @@
 #include <time.h>
+#include <setjmp.h>
 #include "pthread_impl.h"
 
 struct ksigevent {