More NACL updates
authorElijah Taylor <elijahtaylor@google.com>
Tue, 9 Aug 2011 20:03:46 +0000 (22:03 +0200)
committerZoltan Varga <vargaz@gmail.com>
Tue, 9 Aug 2011 20:03:46 +0000 (22:03 +0200)
configure.in
libgc/include/private/gcconfig.h
libgc/pthread_stop_world.c
libgc/pthread_support.c
mono/metadata/rand.c
mono/utils/mono-codeman.c

index d9c10ccc0d86070a621024266cb230148ddcb688..e28918db06013288649d0ef1bb83e232348b5b78 100644 (file)
@@ -2405,6 +2405,12 @@ if test "x$host" != "x$target"; then
                AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
                sizeof_register=8
                ;;
+   *-*-nacl)
+               TARGET=X86
+               arch_target=x86
+               AC_DEFINE(TARGET_X86, 1, [...])
+               sizeof_register=4
+               ;;
    armv7l-unknown-linux-gnueabi*)
                # TEGRA
                TARGET=ARM;
index 8ff4fbfbc0dd1f1f519f8cfc3acb4a6f978f7661..0d28d986f7c8061ec55f033eeccedb504e353172 100644 (file)
 #   ifdef NACL
 #      define OS_TYPE "NACL"
        extern int etext[];
-#      define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
+//#    define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
+#       define DATASTART ((ptr_t)0x10000000)
        extern int _end[];
 #      define DATAEND (_end)
 #      ifdef STACK_GRAN
index b1f98099d1e79e60937a2edebd00630d55df6216..3819693c45cea458812c159cb808312eeeec7e96 100644 (file)
@@ -461,6 +461,7 @@ static void pthread_stop_world()
 #else /* NACL */
     GC_thread p;
     int i;
+    int num_sleeps = 0;
 
     #if DEBUG_THREADS
     GC_printf1("pthread_stop_world: num_threads %d\n", nacl_num_gc_threads - 1);
@@ -470,6 +471,7 @@ static void pthread_stop_world()
     
     while (1) {
        #define NACL_PARK_WAIT_NANOSECONDS 100000
+        #define NANOS_PER_SECOND 1000000000
         int num_threads_parked = 0;
         struct timespec ts;
         int num_used = 0;
@@ -491,6 +493,10 @@ static void pthread_stop_world()
         GC_printf1("sleeping waiting for %d threads to park...\n", nacl_num_gc_threads - num_threads_parked - 1);
         #endif
         nanosleep(&ts, 0);
+        if (++num_sleeps > NANOS_PER_SECOND / NACL_PARK_WAIT_NANOSECONDS) {
+            GC_printf1("GC appears stalled waiting for %d threads to park...\n", nacl_num_gc_threads - num_threads_parked - 1);
+            num_sleeps = 0;
+        }
     }
 
 #endif /* NACL */
index 96e8a011b2ca5ece50e39695416fa5fdedeb56a5..4b3d825fbc7b4e4f9d4a1f0a37d995385a0199bf 100644 (file)
@@ -688,9 +688,14 @@ extern pthread_mutex_t nacl_thread_alloc_lock;
 extern __thread int nacl_thread_idx;
 extern __thread GC_thread nacl_gc_thread_self;
 
+extern void nacl_pre_syscall_hook();
+extern void nacl_post_syscall_hook();
+extern void nacl_register_gc_hooks(void (*pre)(), void (*post)());
+
 void nacl_initialize_gc_thread()
 {
     int i;
+    nacl_register_gc_hooks(nacl_pre_syscall_hook, nacl_post_syscall_hook);
     pthread_mutex_lock(&nacl_thread_alloc_lock);
     if (!nacl_thread_parking_inited)
     {
index 935325ed198af50cf485a5e6d1ad57cdc56fac4c..97b264b6a31bdd7d17025754557a160bc7d6e630 100644 (file)
 #include <mono/metadata/rand.h>
 #include <mono/metadata/exception.h>
 
-#if defined(__native_client__)
-#include <errno.h>
-
-static void
-get_entropy_from_server (const char *path, guchar *buf, int len)
-{
-    return;
-}
-
-#else /* defined(__native_client__) */
-
-#if !defined(HOST_WIN32)
+#if !defined(__native_client__) && !defined(HOST_WIN32)
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <errno.h>
@@ -107,7 +96,6 @@ get_entropy_from_server (const char *path, guchar *buf, int len)
     close (file);
 }
 #endif
-#endif /* __native_client__ */
 
 #if defined (HOST_WIN32)
 
@@ -192,6 +180,56 @@ ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpoint
        CryptReleaseContext ((HCRYPTPROV) handle, 0);
 }
 
+#elif defined (__native_client__)
+
+MonoBoolean
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngOpen (void)
+{
+       srand (time (NULL));
+       return TRUE;
+}
+
+gpointer
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngInitialize (MonoArray *seed)
+{
+       return -1;
+}
+
+gpointer 
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngGetBytes (gpointer handle, MonoArray *arry)
+{      
+       guint32 len = mono_array_length (arry);
+       guchar *buf = mono_array_addr (arry, guchar, 0);
+
+       /* Read until the buffer is filled. This may block if using NAME_DEV_RANDOM. */
+       gint count = 0;
+       gint err;
+
+       do {
+               if (len - count >= sizeof (long))
+               {
+                       *(long*)buf = rand();
+                       count += sizeof (long);
+               }
+               else if (len - count >= sizeof (short))
+               {
+                       *(short*)buf = rand();
+                       count += sizeof (short);
+               }
+               else if (len - count >= sizeof (char))
+               {
+                       *buf = rand();
+                       count += sizeof (char);
+               }
+       } while (count < len);
+
+       return (gpointer)-1L;
+}
+
+void
+ves_icall_System_Security_Cryptography_RNGCryptoServiceProvider_RngClose (gpointer handle) 
+{
+}
 #else
 
 #ifndef NAME_DEV_URANDOM
index 22284de611372e714dadb49096f901fd40c1dd5a..33dc025df3ea6d33a37223627df72bbc48aac4fa 100644 (file)
@@ -22,7 +22,7 @@
 
 #if defined(__native_client_codegen__) && defined(__native_client__)
 #include <malloc.h>
-#include <sys/nacl_syscalls.h>
+#include <nacl/nacl_dyncode.h>
 #endif
 
 /*