ntdll: Store offsets instead of pointers in the debug_info structure.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
f438ff566d
commit
c9bf52502c
|
@ -47,25 +47,20 @@ static const char * const debug_classes[] = { "fixme", "err", "warn", "trace" };
|
||||||
/* get the debug info pointer for the current thread */
|
/* get the debug info pointer for the current thread */
|
||||||
static inline struct debug_info *get_info(void)
|
static inline struct debug_info *get_info(void)
|
||||||
{
|
{
|
||||||
if (!init_done)
|
if (!init_done) return &initial_info;
|
||||||
{
|
|
||||||
if (!initial_info.str_pos) initial_info.str_pos = initial_info.strings;
|
|
||||||
if (!initial_info.out_pos) initial_info.out_pos = initial_info.output;
|
|
||||||
return &initial_info;
|
|
||||||
}
|
|
||||||
return ntdll_get_thread_data()->debug_info;
|
return ntdll_get_thread_data()->debug_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add a string to the output buffer */
|
/* add a string to the output buffer */
|
||||||
static int append_output( struct debug_info *info, const char *str, size_t len )
|
static int append_output( struct debug_info *info, const char *str, size_t len )
|
||||||
{
|
{
|
||||||
if (len >= sizeof(info->output) - (info->out_pos - info->output))
|
if (len >= sizeof(info->output) - info->out_pos)
|
||||||
{
|
{
|
||||||
fprintf( stderr, "wine_dbg_output: debugstr buffer overflow (contents: '%s')\n", info->output );
|
fprintf( stderr, "wine_dbg_output: debugstr buffer overflow (contents: '%s')\n", info->output );
|
||||||
info->out_pos = info->output;
|
info->out_pos = 0;
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
memcpy( info->out_pos, str, len );
|
memcpy( info->output + info->out_pos, str, len );
|
||||||
info->out_pos += len;
|
info->out_pos += len;
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
@ -223,12 +218,13 @@ unsigned char __cdecl __wine_dbg_get_channel_flags( struct __wine_debug_channel
|
||||||
const char * __cdecl __wine_dbg_strdup( const char *str )
|
const char * __cdecl __wine_dbg_strdup( const char *str )
|
||||||
{
|
{
|
||||||
struct debug_info *info = get_info();
|
struct debug_info *info = get_info();
|
||||||
char *res = info->str_pos;
|
unsigned int pos = info->str_pos;
|
||||||
size_t n = strlen( str ) + 1;
|
size_t n = strlen( str ) + 1;
|
||||||
|
|
||||||
if (res + n > &info->strings[sizeof(info->strings)]) res = info->strings;
|
assert( n <= sizeof(info->strings) );
|
||||||
info->str_pos = res + n;
|
if (pos + n > sizeof(info->strings)) pos = 0;
|
||||||
return strcpy( res, str );
|
info->str_pos = pos + n;
|
||||||
|
return memcpy( info->strings + pos, str, n );
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -243,8 +239,8 @@ int __cdecl __wine_dbg_output( const char *str )
|
||||||
if (end)
|
if (end)
|
||||||
{
|
{
|
||||||
ret += append_output( info, str, end + 1 - str );
|
ret += append_output( info, str, end + 1 - str );
|
||||||
write( 2, info->output, info->out_pos - info->output );
|
write( 2, info->output, info->out_pos );
|
||||||
info->out_pos = info->output;
|
info->out_pos = 0;
|
||||||
str = end + 1;
|
str = end + 1;
|
||||||
}
|
}
|
||||||
if (*str) ret += append_output( info, str, strlen( str ));
|
if (*str) ret += append_output( info, str, strlen( str ));
|
||||||
|
@ -264,7 +260,7 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_
|
||||||
if (!(__wine_dbg_get_channel_flags( channel ) & (1 << cls))) return -1;
|
if (!(__wine_dbg_get_channel_flags( channel ) & (1 << cls))) return -1;
|
||||||
|
|
||||||
/* only print header if we are at the beginning of the line */
|
/* only print header if we are at the beginning of the line */
|
||||||
if (info->out_pos > info->output) return 0;
|
if (info->out_pos) return 0;
|
||||||
|
|
||||||
if (init_done)
|
if (init_done)
|
||||||
{
|
{
|
||||||
|
@ -288,8 +284,6 @@ int __cdecl __wine_dbg_header( enum __wine_debug_class cls, struct __wine_debug_
|
||||||
*/
|
*/
|
||||||
void debug_init(void)
|
void debug_init(void)
|
||||||
{
|
{
|
||||||
if (!initial_info.str_pos) initial_info.str_pos = initial_info.strings;
|
|
||||||
if (!initial_info.out_pos) initial_info.out_pos = initial_info.output;
|
|
||||||
ntdll_get_thread_data()->debug_info = &initial_info;
|
ntdll_get_thread_data()->debug_info = &initial_info;
|
||||||
init_done = TRUE;
|
init_done = TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,10 +221,10 @@ extern enum loadorder get_load_order( const WCHAR *app_name, const UNICODE_STRIN
|
||||||
|
|
||||||
struct debug_info
|
struct debug_info
|
||||||
{
|
{
|
||||||
char *str_pos; /* current position in strings buffer */
|
unsigned int str_pos; /* current position in strings buffer */
|
||||||
char *out_pos; /* current position in output buffer */
|
unsigned int out_pos; /* current position in output buffer */
|
||||||
char strings[1024]; /* buffer for temporary strings */
|
char strings[1024]; /* buffer for temporary strings */
|
||||||
char output[1024]; /* current output line */
|
char output[1024]; /* current output line */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
|
/* thread private data, stored in NtCurrentTeb()->GdiTebBatch */
|
||||||
|
|
|
@ -367,8 +367,7 @@ static void start_thread( struct startup_info *info )
|
||||||
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch;
|
struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)&teb->GdiTebBatch;
|
||||||
struct debug_info debug_info;
|
struct debug_info debug_info;
|
||||||
|
|
||||||
debug_info.str_pos = debug_info.strings;
|
debug_info.str_pos = debug_info.out_pos = 0;
|
||||||
debug_info.out_pos = debug_info.output;
|
|
||||||
thread_data->debug_info = &debug_info;
|
thread_data->debug_info = &debug_info;
|
||||||
thread_data->pthread_id = pthread_self();
|
thread_data->pthread_id = pthread_self();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue