Skip to content

Commit e9f8df3

Browse files
dianpopaacatangiu
authored andcommitted
build: remove gnu support and...
adjust for musl only build. Users need to be informed that they need to add musl target beforehand. Signed-off-by: Diana Popa <[email protected]>
1 parent 25755f3 commit e9f8df3

File tree

5 files changed

+46
-89
lines changed

5 files changed

+46
-89
lines changed

.cargo/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
target = "x86_64-unknown-linux-musl"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ So far, no stress testing & benchmarking has been done. This is scheduled for a
3030

3131
# Getting Started
3232

33+
## Add musl target to the active toolchain
34+
Firecracker supports musl-only build, so before building the project add the musl target to rust's active toolchain:
35+
```bash
36+
rustup target add x86_64-unknown-linux-musl
37+
```
38+
3339
## Build the Firecracker Binary
3440
Clone this repo and build it with Rust's: `cargo build --release`.
3541

kvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl Kvm {
6767
/// Gets the size of the mmap required to use vcpu's `kvm_run` structure.
6868
pub fn get_vcpu_mmap_size(&self) -> Result<usize> {
6969
// Safe because we know that our file is a KVM fd and we verify the return result.
70-
let res = unsafe { ioctl(self, KVM_GET_VCPU_MMAP_SIZE() as c_ulong) };
70+
let res = unsafe { ioctl(self, KVM_GET_VCPU_MMAP_SIZE()) };
7171
if res > 0 {
7272
Ok(res as usize)
7373
} else {

sys_util/src/ioctl.rs

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
// found in the LICENSE file.
44

55
//! Macros and wrapper functions for dealing with ioctls.
6-
7-
use std::os::raw::c_uint;
6+
use libc;
7+
use std::os::raw::{c_int, c_uint, c_ulong, c_void};
8+
use std::os::unix::io::AsRawFd;
89

910
/// Raw macro to declare a function that returns an ioctl number.
1011
#[macro_export]
@@ -77,88 +78,38 @@ pub const IOC_INOUT: c_uint = 3221225472;
7778
pub const IOCSIZE_MASK: c_uint = 1073676288;
7879
pub const IOCSIZE_SHIFT: c_uint = 16;
7980

80-
/// separate module to deal with calling ioctl's inside libc
81-
/// libc musl has as second parameter an i32 so separate code goes for that
82-
#[cfg(not(target_env = "musl"))]
83-
pub mod libc_ioctl {
84-
use libc;
85-
use std::os::raw::{c_int, c_ulong, c_void};
86-
use std::os::unix::io::AsRawFd;
87-
88-
/// Run an ioctl with no arguments.
89-
pub unsafe fn ioctl<F: AsRawFd>(fd: &F, request: c_ulong) -> c_int {
90-
libc::ioctl(fd.as_raw_fd(), request, 0)
91-
}
92-
93-
/// Run an ioctl with a single value argument.
94-
pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, request: c_ulong, arg: c_ulong) -> c_int {
95-
libc::ioctl(fd.as_raw_fd(), request, arg)
96-
}
97-
98-
/// Run an ioctl with an immutable reference.
99-
pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, request: c_ulong, arg: &T) -> c_int {
100-
libc::ioctl(fd.as_raw_fd(), request, arg as *const T as *const c_void)
101-
}
102-
103-
/// Run an ioctl with a mutable reference.
104-
pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>(
105-
fd: &F,
106-
request: c_ulong,
107-
arg: &mut T,
108-
) -> c_int {
109-
libc::ioctl(fd.as_raw_fd(), request, arg as *mut T as *mut c_void)
110-
}
111-
112-
/// Run an ioctl with a raw pointer.
113-
pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, request: c_ulong, arg: *const T) -> c_int {
114-
libc::ioctl(fd.as_raw_fd(), request, arg as *const c_void)
115-
}
116-
117-
/// Run an ioctl with a mutable raw pointer.
118-
pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(
119-
fd: &F,
120-
request: c_ulong,
121-
arg: *mut T,
122-
) -> c_int {
123-
libc::ioctl(fd.as_raw_fd(), request, arg as *mut c_void)
124-
}
81+
/// Run an ioctl with no arguments.
82+
pub unsafe fn ioctl<F: AsRawFd>(fd: &F, req: c_ulong) -> c_int {
83+
libc::ioctl(fd.as_raw_fd(), req as c_int, 0)
12584
}
12685

127-
#[cfg(target_env = "musl")]
128-
pub mod libc_ioctl {
129-
use libc;
130-
use std::os::raw::{c_int, c_ulong, c_void};
131-
use std::os::unix::io::AsRawFd;
132-
133-
/// Run an ioctl with no arguments.
134-
pub unsafe fn ioctl<F: AsRawFd>(fd: &F, req: c_ulong) -> c_int {
135-
libc::ioctl(fd.as_raw_fd(), req as i32, 0)
136-
}
137-
138-
/// Run an ioctl with a single value argument.
139-
pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, req: c_ulong, arg: c_ulong) -> c_int {
140-
libc::ioctl(fd.as_raw_fd(), req as i32, arg)
141-
}
86+
/// Run an ioctl with a single value argument.
87+
pub unsafe fn ioctl_with_val<F: AsRawFd>(fd: &F, req: c_ulong, arg: c_ulong) -> c_int {
88+
libc::ioctl(fd.as_raw_fd(), req as c_int, arg)
89+
}
14290

143-
/// Run an ioctl with an immutable reference.
144-
pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &T) -> c_int {
145-
libc::ioctl(fd.as_raw_fd(), req as i32, arg as *const T as *const c_void)
146-
}
91+
/// Run an ioctl with an immutable reference.
92+
pub unsafe fn ioctl_with_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &T) -> c_int {
93+
libc::ioctl(
94+
fd.as_raw_fd(),
95+
req as c_int,
96+
arg as *const T as *const c_void,
97+
)
98+
}
14799

