Permalink
Browse files

NaCl runtime fixes

- fix compile/runtime issues caused by upstream changes
- add NaCl glibc support
- various changes to support running tests in NaCl glibc
  from 'make check'
  • Loading branch information...
1 parent fade2ea commit b491c919a5ad0db2e55b9a8050dd01212046e3d9 @elijahtaylor committed Jan 31, 2013
Showing with 604 additions and 443 deletions.
  1. +24 −6 configure.in
  2. +0 −3 eglib/src/eglib-config.h.in
  3. +10 −0 eglib/src/gfile-posix.c
  4. +3 −39 eglib/src/gmodule-unix.c
  5. +5 −0 ikvm-native/os.c
  6. +5 −5 libgc/dyn_load.c
  7. +30 −29 libgc/include/private/gcconfig.h
  8. +12 −0 libgc/misc.c
  9. +7 −5 libgc/pthread_stop_world.c
  10. +20 −4 libgc/pthread_support.c
  11. +5 −0 mono/dis/dump.c
  12. +29 −0 mono/io-layer/io.c
  13. +1 −1 mono/io-layer/shared.c
  14. +3 −0 mono/metadata/appdomain.c
  15. +3 −3 mono/metadata/assembly.c
  16. +1 −1 mono/metadata/boehm-gc.c
  17. +5 −2 mono/metadata/decimal.c
  18. +4 −0 mono/metadata/gc.c
  19. +12 −0 mono/metadata/icall.c
  20. +31 −0 mono/metadata/nacl-stub.c
  21. +3 −0 mono/metadata/null-gc.c
  22. +2 −0 mono/metadata/rand.c
  23. +8 −0 mono/metadata/threads.c
  24. +14 −2 mono/mini/Makefile.am.in
  25. +2 −0 mono/mini/aot-runtime.c
  26. +2 −2 mono/mini/arrays.cs
  27. +2 −2 mono/mini/basic-calls.cs
  28. +2 −2 mono/mini/basic-float.cs
  29. +2 −2 mono/mini/basic-long.cs
  30. +2 −2 mono/mini/basic-math.cs
  31. +3 −3 mono/mini/basic.cs
  32. +10 −1 mono/mini/driver.c
  33. +4 −2 mono/mini/exceptions.cs
  34. +0 −269 mono/mini/fsacheck.c
  35. +5 −0 mono/mini/genmdesc.c
  36. +3 −0 mono/mini/helpers.c
  37. +3 −0 mono/mini/ldscript
  38. +9 −1 mono/mini/mini-amd64.h
  39. +4 −0 mono/mini/mini-gc.c
  40. +10 −0 mono/mini/mini-posix.c
  41. +7 −0 mono/mini/mini.c
  42. +7 −0 mono/mini/mini.h
  43. +112 −34 mono/mini/nacl.cs
  44. +2 −2 mono/mini/objects.cs
  45. +4 −1 mono/mini/regalloc.h
  46. +1 −1 mono/mini/wapihandles.c
  47. +5 −2 mono/monograph/monograph.c
  48. +4 −0 mono/profiler/Makefile.am
  49. +5 −0 mono/profiler/decode.c
  50. +99 −0 mono/tests/Makefile.am
  51. +17 −9 mono/utils/mono-codeman.c
  52. +4 −0 mono/utils/mono-context.c
  53. +15 −0 mono/utils/mono-mmap.c
  54. +0 −5 mono/utils/mono-path.c
  55. +3 −0 mono/utils/mono-threads-posix.c
  56. +6 −3 mono/utils/monobitset.c
  57. +4 −0 runtime/Makefile.am
  58. +9 −0 runtime/mono-wrapper.in
