Revert "[System.Native] Build a reduced library on Android and iOS"
[mono-project.git] / mono / metadata / pal-icalls.c
blob1d4cd038d540bfecdebb5550d028286782dd07a8
1 /**
2 * \file
3 * System.Native PAL internal calls
4 * Adapter code between the Mono runtime and the CoreFX Platform Abstraction Layer (PAL)
5 * Copyright 2018 Microsoft
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
7 */
9 #include <config.h>
10 #include <glib.h>
11 #include "pal_io.h"
12 #include "mono/utils/mono-threads-api.h"
13 #include "mono/utils/atomic.h"
15 #include "pal-icalls.h"
18 * mono_pal_init:
20 * Initializes Mono's usage of the PAL (probably just by registering the necessary internal calls).
21 * This is called only from managed code, by any Interop.* classes that need to use the code here.
22 * The function may be called multiple times.
25 void
26 mono_pal_init (void)
28 volatile static gboolean module_initialized = FALSE;
29 if (mono_atomic_cas_i32 (&module_initialized, TRUE, FALSE) == FALSE) {
30 mono_add_internal_call ("Interop/Sys::Read", ves_icall_Interop_Sys_Read);
32 #if defined(__APPLE__)
33 mono_add_internal_call ("Interop/RunLoop::CFRunLoopRun", ves_icall_Interop_RunLoop_CFRunLoopRun);
34 #endif
39 gint32
40 ves_icall_Interop_Sys_Read (intptr_t fd, gchar* buffer, gint32 count)
42 gint32 result;
43 MONO_ENTER_GC_SAFE;
44 result = SystemNative_Read (fd, buffer, count);
45 mono_marshal_set_last_error ();
46 MONO_EXIT_GC_SAFE;
47 return result;
50 #if defined(__APPLE__)
52 #include <CoreFoundation/CFRunLoop.h>
54 static void
55 interrupt_CFRunLoop (gpointer data)
57 g_assert (data);
58 CFRunLoopStop (data);
61 void
62 ves_icall_Interop_RunLoop_CFRunLoopRun (void)
64 gpointer runloop_ref = CFRunLoopGetCurrent ();
65 gboolean interrupted;
66 mono_thread_info_install_interrupt (interrupt_CFRunLoop, runloop_ref, &interrupted);
68 if (interrupted)
69 return;
71 MONO_ENTER_GC_SAFE;
72 CFRunLoopRun ();
73 MONO_EXIT_GC_SAFE;
75 mono_thread_info_uninstall_interrupt (&interrupted);
78 #endif