Skip to content

Commit

Permalink
NaCl runtime fixes
Browse files Browse the repository at this point in the history
- 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
elijahtaylor authored and vargaz committed Apr 7, 2013
1 parent 28c53a3 commit 1e726ce
Show file tree
Hide file tree
Showing 58 changed files with 607 additions and 443 deletions.
30 changes: 24 additions & 6 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,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
Expand Down Expand Up @@ -1784,11 +1786,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
Expand Down Expand Up @@ -2304,6 +2308,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__"
Expand Down Expand Up @@ -2472,6 +2486,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
Expand Down Expand Up @@ -2632,7 +2650,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, [...])
Expand Down
3 changes: 0 additions & 3 deletions eglib/src/eglib-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions eglib/src/gfile-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
}
42 changes: 3 additions & 39 deletions eglib/src/gmodule-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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__ */

5 changes: 5 additions & 0 deletions ikvm-native/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions libgc/dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))) && \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)))

Expand Down
59 changes: 30 additions & 29 deletions libgc/include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
12 changes: 12 additions & 0 deletions libgc/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions libgc/pthread_stop_world.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

volatile int nacl_thread_parked[MAX_NACL_GC_THREADS];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -549,6 +549,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. */
Expand All @@ -559,7 +561,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. */
Expand All @@ -578,7 +580,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;

Expand Down Expand Up @@ -688,7 +690,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 */
Expand Down
Loading

0 comments on commit 1e726ce

Please sign in to comment.