From b572cf30253b0922c7c476bfc666c0345eb50256 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 16 Jun 2021 15:33:07 +0200 Subject: [PATCH] ntdll: Copy the implementation of __wine_dbg_output to the PE side. Signed-off-by: Alexandre Julliard --- dlls/ntdll/ntdll.spec | 1 + dlls/ntdll/thread.c | 30 +++++++++++++++++++++++++++++- dlls/ntdll/unix/debug.c | 10 +++++++++- dlls/ntdll/unix/loader.c | 1 - dlls/ntdll/unixlib.h | 5 +---- include/wine/debug.h | 1 + 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 8cba4fa164a..bd72f50b864 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -1621,6 +1621,7 @@ @ extern -arch=i386 __wine_ldt_copy # Debugging +@ stdcall -syscall -norelay __wine_dbg_write(ptr long) @ cdecl -norelay __wine_dbg_get_channel_flags(ptr) @ cdecl -norelay __wine_dbg_header(long long str) @ cdecl -norelay __wine_dbg_output(str) diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index d86d20448bf..d0c2a89d4bb 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -69,6 +69,22 @@ static void init_options(void) while (debug_options[nb_debug_options].name[0]) nb_debug_options++; } +/* add a string to the output buffer */ +static int append_output( struct debug_info *info, const char *str, size_t len ) +{ + if (len >= sizeof(info->output) - info->out_pos) + { + __wine_dbg_write( info->output, info->out_pos ); + info->out_pos = 0; + ERR_(thread)( "debug buffer overflow:\n" ); + __wine_dbg_write( str, len ); + RtlRaiseStatus( STATUS_BUFFER_OVERFLOW ); + } + memcpy( info->output + info->out_pos, str, len ); + info->out_pos += len; + return len; +} + /*********************************************************************** * __wine_dbg_get_channel_flags (NTDLL.@) * @@ -146,7 +162,19 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_ */ int __cdecl __wine_dbg_output( const char *str ) { - return unix_funcs->dbg_output( str ); + struct debug_info *info = get_info(); + const char *end = strrchr( str, '\n' ); + int ret = 0; + + if (end) + { + ret += append_output( info, str, end + 1 - str ); + __wine_dbg_write( info->output, info->out_pos ); + info->out_pos = 0; + str = end + 1; + } + if (*str) ret += append_output( info, str, strlen( str )); + return ret; } diff --git a/dlls/ntdll/unix/debug.c b/dlls/ntdll/unix/debug.c index 0272e68bea6..d43cdaeb917 100644 --- a/dlls/ntdll/unix/debug.c +++ b/dlls/ntdll/unix/debug.c @@ -249,6 +249,14 @@ const char * __cdecl __wine_dbg_strdup( const char *str ) return memcpy( info->strings + pos, str, n ); } +/*********************************************************************** + * __wine_dbg_write (NTDLL.@) + */ +int WINAPI __wine_dbg_write( const char *str, unsigned int len ) +{ + return write( 2, str, len ); +} + /*********************************************************************** * __wine_dbg_output (NTDLL.@) */ @@ -261,7 +269,7 @@ int __cdecl __wine_dbg_output( const char *str ) if (end) { ret += append_output( info, str, end + 1 - str ); - write( 2, info->output, info->out_pos ); + __wine_dbg_write( info->output, info->out_pos ); info->out_pos = 0; str = end + 1; } diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index fca63141ba3..b9f1fee6a9d 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1850,7 +1850,6 @@ static struct unix_funcs unix_funcs = init_builtin_dll, init_unix_lib, unwind_builtin_dll, - __wine_dbg_output, }; diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h index cbe5c9d3ccd..ba37297a324 100644 --- a/dlls/ntdll/unixlib.h +++ b/dlls/ntdll/unixlib.h @@ -26,7 +26,7 @@ struct _DISPATCHER_CONTEXT; /* increment this when you change the function table */ -#define NTDLL_UNIXLIB_VERSION 122 +#define NTDLL_UNIXLIB_VERSION 123 struct unix_funcs { @@ -78,9 +78,6 @@ struct unix_funcs NTSTATUS (CDECL *init_unix_lib)( void *module, DWORD reason, const void *ptr_in, void *ptr_out ); NTSTATUS (CDECL *unwind_builtin_dll)( ULONG type, struct _DISPATCHER_CONTEXT *dispatch, CONTEXT *context ); - - /* debugging functions */ - int (CDECL *dbg_output)( const char *str ); }; #endif /* __NTDLL_UNIXLIB_H */ diff --git a/include/wine/debug.h b/include/wine/debug.h index 2255f62e502..6aac7fe82e8 100644 --- a/include/wine/debug.h +++ b/include/wine/debug.h @@ -143,6 +143,7 @@ struct __wine_debug_channel #endif /* !__GNUC__ && !__SUNPRO_C */ +extern int WINAPI __wine_dbg_write( const char *str, unsigned int len ); extern unsigned char __cdecl __wine_dbg_get_channel_flags( struct __wine_debug_channel *channel ); extern const char * __cdecl __wine_dbg_strdup( const char *str ); extern int __cdecl __wine_dbg_output( const char *str );