View
@@ -1061,6 +1061,8 @@ AC_TRY_COMPILE([
AC_DEFINE_UNQUOTED(MONO_ZERO_LEN_ARRAY, 1, [Length of zero length arrays])
])
+AC_CHECK_HEADERS(nacl/nacl_dyncode.h)
+
if test x$target_win32 = xno; then
dnl hires monotonic clock support
@@ -1697,11 +1699,13 @@ if test x$target_win32 = xno; then
dnl **********************************
dnl *** epoll ***
dnl **********************************
- AC_CHECK_HEADERS(sys/epoll.h)
- haveepoll=no
- AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
- if test "x$haveepoll" = "xyes" -a "x$ac_cv_header_sys_epoll_h" = "xyes" ; then
- AC_DEFINE(HAVE_EPOLL, 1, [epoll supported])
+ if test "x$ac_cv_header_nacl_nacl_dyncode_h" = "xno"; then
+ AC_CHECK_HEADERS(sys/epoll.h)
+ haveepoll=no
+ AC_CHECK_FUNCS(epoll_ctl, [haveepoll=yes], )
+ if test "x$haveepoll" = "xyes" -a "x$ac_cv_header_sys_epoll_h" = "xyes"; then
+ AC_DEFINE(HAVE_EPOLL, 1, [epoll supported])
+ fi
fi
havekqueue=no
@@ -2202,6 +2206,16 @@ AC_ARG_ENABLE(nacl_codegen, [ --enable-nacl-codegen Enable Native Client c
AC_ARG_ENABLE(nacl_gc, [ --enable-nacl-gc Enable Native Client garbage collection], enable_nacl_gc=$enableval, enable_nacl_gc=no)
AM_CONDITIONAL(NACL_CODEGEN, test x$enable_nacl_codegen != xno)
+
+dnl
+dnl Hack to use system mono for operations in build/install not allowed in NaCl.
+dnl
+nacl_self_host=""
+if test "x$ac_cv_header_nacl_nacl_dyncode_h" = "xyes"; then
+ nacl_self_host="nacl_self_host"
+fi
+AC_SUBST(nacl_self_host)
+
if test "x$enable_nacl_codegen" = "xyes"; then
MONO_NACL_ALIGN_MASK_OFF=1
CPPFLAGS="$CPPFLAGS -D__native_client_codegen__"
@@ -2370,6 +2384,10 @@ case "$host" in
TARGET=AMD64;
arch_target=amd64;
JIT_SUPPORTED=yes
+ if test "x$ac_cv_sizeof_void_p" = "x4"; then
+ AC_DEFINE(__mono_ilp32__, 1, [64 bit mode with 4 byte longs and pointers])
+ sizeof_register=8
+ fi
case $host_os in
linux*)
sgen_supported=true
@@ -2551,7 +2569,7 @@ 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)
+ i686-*-nacl)
TARGET=X86
arch_target=x86
AC_DEFINE(TARGET_X86, 1, [...])
@@ -37,9 +37,6 @@ typedef signed @GSIZE@ gssize;
#endif
#if defined (__native_client__)
-#define sem_trywait(x) sem_wait(x)
-#define sem_timedwait(x,y) sem_wait(x)
-#define getdtablesize() (32768)
#undef G_BREAKPOINT
#define G_BREAKPOINT()
#endif
View
@@ -154,6 +154,15 @@ g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error)
gchar *
g_get_current_dir (void)
{
+#ifdef __native_client__
+ char *buffer;
+ if ((buffer = getenv("NACL_PWD"))) {
+ buffer = g_strdup(buffer);
+ } else {
+ buffer = g_strdup(".");
+ }
+ return buffer;
+#else
int s = 32;
char *buffer = NULL, *r;
gboolean fail;
@@ -172,4 +181,5 @@ g_get_current_dir (void)
* so we return the buffer here since it has a pointer to the valid string
*/
return buffer;
+#endif
}
View
@@ -28,46 +28,12 @@
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
+#include <config.h>
+
#include <glib.h>
#include <gmodule.h>
-#if defined(__native_client__)
-GModule *
-g_module_open (const gchar *file, GModuleFlags flags)
-{
- printf("dlopen() not supported on Native Client.\n");
- return NULL;
-}
-
-
-gboolean
-g_module_symbol (GModule *module, const gchar *symbol_name, gpointer *symbol)
-{
- return FALSE;
-}
-
-
-const gchar*
-g_module_error(void)
-{
- return "dlopen not supported on Native Client.";
-}
-
-gboolean
-g_module_close (GModule *module)
-{
- return FALSE;
-}
-
-gchar*
-g_module_build_path (const gchar *directory, const gchar *module_name)
-{
- return NULL;
-}
-
-#else
-
-#ifdef G_OS_UNIX
+#if defined(G_OS_UNIX) && defined(HAVE_DLFCN_H)
#include <dlfcn.h>
/* For Linux and Solaris, need to add others as we port this */
@@ -322,5 +288,3 @@ g_module_build_path (const gchar *directory, const gchar *module_name)
return g_strdup_printf ("%s%s" LIBSUFFIX, lib_prefix, module_name);
}
-#endif /* __native_client__ */
-
View
@@ -95,6 +95,11 @@
JNIEXPORT int JNICALL ikvm_msync(void* address, jint size)
{
+#if defined(__native_client__) && defined(USE_NEWLIB)
+ g_assert_not_reached ();
+ return -1;
+#else
return msync(address, size, MS_SYNC);
+#endif
}
#endif
View
@@ -26,7 +26,7 @@
* None of this is safe with dlclose and incremental collection.
* But then not much of anything is safe in the presence of dlclose.
*/
-#if defined(__linux__) && !defined(_GNU_SOURCE)
+#if (defined(__linux__) || defined(__native_client__)) && !defined(_GNU_SOURCE)
/* Can't test LINUX, since this must be define before other includes */
# define _GNU_SOURCE
#endif
@@ -54,7 +54,7 @@
#if !defined(SUNOS4) && !defined(SUNOS5DL) && !defined(IRIX5) && \
!defined(MSWIN32) && !defined(MSWINCE) && \
!(defined(ALPHA) && defined(OSF1)) && \
- !defined(HPUX) && !(defined(LINUX) && defined(__ELF__)) && \
+ !defined(HPUX) && !((defined(LINUX) || defined(NACL)) && defined(__ELF__)) && \
!defined(RS6000) && !defined(SCO_ELF) && !defined(DGUX) && \
!(defined(FREEBSD) && defined(__ELF__)) && \
!(defined(OPENBSD) && (defined(__ELF__) || defined(M68K))) && \
@@ -91,7 +91,7 @@
# define ELFSIZE ARCH_ELFSIZE
#endif
-#if defined(LINUX) && defined(__ELF__) || defined(SCO_ELF) || \
+#if (defined(LINUX) || defined(NACL)) && defined(__ELF__) || defined(SCO_ELF) || \
(defined(FREEBSD) && defined(__ELF__)) || defined(DGUX) || \
(defined(OPENBSD) && defined(__ELF__)) || \
(defined(NETBSD) && defined(__ELF__)) || defined(HURD)
@@ -297,7 +297,7 @@ void GC_register_dynamic_libraries()
# endif /* !USE_PROC ... */
# endif /* SUNOS */
-#if defined(LINUX) && defined(__ELF__) || defined(SCO_ELF) || \
+#if (defined(LINUX) || defined(NACL)) && defined(__ELF__) || defined(SCO_ELF) || \
(defined(FREEBSD) && defined(__ELF__)) || defined(DGUX) || \
(defined(OPENBSD) && defined(__ELF__)) || \
(defined(NETBSD) && defined(__ELF__)) || defined(HURD)
@@ -394,7 +394,7 @@ GC_bool GC_register_main_static_data()
/* For glibc 2.2.4+. Unfortunately, it doesn't work for older */
/* versions. Thanks to Jakub Jelinek for most of the code. */
-# if defined(LINUX) /* Are others OK here, too? */ \
+# if (defined(LINUX) || defined(NACL)) /* Are others OK here, too? */ \
&& (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ > 2) \
|| (__GLIBC__ == 2 && __GLIBC_MINOR__ == 2 && defined(DT_CONFIG)))
@@ -67,8 +67,12 @@
/* Determine the machine type: */
# if defined(__native_client__)
# define NACL
-# define I386
-# define mach_type_known
+# if !defined(__portable_native_client__)
+# define I386
+# define mach_type_known
+# else
+ /* Here we will rely upon arch-specific defines. */
+# endif
# endif
# if defined(__arm__) || defined(__thumb__)
# define ARM32
@@ -928,6 +932,30 @@
# endif
# endif
+
+# ifdef NACL
+# define OS_TYPE "NACL"
+# if defined(__GLIBC__)
+# define DYNAMIC_LOADING
+# endif
+# define DATASTART ((ptr_t)0x10020000)
+ extern int _end[];
+# define DATAEND (_end)
+# ifdef STACK_GRAN
+# undef STACK_GRAN
+# endif /* STACK_GRAN */
+# define STACK_GRAN 0x10000
+# define HEURISTIC1
+# define USE_MMAP
+# define USE_MUNMAP
+# define USE_MMAP_ANON
+# ifdef USE_MMAP_FIXED
+# undef USE_MMAP_FIXED
+# endif
+# define GETPAGESIZE() 65536
+# define MAX_NACL_GC_THREADS 1024
+# endif
+
# ifdef VAX
# define MACH_TYPE "VAX"
# define ALIGNMENT 4 /* Pointers are longword aligned by 4.2 C compiler */
@@ -1204,33 +1232,6 @@
# define HEAP_START DATAEND
# endif /* USE_MMAP */
# endif /* DGUX */
-# ifdef NACL
-# define OS_TYPE "NACL"
- extern int etext[];
-//# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
-# define DATASTART ((ptr_t)0x10000000)
- extern int _end[];
-# define DATAEND (_end)
-# ifdef STACK_GRAN
-# undef STACK_GRAN
-# endif /* STACK_GRAN */
-# define STACK_GRAN 0x10000
-# define HEURISTIC1
-# ifdef USE_MMAP
-# undef USE_MMAP
-# endif
-# ifdef USE_MUNMAP
-# undef USE_MUNMAP
-# endif
-# ifdef USE_MMAP_ANON
-# undef USE_MMAP_ANON
-# endif
-# ifdef USE_MMAP_FIXED
-# undef USE_MMAP_FIXED
-# endif
-# define GETPAGESIZE() 65536
-# define MAX_NACL_GC_THREADS 1024
-# endif
# ifdef LINUX
# ifndef __GNUC__
/* The Intel compiler doesn't like inline assembly */
View
@@ -1003,7 +1003,11 @@ long a, b, c, d, e, f;
buf[1024] = 0x15;
(void) sprintf(buf, format, a, b, c, d, e, f);
if (buf[1024] != 0x15) ABORT("GC_printf clobbered stack");
+#ifdef NACL
+ WRITE(GC_stdout, buf, strlen(buf));
+#else
if (WRITE(GC_stdout, buf, strlen(buf)) < 0) ABORT("write to stdout failed");
+#endif
}
void GC_err_printf(format, a, b, c, d, e, f)
@@ -1015,13 +1019,21 @@ long a, b, c, d, e, f;
buf[1024] = 0x15;
(void) sprintf(buf, format, a, b, c, d, e, f);
if (buf[1024] != 0x15) ABORT("GC_err_printf clobbered stack");
+#ifdef NACL
+ WRITE(GC_stderr, buf, strlen(buf));
+#else
if (WRITE(GC_stderr, buf, strlen(buf)) < 0) ABORT("write to stderr failed");
+#endif
}
void GC_err_puts(s)
GC_CONST char *s;
{
+#ifdef NACL
+ WRITE(GC_stderr, s, strlen(s));
+#else
if (WRITE(GC_stderr, s, strlen(s)) < 0) ABORT("write to stderr failed");
+#endif
}
#if defined(LINUX) && !defined(SMALL_CONFIG)
View
@@ -24,7 +24,7 @@
#endif
#ifdef NACL
-int nacl_park_threads_now = 0;
+volatile int __nacl_thread_suspension_needed = 0;
pthread_t nacl_thread_parker = -1;
int nacl_thread_parked[MAX_NACL_GC_THREADS];
@@ -471,7 +471,7 @@ static void pthread_stop_world()
GC_printf1("pthread_stop_world: num_threads %d\n", nacl_num_gc_threads - 1);
#endif
nacl_thread_parker = pthread_self();
- nacl_park_threads_now = 1;
+ __nacl_thread_suspension_needed = 1;
while (1) {
#define NACL_PARK_WAIT_NANOSECONDS 100000
@@ -550,6 +550,8 @@ void nacl_pre_syscall_hook()
}
}
+void __nacl_suspend_thread_if_needed();
+
void nacl_post_syscall_hook()
{
/* Calling __nacl_suspend_thread_if_needed() right away should guarantee we don't mutate the GC set. */
@@ -560,7 +562,7 @@ void nacl_post_syscall_hook()
}
void __nacl_suspend_thread_if_needed() {
- if (nacl_park_threads_now) {
+ if (__nacl_thread_suspension_needed) {
pthread_t self = pthread_self();
int local_dummy = 0;
/* Don't try to park the thread parker. */
@@ -579,7 +581,7 @@ void __nacl_suspend_thread_if_needed() {
nacl_gc_thread_self->stop_info.stack_ptr = (ptr_t)(&local_dummy);
}
nacl_thread_parked[nacl_thread_idx] = 1;
- while (nacl_park_threads_now)
+ while (__nacl_thread_suspension_needed)
; /* spin */
nacl_thread_parked[nacl_thread_idx] = 0;
@@ -689,7 +691,7 @@ static void pthread_start_world()
# if DEBUG_THREADS
GC_printf0("World starting\n");
# endif
- nacl_park_threads_now = 0;
+ __nacl_thread_suspension_needed = 0;
if (GC_notify_event)
GC_notify_event (GC_EVENT_POST_START_WORLD);
#endif /* NACL */
Oops, something went wrong.

0 comments on commit b491c91

Please sign in to comment.