]> granicus.if.org Git - php/commitdiff
JIT: Reading php binary symbols list on FreeBSD
authorDavid Carlier <devnexen@gmail.com>
Thu, 4 Jul 2019 17:46:20 +0000 (18:46 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Jul 2019 10:39:18 +0000 (12:39 +0200)
Closes GH-4363.

ext/opcache/jit/zend_elf.c
ext/opcache/jit/zend_jit_perf_dump.c

index 68f5513e6137f286d3382747f5fb2acb4f27b5aa..f5180e0a96ab6cf4b83f94d03b2769a0e6c279e7 100644 (file)
@@ -19,6 +19,9 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#if defined(__FreeBSD__)
+#include <sys/sysctl.h>
+#endif
 #include <fcntl.h>
 #include <unistd.h>
 
@@ -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)
index d99c85a9a0fe6d623f394f96af86e1dece0444bc..c18f9782ee4d71d1863bc2e727d0ea1a93c2840a 100644 (file)
@@ -28,6 +28,7 @@
 # include <pthread.h>
 #elif defined(__FreeBSD__)
 # include <sys/thr.h>
+# include <sys/sysctl.h>
 #elif defined(__NetBSD__)
 # include <lwp.h>
 #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;
        }