Browse Source

1. in printf: va_list might be passed by value; pass by address instead
2. new gcc does not the loop in _DkGetCPUInfo
3. a bug in _DkEventWait where synchronization events aren't handle
properly.

Chia-Che Tsai 8 years ago
parent
commit
eece099382

+ 1 - 1
LibOS/buildglibc.py

@@ -102,7 +102,7 @@ try:
     cflags = '{0} -O2 -U_FORTIFY_SOURCE -fno-stack-protector'.format(debug_flags)
     extra_defs = ''
     disabled_features = { 'nscd' }
-    extra_flags = '--with-tls --enable-add-ons=nptl --without-selinux {0}'.format(' '.join(['--disable-' + f for f in disabled_features]))
+    extra_flags = '--with-tls --enable-add-ons=nptl --without-selinux --disable-test {0}'.format(' '.join(['--disable-' + f for f in disabled_features]))
 
     ##    configure
     commandStr = r'CFLAGS="{2}" {3} {0}/configure --prefix={1} {4} | tee configure.out'.format(glibc, installDir, cflags, extra_defs, extra_flags)

+ 1 - 1
LibOS/shim/include/shim_internal.h

@@ -69,7 +69,7 @@ extern PAL_HANDLE debug_handle;
 void debug_printf (const char * fmt, ...);
 void debug_puts (const char * str);
 void debug_putch (int ch);
-void debug_vprintf (const char * fmt, va_list ap);
+void debug_vprintf (const char * fmt, va_list * ap);
 
 # define VMID_PREFIX     "[P%04u] "
 # define TID_PREFIX      "[%-5u] "

File diff suppressed because it is too large
+ 0 - 0
LibOS/shim/src/.packed/shim.sha384


BIN
LibOS/shim/src/.packed/shim.tar.gz


+ 69 - 69
LibOS/shim/src/shim_parser.c

@@ -50,30 +50,30 @@
 #include <linux/in6.h>
 #include <linux/un.h>
 
-static void parse_open_flags    (const char *, va_list);
-static void parse_open_mode     (const char *, va_list);
-static void parse_access_mode   (const char *, va_list);
-static void parse_clone_flags   (const char *, va_list);
-static void parse_mmap_prot     (const char *, va_list);
-static void parse_mmap_flags    (const char *, va_list);
-static void parse_exec_args     (const char *, va_list);
-static void parse_exec_envp     (const char *, va_list);
-static void parse_pipe_fds      (const char *, va_list);
-static void parse_signum        (const char *, va_list);
-static void parse_sigmask       (const char *, va_list);
-static void parse_sigprocmask_how (const char *, va_list);
-static void parse_timespec      (const char *, va_list);
-static void parse_sockaddr      (const char *, va_list);
-static void parse_futexop       (const char *, va_list);
-static void parse_ioctlop       (const char *, va_list);
-static void parse_seek          (const char *, va_list);
-static void parse_at_fdcwd      (const char *, va_list);
-static void parse_wait_option   (const char *, va_list);
+static void parse_open_flags    (const char *, va_list *);
+static void parse_open_mode     (const char *, va_list *);
+static void parse_access_mode   (const char *, va_list *);
+static void parse_clone_flags   (const char *, va_list *);
+static void parse_mmap_prot     (const char *, va_list *);
+static void parse_mmap_flags    (const char *, va_list *);
+static void parse_exec_args     (const char *, va_list *);
+static void parse_exec_envp     (const char *, va_list *);
+static void parse_pipe_fds      (const char *, va_list *);
+static void parse_signum        (const char *, va_list *);
+static void parse_sigmask       (const char *, va_list *);
+static void parse_sigprocmask_how (const char *, va_list *);
+static void parse_timespec      (const char *, va_list *);
+static void parse_sockaddr      (const char *, va_list *);
+static void parse_futexop       (const char *, va_list *);
+static void parse_ioctlop       (const char *, va_list *);
+static void parse_seek          (const char *, va_list *);
+static void parse_at_fdcwd      (const char *, va_list *);
+static void parse_wait_option   (const char *, va_list *);
 
 struct parser_table {
     int slow;
     int stop;
-    void (*parser[6]) (const char *, va_list);
+    void (*parser[6]) (const char *, va_list *);
 } syscall_parser_table[SHIM_NSYSCALLS] = {
     { .slow = 1, .parser = { NULL } }, /* read */
     { .slow = 1, .parser = { NULL } }, /* write */
@@ -423,22 +423,22 @@ static inline int is_pointer (const char * type)
         debug_vprintf((fmt), (ap));                 \
     } while (0)
 
