Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / libgc / misc.c
index be2555b8f2da054cf61bdf50cc367bc5ef16e9dc..480759c57b9a750d505e053ca2f29a99a5c2a770 100644 (file)
                        /* Used only for assertions, and to prevent      */
                        /* recursive reentry in the system call wrapper. */
 #              endif 
-#            else
+#            elif defined(SN_TARGET_PS3)
+                 #include <pthread.h>
+                 pthread_mutex_t GC_allocate_ml;
+#             else
                  --> declare allocator lock here
 #            endif
 #         endif
@@ -81,6 +84,8 @@
 /* dyn_load.c isn't linked in.                                         */
 #ifdef DYNAMIC_LOADING
 # define GC_REGISTER_MAIN_STATIC_DATA() GC_register_main_static_data()
+#elif defined(GC_DONT_REGISTER_MAIN_STATIC_DATA)
+# define GC_REGISTER_MAIN_STATIC_DATA() FALSE
 #else
 # define GC_REGISTER_MAIN_STATIC_DATA() TRUE
 #endif
@@ -466,10 +471,34 @@ size_t GC_get_total_bytes GC_PROTO(())
     return ((size_t) WORDS_TO_BYTES(GC_words_allocd+GC_words_allocd_before_gc));
 }
 
+int GC_get_suspend_signal GC_PROTO(())
+{
+#if defined(SIG_SUSPEND) && defined(GC_PTHREADS) && !defined(GC_MACOSX_THREADS) && !defined(GC_OPENBSD_THREADS)
+       return SIG_SUSPEND;
+#else
+       return -1;
+#endif
+}
+
+int GC_get_thr_restart_signal GC_PROTO(())
+{
+#if defined(SIG_THR_RESTART) && defined(GC_PTHREADS) && !defined(GC_MACOSX_THREADS) && !defined(GC_OPENBSD_THREADS)
+       return SIG_THR_RESTART;
+#else
+       return -1;
+#endif
+}
+
+
+
 GC_bool GC_is_initialized = FALSE;
 
 void GC_init()
 {
+#if defined(SN_TARGET_PS3)
+       pthread_mutexattr_t mattr;
+#endif
+
     DCL_LOCK_STATE;
     
     DISABLE_SIGNALS();
@@ -479,7 +508,7 @@ void GC_init()
       BOOL (WINAPI *pfn) (LPCRITICAL_SECTION, DWORD) = NULL;
       HMODULE hK32 = GetModuleHandle(_T("kernel32.dll"));
       if (hK32)
-          (FARPROC) pfn = GetProcAddress(hK32,
+          pfn = GetProcAddress(hK32,
                          "InitializeCriticalSectionAndSpinCount");
       if (pfn)
           pfn(&GC_allocate_ml, 4000);
@@ -487,6 +516,13 @@ void GC_init()
          InitializeCriticalSection (&GC_allocate_ml);
     }
 #endif /* MSWIN32 */
+#if defined(SN_TARGET_PS3)
+       pthread_mutexattr_init (&mattr);
+               
+       pthread_mutex_init (&GC_allocate_ml, &mattr);
+       pthread_mutexattr_destroy (&mattr);
+               
+#endif
 
     LOCK();
     GC_init_inner();
@@ -659,7 +695,7 @@ void GC_init_inner()
 #   if defined(SEARCH_FOR_DATA_START)
        GC_init_linux_data_start();
 #   endif
-#   if (defined(NETBSD) || defined(OPENBSD)) && defined(__ELF__)
+#   if defined(NETBSD) && defined(__ELF__)
        GC_init_netbsd_elf();
 #   endif
 #   if defined(GC_PTHREADS) || defined(GC_SOLARIS_THREADS) \
@@ -978,7 +1014,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)
@@ -990,13 +1030,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)