-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[System.IO][runtime] Import INotify CoreFX FileSystemWatcher
System.Native icalls now live in metadata/pal-icalls.c|h
- Loading branch information
Showing
14 changed files
with
190 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
../../../external/corefx/src/Common/src/Interop/Unix/*.cs | ||
corefx/Unix/Interop.cs | ||
corefx/Unix/Interop.Read.cs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
// This file reiimplements CoreFX source file 'src/Common/src/Interop/Unix/System.Native/Interop.Read.cs' | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
using Microsoft.Win32.SafeHandles; | ||
using System; | ||
|
||
internal static partial class Interop | ||
{ | ||
internal static partial class Sys | ||
{ | ||
static Sys () | ||
{ | ||
Interop.mono_pal_init (); | ||
} | ||
|
||
/// <summary> | ||
/// Reads a number of bytes from an open file descriptor into a specified buffer. | ||
/// </summary> | ||
/// <param name="fd">The open file descriptor to try to read from</param> | ||
/// <param name="buffer">The buffer to read info into</param> | ||
/// <param name="count">The size of the buffer</param> | ||
/// <returns> | ||
/// Returns the number of bytes read on success; otherwise, -1 is returned | ||
/// Note - on fail. the position of the stream may change depending on the platform; consult man 2 read for more info | ||
/// </returns> | ||
internal static unsafe int Read (SafeFileHandle fd, byte* buffer, int count) | ||
{ | ||
int bytes_read = -1; | ||
bool release = false; | ||
try { | ||
fd.DangerousAddRef (ref release); | ||
do { | ||
bytes_read = Read (fd.DangerousGetHandle (), buffer, count); | ||
} while (bytes_read < 0 && Marshal.GetLastWin32Error () == (int) Interop.Error.EINTR); | ||
} | ||
finally { | ||
if (release) | ||
fd.DangerousRelease (); | ||
} | ||
return bytes_read; | ||
} | ||
|
||
[MethodImplAttribute(MethodImplOptions.InternalCall)] | ||
internal static extern unsafe int Read (IntPtr fd, byte* buffer, int count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Runtime.InteropServices; | ||
|
||
internal static partial class Interop | ||
{ | ||
[DllImport("__Internal")] | ||
internal static extern void mono_pal_init (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* \file | ||
* System.Native PAL internal calls | ||
* Adapter code between the Mono runtime and the CoreFX Platform Abstraction Layer (PAL) | ||
* Copyright 2018 Microsoft | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
|
||
#include <config.h> | ||
#include <glib.h> | ||
#include "pal_io.h" | ||
#include "mono/utils/mono-threads-api.h" | ||
#include "mono/utils/atomic.h" | ||
|
||
#include "pal-icalls.h" | ||
|
||
/* | ||
* mono_pal_init: | ||
* | ||
* Initializes Mono's usage of the PAL (probably just by registering the necessary internal calls). | ||
* This is called only from managed code, by any Interop.* classes that need to use the code here. | ||
* The function may be called multiple times. | ||
* | ||
*/ | ||
void | ||
mono_pal_init (void) | ||
{ | ||
volatile static gboolean module_initialized = FALSE; | ||
if (mono_atomic_cas_i32 (&module_initialized, TRUE, FALSE) == FALSE) { | ||
mono_add_internal_call ("Interop/Sys::Read", ves_icall_Interop_Sys_Read); | ||
|
||
#if defined(__APPLE__) | ||
mono_add_internal_call ("Interop/RunLoop::CFRunLoopRun", ves_icall_Interop_RunLoop_CFRunLoopRun); | ||
#endif | ||
} | ||
|
||
} | ||
|
||
gint32 | ||
ves_icall_Interop_Sys_Read (intptr_t fd, gchar* buffer, gint32 count) | ||
{ | ||
gint32 result; | ||
MONO_ENTER_GC_SAFE; | ||
result = SystemNative_Read (fd, buffer, count); | ||
mono_marshal_set_last_error (); | ||
MONO_EXIT_GC_SAFE; | ||
return result; | ||
} | ||
|
||
#if defined(__APPLE__) | ||
|
||
#include <CoreFoundation/CFRunLoop.h> | ||
|
||
static void | ||
interrupt_CFRunLoop (gpointer data) | ||
{ | ||
g_assert (data); | ||
CFRunLoopStop (data); | ||
} | ||
|
||
void | ||
ves_icall_Interop_RunLoop_CFRunLoopRun (void) | ||
{ | ||
gpointer runloop_ref = CFRunLoopGetCurrent (); | ||
gboolean interrupted; | ||
mono_thread_info_install_interrupt (interrupt_CFRunLoop, runloop_ref, &interrupted); | ||
|
||
if (interrupted) | ||
return; | ||
|
||
MONO_ENTER_GC_SAFE; | ||
CFRunLoopRun (); | ||
MONO_EXIT_GC_SAFE; | ||
|
||
mono_thread_info_uninstall_interrupt (&interrupted); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* \file | ||
* System.Native PAL internal calls | ||
* Adapter code between the Mono runtime and the CoreFX Platform Abstraction Layer (PAL) | ||
* Copyright 2018 Microsoft | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
|
||
#ifndef __MONO_METADATA_PAL_ICALLS_H__ | ||
#define __MONO_METADATA_PAL_ICALLS_H__ | ||
|
||
#include "metadata.h" | ||
#include "class-internals.h" | ||
|
||
MONO_API void mono_pal_init (void); | ||
|
||
extern void mono_marshal_set_last_error (void); | ||
gint32 ves_icall_Interop_Sys_Read (intptr_t fd, gchar* buffer, gint32 count); | ||
|
||
#if defined(__APPLE__) | ||
extern void mono_thread_info_install_interrupt (void (*callback) (gpointer data), gpointer data, gboolean *interrupted); | ||
extern void mono_thread_info_uninstall_interrupt (gboolean *interrupted); | ||
void ves_icall_Interop_RunLoop_CFRunLoopRun (void); | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
#include <config.h> | ||
|
||
#define MONO 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters