rusticl: check the returned pointer of mmap
Prior Linux 4.17 MAP_FIXED_NOREPLACE might not be respected and might
return a pointer different than the requested one.
Fixes: da4de8d7e3 ("rusticl: add support for coarse-grain buffer SVM")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35286>
This commit is contained in:
@@ -319,7 +319,7 @@ impl Context {
|
||||
unreachable!("SVM supported only on Linux")
|
||||
}
|
||||
|
||||
let res = unsafe {
|
||||
let mut res = unsafe {
|
||||
mmap(
|
||||
vma.get() as usize as *mut c_void,
|
||||
size.get() as usize,
|
||||
@@ -335,6 +335,14 @@ impl Context {
|
||||
return Err(CL_OUT_OF_HOST_MEMORY);
|
||||
}
|
||||
|
||||
if res as usize != vma.get() as usize {
|
||||
unsafe {
|
||||
let ret = munmap(res, size.get() as usize);
|
||||
debug_assert_eq!(0, ret);
|
||||
}
|
||||
res = ptr::null_mut();
|
||||
}
|
||||
|
||||
res.cast()
|
||||
} else {
|
||||
unsafe { alloc::alloc(layout) }.cast()
|
||||
|
||||
Reference in New Issue
Block a user