Browse Source

Try to correct incomplete fix for kernel vs. userspace calling convention. Seems like the current plan is to fix the calling convention in the libos, not libc. Also, fix some cases where timeouts were being cast down to 32-bit integers

Don Porter 6 years ago
parent
commit
e6b3821471

+ 5 - 7
LibOS/glibc-2.19.patch

@@ -1804,19 +1804,17 @@ diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/
 index 92c2f5b..e32ebb2 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
-@@ -31,10 +31,13 @@ ENTRY (syscall)
+@@ -31,10 +31,12 @@
  	movq %rsi, %rdi		/* shift arg1 - arg5.  */
  	movq %rdx, %rsi
  	movq %rcx, %rdx
--	movq %r8, %r10
-+	/* DEP 1/28/17: This is not the Linux kernel; use user-space calling
-+	 * 	convention	 */
-+	/*	movq %r8, %r10 */
-+	movq %r8, %rcx
++	/* DEP 8/17/17: Keep kernel calling
++	 * 	convention and fix in libOS */
+ 	movq %r8, %r10
  	movq %r9, %r8
  	movq 8(%rsp),%r9	/* arg6 is on the stack.  */
 -	syscall			/* Do the system call.  */
-+	SYSCALLDB		/* Do the system call.  */
++	SYSCALLDB			/* Do the system call.  */
  	cmpq $-4095, %rax	/* Check %rax for error.  */
  	jae SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
  	ret			/* Return to caller.  */

+ 3 - 3
Pal/src/db_events.c

@@ -128,10 +128,10 @@ static int event_close (PAL_HANDLE handle)
     return _DkEventClear(handle);
 }
 
-static int event_wait (PAL_HANDLE handle, int timeout)
+static int event_wait (PAL_HANDLE handle, uint64_t timeout)
 {
-    return timeout >=0 ? _DkEventWaitTimeout(handle, timeout) :
-           _DkEventWait(handle);
+    return timeout == NO_TIMEOUT ?    _DkEventWait(handle) : 
+        _DkEventWaitTimeout(handle, timeout);
 }
 
 struct handle_ops event_ops = {

+ 1 - 1
Pal/src/db_semaphore.c

@@ -75,7 +75,7 @@ void DkSemaphoreRelease (PAL_HANDLE handle, PAL_NUM count)
     LEAVE_PAL_CALL();
 }
 
-static int sem_wait (PAL_HANDLE handle, int timeout)
+static int sem_wait (PAL_HANDLE handle, uint64_t timeout)
 {
     return _DkSemaphoreAcquireTimeout(handle, 1, timeout);
 }

+ 1 - 1
Pal/src/host/Linux/db_events.c

@@ -79,7 +79,7 @@ int _DkEventSet (PAL_HANDLE event, int wakeup)
     return IS_ERR(ret) ? PAL_ERROR_TRYAGAIN : ret;
 }
 
