Skip to content

Commit 06fa666

Browse files
committed
Merged in rest of Native Client changes, untested
1 parent 9e73759 commit 06fa666

37 files changed

+2207
-360
lines changed

libgc/configure.in

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ case "$THREADS" in
9494
fi
9595
AC_DEFINE(THREAD_LOCAL_ALLOC)
9696
;;
97-
*-*-linux*)
97+
*-*-linux* | *-*-nacl*)
9898
AC_DEFINE(GC_LINUX_THREADS)
9999
AC_DEFINE(_REENTRANT)
100100
;;
@@ -340,6 +340,9 @@ case "$host" in
340340
machdep="mach_dep.lo ia64_save_regs_in_stack.lo"
341341
target_ia64=true
342342
;;
343+
*-*-nacl*)
344+
AC_DEFINE(NO_EXECUTE_PERMISSION)
345+
;;
343346
esac
344347
if test x"$machdep" = x; then
345348
AC_MSG_RESULT($machdep)

libgc/gc_dlopen.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include "private/gc_priv.h"
2727

28-
# if (defined(GC_PTHREADS) && !defined(GC_DARWIN_THREADS)) \
28+
# if defined(DYNAMIC_LOADING) && (defined(GC_PTHREADS) && !defined(GC_DARWIN_THREADS)) \
2929
|| defined(GC_SOLARIS_THREADS)
3030

3131
# if defined(dlopen) && !defined(GC_USE_LD_WRAP)

libgc/include/gc_pthread_redirects.h

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
#endif
6060
int GC_pthread_join(pthread_t thread, void **retval);
6161
int GC_pthread_detach(pthread_t thread);
62+
#if defined(__native_client__) || defined(NACL)
63+
void GC_pthread_exit(void *status);
64+
# undef pthread_exit
65+
# define pthread_exit GC_pthread_exit
66+
#endif
6267

6368
#if defined(GC_OSF1_THREADS) \
6469
&& defined(_PTHREAD_USE_MANGLED_NAMES_) && !defined(_PTHREAD_USE_PTDNAM_)

libgc/include/private/gc_priv.h

+2
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,8 @@ void GC_err_puts GC_PROTO((GC_CONST char *s));
19621962
/* SPARC/Linux doesn't properly define SIGPWR in <signal.h>.
19631963
* It is aliased to SIGLOST in asm/signal.h, though. */
19641964
# define SIG_SUSPEND SIGLOST
1965+
# elif defined(NACL)
1966+
# define SIG_SUSPEND 0
19651967
# else
19661968
/* Linuxthreads itself uses SIGUSR1 and SIGUSR2. */
19671969
# define SIG_SUSPEND SIGPWR

libgc/include/private/gcconfig.h

+43-7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565
# endif
6666

6767
/* Determine the machine type: */
68+
# if defined(__native_client__)
69+
# define NACL
70+
# define I386
71+
# define mach_type_known
72+
# endif
6873
# if defined(__arm__) || defined(__thumb__)
6974
# define ARM32
7075
# if !defined(LINUX) && !defined(NETBSD) && !defined(DARWIN)
@@ -1086,13 +1091,19 @@
10861091
# endif
10871092

10881093
# ifdef I386
1089-
# define MACH_TYPE "I386"
1090-
# if defined(__LP64__) || defined(_WIN64)
1091-
# define CPP_WORDSZ 64
1092-
# define ALIGNMENT 8
1093-
# else
1094+
# if defined( NACL )
1095+
# define MACH_TYPE "NACL"
10941096
# define CPP_WORDSZ 32
10951097
# define ALIGNMENT 4
1098+
# else
1099+
# define MACH_TYPE "I386"
1100+
# if defined(__LP64__) || defined(_WIN64)
1101+
# define CPP_WORDSZ 64
1102+
# define ALIGNMENT 8
1103+
# else
1104+
# define CPP_WORDSZ 32
1105+
# define ALIGNMENT 4
1106+
# endif
10961107
/* Appears to hold for all "32 bit" compilers */
10971108
/* except Borland. The -a4 option fixes */
10981109
/* Borland. */
@@ -1188,7 +1199,32 @@
11881199
# define HEAP_START DATAEND
11891200
# endif /* USE_MMAP */
11901201
# endif /* DGUX */
1191-
1202+
# ifdef NACL
1203+
# define OS_TYPE "NACL"
1204+
extern int etext[];
1205+
# define DATASTART ((ptr_t)((((word) (etext)) + 0xfff) & ~0xfff))
1206+
extern int _end[];
1207+
# define DATAEND (_end)
1208+
# ifdef STACK_GRAN
1209+
# undef STACK_GRAN
1210+
# endif /* STACK_GRAN */
1211+
# define STACK_GRAN 0x10000
1212+
# define HEURISTIC1
1213+
# ifdef USE_MMAP
1214+
# undef USE_MMAP
1215+
# endif
1216+
# ifdef USE_MUNMAP
1217+
# undef USE_MUNMAP
1218+
# endif
1219+
# ifdef USE_MMAP_ANON
1220+
# undef USE_MMAP_ANON
1221+
# endif
1222+
# ifdef USE_MMAP_FIXED
1223+
# undef USE_MMAP_FIXED
1224+
# endif
1225+
# define GETPAGESIZE() 65536
1226+
# define MAX_NACL_GC_THREADS 1024
1227+
# endif
11921228
# ifdef LINUX
11931229
# ifndef __GNUC__
11941230
/* The Intel compiler doesn't like inline assembly */
@@ -2271,7 +2307,7 @@
22712307
# if defined(GC_IRIX_THREADS) && !defined(IRIX5)
22722308
--> inconsistent configuration
22732309
# endif
2274-
# if defined(GC_LINUX_THREADS) && !defined(LINUX)
2310+
# if defined(GC_LINUX_THREADS) && !(defined(LINUX) || defined(NACL))
22752311
--> inconsistent configuration
22762312
# endif
22772313
# if defined(GC_SOLARIS_THREADS) && !defined(SUNOS5)

