ported from UXP: Issue Pale-Moon#2002 - Remove FreeBSD compat13x dependency on 15.x. Remove the 2 libutil OS_LIBS and dynamically load libutil.so instead. (2a2a85f8)

This commit is contained in:
2025-12-18 00:07:05 +08:00
parent b39f71e0fc
commit 46bae686fe
2 changed files with 26 additions and 11 deletions
-10
View File
@@ -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',
+26 -1
View File
@@ -262,6 +262,9 @@ ResidentFastDistinguishedAmount(int64_t* aN)
#ifdef __FreeBSD__
#include <libutil.h>
#include <algorithm>
#include <dlfcn.h>
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) {