diff --git a/toolkit/library/moz.build b/toolkit/library/moz.build index cbc78e9ad..7110728c1 100644 --- a/toolkit/library/moz.build +++ b/toolkit/library/moz.build @@ -186,11 +186,6 @@ if CONFIG['MOZ_DIRECTSHOW']: 'msdmo', ] -if CONFIG['OS_ARCH'] == 'FreeBSD': - OS_LIBS += [ - 'util', - ] - if CONFIG['OS_ARCH'] == 'WINNT': OS_LIBS += [ 'crypt32', @@ -313,11 +308,6 @@ if CONFIG['OS_ARCH'] == 'SunOS': 'sendfile', ] -if CONFIG['OS_ARCH'] == 'FreeBSD': - OS_LIBS += [ - 'util', - ] - if CONFIG['OS_ARCH'] == 'WINNT': OS_LIBS += [ 'shell32', diff --git a/xpcom/base/nsMemoryReporterManager.cpp b/xpcom/base/nsMemoryReporterManager.cpp index aa3d74dfd..690ecf37d 100644 --- a/xpcom/base/nsMemoryReporterManager.cpp +++ b/xpcom/base/nsMemoryReporterManager.cpp @@ -262,6 +262,9 @@ ResidentFastDistinguishedAmount(int64_t* aN) #ifdef __FreeBSD__ #include #include +#include + +typedef struct kinfo_vmentry *(*kinfo_getvmmap_t)(pid_t, int *); static MOZ_MUST_USE nsresult GetKinfoVmentrySelf(int64_t* aPrss, uint64_t* aMaxreg) @@ -269,7 +272,29 @@ GetKinfoVmentrySelf(int64_t* aPrss, uint64_t* aMaxreg) int cnt; struct kinfo_vmentry* vmmap; struct kinfo_vmentry* kve; - if (!(vmmap = kinfo_getvmmap(getpid(), &cnt))) { + static kinfo_getvmmap_t fp_kinfo_getvmmap = nullptr; + + // Cache the function pointer on first call + // So we can avoid hardlinking libutil + if(!fp_kinfo_getvmmap) { + void *libutil = dlopen("libutil.so", RTLD_LAZY); + if(libutil) { + fp_kinfo_getvmmap = (kinfo_getvmmap_t)dlsym(libutil, "kinfo_getvmmap"); + } + // If we failed to get the function pointer, bail with failure + if(!fp_kinfo_getvmmap) { + if(libutil) { + dlclose(libutil); + } + return NS_ERROR_FAILURE; + } + } + // Abort if API call fails, or there is a struct size mismatch + if (!(vmmap = fp_kinfo_getvmmap(getpid(), &cnt)) + || (vmmap->kve_structsize != sizeof(*vmmap))) { + if(vmmap) { + free(vmmap); + } return NS_ERROR_FAILURE; } if (aPrss) {