Browse Source

minor fix for platform flexibility

Chia-Che Tsai 9 years ago
parent
commit
26d4161af2
8 changed files with 46 additions and 40 deletions
  1. 4 4
      Pal/Makefile
  2. 1 1
      Pal/src/Makefile
  3. 9 12
      Pal/src/db_misc.c
  4. 21 0
      Pal/src/host/Linux/pal_host.h
  5. 5 0
      Pal/src/host/Linux/pal_linux.h
  6. 1 11
      Pal/src/pal.h
  7. 2 9
      Pal/src/pal_internal.h
  8. 3 3
      Pal/src/slab.c

+ 4 - 4
Pal/Makefile

@@ -35,12 +35,12 @@ $(LINUX_SRC)/Makefile:
 	[ ! -f $(LINUX_SRC).patch ] || git apply $(LINUX_SRC).patch
 
 $(LINUX_SRC)/.config:
-	$(error "Configure the Linux kernel source and rerun the make command; Or run 'make linux-deb' to build a Linux kernel package")
+	cd $(LINUX_SRC) && make menuconfig
 
 linux-deb:
-	[ -f $(LINUX_SRC)/.config ] || \
-		(cp /boot/config-$(shell uname -r) $(LINUX_SRC)/.config && \
-		cd $(LINUX_SRC) && make menuconfig)
+	if [ -f $(LINUX_SRC)/.config ]; then \
+		cp /boot/config-$(shell uname -r) $(LINUX_SRC)/.config && \
+		cd $(LINUX_SRC) && make menuconfig; fi
 	cd $(LINUX_SRC) && \
 	CONCURRENCY_LEVEL=$(NPROCS) make-kpkg --rootcmd fakeroot \
 		--append-to-version -graphene --initrd \

+ 1 - 1
Pal/src/Makefile

@@ -29,7 +29,7 @@ objs	= $(addprefix db_,streams memory threading semaphore events process \
 	    object main misc ipc exception rtld) slab printf
 graphene_lib = ../lib/graphene-lib.a
 host_lib = host/$(OS)/libpal-$(OS).a