148-
/// Run an ioctl with a mutable reference.
149-
pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &mut T) -> c_int {
150-
libc::ioctl(fd.as_raw_fd(), req as i32, arg as *mut T as *mut c_void)
151-
}
100+
/// Run an ioctl with a mutable reference.
101+
pub unsafe fn ioctl_with_mut_ref<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: &mut T) -> c_int {
102+
libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *mut T as *mut c_void)
103+
}
152104

153-
/// Run an ioctl with a raw pointer.
154-
pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *const T) -> c_int {
155-
libc::ioctl(fd.as_raw_fd(), req as i32, arg as *const c_void)
156-
}
105+
/// Run an ioctl with a raw pointer.
106+
pub unsafe fn ioctl_with_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *const T) -> c_int {
107+
libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *const c_void)
108+
}
157109

158-
/// Run an ioctl with a mutable raw pointer.
159-
pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *mut T) -> c_int {
160-
libc::ioctl(fd.as_raw_fd(), req as i32, arg as *mut c_void)
161-
}
110+
/// Run an ioctl with a mutable raw pointer.
111+
pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(fd: &F, req: c_ulong, arg: *mut T) -> c_int {
112+
libc::ioctl(fd.as_raw_fd(), req as c_int, arg as *mut c_void)
162113
}
163114

164115
#[cfg(test)]

sys_util/src/lib.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,26 @@ extern crate syscall_defines;
1111
#[macro_use]
1212
pub mod ioctl;
1313

14-
mod mmap;
15-
mod eventfd;
1614
mod errno;
15+
mod eventfd;
1716
mod guest_address;
1817
mod guest_memory;
18+
mod mmap;
19+
mod signal;
1920
mod struct_util;
2021
mod tempdir;
2122
mod terminal;
22-
mod signal;
2323

24-
pub use mmap::*;
24+
pub use errno::{errno_result, Error, Result};
2525
pub use eventfd::*;
26-
pub use errno::{Error, Result};
27-
pub use errno::errno_result;
2826
pub use guest_address::*;
2927
pub use guest_memory::*;
28+
pub use ioctl::*;
29+
pub use mmap::*;
30+
pub use signal::*;
3031
pub use struct_util::*;
3132
pub use tempdir::*;
3233
pub use terminal::*;
33-
pub use signal::*;
34-
pub use ioctl::*;
35-
pub use libc_ioctl::*;
3634

37-
pub use mmap::Error as MmapError;
3835
pub use guest_memory::Error as GuestMemoryError;
36+
pub use mmap::Error as MmapError;

0 commit comments

Comments
 (0)