git: 36173e8b04c7 - main - www/deno: Add a FreeBSD implementation for rss()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 21 Jun 2023 11:35:41 UTC
The branch main has been updated by mikael: URL: https://cgit.FreeBSD.org/ports/commit/?id=36173e8b04c784250fb680e77f92339e2feb5496 commit 36173e8b04c784250fb680e77f92339e2feb5496 Author: Mikael Urankar <mikael@FreeBSD.org> AuthorDate: 2023-06-21 10:20:26 +0000 Commit: Mikael Urankar <mikael@FreeBSD.org> CommitDate: 2023-06-21 11:35:21 +0000 www/deno: Add a FreeBSD implementation for rss() Obtained from: OpenBSD Reviewed by: Val Packett --- www/deno/Makefile | 1 + www/deno/files/patch-runtime_ops_os_mod.rs | 41 +++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/www/deno/Makefile b/www/deno/Makefile index 33a2f65ef317..0fa1b659d4a1 100644 --- a/www/deno/Makefile +++ b/www/deno/Makefile @@ -1,6 +1,7 @@ PORTNAME= deno DISTVERSIONPREFIX= v DISTVERSION= 1.34.3 +PORTREVISION= 1 CATEGORIES= www PATCH_SITES= https://github.com/denoland/${PORTNAME}/commit/ diff --git a/www/deno/files/patch-runtime_ops_os_mod.rs b/www/deno/files/patch-runtime_ops_os_mod.rs index 15557b190562..c32b6594d71e 100644 --- a/www/deno/files/patch-runtime_ops_os_mod.rs +++ b/www/deno/files/patch-runtime_ops_os_mod.rs @@ -1,12 +1,47 @@ --- runtime/ops/os/mod.rs.orig 2023-01-13 13:12:37 UTC +++ runtime/ops/os/mod.rs -@@ -399,6 +399,11 @@ fn rss() -> usize { - task_info.resident_size as usize +@@ -427,6 +427,46 @@ fn rss() -> usize { + } } +#[cfg(target_os = "freebsd")] +fn rss() -> usize { -+ 0 ++ // Uses FreeBSD's KERN_PROC_PID sysctl(2) ++ // to retrieve information about the current ++ // process, part of which is the RSS (ki_rssize) ++ let pid = unsafe { libc::getpid() }; ++ // SAFETY: libc call (get system page size) ++ let pagesize = unsafe { libc::sysconf(libc::_SC_PAGESIZE) } as usize; ++ // KERN_PROC_PID returns a struct libc::kinfo_proc ++ let mut kinfoproc = std::mem::MaybeUninit::<libc::kinfo_proc>::uninit(); ++ let mut size = std::mem::size_of_val(&kinfoproc) as libc::size_t; ++ let mut mib = [ ++ libc::CTL_KERN, ++ libc::KERN_PROC, ++ libc::KERN_PROC_PID, ++ pid, ++ ]; ++ // SAFETY: libc call, mib has been statically initialized, ++ // kinfoproc is a valid pointer to a libc::kinfo_proc struct ++ let res = unsafe { ++ libc::sysctl( ++ mib.as_mut_ptr(), ++ mib.len() as _, ++ kinfoproc.as_mut_ptr() as *mut libc::c_void, ++ &mut size, ++ std::ptr::null_mut(), ++ 0, ++ ) ++ }; ++ ++ if res == 0 { ++ // SAFETY: sysctl returns 0 on success and kinfoproc is initialized ++ // ki_rssize contains size in pages -> multiply with pagesize to ++ // get size in bytes. ++ pagesize * unsafe { (*kinfoproc.as_mut_ptr()).ki_rssize as usize } ++ } else { ++ 0 ++ } +} + #[cfg(windows)]