1
0
mirror of https://github.com/wine-mirror/wine synced 2024-07-08 20:06:18 +00:00

msvcrt: Consistently use the rtti_rva() helper.

This commit is contained in:
Alexandre Julliard 2024-06-04 13:35:30 +02:00
parent b8edf6d920
commit bc76e9cfe0
2 changed files with 38 additions and 52 deletions

View File

@ -56,11 +56,6 @@ typedef struct
const cxx_function_descr *descr;
} se_translator_ctx;
static inline void* rva_to_ptr(UINT rva, ULONG64 base)
{
return rva ? (void*)(base+rva) : NULL;
}
static inline int ip_to_state( const cxx_function_descr *descr, uintptr_t ip, uintptr_t base )
{
const ipmap_info *ipmap = rtti_rva( descr->ipmap, base );
@ -76,7 +71,7 @@ static inline int ip_to_state( const cxx_function_descr *descr, uintptr_t ip, ui
static void cxx_local_unwind(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
const cxx_function_descr *descr, int last_level)
{
const unwind_info *unwind_table = rva_to_ptr(descr->unwind_table, dispatch->ImageBase);
const unwind_info *unwind_table = rtti_rva(descr->unwind_table, dispatch->ImageBase);
void (__cdecl *handler)(ULONG64 unk, ULONG64 rbp);
int *unwind_help = (int *)(frame + descr->unwind_help);
int trylevel;
@ -98,9 +93,9 @@ static void cxx_local_unwind(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
ERR("invalid trylevel %d\n", trylevel);
terminate();
}
handler = rva_to_ptr(unwind_table[trylevel].handler, dispatch->ImageBase);
if (handler)
if (unwind_table[trylevel].handler)
{
handler = rtti_rva(unwind_table[trylevel].handler, dispatch->ImageBase);
TRACE("handler: %p\n", handler);
handler(0, frame);
}
@ -205,7 +200,7 @@ static inline void find_catch_block(EXCEPTION_RECORD *rec, CONTEXT *context,
data->processing_throw++;
for (i=descr->tryblock_count; i>0; i--)
{
in_catch = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
in_catch = rtti_rva(descr->tryblock, dispatch->ImageBase);
in_catch = &in_catch[i-1];
if (trylevel>in_catch->end_level && trylevel<=in_catch->catch_level)
@ -223,7 +218,7 @@ static inline void find_catch_block(EXCEPTION_RECORD *rec, CONTEXT *context,
for (i=0; i<descr->tryblock_count; i++)
{
const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
const tryblock_info *tryblock = rtti_rva(descr->tryblock, dispatch->ImageBase);
tryblock = &tryblock[i];
if (trylevel < tryblock->start_level) continue;
@ -318,21 +313,21 @@ static DWORD cxx_frame_handler(EXCEPTION_RECORD *rec, ULONG64 frame,
/* update orig_frame if it's a nested exception */
throw_func_off = RtlLookupFunctionEntry(dispatch->ControlPc, &throw_base, NULL)->BeginAddress;
throw_func = rva_to_ptr(throw_func_off, throw_base);
throw_func = rtti_rva(throw_func_off, throw_base);
TRACE("reconstructed handler pointer: %p\n", throw_func);
for (i=descr->tryblock_count; i>0; i--)
{
const tryblock_info *tryblock = rva_to_ptr(descr->tryblock, dispatch->ImageBase);
const tryblock_info *tryblock = rtti_rva(descr->tryblock, dispatch->ImageBase);
tryblock = &tryblock[i-1];
if (trylevel>tryblock->end_level && trylevel<=tryblock->catch_level)
{
for (j=0; j<tryblock->catchblock_count; j++)
{
const catchblock_info *catchblock = rva_to_ptr(tryblock->catchblock, dispatch->ImageBase);
const catchblock_info *catchblock = rtti_rva(tryblock->catchblock, dispatch->ImageBase);
catchblock = &catchblock[j];
if (rva_to_ptr(catchblock->handler, dispatch->ImageBase) == throw_func)
if (rtti_rva(catchblock->handler, dispatch->ImageBase) == throw_func)
{
TRACE("nested exception detected\n");
unwindlevel = tryblock->end_level;
@ -418,7 +413,7 @@ EXCEPTION_DISPOSITION CDECL __CxxFrameHandler( EXCEPTION_RECORD *rec, ULONG64 fr
{
TRACE( "%p %I64x %p %p\n", rec, frame, context, dispatch );
return cxx_frame_handler( rec, frame, context, dispatch,
rva_to_ptr(*(UINT*)dispatch->HandlerData, dispatch->ImageBase) );
rtti_rva(*(UINT *)dispatch->HandlerData, dispatch->ImageBase) );
}

View File

@ -149,11 +149,6 @@ static UINT read_rva(BYTE **b)
return ret;
}
static inline void* rva_to_ptr(UINT rva, ULONG64 base)
{
return rva ? (void*)(base+rva) : NULL;
}
static void read_unwind_info(BYTE **b, unwind_info_v4 *ui)
{
BYTE *p = *b;
@ -190,9 +185,9 @@ static void read_tryblock_info(BYTE **b, tryblock_info *ti, ULONG64 image_base)
ti->catch_level = decode_uint(b);
ti->catchblock = read_rva(b);
count = count_end = rva_to_ptr(ti->catchblock, image_base);
if (count)
if (ti->catchblock)
{
count = count_end = rtti_rva(ti->catchblock, image_base);
ti->catchblock_count = decode_uint(&count_end);
ti->catchblock += count_end - count;
}
@ -252,9 +247,9 @@ static void read_ipmap_info(BYTE **b, ipmap_info *ii)
static BOOL validate_cxx_function_descr4(const cxx_function_descr_v4 *descr, DISPATCHER_CONTEXT *dispatch)
{
ULONG64 image_base = dispatch->ImageBase;
BYTE *unwind_map = rva_to_ptr(descr->unwind_map, image_base);
BYTE *tryblock_map = rva_to_ptr(descr->tryblock_map, image_base);
BYTE *ip_map = rva_to_ptr(descr->ip_map, image_base);
BYTE *unwind_map = rtti_rva(descr->unwind_map, image_base);
BYTE *tryblock_map = rtti_rva(descr->tryblock_map, image_base);
BYTE *ip_map = rtti_rva(descr->ip_map, image_base);
UINT i, j;
char *ip;
@ -268,10 +263,9 @@ static BOOL validate_cxx_function_descr4(const cxx_function_descr_v4 *descr, DIS
unwind_info_v4 ui;
read_unwind_info(&unwind_map, &ui);
if (ui.prev < (BYTE*)rva_to_ptr(descr->unwind_map, image_base)) ui.prev = NULL;
TRACE(" %d (%p): type 0x%x prev %p func 0x%x(%p) object 0x%x\n",
i, entry, ui.type, ui.prev, ui.handler,
rva_to_ptr(ui.handler, image_base), ui.object);
if (ui.prev < (BYTE*)rtti_rva(descr->unwind_map, image_base)) ui.prev = NULL;
TRACE(" %d (%p): type 0x%x prev %p func 0x%x object 0x%x\n",
i, entry, ui.type, ui.prev, ui.handler, ui.object);
}
TRACE("try table: 0x%x(%p) %d\n", descr->tryblock_map, tryblock_map, descr->tryblock_count);
@ -281,7 +275,7 @@ static BOOL validate_cxx_function_descr4(const cxx_function_descr_v4 *descr, DIS
BYTE *catchblock;
read_tryblock_info(&tryblock_map, &ti, image_base);
catchblock = rva_to_ptr(ti.catchblock, image_base);
catchblock = rtti_rva(ti.catchblock, image_base);
TRACE(" %d: start %d end %d catchlevel %d catch 0x%x(%p) %d\n",
i, ti.start_level, ti.end_level, ti.catch_level,
ti.catchblock, catchblock, ti.catchblock_count);
@ -290,16 +284,15 @@ static BOOL validate_cxx_function_descr4(const cxx_function_descr_v4 *descr, DIS
catchblock_info_v4 ci;
if (!read_catchblock_info(&catchblock, &ci,
dispatch->FunctionEntry->BeginAddress)) return FALSE;
TRACE(" %d: header 0x%x offset %d handler 0x%x(%p) "
TRACE(" %d: header 0x%x offset %d handler 0x%x "
"ret addr[0] %#x ret_addr[1] %#x type %#x %s\n", j, ci.header, ci.offset,
ci.handler, rva_to_ptr(ci.handler, image_base),
ci.ret_addr[0], ci.ret_addr[1], ci.type_info,
dbgstr_type_info(rva_to_ptr(ci.type_info, image_base)));
ci.handler, ci.ret_addr[0], ci.ret_addr[1], ci.type_info,
dbgstr_type_info(rtti_rva(ci.type_info, image_base)));
}
}
TRACE("ipmap: 0x%x(%p) %d\n", descr->ip_map, ip_map, descr->ip_count);
ip = rva_to_ptr(dispatch->FunctionEntry->BeginAddress, image_base);
ip = rtti_rva(dispatch->FunctionEntry->BeginAddress, image_base);
for (i = 0; i < descr->ip_count; i++)
{
ipmap_info ii;
@ -344,7 +337,7 @@ static void cxx_local_unwind4(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
if (trylevel == -2)
{
trylevel = ip_to_state4(rva_to_ptr(descr->ip_map, dispatch->ImageBase),
trylevel = ip_to_state4(rtti_rva(descr->ip_map, dispatch->ImageBase),
descr->ip_count, dispatch, dispatch->ControlPc);
}
@ -358,7 +351,7 @@ static void cxx_local_unwind4(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
if (trylevel <= last_level) return;
unwind_data = rva_to_ptr(descr->unwind_map, dispatch->ImageBase);
unwind_data = rtti_rva(descr->unwind_map, dispatch->ImageBase);
last = unwind_data - 1;
for (i = 0; i < trylevel; i++)
{
@ -374,7 +367,7 @@ static void cxx_local_unwind4(ULONG64 frame, DISPATCHER_CONTEXT *dispatch,
if (ui.handler)
{
handler_dtor = rva_to_ptr(ui.handler, dispatch->ImageBase);
handler_dtor = rtti_rva(ui.handler, dispatch->ImageBase);
obj = (void *)(frame + ui.object);
if(ui.type == UNWIND_TYPE_DTOR_PTR)
obj = *(void**)obj;
@ -494,12 +487,12 @@ static inline void find_catch_block4(EXCEPTION_RECORD *rec, CONTEXT *context,
if (trylevel == -2)
{
trylevel = ip_to_state4(rva_to_ptr(descr->ip_map, dispatch->ImageBase),
trylevel = ip_to_state4(rtti_rva(descr->ip_map, dispatch->ImageBase),
descr->ip_count, dispatch, dispatch->ControlPc);
}
TRACE("current trylevel: %d\n", trylevel);
tryblock_map = rva_to_ptr(descr->tryblock_map, dispatch->ImageBase);
tryblock_map = rtti_rva(descr->tryblock_map, dispatch->ImageBase);
for (i=0; i<descr->tryblock_count; i++)
{
tryblock_info tryblock;
@ -511,7 +504,7 @@ static inline void find_catch_block4(EXCEPTION_RECORD *rec, CONTEXT *context,
if (trylevel > tryblock.end_level) continue;
/* got a try block */
catchblock = rva_to_ptr(tryblock.catchblock, dispatch->ImageBase);
catchblock = rtti_rva(tryblock.catchblock, dispatch->ImageBase);
for (j=0; j<tryblock.catchblock_count; j++)
{
catchblock_info_v4 ci;
@ -553,18 +546,17 @@ static inline void find_catch_block4(EXCEPTION_RECORD *rec, CONTEXT *context,
catch_record.ExceptionInformation[2] = tryblock.catch_level;
catch_record.ExceptionInformation[3] = tryblock.start_level;
catch_record.ExceptionInformation[4] = (ULONG_PTR)rec;
catch_record.ExceptionInformation[5] =
(ULONG_PTR)rva_to_ptr(ci.handler, dispatch->ImageBase);
catch_record.ExceptionInformation[5] = (ULONG_PTR)rtti_rva(ci.handler, dispatch->ImageBase);
catch_record.ExceptionInformation[6] = (ULONG_PTR)untrans_rec;
catch_record.ExceptionInformation[7] = (ULONG_PTR)context;
if (ci.ret_addr[0])
{
catch_record.ExceptionInformation[8] = (ULONG_PTR)rva_to_ptr(
catch_record.ExceptionInformation[8] = (ULONG_PTR)rtti_rva(
ci.ret_addr[0], dispatch->ImageBase);
}
if (ci.ret_addr[1])
{
catch_record.ExceptionInformation[9] = (ULONG_PTR)rva_to_ptr(
catch_record.ExceptionInformation[9] = (ULONG_PTR)rtti_rva(
ci.ret_addr[1], dispatch->ImageBase);
}
RtlUnwindEx((void*)frame, (void*)dispatch->ControlPc, &catch_record, NULL, &ctx, NULL);
@ -632,7 +624,7 @@ static DWORD cxx_frame_handler4(EXCEPTION_RECORD *rec, ULONG64 frame,
if ((rec->ExceptionFlags & EXCEPTION_TARGET_UNWIND) && cxx_is_consolidate(rec))
last_level = rec->ExceptionInformation[3];
else if ((rec->ExceptionFlags & EXCEPTION_TARGET_UNWIND) && rec->ExceptionCode == STATUS_LONGJUMP)
last_level = ip_to_state4(rva_to_ptr(descr->ip_map, dispatch->ImageBase),
last_level = ip_to_state4(rtti_rva(descr->ip_map, dispatch->ImageBase),
descr->ip_count, dispatch, dispatch->TargetIp);
cxx_local_unwind4(orig_frame, dispatch, descr, trylevel, last_level);
@ -709,7 +701,7 @@ EXCEPTION_DISPOSITION __cdecl __CxxFrameHandler4(EXCEPTION_RECORD *rec,
FlsSetValue(fls_index, (void*)-2);
memset(&descr, 0, sizeof(descr));
p = rva_to_ptr(*(UINT*)dispatch->HandlerData, dispatch->ImageBase);
p = rtti_rva(*(UINT*)dispatch->HandlerData, dispatch->ImageBase);
descr.header = *p++;
if ((descr.header & FUNC_DESCR_EHS) &&
@ -730,14 +722,14 @@ EXCEPTION_DISPOSITION __cdecl __CxxFrameHandler4(EXCEPTION_RECORD *rec,
if (descr.header & FUNC_DESCR_UNWIND_MAP)
{
descr.unwind_map = read_rva(&p);
count_end = count = rva_to_ptr(descr.unwind_map, dispatch->ImageBase);
count_end = count = rtti_rva(descr.unwind_map, dispatch->ImageBase);
descr.unwind_count = decode_uint(&count_end);
descr.unwind_map += count_end - count;
}
if (descr.header & FUNC_DESCR_TRYBLOCK_MAP)
{
descr.tryblock_map = read_rva(&p);
count_end = count = rva_to_ptr(descr.tryblock_map, dispatch->ImageBase);
count_end = count = rtti_rva(descr.tryblock_map, dispatch->ImageBase);
descr.tryblock_count = decode_uint(&count_end);
descr.tryblock_map += count_end - count;
}
@ -745,9 +737,8 @@ EXCEPTION_DISPOSITION __cdecl __CxxFrameHandler4(EXCEPTION_RECORD *rec,
if (descr.header & FUNC_DESCR_IS_SEPARATED)
{
UINT i, num, func;
BYTE *map;
BYTE *map = rtti_rva(descr.ip_map, dispatch->ImageBase);
map = rva_to_ptr(descr.ip_map, dispatch->ImageBase);
num = decode_uint(&map);
for (i = 0; i < num; i++)
{
@ -762,7 +753,7 @@ EXCEPTION_DISPOSITION __cdecl __CxxFrameHandler4(EXCEPTION_RECORD *rec,
return ExceptionContinueSearch;
}
}
count_end = count = rva_to_ptr(descr.ip_map, dispatch->ImageBase);
count_end = count = rtti_rva(descr.ip_map, dispatch->ImageBase);
descr.ip_count = decode_uint(&count_end);
descr.ip_map += count_end - count;
if (descr.header & FUNC_DESCR_IS_CATCH) descr.frame = decode_uint(&p);