소스 검색

More NACL updates

Elijah Taylor 14 년 전
부모
커밋
ff7c67833b
6개의 변경된 파일71개의 추가작업 그리고 15개의 파일을 삭제
  1. 6 0
      configure.in
  2. 2 1
      libgc/include/private/gcconfig.h
  3. 6 0
      libgc/pthread_stop_world.c
  4. 5 0
      libgc/pthread_support.c
  5. 51 13
      mono/metadata/rand.c
  6. 1 1
      mono/utils/mono-codeman.c

+ 6 - 0
configure.in

@@ -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;

+ 2 - 1
libgc/include/private/gcconfig.h

@@ -1202,7 +1202,8 @@
 #   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

+ 6 - 0
libgc/pthread_stop_world.c

@@ -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 */

+ 5 - 0
libgc/pthread_support.c

@@ -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)
     {

+ 51 - 13
mono/metadata/rand.c

@@ -26,18 +26,7 @@
 #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

+ 1 - 1
mono/utils/mono-codeman.c

@@ -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
 
 /*