Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ CFLAGS += -Wno-unused-but-set-variable -Wno-sign-compare
CXXFLAGS = $(CFLAGS) -std=c++17
# For rand_s
CXXFLAGS += -D_CRT_RAND_S
# std::unexpected, which is removed in C++17, conflicts with our unexpected() macro.
# This define tells the glibc to remove the deprecated functions.
# ... until std::unexpected comes back as another thing in C++23.
CXXFLAGS += -D_GLIBCXX_USE_DEPRECATED=0

LDFLAGS += -o $@ -Lbin/bin -Llibs/external_deps/bin

Expand Down
22 changes: 11 additions & 11 deletions thcrap/src/binhack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ static TH_NOINLINE const char* consume_float_value(const char *const expr, patch
char* expr_next;
errno = 0;
double result = _strtod_l(expr, &expr_next, lc_neutral.locale);
if unexpected(expr == expr_next) {
if UNEXPECTED(expr == expr_next) {
// Not actually a floating-point number, keep going though
val->type = PVT_NONE;
return expr + 1;
}
if unexpected(fabs(result) == HUGE_VAL && errno == ERANGE) {
if UNEXPECTED(fabs(result) == HUGE_VAL && errno == ERANGE) {
log_printf("ERROR: Floating point constant \"%.*s\" out of range!\n", expr_next - expr, expr);
return NULL;
}
Expand Down Expand Up @@ -296,7 +296,7 @@ static constexpr size_t patch_val_sizes[] = {
#pragma warning(disable : 4307 4146)
void constpool_apply(HackpointMemoryPage* page_array) {

if unexpected(constpool_prerenders.empty()) {
if UNEXPECTED(constpool_prerenders.empty()) {
return;
}

Expand Down Expand Up @@ -378,7 +378,7 @@ void constpool_apply(HackpointMemoryPage* page_array) {
}
}
element_pos = end_element + 1;
if unexpected(filled_value_size + per_element_size >= current_value_alloc_size) {
if UNEXPECTED(filled_value_size + per_element_size >= current_value_alloc_size) {
current_value = (uint8_t*)realloc(current_value, current_value_alloc_size += BINHACK_BUFSIZE_MIN);
}
switch (per_element_size) {
Expand Down Expand Up @@ -581,7 +581,7 @@ void constpool_apply(HackpointMemoryPage* page_array) {
}
// These are brand new values, so expand the allocation
overaligned_value_size = AlignUpToMultipleOf2(aligned_value_size, sizeof(__m128i));
if unexpected(constpool_memory_size + overaligned_value_size >= rendered_values_alloc_size) {
if UNEXPECTED(constpool_memory_size + overaligned_value_size >= rendered_values_alloc_size) {
size_t new_alloc_size = rendered_values_alloc_size + overaligned_value_size + BINHACK_BUFSIZE_MIN;
rendered_values = (uint8_t*)realloc(rendered_values, new_alloc_size);
padding_tracking = (uint8_t*)realloc(padding_tracking, new_alloc_size);
Expand Down Expand Up @@ -914,7 +914,7 @@ size_t code_string_calc_size(const char* code_str) {
}

// Check for errors
if unexpected(!code_str) {
if UNEXPECTED(!code_str) {
// Code string calc size error
return 0;
}
Expand Down Expand Up @@ -1006,7 +1006,7 @@ int code_string_render(uint8_t* output_buffer, uintptr_t target_addr, const char
case '(': // Expression
code_str = check_for_code_string_cast(++code_str, &val);
code_str = eval_expr(code_str, ')', &val.z, NULL, target_addr, hMod);
if unexpected(!code_str) {
if UNEXPECTED(!code_str) {
break; // Error
}
switch (val.type) {
Expand Down Expand Up @@ -1097,7 +1097,7 @@ int code_string_render(uint8_t* output_buffer, uintptr_t target_addr, const char
}

// Check for errors
if unexpected(!code_str) {
if UNEXPECTED(!code_str) {
log_print("Code string render error!\n");
return CodeStringErrorRet;
}
Expand Down Expand Up @@ -1198,7 +1198,7 @@ int code_string_render(uint8_t* output_buffer, uintptr_t target_addr, const char
break;
case PVT_CODE: {
while (val.code.count--) {
if unexpected(code_string_render(output_buffer, target_addr, val.code.ptr, hMod)) {
if UNEXPECTED(code_string_render(output_buffer, target_addr, val.code.ptr, hMod)) {
return CodeStringErrorRet;
}
output_buffer += val.code.len;
Expand Down Expand Up @@ -1499,7 +1499,7 @@ bool codecave_from_json(const char *name, json_t *in, codecave_t *out) {
} else {
align_val = 1u;
}
if unexpected(align_val > 4096) {
if UNEXPECTED(align_val > 4096) {
log_printf("ERROR: invalid alignment specified for codecave %s, must be <=4096\n", name);
return false;
}
Expand Down Expand Up @@ -1637,7 +1637,7 @@ size_t codecaves_apply(codecave_t *codecaves, size_t codecaves_count, HMODULE hM

// This doesn't make good use of padding bytes
size_t align_offset = codecaves_alloc_size[access] & align - 1;
if unexpected(align_offset) {
if UNEXPECTED(align_offset) {
align_offset = align - align_offset;
codecaves_full_size[last_written_index[access]] += align_offset;
}
Expand Down
8 changes: 4 additions & 4 deletions thcrap/src/bp_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ THREAD_LOCAL(file_rep_t, fr_tls, NULL, file_rep_clear);
size_t BP_file_buffer(x86_reg_t *regs, json_t *bp_info)
{
file_rep_t *fr = fr_tls_get();
if unexpected(fr->disable) {
if UNEXPECTED(fr->disable) {
return 1;
}

Expand All @@ -78,7 +78,7 @@ size_t BP_file_buffer(x86_reg_t *regs, json_t *bp_info)
size_t BP_file_load(x86_reg_t *regs, json_t *bp_info)
{
file_rep_t *fr = fr_tls_get();
if unexpected(fr->disable) {
if UNEXPECTED(fr->disable) {
return 1;
}

Expand Down Expand Up @@ -139,7 +139,7 @@ size_t BP_file_load(x86_reg_t *regs, json_t *bp_info)
// Cool function name.
int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t size, bool overwrite_existing)
{
if unexpected(!buffer || !name) {
if UNEXPECTED(!buffer || !name) {
return -1;
}

Expand All @@ -155,7 +155,7 @@ int DumpDatFile(const char *dir, const char *name, const void *buffer, size_t si
size_t BP_file_loaded(x86_reg_t *regs, json_t *bp_info)
{
file_rep_t *fr = fr_tls_get();
if unexpected(fr->disable) {
if UNEXPECTED(fr->disable) {
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion thcrap/src/breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ patch_val_t json_typed_value(json_t *val, x86_reg_t *regs, patch_value_type_t ty
patch_val_t ret;

void* value = json_pointer_value(val, regs);
if unexpected(!value) {
if UNEXPECTED(!value) {
ret.type = PVT_UNKNOWN;
return ret;
}
Expand Down
16 changes: 8 additions & 8 deletions thcrap/src/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void dialog_adjust_init(
const DLGTEMPLATEEX_FONT *dst_font
)
{
if unexpected(!adj || !dst_header || !dst_font) {
if UNEXPECTED(!adj || !dst_header || !dst_font) {
return;
}
ZeroMemory(adj, sizeof(*adj));
Expand Down Expand Up @@ -266,7 +266,7 @@ void dialog_adjust(
const stringref_t rep
)
{
if unexpected(!adj || !adj->hDC || !item || !rep.data()) {
if UNEXPECTED(!adj || !adj->hDC || !item || !rep.data()) {
return;
}
RECT rect = { 0, 0, item->cx, 0 };
Expand Down Expand Up @@ -302,7 +302,7 @@ void dialog_adjust(

void dialog_adjust_clear(dialog_adjust_t *adj)
{
if unexpected(!adj) {
if UNEXPECTED(!adj) {
return;
}
DeleteObject(adj->hFont);
Expand Down Expand Up @@ -459,7 +459,7 @@ DLGTEMPLATE* dialog_translate_internal(LPCSTR lpTemplateName, HGLOBAL hDlg, size
const char *dlg_format = NULL;
HGLOBAL hDlg_rep = NULL;

if unexpected(!lpTemplateName || !hDlg) {
if UNEXPECTED(!lpTemplateName || !hDlg) {
return NULL;
}

Expand Down Expand Up @@ -533,14 +533,14 @@ DLGTEMPLATE* dialog_translate(HINSTANCE hInstance, LPCSTR lpTemplateName)
HGLOBAL hDlg = NULL;
size_t hDlg_len;

if unexpected(!lpTemplateName) {
if UNEXPECTED(!lpTemplateName) {
return NULL;
}

// MAKEINTRESOURCE(5) == RT_DIALOG.
hrsrc = FindResourceA(hInstance, lpTemplateName, MAKEINTRESOURCEA(5));
hDlg = LoadResource(hInstance, hrsrc);
if unexpected(!hDlg) {
if UNEXPECTED(!hDlg) {
return NULL;
}

Expand All @@ -556,14 +556,14 @@ DLGTEMPLATE* dialog_translatew(HINSTANCE hInstance, LPCWSTR lpTemplateName)
size_t hDlg_len;
DLGTEMPLATE *dlg_out = NULL;

if unexpected(!lpTemplateName) {
if UNEXPECTED(!lpTemplateName) {
return NULL;
}

// MAKEINTRESOURCE(5) == RT_DIALOG.
hrsrc = FindResourceW(hInstance, lpTemplateName, MAKEINTRESOURCEW(5));
hDlg = LoadResource(hInstance, hrsrc);
if unexpected(!hDlg) {
if UNEXPECTED(!hDlg) {
return NULL;
}

Expand Down
18 changes: 9 additions & 9 deletions thcrap/src/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static void log_disassembled_branch_instr(uintptr_t addr) {
branch_target = addr + 1 + *(int8_t*)addr;
print_branch:
log_print("\nOpcode: ");
if unexpected(rep_type == 1) log_print("BND ");
if UNEXPECTED(rep_type == 1) log_print("BND ");
switch (segment) {
case -1: case 0: case 2: case 5: break;
case 1: log_print("-"); break; // Not taken hint
Expand Down Expand Up @@ -383,7 +383,7 @@ static void log_disassembled_branch_instr(uintptr_t addr) {
TH_UNREACHABLE;
case 0xE8: case 0xE9: // JMP, CALL
log_print("\nOpcode: ");
if unexpected(rep_type == 1) log_print("BND ");
if UNEXPECTED(rep_type == 1) log_print("BND ");
if (DATASIZE_NOT_16) {
branch_target = addr + 4 + *(int32_t*)addr;
log_printf(
Expand Down Expand Up @@ -440,8 +440,8 @@ static void log_disassembled_branch_instr(uintptr_t addr) {
goto unrecognized_opcode;
case 2: // CALL rm
log_print("\nOpcode: ");
if unexpected(rep_type == 1) log_print("BND ");
if unexpected(segment == 3) log_print("NOTRACK ");
if UNEXPECTED(rep_type == 1) log_print("BND ");
if UNEXPECTED(segment == 3) log_print("NOTRACK ");
log_print("CALL ");
print_indirect:
mod = opcode >> 6;
Expand Down Expand Up @@ -617,7 +617,7 @@ static void log_disassembled_branch_instr(uintptr_t addr) {
#ifdef TH_X64
case 6: // Relative addr
final_addr = addr + 4 + offset;
if unexpected(addrsize) final_addr = (uint32_t)final_addr;
if UNEXPECTED(addrsize) final_addr = (uint32_t)final_addr;
if (offset >= 0) {
log_printf(
!addrsize ? "RIP + 0x%X] (0x%p)" : "EIP + 0x%X] (0x%08X)"
Expand Down Expand Up @@ -769,8 +769,8 @@ static void log_disassembled_branch_instr(uintptr_t addr) {
TH_UNREACHABLE;
case 4: // JMP rm
log_print("\nOpcode: ");
if unexpected(rep_type == 1) log_print("BND ");
if unexpected(segment == 3) log_print("NOTRACK ");
if UNEXPECTED(rep_type == 1) log_print("BND ");
if UNEXPECTED(segment == 3) log_print("NOTRACK ");
log_print("JMP ");
goto print_indirect;
case 5: // JMP FAR m
Expand Down Expand Up @@ -820,7 +820,7 @@ static void log_print_context(CONTEXT* ctx)
);
#endif
}
if unexpected(last_branch_logging) {
if UNEXPECTED(last_branch_logging) {
#ifdef TH_X64
uintptr_t exception_from = ctx->LastExceptionFromRip;
#else
Expand Down Expand Up @@ -1187,7 +1187,7 @@ TH_CALLER_FREE static char* get_windows_error_message(DWORD ExceptionCode) {
HGLOBAL resource_handle = LoadResource(ntdll_handle, resource_info_handle);

MESSAGE_RESOURCE_DATA* resource_pointer = (MESSAGE_RESOURCE_DATA*)LockResource(resource_handle);
if unexpected(resource_pointer == NULL) {
if UNEXPECTED(resource_pointer == NULL) {
// TODO Figure out why Wine isn't finding the message table resource in ntdll
return NULL;
}
Expand Down
Loading