using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
+using Microsoft.Win32.SafeHandles;
#if NET_2_1
using System.IO.IsolatedStorage;
#endif
public extern static bool SetFileAttributes (string path, FileAttributes attrs, out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static MonoFileType GetFileType (IntPtr handle, out MonoIOError error);
+ public extern static MonoFileType GetFileType (SafeHandle safeHandle, out MonoIOError error);
//
// Find file methods
FileShare share,
FileOptions options,
out MonoIOError error);
-
+
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static bool Close (IntPtr handle,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int Read (IntPtr handle, byte [] dest,
+ public extern static int Read (SafeHandle safeHandle, byte [] dest,
int dest_offset, int count,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static int Write (IntPtr handle, [In] byte [] src,
+ public extern static int Write (SafeHandle safeHandle, [In] byte [] src,
int src_offset, int count,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long Seek (IntPtr handle, long offset,
+ public extern static long Seek (SafeHandle safeHandle, long offset,
SeekOrigin origin,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static bool Flush (IntPtr handle,
+ public extern static bool Flush (SafeHandle safeHandle,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static long GetLength (IntPtr handle,
+ public extern static long GetLength (SafeHandle handle,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static bool SetLength (IntPtr handle,
+ public extern static bool SetLength (SafeHandle safeHandle,
long length,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static bool SetFileTime (IntPtr handle,
+ public extern static bool SetFileTime (SafeHandle safeHandle,
long creation_time,
long last_access_time,
long last_write_time,
break;
}
- result = SetFileTime (handle, creation_time,
+ result = SetFileTime (new SafeFileHandle(handle, false), creation_time,
last_access_time,
last_write_time, out error);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void Lock (IntPtr handle,
+ public extern static void Lock (SafeHandle safeHandle,
long position, long length,
out MonoIOError error);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
- public extern static void Unlock (IntPtr handle,
+ public extern static void Unlock (SafeHandle safeHandle,
long position, long length,
out MonoIOError error);
* of icalls, do not require an increment.
*/
#pragma warning disable 169
- private const int mono_corlib_version = 114;
+ private const int mono_corlib_version = 115;
#pragma warning restore 169
[ComVisible (true)]
* Changes which are already detected at runtime, like the addition
* of icalls, do not require an increment.
*/
-#define MONO_CORLIB_VERSION 114
+#define MONO_CORLIB_VERSION 115
typedef struct
{
}
gint32
-ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error)
+ves_icall_System_IO_MonoIO_GetFileType (MonoSafeHandle *safeHandle, gint32 *error)
{
gboolean ret;
*error=ERROR_SUCCESS;
- ret=GetFileType (handle);
+ ret=GetFileType (safeHandle->handle);
if(ret==FILE_TYPE_UNKNOWN) {
/* Not necessarily an error, but the caller will have
* to decide based on the error value.
}
gint32
-ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
+ves_icall_System_IO_MonoIO_Read (MonoSafeHandle *safeHandle, MonoArray *dest,
gint32 dest_offset, gint32 count,
gint32 *error)
{
mono_raise_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
buffer = mono_array_addr (dest, guchar, dest_offset);
- result = ReadFile (handle, buffer, count, &n, NULL);
+ result = ReadFile (safeHandle->handle, buffer, count, &n, NULL);
if (!result) {
*error=GetLastError ();
}
gint32
-ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
+ves_icall_System_IO_MonoIO_Write (MonoSafeHandle *safeHandle, MonoArray *src,
gint32 src_offset, gint32 count,
gint32 *error)
{
mono_raise_exception (mono_get_exception_argument ("array", "array too small. numBytes/offset wrong."));
buffer = mono_array_addr (src, guchar, src_offset);
- result = WriteFile (handle, buffer, count, &n, NULL);
+ result = WriteFile (safeHandle->handle, buffer, count, &n, NULL);
if (!result) {
*error=GetLastError ();
}
gint64
-ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
+ves_icall_System_IO_MonoIO_Seek (MonoSafeHandle *safeHandle, gint64 offset, gint32 origin,
gint32 *error)
{
gint32 offset_hi;
*error=ERROR_SUCCESS;
offset_hi = offset >> 32;
- offset = SetFilePointer (handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
+ offset = SetFilePointer (safeHandle->handle, (gint32) (offset & 0xFFFFFFFF), &offset_hi,
convert_seekorigin (origin));
if(offset==INVALID_SET_FILE_POINTER) {
}
MonoBoolean
-ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error)
+ves_icall_System_IO_MonoIO_Flush (MonoSafeHandle *safeHandle, gint32 *error)
{
gboolean ret;
*error=ERROR_SUCCESS;
- ret=FlushFileBuffers (handle);
+ ret=FlushFileBuffers (safeHandle->handle);
if(ret==FALSE) {
*error=GetLastError ();
}
}
gint64
-ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error)
+ves_icall_System_IO_MonoIO_GetLength (MonoSafeHandle *safeHandle, gint32 *error)
{
gint64 length;
guint32 length_hi;
*error=ERROR_SUCCESS;
- length = GetFileSize (handle, &length_hi);
+ length = GetFileSize (safeHandle->handle, &length_hi);
if(length==INVALID_FILE_SIZE) {
*error=GetLastError ();
}
}
MonoBoolean
-ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
+ves_icall_System_IO_MonoIO_SetLength (MonoSafeHandle *safeHandle, gint64 length,
gint32 *error)
{
gint64 offset, offset_set;
/* save file pointer */
offset_hi = 0;
- offset = SetFilePointer (handle, 0, &offset_hi, FILE_CURRENT);
+ offset = SetFilePointer (safeHandle->handle, 0, &offset_hi, FILE_CURRENT);
if(offset==INVALID_SET_FILE_POINTER) {
*error=GetLastError ();
return(FALSE);
/* extend or truncate */
length_hi = length >> 32;
- offset_set=SetFilePointer (handle, length & 0xFFFFFFFF, &length_hi,
+ offset_set=SetFilePointer (safeHandle->handle, length & 0xFFFFFFFF, &length_hi,
FILE_BEGIN);
if(offset_set==INVALID_SET_FILE_POINTER) {
*error=GetLastError ();
return(FALSE);
}
- result = SetEndOfFile (handle);
+ result = SetEndOfFile (safeHandle->handle);
if(result==FALSE) {
*error=GetLastError ();
return(FALSE);
/* restore file pointer */
- offset_set=SetFilePointer (handle, offset & 0xFFFFFFFF, &offset_hi,
+ offset_set=SetFilePointer (safeHandle->handle, offset & 0xFFFFFFFF, &offset_hi,
FILE_BEGIN);
if(offset_set==INVALID_SET_FILE_POINTER) {
*error=GetLastError ();
}
MonoBoolean
-ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
+ves_icall_System_IO_MonoIO_SetFileTime (MonoSafeHandle *safeHandle, gint64 creation_time,
gint64 last_access_time,
gint64 last_write_time, gint32 *error)
{
else
last_write_filetime = (FILETIME *)&last_write_time;
- ret=SetFileTime (handle, creation_filetime, last_access_filetime, last_write_filetime);
+ ret=SetFileTime (safeHandle->handle, creation_filetime, last_access_filetime, last_write_filetime);
if(ret==FALSE) {
*error=GetLastError ();
}
return(ret);
}
-void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
+void ves_icall_System_IO_MonoIO_Lock (MonoSafeHandle *safeHandle, gint64 position,
gint64 length, gint32 *error)
{
gboolean ret;
*error=ERROR_SUCCESS;
- ret=LockFile (handle, position & 0xFFFFFFFF, position >> 32,
+ ret=LockFile (safeHandle->handle, position & 0xFFFFFFFF, position >> 32,
length & 0xFFFFFFFF, length >> 32);
if (ret == FALSE) {
*error = GetLastError ();
}
}
-void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
+void ves_icall_System_IO_MonoIO_Unlock (MonoSafeHandle *safeHandle, gint64 position,
gint64 length, gint32 *error)
{
gboolean ret;
*error=ERROR_SUCCESS;
- ret=UnlockFile (handle, position & 0xFFFFFFFF, position >> 32,
+ ret=UnlockFile (safeHandle->handle, position & 0xFFFFFFFF, position >> 32,
length & 0xFFFFFFFF, length >> 32);
if (ret == FALSE) {
*error = GetLastError ();
gint32 *error) MONO_INTERNAL;
extern gint32
-ves_icall_System_IO_MonoIO_GetFileType (HANDLE handle, gint32 *error) MONO_INTERNAL;
+ves_icall_System_IO_MonoIO_GetFileType (MonoSafeHandle *safeHandle, gint32 *error) MONO_INTERNAL;
extern MonoBoolean
ves_icall_System_IO_MonoIO_GetFileStat (MonoString *path, MonoIOStat *stat,
ves_icall_System_IO_MonoIO_Close (HANDLE handle, gint32 *error) MONO_INTERNAL;
extern gint32
-ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArray *dest,
+ves_icall_System_IO_MonoIO_Read (MonoSafeHandle *safeHandle, MonoArray *dest,
gint32 dest_offset, gint32 count,
gint32 *error) MONO_INTERNAL;
extern gint32
-ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArray *src,
+ves_icall_System_IO_MonoIO_Write (MonoSafeHandle *safeHandle, MonoArray *src,
gint32 src_offset, gint32 count,
gint32 *error) MONO_INTERNAL;
extern gint64
-ves_icall_System_IO_MonoIO_Seek (HANDLE handle, gint64 offset, gint32 origin,
+ves_icall_System_IO_MonoIO_Seek (MonoSafeHandle *safeHandle, gint64 offset, gint32 origin,
gint32 *error) MONO_INTERNAL;
extern MonoBoolean
-ves_icall_System_IO_MonoIO_Flush (HANDLE handle, gint32 *error) MONO_INTERNAL;
+ves_icall_System_IO_MonoIO_Flush (MonoSafeHandle *safeHandle, gint32 *error) MONO_INTERNAL;
extern gint64
-ves_icall_System_IO_MonoIO_GetLength (HANDLE handle, gint32 *error) MONO_INTERNAL;
+ves_icall_System_IO_MonoIO_GetLength (MonoSafeHandle *safeHandle, gint32 *error) MONO_INTERNAL;
extern MonoBoolean
-ves_icall_System_IO_MonoIO_SetLength (HANDLE handle, gint64 length,
+ves_icall_System_IO_MonoIO_SetLength (MonoSafeHandle *safeHandle, gint64 length,
gint32 *error) MONO_INTERNAL;
extern MonoBoolean
-ves_icall_System_IO_MonoIO_SetFileTime (HANDLE handle, gint64 creation_time,
+ves_icall_System_IO_MonoIO_SetFileTime (MonoSafeHandle *safeHandle, gint64 creation_time,
gint64 last_access_time,
gint64 last_write_time, gint32 *error) MONO_INTERNAL;
extern gint32
ves_icall_System_IO_MonoIO_GetTempPath (MonoString **mono_name) MONO_INTERNAL;
-extern void ves_icall_System_IO_MonoIO_Lock (HANDLE handle, gint64 position,
+extern void ves_icall_System_IO_MonoIO_Lock (MonoSafeHandle *safeHandle, gint64 position,
gint64 length, gint32 *error) MONO_INTERNAL;
-extern void ves_icall_System_IO_MonoIO_Unlock (HANDLE handle, gint64 position,
+extern void ves_icall_System_IO_MonoIO_Unlock (MonoSafeHandle *safeHandle, gint64 position,
gint64 length, gint32 *error) MONO_INTERNAL;
extern MonoBoolean
ICALL(MONOIO_37, "FindClose", ves_icall_System_IO_MonoIO_FindClose)
ICALL(MONOIO_35, "FindFirst", ves_icall_System_IO_MonoIO_FindFirst)
ICALL(MONOIO_36, "FindNext", ves_icall_System_IO_MonoIO_FindNext)
-ICALL(MONOIO_6, "Flush(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush)
+ICALL(MONOIO_6, "Flush(System.Runtime.InteropServices.SafeHandle,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Flush)
ICALL(MONOIO_7, "GetCurrentDirectory(System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetCurrentDirectory)
ICALL(MONOIO_8, "GetFileAttributes(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileAttributes)
ICALL(MONOIO_9, "GetFileStat(string,System.IO.MonoIOStat&,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileStat)
ICALL(MONOIO_10, "GetFileSystemEntries", ves_icall_System_IO_MonoIO_GetFileSystemEntries)
-ICALL(MONOIO_11, "GetFileType(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType)
-ICALL(MONOIO_12, "GetLength(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength)
+ICALL(MONOIO_11, "GetFileType(System.Runtime.InteropServices.SafeHandle,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetFileType)
+ICALL(MONOIO_12, "GetLength(System.Runtime.InteropServices.SafeHandle,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_GetLength)
#ifndef PLATFORM_RO_FS
ICALL(MONOIO_13, "GetTempPath(string&)", ves_icall_System_IO_MonoIO_GetTempPath)
-ICALL(MONOIO_14, "Lock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock)
+ICALL(MONOIO_14, "Lock(System.Runtime.InteropServices.SafeHandle,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Lock)
ICALL(MONOIO_15, "MoveFile(string,string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_MoveFile)
#endif /* !PLATFORM_RO_FS */
ICALL(MONOIO_16, "Open(string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,System.IO.FileOptions,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Open)
-ICALL(MONOIO_17, "Read(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read)
+ICALL(MONOIO_17, "Read(System.Runtime.InteropServices.SafeHandle,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Read)
#ifndef PLATFORM_RO_FS
ICALL(MONOIO_18, "RemoveDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_RemoveDirectory)
ICALL(MONOIO_18M, "ReplaceFile(string,string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_ReplaceFile)
#endif /* !PLATFORM_RO_FS */
-ICALL(MONOIO_19, "Seek(intptr,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek)
+ICALL(MONOIO_19, "Seek(System.Runtime.InteropServices.SafeHandle,long,System.IO.SeekOrigin,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Seek)
ICALL(MONOIO_20, "SetCurrentDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetCurrentDirectory)
ICALL(MONOIO_21, "SetFileAttributes(string,System.IO.FileAttributes,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileAttributes)
-ICALL(MONOIO_22, "SetFileTime(intptr,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime)
-ICALL(MONOIO_23, "SetLength(intptr,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength)
+ICALL(MONOIO_22, "SetFileTime(System.Runtime.InteropServices.SafeHandle,long,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetFileTime)
+ICALL(MONOIO_23, "SetLength(System.Runtime.InteropServices.SafeHandle,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_SetLength)
#ifndef PLATFORM_RO_FS
-ICALL(MONOIO_24, "Unlock(intptr,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock)
+ICALL(MONOIO_24, "Unlock(System.Runtime.InteropServices.SafeHandle,long,long,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Unlock)
#endif
-ICALL(MONOIO_25, "Write(intptr,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write)
+ICALL(MONOIO_25, "Write(System.Runtime.InteropServices.SafeHandle,byte[],int,int,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_Write)
ICALL(MONOIO_26, "get_AltDirectorySeparatorChar", ves_icall_System_IO_MonoIO_get_AltDirectorySeparatorChar)
ICALL(MONOIO_27, "get_ConsoleError", ves_icall_System_IO_MonoIO_get_ConsoleError)
ICALL(MONOIO_28, "get_ConsoleInput", ves_icall_System_IO_MonoIO_get_ConsoleInput)