[netcore] Read NETCORETESTS_VERSION and NETCOREAPP_VERSION fro… (#15584)
[mono-project.git] / mono / native / pal-icalls.c
blob1730fe58cff75a6ff9a3afb09eff814ef97f2f96
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 #if !defined (HOST_WATCHOS) && !defined (HOST_TVOS) /* These platforms don't support async suspend and do not need this code for now */
11 #include <config.h>
12 #include <glib.h>
13 #include "mono/utils/mono-threads-api.h"
14 #include "mono/utils/atomic.h"
15 #include "mono/metadata/loader-internals.h"
16 #include "mono/metadata/icall-internals.h"
17 #include "pal-icalls.h"
21 * mono_pal_init:
23 * Initializes Mono's usage of the PAL (probably just by registering the necessary internal calls).
24 * This is called only from managed code, by any Interop.* classes that need to use the code here.
25 * The function may be called multiple times.
28 void
29 mono_pal_init (void)
31 volatile static gboolean module_initialized = FALSE;
32 if (mono_atomic_cas_i32 (&module_initialized, TRUE, FALSE) == FALSE) {
33 mono_add_internal_call_with_flags ("Interop/Sys::Read", ves_icall_Interop_Sys_Read, TRUE);
35 #if defined(__APPLE__)
36 mono_add_internal_call_with_flags ("Interop/RunLoop::CFRunLoopRun", ves_icall_Interop_RunLoop_CFRunLoopRun, TRUE);
37 #endif
42 gint32
43 ves_icall_Interop_Sys_Read (intptr_t fd, gchar* buffer, gint32 count)
45 gint32 result;
46 MONO_ENTER_GC_SAFE;
47 result = SystemNative_Read (fd, buffer, count);
48 mono_marshal_set_last_error ();
49 MONO_EXIT_GC_SAFE;
50 return result;
53 #if defined(__APPLE__)
55 #include <CoreFoundation/CFRunLoop.h>
57 static void
58 interrupt_CFRunLoop (gpointer data)
60 g_assert (data);
61 CFRunLoopStop ((CFRunLoopRef)data);
64 void
65 ves_icall_Interop_RunLoop_CFRunLoopRun (void)
67 gpointer runloop_ref = CFRunLoopGetCurrent ();
68 gboolean interrupted;
69 mono_thread_info_install_interrupt (interrupt_CFRunLoop, runloop_ref, &interrupted);
71 if (interrupted)
72 return;
74 MONO_ENTER_GC_SAFE;
75 CFRunLoopRun ();
76 MONO_EXIT_GC_SAFE;
78 mono_thread_info_uninstall_interrupt (&interrupted);
81 #endif
83 #endif /* !defined (HOST_WATCHOS) && !defined (HOST_TVOS) */