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

add ido support for FreeBSD #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions tools/ido-static-recomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions tools/ido-static-recomp/libc_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down