libgc/include/private/pthread_stop_world.h

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ struct thread_stop_info {
77
/* last successfully handled a suspend */
88
/* signal. */
99
ptr_t stack_ptr; /* Valid only when stopped. */
10+
#ifdef NACL
11+
/* Grab NACL_GC_REG_STORAGE_SIZE pointers off the stack when going into */
12+
/* a syscall. 20 is more than we need, but it's an overestimate in case*/
13+
/* the instrumented function uses any callee saved registers, they may */
14+
/* be pushed to the stack much earlier. Also, on amd64 'push' puts 8 */
15+
/* bytes on the stack even though our pointers are 4 bytes. */
16+
#define NACL_GC_REG_STORAGE_SIZE 20
17+
ptr_t reg_storage[NACL_GC_REG_STORAGE_SIZE];
18+
#endif
1019
};
1120

1221
#endif

libgc/include/private/pthread_support.h

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ typedef struct GC_Thread_Rep {
9292

9393
# define THREAD_TABLE_SZ 128 /* Must be power of 2 */
9494
extern volatile GC_thread GC_threads[THREAD_TABLE_SZ];
95+
#ifdef NACL
96+
extern __thread GC_thread gc_thread_self;
97+
#endif
9598

9699
extern GC_bool GC_thr_initialized;
97100

libgc/os_dep.c

+20-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
# include <errno.h>
134134
#endif
135135

136-
#ifdef UNIX_LIKE
136+
#if defined( UNIX_LIKE ) || defined(NACL)
137137
# include <fcntl.h>
138138
#endif
139139

@@ -618,6 +618,12 @@ void GC_enable_signals(void)
618618
/* longjmp implementations. Most systems appear not to have */
619619
/* a signal 32. */
620620
# define SIGSETMASK(old, new) (old) = sigsetmask(new)
621+
# elif defined(NACL)
622+
/* We don't use signals in NaCl. */
623+
# define SIGSET_T int
624+
# define SIG_DEL(set, signal)
625+
# define SIG_FILL(set)
626+
# define SIGSETMASK(old, new)
621627
# else
622628
/* Use POSIX/SYSV interface */
623629
# define SIGSET_T sigset_t
@@ -2067,8 +2073,21 @@ void GC_remap(ptr_t start, word bytes)
20672073
int result;
20682074

20692075
if (0 == start_addr) return;
2076+
#ifdef NACL
2077+
{
2078+
/* NaCl doesn't expose mprotect, but mmap should work fine */
2079+
void * mmap_result;
2080+
mmap_result = mmap(start_addr, len, PROT_READ | PROT_WRITE | OPT_PROT_EXEC,
2081+
MAP_PRIVATE | MAP_FIXED | OPT_MAP_ANON,
2082+
zero_fd, 0/* offset */);
2083+
if (mmap_result != (void *)start_addr) ABORT("mmap as mprotect failed");
2084+
/* Fake the return value as if mprotect succeeded. */
2085+
result = 0;
2086+
}
2087+
#else /* NACL */
20702088
result = mprotect(start_addr, len,
20712089
PROT_READ | PROT_WRITE | OPT_PROT_EXEC);
2090+
#endif /* NACL */
20722091
if (result != 0) {
20732092
GC_err_printf3(
20742093
"Mprotect failed at 0x%lx (length %ld) with errno %ld\n",

0 commit comments

Comments
 (0)