-int _DkEventWaitTimeout (PAL_HANDLE event, int timeout)
+int _DkEventWaitTimeout (PAL_HANDLE event, uint64_t timeout)
 {
     int ret = 0;
 

+ 1 - 1
Pal/src/host/Linux/db_mutex.c

@@ -56,7 +56,7 @@
 
 #define MUTEX_SPINLOCK_TIMES    100
 
-int _DkMutexLockTimeout (struct mutex_handle * m, int timeout)
+int _DkMutexLockTimeout (struct mutex_handle * m, uint64_t timeout)
 {
     int ret = 0;
 #ifdef DEBUG_MUTEX

+ 2 - 2
Pal/src/host/Linux/db_object.c

@@ -46,7 +46,7 @@
  *
  *  Returns 0 on success, negative value on failure (e.g., -PAL_ERROR_TRYAGAIN)
  */
-static int _DkObjectWaitOne (PAL_HANDLE handle, int timeout)
+static int _DkObjectWaitOne (PAL_HANDLE handle, uint64_t timeout)
 {
     /* only for all these handle which has a file descriptor, or
        a eventfd. events and semaphores will skip this part */
@@ -126,7 +126,7 @@ static int _DkObjectWaitOne (PAL_HANDLE handle, int timeout)
 
 /* _DkObjectsWaitAny for internal use. The function wait for any of the handle
    in the handle array. timeout can be set for the wait. */
-int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, int timeout,
+int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, uint64_t timeout,
                        PAL_HANDLE * polled)
 {
     if (count <= 0)

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

@@ -82,7 +82,7 @@ void _DkSemaphoreDestroy (PAL_HANDLE semaphoreHandle)
     free(semaphoreHandle);
 }
 
-int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout);
+int _DkMutexLockTimeout (struct mutex_handle * mut, uint64_t timeout);
 
 int _DkSemaphoreAcquire (PAL_HANDLE sem, int count)
 {
@@ -151,10 +151,10 @@ int _DkSemaphoreAcquire (PAL_HANDLE sem, int count)
     return ret;
 }
 
-int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, int timeout)
+int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, uint64_t timeout)
 {
     /* Pass it up to the no-timeout version if no timeout requested */
-    if (timeout == -1)
+    if (timeout == NO_TIMEOUT)
         return _DkSemaphoreAcquire(sem, count);
 
     /* optimization: use it as a mutex */

+ 1 - 1
Pal/src/host/Linux/pal_linux.h

@@ -156,7 +156,7 @@ bool stataccess (struct stat * stats, int acc);
 
 /* Locking and unlocking of Mutexes */
 int _DkMutexLock (struct mutex_handle * mut);
-int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout);
+int _DkMutexLockTimeout (struct mutex_handle * mut, uint64_t timeout);
 int _DkMutexUnlock (struct mutex_handle * mut);
 
 void init_child_process (PAL_HANDLE * parent, PAL_HANDLE * exec,

+ 3 - 1
Pal/src/pal.h

@@ -466,7 +466,9 @@ DkEventClear (PAL_HANDLE eventHandle);
 
 #define NO_TIMEOUT      ((PAL_NUM) -1)
 
-/* assuming timeout to be in microseconds */
+/* assuming timeout to be in microseconds 
+ * NO_TIMEOUT means no timeout, as the name implies.
+ */
 /* Returns: NULL if the call times out, the ready handle on success */
 PAL_HANDLE
 DkObjectsWaitAny (PAL_NUM count, PAL_HANDLE * handleArray, PAL_NUM timeout);

+ 5 - 4
Pal/src/pal_internal.h

@@ -104,11 +104,12 @@ struct handle_ops {
     int (*attrsetbyhdl) (PAL_HANDLE handle, PAL_STREAM_ATTR * attr);
 
     /* 'wait' is used for synchronous wait.
+     * Time is in microseconds, NO_TIMEOUT means no timeout.
      * Returns 0 on success, a negative value on failure.
      * Timeout: -PAL_ERROR_TRYAGAIN
      * Positive return values are undefined.
      */
-    int (*wait) (PAL_HANDLE handle, int time);
+    int (*wait) (PAL_HANDLE handle, uint64_t time);
 
     /* 'rename' is used to change name of a stream, or reset its share
        option */
@@ -327,7 +328,7 @@ int _DkProcessSandboxCreate (const char * manifest, int flags);
 int _DkSemaphoreCreate (PAL_HANDLE handle, int initialCount, int maxCount);
 void _DkSemaphoreDestroy (PAL_HANDLE semaphoreHandle);
 int _DkSemaphoreAcquire (PAL_HANDLE sem, int count);
-int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, int timeout);
+int _DkSemaphoreAcquireTimeout (PAL_HANDLE sem, int count, uint64_t timeout);
 void _DkSemaphoreRelease (PAL_HANDLE sem, int count);
 int _DkSemaphoreGetCurrentCount (PAL_HANDLE sem);
 
@@ -336,7 +337,7 @@ int _DkEventCreate (PAL_HANDLE * event, bool initialState,
                     bool isnotification);
 void _DkEventDestroy (PAL_HANDLE handle);
 int _DkEventSet (PAL_HANDLE event, int wakeup);
-int _DkEventWaitTimeout (PAL_HANDLE event, int timeout);
+int _DkEventWaitTimeout (PAL_HANDLE event, uint64_t timeout);
 int _DkEventWait (PAL_HANDLE event);
 int _DkEventClear (PAL_HANDLE event);
 
@@ -348,7 +349,7 @@ int _DkVirtualMemoryProtect (void * addr, uint64_t size, int prot);
 /* DkObject calls */
 int _DkObjectReference (PAL_HANDLE objectHandle);
 int _DkObjectClose (PAL_HANDLE objectHandle);
-int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, int timeout,
+int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, uint64_t timeout,
                        PAL_HANDLE * polled);
 
 /* DkException calls & structures */