Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Therning <niklas@therning.org>2016-11-15 18:22:33 +0300
committerNiklas Therning <niklas@therning.org>2016-11-16 11:14:25 +0300
commited892ccf27849c082ce6ca46fa8b96d86ca7c329 (patch)
tree8240e5df0bcd09dfd2b8a84c769e5b22ef758a46 /support
parentf3002a1f72df7165dd42b7abb6d5b1b5ccaa035b (diff)
Prevent Mono.Posix from using multiple C runtimes on Windows
Since libMonoPosixHelper.dll is linked against ucrtbase.dll the C runtime wrapper functions in it will call into ucrtbase.dll. Some pinvokes in Mono.Unix.Native.Stdlib, however, bind directly to C runtime functions in msvcrt. This is problematic if a resource (heap memory, file pointer, etc) is allocated using one C runtime and then operated upon using funcitons form the other C runtime. E.g., Stdlib.malloc() calls into a wrapper in libMonoPosixHelper so it will use the ucrtbase heap while Stdlib.free() calls directly into msvcrt's free() which will abort the process since it's called with a pointer in an unknown heap. This commit adds libMonoPosixHelper wrappers for all memory and file related functions in Stdlib to ensure that all such functions use the same C runtime. Some of the Mono.Posix tests still fail but at least the test suite doesn't crash after this change. The test failures will be addressed in a future PR.
Diffstat (limited to 'support')
-rw-r--r--support/map.h14
-rw-r--r--support/stdio.c78
-rw-r--r--support/stdlib.c6
3 files changed, 98 insertions, 0 deletions
diff --git a/support/map.h b/support/map.h
index ccd221b106a..8c6ef5000f2 100644
--- a/support/map.h
+++ b/support/map.h
@@ -2181,10 +2181,24 @@ int Mono_Posix_Stdlib_MB_CUR_MAX (void);
int Mono_Posix_Stdlib_perror (const char* s, int err);
int Mono_Posix_Stdlib_RAND_MAX (void);
void* Mono_Posix_Stdlib_realloc (void* ptr, guint64 size);
+void Mono_Posix_Stdlib_free (void* p);
int Mono_Posix_Stdlib_rewind (void* stream);
int Mono_Posix_Stdlib_setbuf (void* stream, void* buf);
void Mono_Posix_Stdlib_SetLastError (int error);
int Mono_Posix_Stdlib_setvbuf (void* stream, void* buf, int mode, guint64 size);
+void* Mono_Posix_Stdlib_fopen (char* path, char* mode);
+void* Mono_Posix_Stdlib_freopen (char* path, char* mode, void *stream);
+gint32 Mono_Posix_Stdlib_fprintf (void* stream, char* format, char *message);
+gint32 Mono_Posix_Stdlib_fgetc (void* stream);
+char* Mono_Posix_Stdlib_fgets (char* str, gint32 size, void* stream);
+gint32 Mono_Posix_Stdlib_fputc (gint32 c, void* stream);
+gint32 Mono_Posix_Stdlib_fputs (char* s, void* stream);
+gint32 Mono_Posix_Stdlib_fclose (void* stream);
+gint32 Mono_Posix_Stdlib_fflush (void* stream);
+void* Mono_Posix_Stdlib_tmpfile (void);
+gint32 Mono_Posix_Stdlib_ungetc (gint32 c, void* stream);
+gint32 Mono_Posix_Stdlib_feof (void* stream);
+gint32 Mono_Posix_Stdlib_ferror (void* stream);
void* Mono_Posix_Stdlib_SIG_DFL (void);
void* Mono_Posix_Stdlib_SIG_ERR (void);
void* Mono_Posix_Stdlib_SIG_IGN (void);
diff --git a/support/stdio.c b/support/stdio.c
index e5b54da47b9..b914dfdb1d0 100644
--- a/support/stdio.c
+++ b/support/stdio.c
@@ -142,6 +142,12 @@ Mono_Posix_Stdlib_TMP_MAX (void)
return TMP_MAX;
}
+void*
+Mono_Posix_Stdlib_tmpfile (void)
+{
+ return tmpfile ();
+}
+
gint32
Mono_Posix_Stdlib_setvbuf (void* stream, void *buf, int mode, mph_size_t size)
{
@@ -156,6 +162,60 @@ Mono_Posix_Stdlib_setbuf (void* stream, void* buf)
return 0;
}
+void*
+Mono_Posix_Stdlib_fopen (char* path, char* mode)
+{
+ return fopen (path, mode);
+}
+
+void*
+Mono_Posix_Stdlib_freopen (char* path, char* mode, void *stream)
+{
+ return freopen (path, mode, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fprintf (void* stream, char* format, char *message)
+{
+ return fprintf (stream, format, message);
+}
+
+gint32
+Mono_Posix_Stdlib_fgetc (void* stream)
+{
+ return fgetc (stream);
+}
+
+char*
+Mono_Posix_Stdlib_fgets (char* str, gint32 size, void* stream)
+{
+ return fgets (str, size, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fputc (gint32 c, void* stream)
+{
+ return fputc (c, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fputs (char* s, void* stream)
+{
+ return fputs (s, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fclose (void* stream)
+{
+ return fclose (stream);
+}
+
+gint32
+Mono_Posix_Stdlib_fflush (void* stream)
+{
+ return fflush (stream);
+}
+
gint32
Mono_Posix_Stdlib_fseek (void* stream, gint64 offset, int origin)
{
@@ -207,6 +267,24 @@ Mono_Posix_Stdlib_clearerr (void* stream)
return 0;
}
+gint32
+Mono_Posix_Stdlib_ungetc (gint32 c, void* stream)
+{
+ return ungetc (c, stream);
+}
+
+gint32
+Mono_Posix_Stdlib_feof (void* stream)
+{
+ return feof (stream);
+}
+
+gint32
+Mono_Posix_Stdlib_ferror (void* stream)
+{
+ return ferror (stream);
+}
+
int
Mono_Posix_Stdlib_perror (const char* s, int err)
{
diff --git a/support/stdlib.c b/support/stdlib.c
index 0c4358a5140..077a85e58f5 100644
--- a/support/stdlib.c
+++ b/support/stdlib.c
@@ -72,6 +72,12 @@ Mono_Posix_Stdlib_realloc (void* ptr, mph_size_t size)
return realloc (ptr, (size_t) size);
}
+void
+Mono_Posix_Stdlib_free (void* p)
+{
+ free (p);
+}
+
G_END_DECLS
/*