From 5e1368814265871695ffb35ceb927cd1bae06a25 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Thu, 4 Jul 2019 18:46:20 +0100 Subject: [PATCH] JIT: Reading php binary symbols list on FreeBSD Closes GH-4363. --- ext/opcache/jit/zend_elf.c | 19 +++++++++++++++++++ ext/opcache/jit/zend_jit_perf_dump.c | 15 +++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/ext/opcache/jit/zend_elf.c b/ext/opcache/jit/zend_elf.c index 68f5513e61..f5180e0a96 100644 --- a/ext/opcache/jit/zend_elf.c +++ b/ext/opcache/jit/zend_elf.c @@ -19,6 +19,9 @@ #include #include +#if defined(__FreeBSD__) +#include +#endif #include #include @@ -46,7 +49,23 @@ void zend_elf_load_symbols(void) zend_elf_header hdr; zend_elf_sectheader sect; int i; +#if defined(__linux__) int fd = open("/proc/self/exe", O_RDONLY); +#elif defined(__NetBSD__) + int fd = open("/proc/curproc/exe", O_RDONLY); +#elif defined(__FreeBSD__) + char path[PATH_MAX]; + size_t pathlen = sizeof(path); + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + if (sysctl(mib, 4, path, &pathlen, NULL, 0) == -1) { + return; + } + int fd = open(path, O_RDONLY); +#else + // To complete eventually for other ELF platforms. + // Otherwise APPLE is Mach-O + int fd = -1; +#endif if (fd >= 0) { if (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr) diff --git a/ext/opcache/jit/zend_jit_perf_dump.c b/ext/opcache/jit/zend_jit_perf_dump.c index d99c85a9a0..c18f9782ee 100644 --- a/ext/opcache/jit/zend_jit_perf_dump.c +++ b/ext/opcache/jit/zend_jit_perf_dump.c @@ -28,6 +28,7 @@ # include #elif defined(__FreeBSD__) # include +# include #elif defined(__NetBSD__) # include #endif @@ -113,7 +114,21 @@ static void zend_jit_perf_jitdump_open(void) return; } +#if defined(__linux__) fd = open("/proc/self/exe", O_RDONLY); +#elif defined(__NetBSD__) + int fd = open("/proc/curproc/exe", O_RDONLY); +#elif defined(__FreeBSD__) + char path[PATH_MAX]; + size_t pathlen = sizeof(path); + int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1}; + if (sysctl(mib, 4, path, &pathlen, NULL, 0) == -1) { + return; + } + fd = open(path, O_RDONLY); +#else + fd = -1; +#endif if (fd < 0) { return; } -- 2.40.0