add rutabaga-gfx-ffi patches
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
From 91ad77f0d41ce7043a0bc4cfc3887d64b9763ba9 Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
|
||||||
|
Date: Thu, 7 Dec 2023 17:09:28 +0100
|
||||||
|
Subject: [PATCH 1/2] rutabaga_gfx: don't clone wayland memfd file descriptor
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
After cloning these file descriptor mmap will fail on the new file descriptor.
|
||||||
|
This results in mmap errors.
|
||||||
|
|
||||||
|
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
|
||||||
|
---
|
||||||
|
rutabaga_gfx/src/rutabaga_core.rs | 3 +--
|
||||||
|
rutabaga_gfx/src/rutabaga_os/memory_mapping.rs | 2 +-
|
||||||
|
rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs | 2 +-
|
||||||
|
3 files changed, 3 insertions(+), 4 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/rutabaga_gfx/src/rutabaga_core.rs b/rutabaga_gfx/src/rutabaga_core.rs
|
||||||
|
index 740f840fd..8361ec067 100644
|
||||||
|
--- a/rutabaga_gfx/src/rutabaga_core.rs
|
||||||
|
+++ b/rutabaga_gfx/src/rutabaga_core.rs
|
||||||
|
@@ -757,7 +757,6 @@ pub fn map(&mut self, resource_id: u32) -> RutabagaResult<RutabagaMapping> {
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
- let clone = handle.try_clone()?;
|
||||||
|
let resource_size: usize = resource.size.try_into()?;
|
||||||
|
let map_info = resource
|
||||||
|
.map_info
|
||||||
|
@@ -765,7 +764,7 @@ pub fn map(&mut self, resource_id: u32) -> RutabagaResult<RutabagaMapping> {
|
||||||
|
|
||||||
|
// Creating the mapping closes the cloned descriptor.
|
||||||
|
let mapping = MemoryMapping::from_safe_descriptor(
|
||||||
|
- clone.os_handle,
|
||||||
|
+ &handle.os_handle,
|
||||||
|
resource_size,
|
||||||
|
map_info,
|
||||||
|
)?;
|
||||||
|
diff --git a/rutabaga_gfx/src/rutabaga_os/memory_mapping.rs b/rutabaga_gfx/src/rutabaga_os/memory_mapping.rs
|
||||||
|
index d15fe81bd..885c6c9d8 100644
|
||||||
|
--- a/rutabaga_gfx/src/rutabaga_os/memory_mapping.rs
|
||||||
|
+++ b/rutabaga_gfx/src/rutabaga_os/memory_mapping.rs
|
||||||
|
@@ -13,7 +13,7 @@ pub struct MemoryMapping {
|
||||||
|
|
||||||
|
impl MemoryMapping {
|
||||||
|
pub fn from_safe_descriptor(
|
||||||
|
- descriptor: SafeDescriptor,
|
||||||
|
+ descriptor: &SafeDescriptor,
|
||||||
|
size: usize,
|
||||||
|
map_info: u32,
|
||||||
|
) -> RutabagaResult<MemoryMapping> {
|
||||||
|
diff --git a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
index 629e4f9e7..e16c32747 100644
|
||||||
|
--- a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
+++ b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
@@ -38,7 +38,7 @@ fn drop(&mut self) {
|
||||||
|
|
||||||
|
impl MemoryMapping {
|
||||||
|
pub fn from_safe_descriptor(
|
||||||
|
- descriptor: SafeDescriptor,
|
||||||
|
+ descriptor: &SafeDescriptor,
|
||||||
|
size: usize,
|
||||||
|
map_info: u32,
|
||||||
|
) -> RutabagaResult<MemoryMapping> {
|
||||||
|
--
|
||||||
|
2.42.0
|
||||||
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
From d0173b741cface0b49fc105bd66dc8c8d9276591 Mon Sep 17 00:00:00 2001
|
||||||
|
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
|
||||||
|
Date: Thu, 7 Dec 2023 18:45:37 +0100
|
||||||
|
Subject: [PATCH 2/2] rutabaga_gfx: super ugly workaround to get private
|
||||||
|
keyboard resources forwarded
|
||||||
|
MIME-Version: 1.0
|
||||||
|
Content-Type: text/plain; charset=UTF-8
|
||||||
|
Content-Transfer-Encoding: 8bit
|
||||||
|
|
||||||
|
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
|
||||||
|
---
|
||||||
|
.../rutabaga_os/sys/linux/memory_mapping.rs | 35 +++++++++++++++++--
|
||||||
|
1 file changed, 33 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
index e16c32747..b37e2c351 100644
|
||||||
|
--- a/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
+++ b/rutabaga_gfx/src/rutabaga_os/sys/linux/memory_mapping.rs
|
||||||
|
@@ -9,6 +9,7 @@
|
||||||
|
use nix::sys::mman::munmap;
|
||||||
|
use nix::sys::mman::MapFlags;
|
||||||
|
use nix::sys::mman::ProtFlags;
|
||||||
|
+use nix::errno::Errno;
|
||||||
|
|
||||||
|
use crate::rutabaga_os::descriptor::SafeDescriptor;
|
||||||
|
use crate::rutabaga_utils::RutabagaError;
|
||||||
|
@@ -51,15 +52,45 @@ pub fn from_safe_descriptor(
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(non_zero_size) = non_zero_opt {
|
||||||
|
+
|
||||||
|
let addr = unsafe {
|
||||||
|
- mmap(
|
||||||
|
+ let mut res = mmap(
|
||||||
|
None,
|
||||||
|
non_zero_size,
|
||||||
|
prot,
|
||||||
|
MapFlags::MAP_SHARED,
|
||||||
|
Some(descriptor),
|
||||||
|
0,
|
||||||
|
- )?
|
||||||
|
+ );
|
||||||
|
+ if let Err(Errno::EPERM) = res {
|
||||||
|
+ if prot == ProtFlags::PROT_READ {
|
||||||
|
+ let tmp = mmap(
|
||||||
|
+ None,
|
||||||
|
+ non_zero_size,
|
||||||
|
+ ProtFlags::PROT_READ,
|
||||||
|
+ MapFlags::MAP_PRIVATE,
|
||||||
|
+ Some(descriptor),
|
||||||
|
+ 0)?;
|
||||||
|
+
|
||||||
|
+ let addr = libc::mmap(
|
||||||
|
+ std::ptr::null_mut(),
|
||||||
|
+ non_zero_size.into(),
|
||||||
|
+ libc::PROT_READ|libc::PROT_WRITE,
|
||||||
|
+ libc::MAP_SHARED | libc::MAP_ANONYMOUS,
|
||||||
|
+ -1,
|
||||||
|
+ 0);
|
||||||
|
+
|
||||||
|
+ if addr == libc::MAP_FAILED {
|
||||||
|
+ munmap(tmp, non_zero_size.into()).unwrap();
|
||||||
|
+ return Err(RutabagaError::SpecViolation("failed to mmap"));
|
||||||
|
+ } else {
|
||||||
|
+ std::ptr::copy_nonoverlapping(tmp, addr, non_zero_size.into());
|
||||||
|
+ munmap(tmp, non_zero_size.into()).unwrap();
|
||||||
|
+ res = Ok(addr);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ res?
|
||||||
|
};
|
||||||
|
Ok(MemoryMapping { addr, size })
|
||||||
|
} else {
|
||||||
|
--
|
||||||
|
2.42.0
|
||||||
|
|
||||||
@@ -18,6 +18,11 @@ rustPlatform.buildRustPackage {
|
|||||||
fetchSubmodules = true;
|
fetchSubmodules = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
patches = [
|
||||||
|
./0001-rutabaga_gfx-don-t-clone-wayland-memfd-file-descript.patch
|
||||||
|
./0002-rutabaga_gfx-super-ugly-workaround-to-get-private-ke.patch
|
||||||
|
];
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
cd rutabaga_gfx/ffi
|
cd rutabaga_gfx/ffi
|
||||||
make build
|
make build
|
||||||
|
|||||||
Reference in New Issue
Block a user