|
|
@ -357,25 +357,21 @@ impl IrUser { |
|
|
|
let mut shared_mem_guard = IR_USER_STATE.lock().unwrap(); |
|
|
|
let mut shared_mem_guard = IR_USER_STATE.lock().unwrap(); |
|
|
|
let shared_mem = shared_mem_guard.as_mut().unwrap(); |
|
|
|
let shared_mem = shared_mem_guard.as_mut().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
// Set up the request
|
|
|
|
|
|
|
|
let thread_command_buffer = unsafe { ctru_sys::getThreadCommandBuffer() }; |
|
|
|
|
|
|
|
unsafe { |
|
|
|
unsafe { |
|
|
|
|
|
|
|
// Set up the request
|
|
|
|
|
|
|
|
let thread_command_buffer = unsafe { ctru_sys::getThreadCommandBuffer() }; |
|
|
|
std::ptr::copy(request.as_ptr(), thread_command_buffer, request.len()); |
|
|
|
std::ptr::copy(request.as_ptr(), thread_command_buffer, request.len()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send the request
|
|
|
|
// Send the request
|
|
|
|
unsafe { |
|
|
|
|
|
|
|
ResultCode(ctru_sys::svcSendSyncRequest(shared_mem.service_handle))?; |
|
|
|
ResultCode(ctru_sys::svcSendSyncRequest(shared_mem.service_handle))?; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle the result returned by the service
|
|
|
|
// Handle the result returned by the service
|
|
|
|
let result = unsafe { std::ptr::read(thread_command_buffer.add(1)) }; |
|
|
|
let result = unsafe { std::ptr::read(thread_command_buffer.add(1)) }; |
|
|
|
ResultCode(result as ctru_sys::Result)?; |
|
|
|
ResultCode(result as ctru_sys::Result)?; |
|
|
|
|
|
|
|
|
|
|
|
// Copy back the response
|
|
|
|
// Copy back the response
|
|
|
|
request.clear(); |
|
|
|
request.clear(); |
|
|
|
request.resize(expected_response_len, 0); |
|
|
|
request.resize(expected_response_len, 0); |
|
|
|
unsafe { |
|
|
|
|
|
|
|
std::ptr::copy( |
|
|
|
std::ptr::copy( |
|
|
|
thread_command_buffer, |
|
|
|
thread_command_buffer, |
|
|
|
request.as_mut_ptr(), |
|
|
|
request.as_mut_ptr(), |
|
|
@ -409,22 +405,27 @@ struct InitializeIrnopSharedParams { |
|
|
|
|
|
|
|
|
|
|
|
/// Internal helper for initializing the ir:USER service
|
|
|
|
/// Internal helper for initializing the ir:USER service
|
|
|
|
unsafe fn initialize_irnop_shared(params: InitializeIrnopSharedParams) -> crate::Result<()> { |
|
|
|
unsafe fn initialize_irnop_shared(params: InitializeIrnopSharedParams) -> crate::Result<()> { |
|
|
|
let cmd_buffer = &mut *(slice_from_raw_parts_mut(ctru_sys::getThreadCommandBuffer(), 9)); |
|
|
|
// Set up the request
|
|
|
|
cmd_buffer[0] = INITIALIZE_IRNOP_SHARED_COMMAND_HEADER; |
|
|
|
let request = [ |
|
|
|
cmd_buffer[1] = params.shared_memory_len; |
|
|
|
INITIALIZE_IRNOP_SHARED_COMMAND_HEADER, |
|
|
|
cmd_buffer[2] = params.recv_packet_buffer_len; |
|
|
|
params.shared_memory_len, |
|
|
|
cmd_buffer[3] = params.recv_packet_count; |
|
|
|
params.recv_packet_buffer_len, |
|
|
|
cmd_buffer[4] = params.send_packet_buffer_len; |
|
|
|
params.recv_packet_count, |
|
|
|
cmd_buffer[5] = params.send_packet_count; |
|
|
|
params.send_packet_buffer_len, |
|
|
|
cmd_buffer[6] = params.bit_rate; |
|
|
|
params.send_packet_count, |
|
|
|
cmd_buffer[7] = 0; |
|
|
|
params.bit_rate, |
|
|
|
cmd_buffer[8] = params.shared_memory_handle; |
|
|
|
0, |
|
|
|
|
|
|
|
params.shared_memory_handle, |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
let cmd_buffer_ptr = ctru_sys::getThreadCommandBuffer(); |
|
|
|
|
|
|
|
std::ptr::copy_nonoverlapping(request.as_ptr(), cmd_buffer_ptr, request.len()); |
|
|
|
|
|
|
|
|
|
|
|
// Send the request
|
|
|
|
// Send the request
|
|
|
|
ResultCode(ctru_sys::svcSendSyncRequest(params.ir_user_handle))?; |
|
|
|
ResultCode(ctru_sys::svcSendSyncRequest(params.ir_user_handle))?; |
|
|
|
|
|
|
|
|
|
|
|
// Handle the result returned by the service
|
|
|
|
// Handle the result returned by the service
|
|
|
|
ResultCode(cmd_buffer[1] as ctru_sys::Result)?; |
|
|
|
let result = std::ptr::read(cmd_buffer_ptr.add(1)); |
|
|
|
|
|
|
|
ResultCode(result as ctru_sys::Result)?; |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|