mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Expose shared ports for manual GDK composite queues
Signed-off-by: Adeeb Rahman <therealabeeb@icloud.com>
This commit is contained in:
1 parent
f6c87de433
commit
4b370efa12
2 files changed
+58
-3
No files matched your search
@@ -18,13 +18,13 @@ const MANUAL: u32 = 0;
|
||||
#[derive(Default)]
|
||||
pub(super) struct QueueHandles {
|
||||
last_id: u64,
|
||||
queues: BTreeMap<u64, u64>,
|
||||
queues: BTreeMap<u64, [u64; 2]>,
|
||||
}
|
||||
|
||||
impl QueueHandles {
|
||||
fn open(
|
||||
&mut self,
|
||||
object: Option<u64>,
|
||||
ports: Option<[u64; 2]>,
|
||||
output: u64,
|
||||
memory: &mut GuestMemory,
|
||||
) -> Result<(), u32> {
|
||||
@@ -44,7 +44,10 @@ impl QueueHandles {
|
||||
.write_u64(output, handle)
|
||||
.map_err(|_| ERROR_INVALID_PARAMETER)?;
|
||||
self.last_id = next;
|
||||
self.queues.insert(handle, object.unwrap_or(handle));
|
||||
self.queues.insert(
|
||||
handle,
|
||||
ports.unwrap_or([0x5157_0000_0000_0000 | next, 0x5143_0000_0000_0000 | next]),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -100,4 +103,45 @@ pub(super) fn register(registry: &mut ImportRegistry, state: &Arc<ServicesState>
|
||||
Ok(0)
|
||||
},
|
||||
);
|
||||
|
||||
let get = Arc::clone(state);
|
||||
registry.register_with_status(
|
||||
MODULE,
|
||||
"XTaskQueueGetPort",
|
||||
ServiceStatus::Partial,
|
||||
move |args, _, memory| {
|
||||
let result = (|| {
|
||||
let queues = get.gdk_queues.lock().expect("GDK queue handle table");
|
||||
let ports = queues.queues.get(&args.rcx).ok_or(ERROR_INVALID_HANDLE)?;
|
||||
let port = ports
|
||||
.get(args.rdx as u32 as usize)
|
||||
.ok_or(ERROR_INVALID_PARAMETER)?;
|
||||
if args.r8 == 0 {
|
||||
return Err(ERROR_INVALID_PARAMETER);
|
||||
}
|
||||
memory
|
||||
.write_u64(args.r8, *port)
|
||||
.map_err(|_| ERROR_INVALID_PARAMETER)
|
||||
})();
|
||||
Ok(guest_hresult(result))
|
||||
},
|
||||
);
|
||||
|
||||
let composite = Arc::clone(state);
|
||||
registry.register_with_status(
|
||||
MODULE,
|
||||
"XTaskQueueCreateComposite",
|
||||
ServiceStatus::Partial,
|
||||
move |args, _, memory| {
|
||||
let mut queues = composite.gdk_queues.lock().expect("GDK queue handle table");
|
||||
let ports = [args.rcx, args.rdx];
|
||||
if ports
|
||||
.iter()
|
||||
.any(|port| !queues.queues.values().any(|live| live.contains(port)))
|
||||
{
|
||||
return Ok(guest_hresult(Err(ERROR_INVALID_HANDLE)));
|
||||
}
|
||||
Ok(guest_hresult(queues.open(Some(ports), args.r8, memory)))
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1143,6 +1143,9 @@ fn guest_gdk_manual_queue_handles_have_independent_lifetimes() {
|
||||
};
|
||||
let first = open("XTaskQueueCreate", &[0, 0, output]);
|
||||
let second = open("XTaskQueueDuplicateHandle", &[first, output]);
|
||||
let work = open("XTaskQueueGetPort", &[first, 0, output]);
|
||||
let completion = open("XTaskQueueGetPort", &[first, 1, output]);
|
||||
assert_ne!(work, completion);
|
||||
assert_ne!(first, second);
|
||||
call("XTaskQueueCloseHandle", &[first]);
|
||||
let stale = call("XTaskQueueDuplicateHandle", &[first, output]);
|
||||
@@ -1150,8 +1153,16 @@ fn guest_gdk_manual_queue_handles_have_independent_lifetimes() {
|
||||
assert_eq!(stale.image.memory.read_u64(output).unwrap(), 0);
|
||||
let third = open("XTaskQueueDuplicateHandle", &[second, output]);
|
||||
assert!(third > second);
|
||||
assert_eq!(open("XTaskQueueGetPort", &[third, 0, output]), work);
|
||||
let composite = open("XTaskQueueCreateComposite", &[work, work, output]);
|
||||
call("XTaskQueueCloseHandle", &[second]);
|
||||
call("XTaskQueueCloseHandle", &[third]);
|
||||
assert_eq!(open("XTaskQueueGetPort", &[composite, 1, output]), work);
|
||||
let stale = call("XTaskQueueCreateComposite", &[work, completion, output]);
|
||||
assert_eq!(stale.execution.final_state.get(Register::Rax), 0x8007_0006);
|
||||
call("XTaskQueueCloseHandle", &[composite]);
|
||||
let stale = call("XTaskQueueCreateComposite", &[work, work, output]);
|
||||
assert_eq!(stale.execution.final_state.get(Register::Rax), 0x8007_0006);
|
||||
let next = open("XTaskQueueCreate", &[0, 0, output]);
|
||||
assert!(next > third);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user