Skip to content

dragonflybsd adding subset of kvm api #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1208,6 +1208,7 @@ fn test_dragonflybsd(target: &str) {
"glob.h",
"grp.h",
"ifaddrs.h",
"kvm.h",
"langinfo.h",
"limits.h",
"link.h",
Expand Down Expand Up @@ -1275,6 +1276,7 @@ fn test_dragonflybsd(target: &str) {
"utime.h",
"utmpx.h",
"vfs/ufs/quota.h",
"vm/vm_map.h",
"wchar.h",
"iconv.h",
}
Expand Down Expand Up @@ -1328,6 +1330,9 @@ fn test_dragonflybsd(target: &str) {
});

cfg.skip_struct(move |ty| {
if ty.starts_with("__c_anonymous_") {
return true;
}
match ty {
// FIXME: These are tested as part of the linux_fcntl tests since
// there are header conflicts when including them with all the other
Expand Down
11 changes: 11 additions & 0 deletions libc-test/semver/dragonfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,16 @@ kinfo_cputime
kinfo_file
kinfo_lwp
kinfo_proc
kvm_close
kvm_getloadavg
kvm_getprocs
kvm_open
kvm_openfiles
kvm_read
kvm_t
kvm_vm_map_entry_first
kvm_vm_map_entry_next
kvm_write
kqueue
labs
lastlog
Expand Down Expand Up @@ -1512,6 +1522,7 @@ utmpxname
utrace
uuid
uuid_t
vm_map_entry_t
vm_size_t
wait4
waitid
Expand Down
38 changes: 38 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ pub type pthread_spinlock_t = ::uintptr_t;

pub type segsz_t = usize;

pub type vm_prot_t = u8;
pub type vm_maptype_t = u8;
pub type vm_inherit_t = i8;
pub type vm_subsys_t = ::c_int;
pub type vm_eflags_t = ::c_uint;

pub type vm_map_t = *mut __c_anonymous_vm_map;
pub type vm_map_entry_t = *mut vm_map_entry;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum sem {}
impl ::Copy for sem {}
Expand Down Expand Up @@ -336,6 +345,21 @@ s! {
kp_spare: [::c_int; 2],
}

pub struct __c_anonymous_vm_map {
_priv: [::uintptr_t; 36],
}

pub struct vm_map_entry {
_priv: [::uintptr_t; 15],
pub eflags: ::vm_eflags_t,
pub maptype: ::vm_maptype_t,
pub protection: ::vm_prot_t,
pub max_protection: ::vm_prot_t,
pub inheritance: ::vm_inherit_t,
pub wired_count: ::c_int,
pub id: ::vm_subsys_t,
}

pub struct cpuctl_msr_args_t {
pub msr: ::c_int,
pub data: u64,
Expand Down Expand Up @@ -1613,6 +1637,20 @@ extern "C" {
pub fn freezero(ptr: *mut ::c_void, size: ::size_t);
}

#[link(name = "kvm")]
extern "C" {
pub fn kvm_vm_map_entry_first(
kvm: *mut ::kvm_t,
map: vm_map_t,
entry: vm_map_entry_t,
) -> vm_map_entry_t;
pub fn kvm_vm_map_entry_next(
kvm: *mut ::kvm_t,
map: vm_map_entry_t,
entry: vm_map_entry_t,
) -> vm_map_entry_t;
}

cfg_if! {
if #[cfg(libc_thread_local)] {
mod errno;
Expand Down
78 changes: 21 additions & 57 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ pub type fhandle_t = fhandle;
pub type au_id_t = ::uid_t;
pub type au_asid_t = ::pid_t;

// It's an alias over "struct __kvm_t". However, its fields aren't supposed to be used directly,
// making the type definition system dependent. Better not bind it exactly.
pub type kvm_t = ::c_void;

#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
#[repr(u32)]
pub enum devstat_support_flags {
Expand Down Expand Up @@ -4272,71 +4268,39 @@ extern "C" {

#[link(name = "kvm")]
extern "C" {
pub fn kvm_open(
execfile: *const ::c_char,
corefile: *const ::c_char,
swapfile: *const ::c_char,
flags: ::c_int,
errstr: *const ::c_char,
) -> *mut kvm_t;
pub fn kvm_close(kd: *mut kvm_t) -> ::c_int;
pub fn kvm_dpcpu_setcpu(kd: *mut kvm_t, cpu: ::c_uint) -> ::c_int;
pub fn kvm_getargv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
pub fn kvm_getcptime(kd: *mut kvm_t, cp_time: *mut ::c_long) -> ::c_int;
pub fn kvm_getenvv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
pub fn kvm_geterr(kd: *mut kvm_t) -> *mut ::c_char;
pub fn kvm_getloadavg(kd: *mut kvm_t, loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
pub fn kvm_getmaxcpu(kd: *mut kvm_t) -> ::c_int;
pub fn kvm_getncpus(kd: *mut kvm_t) -> ::c_int;
pub fn kvm_getpcpu(kd: *mut kvm_t, cpu: ::c_int) -> *mut ::c_void;
pub fn kvm_counter_u64_fetch(kd: *mut kvm_t, base: ::c_ulong) -> u64;
pub fn kvm_getprocs(
kd: *mut kvm_t,
op: ::c_int,
arg: ::c_int,
cnt: *mut ::c_int,
) -> *mut kinfo_proc;
pub fn kvm_dpcpu_setcpu(kd: *mut ::kvm_t, cpu: ::c_uint) -> ::c_int;
pub fn kvm_getargv(kd: *mut ::kvm_t, p: *const kinfo_proc, nchr: ::c_int)
-> *mut *mut ::c_char;
pub fn kvm_getcptime(kd: *mut ::kvm_t, cp_time: *mut ::c_long) -> ::c_int;
pub fn kvm_getenvv(kd: *mut ::kvm_t, p: *const kinfo_proc, nchr: ::c_int)
-> *mut *mut ::c_char;
pub fn kvm_geterr(kd: *mut ::kvm_t) -> *mut ::c_char;
pub fn kvm_getmaxcpu(kd: *mut ::kvm_t) -> ::c_int;
pub fn kvm_getncpus(kd: *mut ::kvm_t) -> ::c_int;
pub fn kvm_getpcpu(kd: *mut ::kvm_t, cpu: ::c_int) -> *mut ::c_void;
pub fn kvm_counter_u64_fetch(kd: *mut ::kvm_t, base: ::c_ulong) -> u64;
pub fn kvm_getswapinfo(
kd: *mut kvm_t,
kd: *mut ::kvm_t,
info: *mut kvm_swap,
maxswap: ::c_int,
flags: ::c_int,
) -> ::c_int;
pub fn kvm_native(kd: *mut kvm_t) -> ::c_int;
pub fn kvm_nlist(kd: *mut kvm_t, nl: *mut nlist) -> ::c_int;
pub fn kvm_nlist2(kd: *mut kvm_t, nl: *mut kvm_nlist) -> ::c_int;
pub fn kvm_openfiles(
execfile: *const ::c_char,
corefile: *const ::c_char,
swapfile: *const ::c_char,
flags: ::c_int,
errbuf: *mut ::c_char,
) -> *mut kvm_t;
pub fn kvm_read(
kd: *mut kvm_t,
addr: ::c_ulong,
buf: *mut ::c_void,
nbytes: ::size_t,
) -> ::ssize_t;
pub fn kvm_native(kd: *mut ::kvm_t) -> ::c_int;
pub fn kvm_nlist(kd: *mut ::kvm_t, nl: *mut nlist) -> ::c_int;
pub fn kvm_nlist2(kd: *mut ::kvm_t, nl: *mut kvm_nlist) -> ::c_int;
pub fn kvm_read_zpcpu(
kd: *mut kvm_t,
kd: *mut ::kvm_t,
base: ::c_ulong,
buf: *mut ::c_void,
size: ::size_t,
cpu: ::c_int,
) -> ::ssize_t;
pub fn kvm_read2(
kd: *mut kvm_t,
kd: *mut ::kvm_t,
addr: kvaddr_t,
buf: *mut ::c_void,
nbytes: ::size_t,
) -> ::ssize_t;
pub fn kvm_write(
kd: *mut kvm_t,
addr: ::c_ulong,
buf: *const ::c_void,
nbytes: ::size_t,
) -> ::ssize_t;
}

#[link(name = "util")]
Expand Down Expand Up @@ -4486,10 +4450,10 @@ extern "C" {

#[link(name = "devstat")]
extern "C" {
pub fn devstat_getnumdevs(kd: *mut kvm_t) -> ::c_int;
pub fn devstat_getgeneration(kd: *mut kvm_t) -> ::c_long;
pub fn devstat_getversion(kd: *mut kvm_t) -> ::c_int;
pub fn devstat_checkversion(kd: *mut kvm_t) -> ::c_int;
pub fn devstat_getnumdevs(kd: *mut ::kvm_t) -> ::c_int;
pub fn devstat_getgeneration(kd: *mut ::kvm_t) -> ::c_long;
pub fn devstat_getversion(kd: *mut ::kvm_t) -> ::c_int;
pub fn devstat_checkversion(kd: *mut ::kvm_t) -> ::c_int;
pub fn devstat_selectdevs(
dev_select: *mut *mut device_selection,
num_selected: *mut ::c_int,
Expand Down
42 changes: 42 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ pub type Elf64_Xword = u64;

pub type iconv_t = *mut ::c_void;

// It's an alias over "struct __kvm_t". However, its fields aren't supposed to be used directly,
// making the type definition system dependent. Better not bind it exactly.
pub type kvm_t = ::c_void;

cfg_if! {
if #[cfg(target_pointer_width = "64")] {
type Elf_Addr = Elf64_Addr;
Expand Down Expand Up @@ -1790,6 +1794,44 @@ extern "C" {
) -> ::c_int;
}

#[link(name = "kvm")]
extern "C" {
pub fn kvm_open(
execfile: *const ::c_char,
corefile: *const ::c_char,
swapfile: *const ::c_char,
flags: ::c_int,
errstr: *const ::c_char,
) -> *mut ::kvm_t;
pub fn kvm_close(kd: *mut ::kvm_t) -> ::c_int;
pub fn kvm_getprocs(
kd: *mut ::kvm_t,
op: ::c_int,
arg: ::c_int,
cnt: *mut ::c_int,
) -> *mut ::kinfo_proc;
pub fn kvm_getloadavg(kd: *mut kvm_t, loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
pub fn kvm_openfiles(
execfile: *const ::c_char,
corefile: *const ::c_char,
swapfile: *const ::c_char,
flags: ::c_int,
errbuf: *mut ::c_char,
) -> *mut ::kvm_t;
pub fn kvm_read(
kd: *mut ::kvm_t,
addr: ::c_ulong,
buf: *mut ::c_void,
nbytes: ::size_t,
) -> ::ssize_t;
pub fn kvm_write(
kd: *mut ::kvm_t,
addr: ::c_ulong,
buf: *const ::c_void,
nbytes: ::size_t,
) -> ::ssize_t;
}

cfg_if! {
if #[cfg(target_os = "freebsd")] {
mod freebsd;
Expand Down