-static inline void parse_string_arg (va_list ap)
+static inline void parse_string_arg (va_list * ap)
 {
     VPRINTF("\"%s\"", ap);
 }
 
-static inline void parse_pointer_arg (va_list ap)
+static inline void parse_pointer_arg (va_list * ap)
 {
     VPRINTF("%p", ap);
 }
 
-static inline void parse_integer_arg (va_list ap)
+static inline void parse_integer_arg (va_list * ap)
 {
     VPRINTF("%d", ap);
 }
 
-static inline void parse_syscall_args (va_list ap)
+static inline void parse_syscall_args (va_list * ap)
 {
     const char * arg_type = va_arg(ap, const char *);
 
@@ -450,7 +450,7 @@ static inline void parse_syscall_args (va_list ap)
         parse_integer_arg(ap);
 }
 
-static inline void skip_syscall_args (va_list ap)
+static inline void skip_syscall_args (va_list * ap)
 {
     const char * arg_type = va_arg (ap, const char *);
 
@@ -466,7 +466,7 @@ void sysparser_printf (const char * fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    VPRINTF(fmt, ap);
+    VPRINTF(fmt, &ap);
     va_end(ap);
 }
 
@@ -494,9 +494,9 @@ void parse_syscall_before (int sysno, const char * name, int nr, ...)
 
         if (parser->parser[i]) {
             const char * type = va_arg(ap, const char *);
-            (*parser->parser[i])(type, ap);
+            (*parser->parser[i])(type, &ap);
         } else
-            parse_syscall_args(ap);
+            parse_syscall_args(&ap);
     }
 
     PUTCH(')');
@@ -513,7 +513,7 @@ void parse_syscall_after (int sysno, const char * name, int nr, ...)
     struct parser_table * parser = &syscall_parser_table[sysno];
 
     va_list ap;
-    va_start (ap, nr);
+    va_start(ap, nr);
 
     const char * ret_type = va_arg(ap, const char *);
 
@@ -533,7 +533,7 @@ void parse_syscall_after (int sysno, const char * name, int nr, ...)
     if (!parser->slow || parser->stop)
         for (int i = 0 ; i < nr ; i++) {
             if (parser->stop && i < parser->stop) {
-                skip_syscall_args (ap);
+                skip_syscall_args(&ap);
                 continue;
             }
 
@@ -542,9 +542,9 @@ void parse_syscall_after (int sysno, const char * name, int nr, ...)
 
             if (parser->parser[i]) {
                 const char * type = va_arg(ap, const char *);
-                (*parser->parser[i])(type, ap);
+                (*parser->parser[i])(type, &ap);
             } else
-                parse_syscall_args(ap);
+                parse_syscall_args(&ap);
         }
 
     if (is_pointer(ret_type)) {
@@ -562,9 +562,9 @@ void parse_syscall_after (int sysno, const char * name, int nr, ...)
     va_end (ap);
 }
 
-static void parse_open_flags (const char * type, va_list ap)
+static void parse_open_flags (const char * type, va_list * ap)
 {
-    int flags = va_arg (ap, int);
+    int flags = va_arg(*ap, int);
 
     if (flags & O_WRONLY) {
         PUTS("O_WRONLY");
@@ -596,14 +596,14 @@ static void parse_open_flags (const char * type, va_list ap)
         PRINTF("|%o", flags);
 }
 
-static void parse_open_mode (const char * type, va_list ap)
+static void parse_open_mode (const char * type, va_list * ap)
 {
     VPRINTF("%04o", ap);
 }
 
-static void parse_access_mode (const char * type, va_list ap)
+static void parse_access_mode (const char * type, va_list * ap)
 {
-    int mode = va_arg (ap, int);
+    int mode = va_arg(*ap, int);
 
     PUTS("F_OK");
 
@@ -617,9 +617,9 @@ static void parse_access_mode (const char * type, va_list ap)
     }
 }
 
