Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little touches to windows platform code #331

Merged
merged 9 commits into from
May 25, 2024
2 changes: 1 addition & 1 deletion .github/workflows/workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
cd build
ctest --verbose
- name: Upload Artifact
if: startsWith(github.ref, 'refs/tags/') || github.ref_name == 'main'
# if: startsWith(github.ref, 'refs/tags/') || github.ref_name == 'main'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled this line such that the user at #330 can download a built binary.

uses: actions/upload-artifact@v3
with:
name: ${{ steps.build.outputs.filename }}
Expand Down
2 changes: 1 addition & 1 deletion src/BRSRC13/CORE/FW/datafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ br_uint_32 DfStructReadBinary(br_datafile* df, br_file_struct* str, void* base)

return 1;
}
#include <stdio.h>

// IDA: int __usercall DfStructSizeBinary@<EAX>(br_datafile *df@<EAX>, br_file_struct *str@<EDX>, void *base@<EBX>)
int DfStructSizeBinary(br_datafile* df, br_file_struct* str, void* base) {
unsigned char* mp;
Expand Down
3 changes: 3 additions & 0 deletions src/harness/os/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ FILE* OS_fopen(const char* pathname, const char* mode) {
}
}
closedir(pDir);
if (f == NULL) {
fprintf(stderr, "Failed to open \"%s\" (%s)\n", pathname, strerror(errno));
}
return f;
}

Expand Down
9 changes: 8 additions & 1 deletion src/harness/os/macos.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,14 @@ void OS_InstallSignalHandler(char* program_name) {
}

FILE* OS_fopen(const char* pathname, const char* mode) {
return fopen(pathname, mode);
FILE* f;

f = fopen(pathname, mode);
if (f == NULL) {
fprintf(stderr, "Failed to open \"%s\" (%s)\n", pathname, strerror(errno));
}

return f;
}

size_t OS_ConsoleReadPassword(char* pBuffer, size_t pBufferLen) {
Expand Down
16 changes: 8 additions & 8 deletions src/harness/os/windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
void dr_dprintf(char* fmt_string, ...);

static int stack_nbr = 0;
static char _program_name[1024];
static char windows_program_name[1024];

static char dirname_buf[_MAX_DIR];
static char fname_buf[_MAX_FNAME];

int addr2line(char const* const program_name, void const* const addr) {
static int addr2line(char const* const program_name, void const* const addr) {
char addr2line_cmd[512] = { 0 };

sprintf(addr2line_cmd, "addr2line -f -p -e %.256s %p", program_name, addr);
Expand All @@ -41,7 +41,7 @@ int addr2line(char const* const program_name, void const* const addr) {
return system(addr2line_cmd);
}

void print_stacktrace(CONTEXT* context) {
static void print_stacktrace(CONTEXT* context) {

SymInitialize(GetCurrentProcess(), 0, true);

Expand All @@ -64,13 +64,13 @@ void print_stacktrace(CONTEXT* context) {
SymFunctionTableAccess,
SymGetModuleBase,
0)) {
addr2line(_program_name, (void*)frame.AddrPC.Offset);
addr2line(windows_program_name, (void*)frame.AddrPC.Offset);
}

SymCleanup(GetCurrentProcess());
}

LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS* ExceptionInfo) {
static LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS* ExceptionInfo) {
switch (ExceptionInfo->ExceptionRecord->ExceptionCode) {
case EXCEPTION_ACCESS_VIOLATION:
fputs("Error: EXCEPTION_ACCESS_VIOLATION\n", stderr);
Expand Down Expand Up @@ -142,14 +142,14 @@ LONG WINAPI windows_exception_handler(EXCEPTION_POINTERS* ExceptionInfo) {
if (EXCEPTION_STACK_OVERFLOW != ExceptionInfo->ExceptionRecord->ExceptionCode) {
print_stacktrace(ExceptionInfo->ContextRecord);
} else {
addr2line(_program_name, (void*)ExceptionInfo->ContextRecord->Eip);
addr2line(windows_program_name, (void*)ExceptionInfo->ContextRecord->Eip);
}

return EXCEPTION_EXECUTE_HANDLER;
}

void OS_InstallSignalHandler(char* program_name) {
strcpy(_program_name, program_name);
strcpy(windows_program_name, program_name);
SetUnhandledExceptionFilter(windows_exception_handler);
}

Expand All @@ -160,7 +160,7 @@ FILE* OS_fopen(const char* pathname, const char* mode) {
f = NULL;
err = fopen_s(&f, pathname, mode);
if (err != 0) {
fprintf(stderr, "Failed to open \"%s\"", pathname);
fprintf(stderr, "Failed to open \"%s\" (%s)\n", pathname, strerror(err));
}

return f;
Expand Down
Loading