Skip to content

Commit

Permalink
Explicitly cast pointers for AArch64 compatibility
Browse files Browse the repository at this point in the history
Implicitly, pointers are i8 on x86_64 and u8 on AArch64. Cast them
explicitly so we can compile cleaner in the later architecture.

Signed-off-by: Sergio Lopez <[email protected]>
  • Loading branch information
slp committed Jan 28, 2021
1 parent b841e3e commit 8e84090
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ unsafe fn exec_vm(vmcfg: &VmConfig, rootfs: &str, cmd: &str, args: Vec<CString>)
}

let c_rootfs = CString::new(rootfs).unwrap();
let ret = bindings::krun_set_root(ctx, c_rootfs.as_ptr());
let ret = bindings::krun_set_root(ctx, c_rootfs.as_ptr() as *const i8);
if ret < 0 {
println!("Error setting VM rootfs");
std::process::exit(-1);
Expand All @@ -92,7 +92,7 @@ unsafe fn exec_vm(vmcfg: &VmConfig, rootfs: &str, cmd: &str, args: Vec<CString>)
}
let mut ps: Vec<*const i8> = Vec::new();
for port in ports.iter() {
ps.push(port.as_ptr());
ps.push(port.as_ptr() as *const i8);
}
ps.push(std::ptr::null());
let ret = bindings::krun_set_port_map(ctx, ps.as_ptr());
Expand All @@ -102,30 +102,35 @@ unsafe fn exec_vm(vmcfg: &VmConfig, rootfs: &str, cmd: &str, args: Vec<CString>)
}

let c_workdir = CString::new(vmcfg.workdir.clone()).unwrap();
let ret = bindings::krun_set_workdir(ctx, c_workdir.as_ptr());
let ret = bindings::krun_set_workdir(ctx, c_workdir.as_ptr() as *const i8);
if ret < 0 {
println!("Error setting VM workdir");
std::process::exit(-1);
}

let mut argv: Vec<*const i8> = Vec::new();
for a in args.iter() {
argv.push(a.as_ptr());
argv.push(a.as_ptr() as *const i8);
}
argv.push(std::ptr::null());

let hostname = CString::new(format!("HOSTNAME={}", vmcfg.name)).unwrap();
let home = CString::new("HOME=/root").unwrap();
let path = CString::new("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin").unwrap();
let env: [*const i8; 4] = [
hostname.as_ptr(),
home.as_ptr(),
path.as_ptr(),
hostname.as_ptr() as *const i8,
home.as_ptr() as *const i8,
path.as_ptr() as *const i8,
std::ptr::null(),
];

let c_cmd = CString::new(cmd).unwrap();
let ret = bindings::krun_set_exec(ctx, c_cmd.as_ptr(), argv.as_ptr(), env.as_ptr());
let ret = bindings::krun_set_exec(
ctx,
c_cmd.as_ptr() as *const i8,
argv.as_ptr() as *const *const i8,
env.as_ptr() as *const *const i8,
);
if ret < 0 {
println!("Error setting VM config");
std::process::exit(-1);
Expand Down

0 comments on commit 8e84090

Please sign in to comment.