-static void parse_clone_flags (const char * type, va_list ap)
+static void parse_clone_flags (const char * type, va_list * ap)
 {
-    int flags = va_arg (ap, int);
+    int flags = va_arg(*ap, int);
 
 #define FLG(n) { "CLONE_" #n, CLONE_##n, }
     const struct {
@@ -648,9 +648,9 @@ static void parse_clone_flags (const char * type, va_list ap)
         PRINTF("|0x%x", flags);
 }
 
-static void parse_mmap_prot (const char * type, va_list ap)
+static void parse_mmap_prot (const char * type, va_list * ap)
 {
-    int prot = va_arg (ap, int);
+    int prot = va_arg(*ap, int);
     int nflags = 0;
 
     if (prot == PROT_NONE) {
@@ -678,9 +678,9 @@ static void parse_mmap_prot (const char * type, va_list ap)
     }
 }
 
-static void parse_mmap_flags (const char * type, va_list ap)
+static void parse_mmap_flags (const char * type, va_list * ap)
 {
-    int flags = va_arg (ap, int);
+    int flags = va_arg(*ap, int);
 
     if (flags & MAP_SHARED) {
         PUTS("MAP_SHARED");
@@ -718,9 +718,9 @@ static void parse_mmap_flags (const char * type, va_list ap)
         PRINTF("|0x%x", flags);
 }
 
-static void parse_exec_args (const char * type, va_list ap)
+static void parse_exec_args (const char * type, va_list * ap)
 {
-    const char ** args = va_arg (ap, const char **);
+    const char ** args = va_arg(*ap, const char **);
 
     PUTS("[");
 
@@ -732,9 +732,9 @@ static void parse_exec_args (const char * type, va_list ap)
     PUTS("]");
 }
 
-static void parse_exec_envp (const char * type, va_list ap)
+static void parse_exec_envp (const char * type, va_list * ap)
 {
-    const char ** envp = va_arg (ap, const char **);
+    const char ** envp = va_arg(*ap, const char **);
 
     if (!envp) {
         PUTS("NULL");
@@ -757,9 +757,9 @@ static void parse_exec_envp (const char * type, va_list ap)
     PUTS("]");
 }
 
-static void parse_pipe_fds (const char * type, va_list ap)
+static void parse_pipe_fds (const char * type, va_list * ap)
 {
-    int * fds = va_arg (ap, int *);
+    int * fds = va_arg(*ap, int *);
 
     PRINTF("[%d, %d]", fds[0], fds[1]);
 }
@@ -791,17 +791,17 @@ const char *const siglist[NUM_KNOWN_SIGS + 1] =
         S(SIGTTIN),
         S(SIGTTOU),  };
 
-static void parse_signum (const char * type, va_list ap)
+static void parse_signum (const char * type, va_list * ap)
 {
-    unsigned int signum = va_arg (ap, unsigned int);
+    unsigned int signum = va_arg(*ap, unsigned int);
 
     if (signum > 0 && signum <= NUM_KNOWN_SIGS)
         PUTS(signal_name(signum));
 }
 
-static void parse_sigmask (const char * type, va_list ap)
+static void parse_sigmask (const char * type, va_list * ap)
 {
-    __sigset_t * sigset = va_arg(ap, __sigset_t *);
+    __sigset_t * sigset = va_arg(*ap, __sigset_t *);
 
     if (!sigset) {
         PUTS("NULL");
@@ -819,9 +819,9 @@ static void parse_sigmask (const char * type, va_list ap)
     PUTS("]");
 }
 
-static void parse_sigprocmask_how (const char * type, va_list ap)
+static void parse_sigprocmask_how (const char * type, va_list * ap)
 {
-    int how = va_arg (ap, int);
+    int how = va_arg(*ap, int);
 
     switch (how) {
         case SIG_BLOCK:
@@ -839,9 +839,9 @@ static void parse_sigprocmask_how (const char * type, va_list ap)
     }
 }
 
-static void parse_timespec (const char * type, va_list ap)
+static void parse_timespec (const char * type, va_list * ap)
 {
-    const struct timespec *tv = va_arg (ap, const struct timespec *);
+    const struct timespec * tv = va_arg(*ap, const struct timespec *);
 
     if (!tv) {
         PUTS("NULL");
@@ -851,9 +851,9 @@ static void parse_timespec (const char * type, va_list ap)
     PRINTF("[%ld,%lld]", tv->tv_sec, tv->tv_nsec);
 }
 
-static void parse_sockaddr (const char * type, va_list ap)
+static void parse_sockaddr (const char * type, va_list *ap)
 {
-    const struct sockaddr *addr = va_arg (ap, const struct sockaddr *);
+    const struct sockaddr *addr = va_arg(*ap, const struct sockaddr *);
 
     if (!addr) {
         PUTS("NULL");
@@ -891,9 +891,9 @@ static void parse_sockaddr (const char * type, va_list ap)
     }
 }
 
-static void parse_futexop (const char * type, va_list ap)
+static void parse_futexop (const char * type, va_list * ap)
 {
-    int op = va_arg (ap, int);
+    int op = va_arg(*ap, int);
 
 #ifdef FUTEX_PRIVATE_FLAG
     if (op & FUTEX_PRIVATE_FLAG) {
@@ -936,9 +936,9 @@ static void parse_futexop (const char * type, va_list ap)
     }
 }
 
-static void parse_ioctlop (const char * type, va_list ap)
+static void parse_ioctlop (const char * type, va_list * ap)
 {
-    int op = va_arg (ap, int);
+    int op = va_arg(*ap, int);
 
     if (op >= TCGETS && op <= TIOCVHANGUP) {
         const char * opnames[] = {
@@ -977,9 +977,9 @@ static void parse_ioctlop (const char * type, va_list ap)
     PRINTF("OP 0x%04u", op);
 }
 
-static void parse_seek (const char * type, va_list ap)
+static void parse_seek (const char * type, va_list * ap)
 {
-    int seek = va_arg (ap, int);
+    int seek = va_arg(*ap, int);
 
     switch(seek) {
         case SEEK_CUR:
@@ -997,9 +997,9 @@ static void parse_seek (const char * type, va_list ap)
     }
 }
 
-static void parse_at_fdcwd (const char * type, va_list ap)
+static void parse_at_fdcwd (const char * type, va_list * ap)
 {
-    int fd = va_arg (ap, int);
+    int fd = va_arg(*ap, int);
 
     switch(fd) {
         case AT_FDCWD:
@@ -1011,9 +1011,9 @@ static void parse_at_fdcwd (const char * type, va_list ap)
     }
 }
 
-static void parse_wait_option (const char * type, va_list ap)
+static void parse_wait_option (const char * type, va_list * ap)
 {
-    int option = va_arg (ap, int);
+    int option = va_arg(*ap, int);
 
     if (option & WNOHANG)
         PUTS("WNOHANG");

+ 4 - 4
LibOS/shim/src/utils/printf.c

@@ -100,7 +100,7 @@ void debug_putch (int ch)
     debug_fputch(NULL, ch, SHIM_GET_TLS()->debug_buf);
 }
 
-void debug_vprintf (const char * fmt, va_list ap)
+void debug_vprintf (const char * fmt, va_list * ap)
 {
     vfprintfmt((void *) debug_fputch, NULL, SHIM_GET_TLS()->debug_buf,
                fmt, ap);
@@ -110,7 +110,7 @@ void debug_printf (const char * fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    debug_vprintf(fmt, ap);
+    debug_vprintf(fmt, &ap);
     va_end(ap);
 }
 
@@ -162,7 +162,7 @@ sys_fputch (void * f, int ch, void * b)
 }
 
 static void
-sys_vfprintf (PAL_HANDLE hdl, const char * fmt, va_list ap)
+sys_vfprintf (PAL_HANDLE hdl, const char * fmt, va_list * ap)
 {
     vfprintfmt((void *) &sys_fputch, hdl, NULL, fmt, ap);
 }
@@ -171,6 +171,6 @@ void handle_printf (PAL_HANDLE hdl, const char * fmt, ...)
 {
     va_list ap;
     va_start(ap, fmt);
-    sys_vfprintf(hdl, fmt, ap);
+    sys_vfprintf(hdl, fmt, &ap);
     va_end(ap);
 }

+ 1 - 1
Pal/lib/api.h

@@ -42,7 +42,7 @@ void fprintfmt (void (*_fputch)(void *, int, void *), void * f, void * putdat,
                 const char * fmt, ...);
 
 void vfprintfmt (void (*_fputch)(void *, int, void *), void * f, void * putdat,
-                 const char * fmt, va_list ap);
+                 const char * fmt, va_list *ap);
 
 int snprintf (char * buf, int n, const char * fmt, ...);
 

+ 19 - 19
Pal/lib/stdlib/printfmt.c

@@ -38,42 +38,42 @@ printnum(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 // depending on the lflag parameter.
 #if !defined(__i386__)
 inline unsigned long long
-getuint(va_list ap, int lflag)
+getuint(va_list *ap, int lflag)
 #else
 inline unsigned long
-getuint(va_list ap, int lflag)
+getuint(va_list *ap, int lflag)
 #endif
 {
 #if !defined(__i386__)
 	if (lflag >= 2)
-		return va_arg(ap, unsigned long long);
+		return va_arg(*ap, unsigned long long);
 	else 
 #endif
 	if (lflag)
-		return va_arg(ap, unsigned long);
+		return va_arg(*ap, unsigned long);
 	else
-		return va_arg(ap, unsigned int);
+		return va_arg(*ap, unsigned int);
 }
 
 // Same as getuint but signed - can't use getuint
 // because of sign extension
 #if !defined(__i386__)
 inline long long
-getint(va_list ap, int lflag)
+getint(va_list *ap, int lflag)
 #else
 inline long
-getint(va_list ap, int lflag)
+getint(va_list *ap, int lflag)
 #endif
 {
 #if !defined(__i386__)
 	if (lflag >= 2)
-		return va_arg(ap, long long);
+		return va_arg(*ap, long long);
 	else
 #endif
 	if (lflag)
-		return va_arg(ap, long);
+		return va_arg(*ap, long);
 	else
-		return va_arg(ap, int);
+		return va_arg(*ap, int);
 }
 
 // Main function to format and print a string.
@@ -82,7 +82,7 @@ void fprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 
 void
 vfprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
-			   const char * fmt, va_list ap)
+			   const char * fmt, va_list *ap)
 {
 	register const char *p;
 	register int ch;
@@ -139,7 +139,7 @@ vfprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 			goto process_precision;
 
 		case '*':
-			precision = va_arg(ap, int);
+			precision = va_arg(*ap, int);
 			goto process_precision;
 
 		case '.':
@@ -163,12 +163,12 @@ vfprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 
 		// character
 		case 'c':
-			(*_fputch) (f, va_arg(ap, int), putdat);
+			(*_fputch) (f, va_arg(*ap, int), putdat);
 			break;
 
 		// string
 		case 's':
-			if ((p = va_arg(ap, char *)) == NULL)
+			if ((p = va_arg(*ap, char *)) == NULL)
 				p = "(null)";
 			if (width > 0 && padc != '-')
 				for (width -= strnlen(p, precision); width > 0; width--)
@@ -218,10 +218,10 @@ vfprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 			(*_fputch) (f, 'x', putdat);
 #if !defined(__i386__)
 			num = (unsigned long long)
-				(uintptr_t) va_arg(ap, void *);
+				(uintptr_t) va_arg(*ap, void *);
 #else
 			num = (unsigned long)
-				(uintptr_t) va_arg(ap, void *);
+				(uintptr_t) va_arg(*ap, void *);
 #endif
 			base = 16;
 			goto number;
@@ -261,7 +261,7 @@ fprintfmt(void (*_fputch)(void *, int, void *), void * f, void * putdat,
 	va_list ap;
 
 	va_start(ap, fmt);
-	vfprintfmt(_fputch, f, putdat, fmt, ap);
+	vfprintfmt(_fputch, f, putdat, fmt, &ap);
 	va_end(ap);
 }
 
@@ -280,7 +280,7 @@ sprintputch(void * f, int ch, struct sprintbuf * b)
 }
 
 static int
-vsprintf(char * buf, int n, const char * fmt, va_list ap)
+vsprintf(char * buf, int n, const char * fmt, va_list *ap)
 {
     struct sprintbuf b = {buf, buf + n - 1, 0};
 
@@ -304,7 +304,7 @@ snprintf(char * buf, int n, const char * fmt, ...)
     int rc;
 
     va_start(ap, fmt);
-    rc = vsprintf(buf, n, fmt, ap);
+    rc = vsprintf(buf, n, fmt, &ap);
     va_end(ap);
 
     return rc;

+ 1 - 1
Pal/src/Makefile

@@ -7,7 +7,7 @@ LD	= ld
 CFLAGS	= -Wall -fPIC -O2 -std=gnu99 -fgnu89-inline -U_FORTIFY_SOURCE \
 	  -fno-omit-frame-pointer \
 	  -fno-stack-protector -fno-builtin
-LDFLAGS	= -shared -static -nostdlib -z combreloc -z defs
+LDFLAGS	= -shared -nostdlib -z combreloc -z defs
 ARFLAGS	=
 
 pal_loader = libpal.so

+ 1 - 1
Pal/src/db_events.c

@@ -73,7 +73,7 @@ void DkEventSet (PAL_HANDLE handle)
     if (!handle || !IS_HANDLE_TYPE(handle, event))
         leave_frame(, PAL_ERROR_INVAL);
 
-    int ret = _DkEventSet (handle);
+    int ret = _DkEventSet(handle, -1);
 
     if (ret < 0)
         leave_frame(, -ret);

+ 11 - 6
Pal/src/host/FreeBSD/db_events.c

@@ -52,7 +52,7 @@ void _DkEventDestroy (PAL_HANDLE handle)
     free(handle);
 }
 
-int _DkEventSet (PAL_HANDLE event)
+int _DkEventSet (PAL_HANDLE event, int wakeup)
 {
     int ret = 0;
     if (event->event.isnotification) {
@@ -60,6 +60,9 @@ int _DkEventSet (PAL_HANDLE event)
         if (atomic_cmpxchg(&event->event.signaled, 0, 1) == 0) {
             int nwaiters = atomic_read(&event->event.nwaiters);
             if (nwaiters) {
+                if (wakeup != -1 && nwaiters > wakeup)
+                    nwaiters = wakeup;
+
                 ret = INLINE_SYSCALL(_umtx_op, 5, &event->event.signaled,
                                      UMTX_OP_WAKE, nwaiters, NULL, NULL);
                 if (IS_ERR(ret))
@@ -72,13 +75,13 @@ int _DkEventSet (PAL_HANDLE event)
                              UMTX_OP_WAKE, 1, NULL, NULL);
     }
 
-    return IS_ERR(ret) ? PAL_ERROR_TRYAGAIN : 0;
+    return IS_ERR(ret) ? PAL_ERROR_TRYAGAIN : ret;
 }
 
 int _DkEventWaitTimeout (PAL_HANDLE event, int timeout)
 {
     int ret = 0;
-    if (!atomic_read(&event->event.signaled)) {
+    if (!event->event.isnotification || !atomic_read(&event->event.signaled)) {
         struct timespec waittime;
         unsigned long sec = timeout / 1000000UL;
         unsigned long microsec = timeout - (sec * 1000000UL);
@@ -98,7 +101,8 @@ int _DkEventWaitTimeout (PAL_HANDLE event, int timeout)
                     break;
                 }
             }
-        } while (!atomic_read(&event->event.signaled));
+        } while (event->event.isnotification &&
+                 !atomic_read(&event->event.signaled));
 
         atomic_dec(&event->event.nwaiters);
     }
@@ -110,7 +114,7 @@ int _DkEventWait (PAL_HANDLE event)
 {
     int ret = 0;
 
-    if (!atomic_read(&event->event.signaled)) {
+    if (!event->event.isnotification || !atomic_read(&event->event.signaled)) {
         atomic_inc(&event->event.nwaiters);
 
         do {
@@ -124,7 +128,8 @@ int _DkEventWait (PAL_HANDLE event)
                     break;
                 }
             }
-        } while (!atomic_read(&event->event.signaled));
+        } while (event->event.isnotification &&
+                 !atomic_read(&event->event.signaled));
 
         atomic_dec(&event->event.nwaiters);
     }

+ 4 - 3
Pal/src/host/FreeBSD/db_main.c

@@ -344,12 +344,13 @@ static void cpuid (int cpuid_fd, unsigned int reg,
 
 #define BPI  32
 #define POWER2(power) \
-   (1 << (power))
+   (1ULL << (power))
 #define RIGHTMASK(width) \
-   (((width) >= BPI) ? ~0 : POWER2(width)-1)
+   (((unsigned long) (width) >= BPI) ? ~0ULL : POWER2(width)-1ULL)
 
 #define BIT_EXTRACT_LE(value, start, after) \
-   (((value) & RIGHTMASK(after)) >> start)
+   (((unsigned long) (value) & RIGHTMASK(after)) >> start)
+
 
 static char * cpu_flags[]
        = { "fpu",    // "x87 FPU on chip"

+ 11 - 6
Pal/src/host/Linux/db_events.c

@@ -52,7 +52,7 @@ void _DkEventDestroy (PAL_HANDLE handle)
     free(handle);
 }
 
-int _DkEventSet (PAL_HANDLE event)
+int _DkEventSet (PAL_HANDLE event, int wakeup)
 {
     int ret = 0;
 
@@ -61,6 +61,9 @@ int _DkEventSet (PAL_HANDLE event)
         if (atomic_cmpxchg(&event->event.signaled, 0, 1) == 0) {
             int nwaiters = atomic_read(&event->event.nwaiters);
             if (nwaiters) {
+                if (wakeup != -1 && nwaiters > wakeup)
+                    nwaiters = wakeup;
+
                 ret = INLINE_SYSCALL(futex, 6, &event->event.signaled,
                                      FUTEX_WAKE, nwaiters, NULL, NULL, 0);
                 if (IS_ERR(ret))
@@ -73,14 +76,14 @@ int _DkEventSet (PAL_HANDLE event)
                              NULL, NULL, 0);
     }
 
-    return IS_ERR(ret) ? PAL_ERROR_TRYAGAIN : 0;
+    return IS_ERR(ret) ? PAL_ERROR_TRYAGAIN : ret;
 }
 
 int _DkEventWaitTimeout (PAL_HANDLE event, int timeout)
 {
     int ret = 0;
 
-    if (!atomic_read(&event->event.signaled)) {
+    if (!event->event.isnotification || !atomic_read(&event->event.signaled)) {
         struct timespec waittime;
         unsigned long sec = timeout / 1000000UL;
         unsigned long microsec = timeout - (sec * 1000000UL);
@@ -101,7 +104,8 @@ int _DkEventWaitTimeout (PAL_HANDLE event, int timeout)
                     break;
                 }
             }
-        } while (!atomic_read(&event->event.signaled));
+        } while (event->event.isnotification &&
+                 !atomic_read(&event->event.signaled));
 
         atomic_dec(&event->event.nwaiters);
     }
@@ -113,7 +117,7 @@ int _DkEventWait (PAL_HANDLE event)
 {
     int ret = 0;
 
-    if (!atomic_read(&event->event.signaled)) {
+    if (!event->event.isnotification || !atomic_read(&event->event.signaled)) {
         atomic_inc(&event->event.nwaiters);
 
         do {
@@ -128,7 +132,8 @@ int _DkEventWait (PAL_HANDLE event)
                     break;
                 }
             }
-        } while (!atomic_read(&event->event.signaled));
+        } while (event->event.isnotification &&
+                 !atomic_read(&event->event.signaled));
 
         atomic_dec(&event->event.nwaiters);
     }