-headers	= $(wildcard *.h) $(wildcard ../lib/*.h)
+headers	= $(wildcard *.h) $(wildcard ../lib/*.h) host/$(OS)/pal_host.h
 
 all: $(pal_target)
 

+ 9 - 12
Pal/src/db_misc.c

@@ -32,13 +32,11 @@
 PAL_NUM DkSystemTimeQuery (void)
 {
     store_frame(SystemTimeQuery);
-
     unsigned long time = _DkSystemTimeQuery();
-
     return time;
 }
 
-static struct mutex_handle lock = MUTEX_HANDLE_INIT;
+static PAL_LOCK lock = LOCK_INIT;
 static unsigned long randval = 0;
 
 static int init_randgen (void)
@@ -48,10 +46,9 @@ static int init_randgen (void)
     if (_DkRandomBitsRead(&val, sizeof(val)) < sizeof(val))
         return -PAL_ERROR_DENIED;
 
-    _DkMutexLock(&lock);
+    _DkInternalLock(&lock);
     randval = val;
-    _DkMutexUnlock(&lock);
-
+    _DkInternalUnlock(&lock);
     return 0;
 }
 
@@ -60,17 +57,17 @@ int getrand (void * buffer, int size)
     unsigned long val;
     int bytes = 0;
 
-    _DkMutexLock(&lock);
+    _DkInternalLock(&lock);
     while (!randval) {
-        _DkMutexUnlock(&lock);
+        _DkInternalUnlock(&lock);
         if (init_randgen() < 0)
             return -PAL_ERROR_DENIED;
-        _DkMutexLock(&lock);
+        _DkInternalLock(&lock);
     }
 
     val = randval;
     randval++;
-    _DkMutexUnlock(&lock);
+    _DkInternalUnlock(&lock);
 
     while (bytes + sizeof(unsigned long) <= size) {
         *(unsigned long *) (buffer + bytes) = val;
@@ -100,9 +97,9 @@ int getrand (void * buffer, int size)
         randval = hash64(randval);
     }
 
-    _DkMutexLock(&lock);
+    _DkInternalLock(&lock);
     randval = val;
-    _DkMutexUnlock(&lock);
+    _DkInternalUnlock(&lock);
 
     return bytes;
 }

+ 21 - 0
Pal/src/host/Linux/pal_host.h

@@ -30,6 +30,27 @@
 # error "cannot be included outside PAL"
 #endif
 
+/* internal Mutex design, the structure has to align at integer boundary
+   because it is required by futex call. If DEBUG_MUTEX is defined,
+   mutex_handle will record the owner of mutex locking. */
+typedef struct mutex_handle {
+    struct atomic_int value;
+#ifdef DEBUG_MUTEX
+    int owner;
+#endif
+} PAL_LOCK;
+
+/* Initializer of Mutexes */
+#define MUTEX_HANDLE_INIT    { .value = { .counter = 1 } }
+#define INIT_MUTEX_HANDLE(mut)  \
+    do { atomic_set(&(mut)->value, 1); } while (0)
+
+#define LOCK_INIT MUTEX_HANDLE_INIT
+#define INIT_LOCK(lock) INIT_MUTEX_HANDLE(lock);
+
+#define _DkInternalLock _DkMutexLock
+#define _DkInternalUnlock _DkMutexUnlock
+
 typedef union pal_handle
 {
     /* TSAI: Here we define the internal types of PAL_HANDLE

+ 5 - 0
Pal/src/host/Linux/pal_linux.h

@@ -105,6 +105,11 @@ int __clone (int (*__fn) (void * __arg), void * __child_stack,
 struct stat;
 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 _DkMutexUnlock (struct mutex_handle * mut);
+
 #if USE_VDSO_GETTIME == 1
 # if USE_CLOCK_GETTIME == 1
 struct timespec;

+ 1 - 11
Pal/src/pal.h

@@ -76,7 +76,7 @@ enum {
 
 #ifdef IN_PAL
 struct atomic_int {
-    volatile int32_t counter;
+    volatile int counter;
 } __attribute__((aligned(sizeof(int))));
 
 typedef struct atomic_int PAL_REF;
@@ -87,16 +87,6 @@ typedef struct {
     PAL_FLG flags;
 } PAL_HDR;
 
-/* internal Mutex design, the structure has to align at integer boundary
-   because it is required by futex call. If DEBUG_MUTEX is defined,
-   mutex_handle will record the owner of mutex locking. */
-struct mutex_handle {
-    struct atomic_int value;
-#ifdef DEBUG_MUTEX
-    int owner;
-#endif
-};
-
 # include "pal_host.h"
 
 # define SET_HANDLE_TYPE(handle, t)             \

+ 2 - 9
Pal/src/pal_internal.h

@@ -324,15 +324,8 @@ int _DkInitHost (int * pargc, const char *** pargv);
 
 #include <atomic.h>
 
-/* Initializer of Mutexes */
-#define MUTEX_HANDLE_INIT    { .value = { .counter = 1 } }
-#define INIT_MUTEX_HANDLE(mut)  \
-    do { atomic_set(&(mut)->value, 1); } while (0)
-
-/* Locking and unlocking of Mutexes */
-int _DkMutexLock (struct mutex_handle * mut);
-int _DkMutexLockTimeout (struct mutex_handle * mut, int timeout);
-int _DkMutexUnlock (struct mutex_handle * mut);
+int _DkInternalLock (PAL_LOCK * mut);
+int _DkInternalUnlock (PAL_LOCK * mut);
 
 /* Internal DK calls, in case any of the internal routines needs to use them */
 /* DkStream calls */

+ 3 - 3
Pal/src/slab.c

@@ -29,10 +29,10 @@
 #include "linux_list.h"
 #include "api.h"
 
-static struct mutex_handle slab_mgr_lock = MUTEX_HANDLE_INIT;
+static PAL_LOCK slab_mgr_lock = LOCK_INIT;
 
-#define system_lock()   _DkMutexLock(&slab_mgr_lock)
-#define system_unlock() _DkMutexUnlock(&slab_mgr_lock)
+#define system_lock()   _DkInternalLock(&slab_mgr_lock)
+#define system_unlock() _DkInternalUnlock(&slab_mgr_lock)
 
 #if STATIC_SLAB == 1
 # define POOL_SIZE 4096 * 20480