Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 327bb91

Browse files
committed
Kernel compatibility changes up to 5.2
* 4.19 (torvalds/linux@45cd0faa) added file_operations.fadvise * 4.20 (torvalds/linux@2e5dfc99) turned clone_file_range and dedupe_file_range into remap_file_range * 5.0 (torvalds/linux@96d4f267) removed the type argument from access_ok * 5.1 (torvalds/linux@fb7e1600) added file_operations.iopoll There's also a required change to kernel-cflags-finder, coming as a separate commit.
1 parent f7f8551 commit 327bb91

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,16 @@ fn handle_kernel_version_cfg(bindings_path: &PathBuf) {
6969
}
7070
let version = version.expect("Couldn't find kernel version");
7171
if version >= kernel_version_code(4, 15, 0) {
72-
println!("cargo:rustc-cfg=kernel_4_15_0_or_greataer")
72+
println!("cargo:rustc-cfg=kernel_4_15_0_or_greater")
73+
}
74+
if version >= kernel_version_code(4, 19, 0) {
75+
println!("cargo:rustc-cfg=kernel_4_19_0_or_greater")
76+
}
77+
if version >= kernel_version_code(4, 20, 0) {
78+
println!("cargo:rustc-cfg=kernel_4_20_0_or_greater")
79+
}
80+
if version >= kernel_version_code(5, 1, 0) {
81+
println!("cargo:rustc-cfg=kernel_5_1_0_or_greater")
7382
}
7483
}
7584

src/chrdev.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,26 +152,34 @@ impl FileOperationsVtable {
152152
release: Some(release_callback::<T>),
153153

154154
check_flags: None,
155+
#[cfg(not(kernel_4_20_0_or_greater))]
155156
clone_file_range: None,
156157
compat_ioctl: None,
157158
copy_file_range: None,
159+
#[cfg(not(kernel_4_20_0_or_greater))]
158160
dedupe_file_range: None,
159161
fallocate: None,
162+
#[cfg(kernel_4_19_0_or_greater)]
163+
fadvise: None,
160164
fasync: None,
161165
flock: None,
162166
flush: None,
163167
fsync: None,
164168
get_unmapped_area: None,
165169
iterate: None,
166170
iterate_shared: None,
171+
#[cfg(kernel_5_1_0_or_greater)]
172+
iopoll: None,
167173
llseek: None,
168174
lock: None,
169175
mmap: None,
170-
#[cfg(kernel_4_15_0_or_greataer)]
176+
#[cfg(kernel_4_15_0_or_greater)]
171177
mmap_supported_flags: 0,
172178
owner: ptr::null_mut(),
173179
poll: None,
174180
read_iter: None,
181+
#[cfg(kernel_4_20_0_or_greater)]
182+
remap_file_range: None,
175183
sendpage: None,
176184
setfl: None,
177185
setlease: None,

src/helpers.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <linux/bug.h>
22
#include <linux/printk.h>
33
#include <linux/uaccess.h>
4+
#include <linux/version.h>
45

56

67
int printk_helper(const unsigned char *s, int len)
@@ -13,7 +14,11 @@ void bug_helper(void)
1314
BUG();
1415
}
1516

16-
int access_ok_helper(unsigned int mode, const void __user *addr, unsigned long n)
17+
int access_ok_helper(const void __user *addr, unsigned long n)
1718
{
18-
return access_ok(mode, addr, n);
19+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0) /* v5.0-rc1~46 */
20+
return access_ok(addr, n);
21+
#else
22+
return access_ok(0, addr, n);
23+
#endif
1924
}

src/user_ptr.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ use crate::c_types;
77
use crate::error;
88

99
extern "C" {
10-
fn access_ok_helper(
11-
mode: c_types::c_uint,
12-
addr: *const c_types::c_void,
13-
len: c_types::c_ulong,
14-
) -> c_types::c_int;
10+
fn access_ok_helper(addr: *const c_types::c_void, len: c_types::c_ulong) -> c_types::c_int;
1511
}
1612

1713
/// A reference to an area in userspace memory, which can be either
@@ -53,11 +49,7 @@ impl UserSlicePtr {
5349
ptr: *mut c_types::c_void,
5450
length: usize,
5551
) -> error::KernelResult<UserSlicePtr> {
56-
// No current access_ok implementation actually distinguishes
57-
// between VERIFY_READ and VERIFY_WRITE, so passing VERIFY_WRITE
58-
// is fine in practice and fails safe if a future implementation
59-
// bothers.
60-
if access_ok_helper(bindings::VERIFY_WRITE, ptr, length as c_types::c_ulong) == 0 {
52+
if access_ok_helper(ptr, length as c_types::c_ulong) == 0 {
6153
return Err(error::Error::EFAULT);
6254
}
6355
Ok(UserSlicePtr(ptr, length))

0 commit comments

Comments
 (0)