rusticl: check the returned pointer of mmap
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

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:
Karol Herbst 2025-06-02 18:26:45 +02:00 committed by Marge Bot
parent 9b28067b59
commit fa94b1b29c

View file

@ -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()