Skip to content

Commit 91e6aa5

Browse files
committed
Auto merge of #2796 - devnexen:dfbsd_kvm_update, r=Amanieu
dragonflybsd adding subset of kvm api
2 parents ce9aa3c + fce832a commit 91e6aa5

File tree

5 files changed

+117
-57
lines changed

5 files changed

+117
-57
lines changed

libc-test/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ fn test_dragonflybsd(target: &str) {
12081208
"glob.h",
12091209
"grp.h",
12101210
"ifaddrs.h",
1211+
"kvm.h",
12111212
"langinfo.h",
12121213
"limits.h",
12131214
"link.h",
@@ -1275,6 +1276,7 @@ fn test_dragonflybsd(target: &str) {
12751276
"utime.h",
12761277
"utmpx.h",
12771278
"vfs/ufs/quota.h",
1279+
"vm/vm_map.h",
12781280
"wchar.h",
12791281
"iconv.h",
12801282
}
@@ -1328,6 +1330,9 @@ fn test_dragonflybsd(target: &str) {
13281330
});
13291331

13301332
cfg.skip_struct(move |ty| {
1333+
if ty.starts_with("__c_anonymous_") {
1334+
return true;
1335+
}
13311336
match ty {
13321337
// FIXME: These are tested as part of the linux_fcntl tests since
13331338
// there are header conflicts when including them with all the other

libc-test/semver/dragonfly.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,16 @@ kinfo_cputime
13171317
kinfo_file
13181318
kinfo_lwp
13191319
kinfo_proc
1320+
kvm_close
1321+
kvm_getloadavg
1322+
kvm_getprocs
1323+
kvm_open
1324+
kvm_openfiles
1325+
kvm_read
1326+
kvm_t
1327+
kvm_vm_map_entry_first
1328+
kvm_vm_map_entry_next
1329+
kvm_write
13201330
kqueue
13211331
labs
13221332
lastlog
@@ -1512,6 +1522,7 @@ utmpxname
15121522
utrace
15131523
uuid
15141524
uuid_t
1525+
vm_map_entry_t
15151526
vm_size_t
15161527
wait4
15171528
waitid

src/unix/bsd/freebsdlike/dragonfly/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ pub type pthread_spinlock_t = ::uintptr_t;
3434

3535
pub type segsz_t = usize;
3636

37+
pub type vm_prot_t = u8;
38+
pub type vm_maptype_t = u8;
39+
pub type vm_inherit_t = i8;
40+
pub type vm_subsys_t = ::c_int;
41+
pub type vm_eflags_t = ::c_uint;
42+
43+
pub type vm_map_t = *mut __c_anonymous_vm_map;
44+
pub type vm_map_entry_t = *mut vm_map_entry;
45+
3746
#[cfg_attr(feature = "extra_traits", derive(Debug))]
3847
pub enum sem {}
3948
impl ::Copy for sem {}
@@ -336,6 +345,21 @@ s! {
336345
kp_spare: [::c_int; 2],
337346
}
338347

348+
pub struct __c_anonymous_vm_map {
349+
_priv: [::uintptr_t; 36],
350+
}
351+
352+
pub struct vm_map_entry {
353+
_priv: [::uintptr_t; 15],
354+
pub eflags: ::vm_eflags_t,
355+
pub maptype: ::vm_maptype_t,
356+
pub protection: ::vm_prot_t,
357+
pub max_protection: ::vm_prot_t,
358+
pub inheritance: ::vm_inherit_t,
359+
pub wired_count: ::c_int,
360+
pub id: ::vm_subsys_t,
361+
}
362+
339363
pub struct cpuctl_msr_args_t {
340364
pub msr: ::c_int,
341365
pub data: u64,
@@ -1613,6 +1637,20 @@ extern "C" {
16131637
pub fn freezero(ptr: *mut ::c_void, size: ::size_t);
16141638
}
16151639

1640+
#[link(name = "kvm")]
1641+
extern "C" {
1642+
pub fn kvm_vm_map_entry_first(
1643+
kvm: *mut ::kvm_t,
1644+
map: vm_map_t,
1645+
entry: vm_map_entry_t,
1646+
) -> vm_map_entry_t;
1647+
pub fn kvm_vm_map_entry_next(
1648+
kvm: *mut ::kvm_t,
1649+
map: vm_map_entry_t,
1650+
entry: vm_map_entry_t,
1651+
) -> vm_map_entry_t;
1652+
}
1653+
16161654
cfg_if! {
16171655
if #[cfg(libc_thread_local)] {
16181656
mod errno;

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ pub type fhandle_t = fhandle;
4444
pub type au_id_t = ::uid_t;
4545
pub type au_asid_t = ::pid_t;
4646

47-
// It's an alias over "struct __kvm_t". However, its fields aren't supposed to be used directly,
48-
// making the type definition system dependent. Better not bind it exactly.
49-
pub type kvm_t = ::c_void;
50-
5147
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
5248
#[repr(u32)]
5349
pub enum devstat_support_flags {
@@ -4272,71 +4268,39 @@ extern "C" {
42724268

42734269
#[link(name = "kvm")]
42744270
extern "C" {
4275-
pub fn kvm_open(
4276-
execfile: *const ::c_char,
4277-
corefile: *const ::c_char,
4278-
swapfile: *const ::c_char,
4279-
flags: ::c_int,
4280-
errstr: *const ::c_char,
4281-
) -> *mut kvm_t;
4282-
pub fn kvm_close(kd: *mut kvm_t) -> ::c_int;
4283-
pub fn kvm_dpcpu_setcpu(kd: *mut kvm_t, cpu: ::c_uint) -> ::c_int;
4284-
pub fn kvm_getargv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
4285-
pub fn kvm_getcptime(kd: *mut kvm_t, cp_time: *mut ::c_long) -> ::c_int;
4286-
pub fn kvm_getenvv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
4287-
pub fn kvm_geterr(kd: *mut kvm_t) -> *mut ::c_char;
4288-
pub fn kvm_getloadavg(kd: *mut kvm_t, loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
4289-
pub fn kvm_getmaxcpu(kd: *mut kvm_t) -> ::c_int;
4290-
pub fn kvm_getncpus(kd: *mut kvm_t) -> ::c_int;
4291-
pub fn kvm_getpcpu(kd: *mut kvm_t, cpu: ::c_int) -> *mut ::c_void;
4292-
pub fn kvm_counter_u64_fetch(kd: *mut kvm_t, base: ::c_ulong) -> u64;
4293-
pub fn kvm_getprocs(
4294-
kd: *mut kvm_t,
4295-
op: ::c_int,
4296-
arg: ::c_int,
4297-
cnt: *mut ::c_int,
4298-
) -> *mut kinfo_proc;
4271+
pub fn kvm_dpcpu_setcpu(kd: *mut ::kvm_t, cpu: ::c_uint) -> ::c_int;
4272+
pub fn kvm_getargv(kd: *mut ::kvm_t, p: *const kinfo_proc, nchr: ::c_int)
4273+
-> *mut *mut ::c_char;
4274+
pub fn kvm_getcptime(kd: *mut ::kvm_t, cp_time: *mut ::c_long) -> ::c_int;
4275+
pub fn kvm_getenvv(kd: *mut ::kvm_t, p: *const kinfo_proc, nchr: ::c_int)
4276+
-> *mut *mut ::c_char;
4277+
pub fn kvm_geterr(kd: *mut ::kvm_t) -> *mut ::c_char;
4278+
pub fn kvm_getmaxcpu(kd: *mut ::kvm_t) -> ::c_int;
4279+
pub fn kvm_getncpus(kd: *mut ::kvm_t) -> ::c_int;
4280+
pub fn kvm_getpcpu(kd: *mut ::kvm_t, cpu: ::c_int) -> *mut ::c_void;
4281+
pub fn kvm_counter_u64_fetch(kd: *mut ::kvm_t, base: ::c_ulong) -> u64;
42994282
pub fn kvm_getswapinfo(
4300-
kd: *mut kvm_t,
4283+
kd: *mut ::kvm_t,
43014284
info: *mut kvm_swap,
43024285
maxswap: ::c_int,
43034286
flags: ::c_int,
43044287
) -> ::c_int;
4305-
pub fn kvm_native(kd: *mut kvm_t) -> ::c_int;
4306-
pub fn kvm_nlist(kd: *mut kvm_t, nl: *mut nlist) -> ::c_int;
4307-
pub fn kvm_nlist2(kd: *mut kvm_t, nl: *mut kvm_nlist) -> ::c_int;
4308-
pub fn kvm_openfiles(
4309-
execfile: *const ::c_char,
4310-
corefile: *const ::c_char,
4311-
swapfile: *const ::c_char,
4312-
flags: ::c_int,
4313-
errbuf: *mut ::c_char,
4314-
) -> *mut kvm_t;
4315-
pub fn kvm_read(
4316-
kd: *mut kvm_t,
4317-
addr: ::c_ulong,
4318-
buf: *mut ::c_void,
4319-
nbytes: ::size_t,
4320-
) -> ::ssize_t;
4288+
pub fn kvm_native(kd: *mut ::kvm_t) -> ::c_int;
4289+
pub fn kvm_nlist(kd: *mut ::kvm_t, nl: *mut nlist) -> ::c_int;
4290+
pub fn kvm_nlist2(kd: *mut ::kvm_t, nl: *mut kvm_nlist) -> ::c_int;
43214291
pub fn kvm_read_zpcpu(
4322-
kd: *mut kvm_t,
4292+
kd: *mut ::kvm_t,
43234293
base: ::c_ulong,
43244294
buf: *mut ::c_void,
43254295
size: ::size_t,
43264296
cpu: ::c_int,
43274297
) -> ::ssize_t;
43284298
pub fn kvm_read2(
4329-
kd: *mut kvm_t,
4299+
kd: *mut ::kvm_t,
43304300
addr: kvaddr_t,
43314301
buf: *mut ::c_void,
43324302
nbytes: ::size_t,
43334303
) -> ::ssize_t;
4334-
pub fn kvm_write(
4335-
kd: *mut kvm_t,
4336-
addr: ::c_ulong,
4337-
buf: *const ::c_void,
4338-
nbytes: ::size_t,
4339-
) -> ::ssize_t;
43404304
}
43414305

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

44874451
#[link(name = "devstat")]
44884452
extern "C" {
4489-
pub fn devstat_getnumdevs(kd: *mut kvm_t) -> ::c_int;
4490-
pub fn devstat_getgeneration(kd: *mut kvm_t) -> ::c_long;
4491-
pub fn devstat_getversion(kd: *mut kvm_t) -> ::c_int;
4492-
pub fn devstat_checkversion(kd: *mut kvm_t) -> ::c_int;
4453+
pub fn devstat_getnumdevs(kd: *mut ::kvm_t) -> ::c_int;
4454+
pub fn devstat_getgeneration(kd: *mut ::kvm_t) -> ::c_long;
4455+
pub fn devstat_getversion(kd: *mut ::kvm_t) -> ::c_int;
4456+
pub fn devstat_checkversion(kd: *mut ::kvm_t) -> ::c_int;
44934457
pub fn devstat_selectdevs(
44944458
dev_select: *mut *mut device_selection,
44954459
num_selected: *mut ::c_int,

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub type Elf64_Xword = u64;
3535

3636
pub type iconv_t = *mut ::c_void;
3737

38+
// It's an alias over "struct __kvm_t". However, its fields aren't supposed to be used directly,
39+
// making the type definition system dependent. Better not bind it exactly.
40+
pub type kvm_t = ::c_void;
41+
3842
cfg_if! {
3943
if #[cfg(target_pointer_width = "64")] {
4044
type Elf_Addr = Elf64_Addr;
@@ -1790,6 +1794,44 @@ extern "C" {
17901794
) -> ::c_int;
17911795
}
17921796

1797+
#[link(name = "kvm")]
1798+
extern "C" {
1799+
pub fn kvm_open(
1800+
execfile: *const ::c_char,
1801+
corefile: *const ::c_char,
1802+
swapfile: *const ::c_char,
1803+
flags: ::c_int,
1804+
errstr: *const ::c_char,
1805+
) -> *mut ::kvm_t;
1806+
pub fn kvm_close(kd: *mut ::kvm_t) -> ::c_int;
1807+
pub fn kvm_getprocs(
1808+
kd: *mut ::kvm_t,
1809+
op: ::c_int,
1810+
arg: ::c_int,
1811+
cnt: *mut ::c_int,
1812+
) -> *mut ::kinfo_proc;
1813+
pub fn kvm_getloadavg(kd: *mut kvm_t, loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
1814+
pub fn kvm_openfiles(
1815+
execfile: *const ::c_char,
1816+
corefile: *const ::c_char,
1817+
swapfile: *const ::c_char,
1818+
flags: ::c_int,
1819+
errbuf: *mut ::c_char,
1820+
) -> *mut ::kvm_t;
1821+
pub fn kvm_read(
1822+
kd: *mut ::kvm_t,
1823+
addr: ::c_ulong,
1824+
buf: *mut ::c_void,
1825+
nbytes: ::size_t,
1826+
) -> ::ssize_t;
1827+
pub fn kvm_write(
1828+
kd: *mut ::kvm_t,
1829+
addr: ::c_ulong,
1830+
buf: *const ::c_void,
1831+
nbytes: ::size_t,
1832+
) -> ::ssize_t;
1833+
}
1834+
17931835
cfg_if! {
17941836
if #[cfg(target_os = "freebsd")] {
17951837
mod freebsd;

0 commit comments

Comments
 (0)