Closed
Description
example:
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
uintptr_t virt_to_phys(void* virt) {
long pagesize = sysconf(_SC_PAGESIZE);
int fd = open("/proc/self/pagemap", O_RDONLY);
lseek(fd, (uintptr_t) virt / pagesize * sizeof(uintptr_t), SEEK_SET);
uintptr_t phy = 0;
read(fd, &phy, sizeof(phy));
return (phy & 0x7fffffffffffffULL) * pagesize + ((uintptr_t) virt) % pagesize;
}
is translated to
#![allow(dead_code,
mutable_transmutes,
non_camel_case_types,
non_snake_case,
non_upper_case_globals,
unused_assignments,
unused_mut)]
extern crate libc;
extern "C" {
#[no_mangle]
fn read(__fd: libc::c_int, __buf: *mut libc::c_void, __nbytes: size_t)
-> ssize_t;
#[no_mangle]
fn sysconf(__name: libc::c_int) -> libc::c_long;
#[no_mangle]
fn open(__file: *const libc::c_char, __oflag: libc::c_int, _: ...)
-> libc::c_int;
}
(...)
#[no_mangle]
pub unsafe extern "C" fn virt_to_phys(mut virt: *mut libc::c_void)
-> intptr_t {
let mut pagesize: libc::c_long = sysconf(_SC_PAGESIZE as libc::c_int);
let mut fd: libc::c_int =
open(b"/proc/self/pagemap\x00" as *const u8 as *const libc::c_char,
0i32);
let mut phy: intptr_t = 0i32 as intptr_t;
read(fd, &mut phy as *mut intptr_t as *mut libc::c_void,
::std::mem::size_of::<intptr_t>() as libc::c_ulong);
panic!("Reached end of non-void function without returning");
}