+ 3 - 3
Pal/src/host/Linux/db_main.c

@@ -326,12 +326,12 @@ static void cpuid (int cpuid_fd, unsigned int reg,
 
 #define BPI  32
 #define POWER2(power) \
-   (1 << (power))
+   (1ULL << (power))
 #define RIGHTMASK(width) \
-   (((width) >= BPI) ? ~0 : POWER2(width)-1)
+   (((unsigned long) (width) >= BPI) ? ~0ULL : POWER2(width)-1ULL)
 
 #define BIT_EXTRACT_LE(value, start, after) \
-   (((value) & RIGHTMASK(after)) >> start)
+   (((unsigned long) (value) & RIGHTMASK(after)) >> start)
 
 static char * cpu_flags[]
       = { "fpu",    // "x87 FPU on chip"

+ 4 - 3
Pal/src/pal_internal.h

@@ -427,7 +427,7 @@ int _DkSemaphoreGetCurrentCount (PAL_HANDLE sem);
 int _DkEventCreate (PAL_HANDLE * event, bool initialState,
                     bool isnotification);
 void _DkEventDestroy (PAL_HANDLE handle);
-int _DkEventSet (PAL_HANDLE event);
+int _DkEventSet (PAL_HANDLE event, int wakeup);
 int _DkEventWaitTimeout (PAL_HANDLE event, int timeout);
 int _DkEventWait (PAL_HANDLE event);
 int _DkEventClear (PAL_HANDLE event);
@@ -466,8 +466,9 @@ unsigned long _DkHandleCompatibilityException (unsigned long syscallno,
 
 #define init_fail(exitcode, reason)                                     \
     do {                                                                \
-        printf("PAL failed at " __FILE__ ":%s:%d (exitcode = %d, reason = %s)\n", \
-               __FUNCTION__, __LINE__, exitcode, reason);               \
+        printf("PAL failed at " __FILE__  ":%s:%u (exitcode = %u, reason=%s)\n", \
+               __FUNCTION__, (unsigned int)__LINE__,                    \
+               (unsigned int) (exitcode), (const char *) (reason));     \
         _DkProcessExit(exitcode);                                       \
     } while (0)
 

+ 2 - 2
Pal/src/printf.c

@@ -46,7 +46,7 @@ fputch(void * f, int ch, struct printbuf * b)
 }
 
 static int
-vprintf(const char * fmt, va_list ap)
+vprintf(const char * fmt, va_list *ap)
 {
     struct printbuf b;
 
@@ -65,7 +65,7 @@ printf(const char * fmt, ...)
     int cnt;
 
     va_start(ap, fmt);
-    cnt = vprintf(fmt, ap);
+    cnt = vprintf(fmt, &ap);
     va_end(ap);
 
     return cnt;

+ 2 - 2
Pal/src/security/Linux/printf.c

@@ -42,7 +42,7 @@ fputch(int fd, int ch, struct printbuf *b)
 }
 
 static int
-vprintf(const char *fmt, va_list ap)
+vprintf(const char *fmt, va_list *ap)
 {
 	struct printbuf b;
 
@@ -61,7 +61,7 @@ printf(const char *fmt, ...)
 	int cnt;
 
 	va_start(ap, fmt);
-	cnt = vprintf(fmt, ap);
+	cnt = vprintf(fmt, &ap);
 	va_end(ap);
 
 	return cnt;

Some files were not shown because too many files changed in this diff