[PATCH] mscoree: Add a buffer for Mono's debug output.
Esme Povirk
esme at codeweavers.com
Tue Aug 31 15:17:20 CDT 2021
Signed-off-by: Esme Povirk <esme at codeweavers.com>
---
dlls/mscoree/metahost.c | 13 -------
dlls/mscoree/mscoree_main.c | 64 +++++++++++++++++++++++++++++++++-
dlls/mscoree/mscoree_private.h | 2 ++
3 files changed, 65 insertions(+), 14 deletions(-)
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index a272f83020a..c362265cf5d 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -137,8 +137,6 @@ static MonoAssembly* CDECL mono_assembly_preload_hook_fn(MonoAssemblyName *aname
static void CDECL mono_shutdown_callback_fn(MonoProfiler *prof);
-static void CDECL mono_print_handler_fn(const char *string, INT is_stdout);
-
static MonoImage* CDECL image_open_module_handle_dummy(HMODULE module_handle,
char* fname, UINT has_entry_point, MonoImageOpenStatus* status)
{
@@ -378,17 +376,6 @@ static void CDECL mono_shutdown_callback_fn(MonoProfiler *prof)
is_mono_shutdown = TRUE;
}
-static void CDECL mono_print_handler_fn(const char *string, INT is_stdout)
-{
- const char *p;
- for (; *string; string = p)
- {
- if ((p = strstr(string, "\n"))) p++;
- else p = string + strlen(string);
- wine_dbg_printf("%.*s", (int)(p - string), string);
- }
-}
-
static HRESULT WINAPI thread_set_fn(void)
{
WARN("stub\n");
diff --git a/dlls/mscoree/mscoree_main.c b/dlls/mscoree/mscoree_main.c
index a4567e96de2..a268638c879 100644
--- a/dlls/mscoree/mscoree_main.c
+++ b/dlls/mscoree/mscoree_main.c
@@ -50,6 +50,14 @@
WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
WINE_DECLARE_DEBUG_CHANNEL(winediag);
+struct print_handler_tls
+{
+ int length;
+ char buffer[1018];
+};
+
+DWORD print_tls_index = TLS_OUT_OF_INDEXES;
+
typedef HRESULT (*fnCreateInstance)(REFIID riid, LPVOID *ppObj);
char *WtoA(LPCWSTR wstr)
@@ -214,6 +222,46 @@ HRESULT WINAPI CorBindToRuntimeHost(LPCWSTR pwszVersion, LPCWSTR pwszBuildFlavor
return ret;
}
+void CDECL mono_print_handler_fn(const char *string, INT is_stdout)
+{
+ struct print_handler_tls *tls = TlsGetValue(print_tls_index);
+
+ if (!tls)
+ {
+ tls = HeapAlloc(GetProcessHeap(), 0, sizeof(*tls));
+ tls->length = 0;
+ TlsSetValue(print_tls_index, tls);
+ }
+
+ while (*string)
+ {
+ int remaining_buffer = sizeof(tls->buffer) - tls->length;
+ int length = strlen(string);
+ const char *newline = memchr(string, '\n', min(length, remaining_buffer));
+
+ if (newline)
+ {
+ length = newline - string + 1;
+ wine_dbg_printf("%.*s%.*s", tls->length, tls->buffer, length, string);
+ tls->length = 0;
+ string += length;
+ }
+ else if (length > remaining_buffer)
+ {
+ /* this would overflow Wine's debug buffer */
+ wine_dbg_printf("%.*s%.*s\n", tls->length, tls->buffer, remaining_buffer, string);
+ tls->length = 0;
+ string += remaining_buffer;
+ }
+ else
+ {
+ memcpy(tls->buffer + tls->length, string, length);
+ tls->length += length;
+ break;
+ }
+ }
+}
+
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
TRACE("(%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
@@ -222,12 +270,26 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
case DLL_PROCESS_ATTACH:
runtimehost_init();
- DisableThreadLibraryCalls(hinstDLL);
+
+ print_tls_index = TlsAlloc();
+
+ if (print_tls_index == TLS_OUT_OF_INDEXES)
+ return FALSE;
+
+ break;
+ case DLL_THREAD_DETACH:
+ if (print_tls_index != TLS_OUT_OF_INDEXES)
+ HeapFree(GetProcessHeap(), 0, TlsGetValue(print_tls_index));
break;
case DLL_PROCESS_DETACH:
expect_no_runtimes();
if (lpvReserved) break; /* process is terminating */
runtimehost_uninit();
+ if (print_tls_index != TLS_OUT_OF_INDEXES)
+ {
+ HeapFree(GetProcessHeap(), 0, TlsGetValue(print_tls_index));
+ TlsFree(print_tls_index);
+ }
break;
}
return TRUE;
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index c4692b4e656..106171f8e43 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -219,4 +219,6 @@ extern HRESULT get_file_from_strongname(WCHAR* stringnameW, WCHAR* assemblies_pa
extern void runtimehost_init(void) DECLSPEC_HIDDEN;
extern void runtimehost_uninit(void) DECLSPEC_HIDDEN;
+extern void CDECL mono_print_handler_fn(const char *string, INT is_stdout);
+
#endif /* __MSCOREE_PRIVATE__ */
--
2.30.2
More information about the wine-devel
mailing list