[PATCH] D73990: [Sanitizers] Get link map on FreeBSD via documented API
Dimitry Andric via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 4 13:55:44 PST 2020
dim updated this revision to Diff 242425.
dim added a comment.
Cast return value to link_map to avoid call site errors.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73990/new/
https://reviews.llvm.org/D73990
Files:
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
@@ -21,15 +21,17 @@
#include "sanitizer_platform_limits_posix.h"
-// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
-// incorporates the map structure.
-# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
- ((link_map*)((handle) == nullptr ? nullptr : ((char*)(handle) + 560)))
// Get sys/_types.h, because that tells us whether 64-bit inodes are
// used in struct dirent below.
#include <sys/_types.h>
namespace __sanitizer {
+// FreeBSD's dlopen() returns a pointer to an Obj_Entry structure that
+// incorporates the map structure.
+void *__sanitizer_get_link_map_by_dlopen_handle(void *handle);
+# define GET_LINK_MAP_BY_DLOPEN_HANDLE(handle) \
+ (link_map *)__sanitizer_get_link_map_by_dlopen_handle(handle)
+
extern unsigned struct_utsname_sz;
extern unsigned struct_stat_sz;
#if defined(__powerpc64__)
Index: compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.cpp
@@ -17,6 +17,7 @@
#include <arpa/inet.h>
#include <dirent.h>
+#include <dlfcn.h>
#include <fts.h>
#include <fstab.h>
#include <grp.h>
@@ -91,6 +92,12 @@
#include "sanitizer_platform_limits_freebsd.h"
namespace __sanitizer {
+ void *__sanitizer_get_link_map_by_dlopen_handle(void* handle)
+ {
+ void *p = nullptr;
+ return dlinfo(handle, RTLD_DI_LINKMAP, &p) == 0 ? p : nullptr;
+ }
+
unsigned struct_cap_rights_sz = sizeof(cap_rights_t);
unsigned struct_utsname_sz = sizeof(struct utsname);
unsigned struct_stat_sz = sizeof(struct stat);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73990.242425.patch
Type: text/x-patch
Size: 2000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200204/77a8f87a/attachment.bin>
More information about the llvm-commits
mailing list