This commit is contained in:
mrpotatogun 2023-09-04 14:35:28 -04:00 committed by GitHub
commit 0631bb7f17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -35,6 +35,8 @@ ifeq ($(OS),Windows_NT)
DETECTED_OS := windows
else ifeq ($(UNAME_S),Linux)
DETECTED_OS := linux
else ifeq ($(UNAME_S),FreeBSD)
DETECTED_OS := freebsd
else ifeq ($(UNAME_S),Darwin)
DETECTED_OS := macos
MAKE := gmake
@ -122,6 +124,10 @@ ifeq ($(DETECTED_OS),linux)
# For traceback
$(RECOMP_ELF): LDFLAGS += -Wl,-export-dynamic
endif
ifeq ($(DETECTED_OS),freebsd)
# For traceback
$(RECOMP_ELF): LDFLAGS += -Wl,-export-dynamic -lexecinfo
endif
# Too many warnings, disable everything for now...
$(RECOMP_ELF): WARNINGS += -Wpedantic -Wno-shadow -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter -Wno-implicit-fallthrough

View File

@ -308,6 +308,11 @@ static void init_usr_lib_redirect(void) {
if (_NSGetExecutablePath(path, &size) < 0) {
return;
}
#elif defined __FreeBSD__
ssize_t size = readlink("/proc/curproc/file", path, PATH_MAX);
if (size < 0 || size == PATH_MAX) {
return;
}
#else
ssize_t size = readlink("/proc/self/exe", path, PATH_MAX);
if (size < 0 || size == PATH_MAX) {
@ -2499,7 +2504,17 @@ void wrapper_longjmp(uint8_t* mem, uint32_t addr, int status) {
uint32_t wrapper_tempnam(uint8_t *mem, uint32_t dir_addr, uint32_t pfx_addr) {
STRING(dir)
STRING(pfx)
#ifdef __FreeBSD__
//dir is coming in as empty string, or a / at best, force sane location, NULL would force /tmp/ too
//linux man on this call suggests maybe it overrides in-appropriate, ie non-writable, etc to $TEMPDIR
//or /tmp, bsd man for this call doesn't mention it checks at all. not sure if dir is truly coming in
//empty and being masked by glibc checking if its valid, or if its fine and maybe truly a freebsd issue.
//under bsd this is an example ret output passing in dir: /cQyXjG obviously root is a bad place for temp
//files forcing works and might just be replicating the linux/glibc behavior anyway
char *ret = tempnam("/tmp/", pfx);
#else
char *ret = tempnam(dir, pfx);
#endif
char *ret_saved = ret;
if (ret == NULL) {
MEM_U32(ERRNO_ADDR) = errno;
@ -2932,7 +2947,12 @@ uint32_t wrapper_regex(uint8_t* mem, uint32_t re_addr, uint32_t subject_addr, ui
void wrapper___assert(uint8_t* mem, uint32_t assertion_addr, uint32_t file_addr, int line) {
STRING(assertion)
STRING(file)
#ifdef __FreeBSD__
//#define assert(e) ((e) ? (void)0 : __assert(__func__, __FILE__, __LINE__, #e))
__assert("undefinedfunc", file, line, assertion);
#else
__assert(assertion, file, line);
#endif
}
union host_doubleword {