mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-11-04 07:38:47 +00:00 
			
		
		
		
	Memory: move Read/Write8/16/32/64 and ReadCString into class
This commit is contained in:
		
							parent
							
								
									1ec9ed6827
								
							
						
					
					
						commit
						323990d402
					
				
					 11 changed files with 119 additions and 99 deletions
				
			
		| 
						 | 
				
			
			@ -65,7 +65,7 @@ SharedPtr<Thread> AddressArbiter::ResumeHighestPriorityThread(VAddr address) {
 | 
			
		|||
    return thread;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AddressArbiter::AddressArbiter(KernelSystem& kernel) : Object(kernel) {}
 | 
			
		||||
AddressArbiter::AddressArbiter(KernelSystem& kernel) : Object(kernel), kernel(kernel) {}
 | 
			
		||||
AddressArbiter::~AddressArbiter() {}
 | 
			
		||||
 | 
			
		||||
SharedPtr<AddressArbiter> KernelSystem::CreateAddressArbiter(std::string name) {
 | 
			
		||||
| 
						 | 
				
			
			@ -103,31 +103,31 @@ ResultCode AddressArbiter::ArbitrateAddress(SharedPtr<Thread> thread, Arbitratio
 | 
			
		|||
 | 
			
		||||
    // Wait current thread (acquire the arbiter)...
 | 
			
		||||
    case ArbitrationType::WaitIfLessThan:
 | 
			
		||||
        if ((s32)Memory::Read32(address) < value) {
 | 
			
		||||
        if ((s32)kernel.memory.Read32(address) < value) {
 | 
			
		||||
            WaitThread(std::move(thread), address);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case ArbitrationType::WaitIfLessThanWithTimeout:
 | 
			
		||||
        if ((s32)Memory::Read32(address) < value) {
 | 
			
		||||
        if ((s32)kernel.memory.Read32(address) < value) {
 | 
			
		||||
            thread->wakeup_callback = timeout_callback;
 | 
			
		||||
            thread->WakeAfterDelay(nanoseconds);
 | 
			
		||||
            WaitThread(std::move(thread), address);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case ArbitrationType::DecrementAndWaitIfLessThan: {
 | 
			
		||||
        s32 memory_value = Memory::Read32(address);
 | 
			
		||||
        s32 memory_value = kernel.memory.Read32(address);
 | 
			
		||||
        if (memory_value < value) {
 | 
			
		||||
            // Only change the memory value if the thread should wait
 | 
			
		||||
            Memory::Write32(address, (s32)memory_value - 1);
 | 
			
		||||
            kernel.memory.Write32(address, (s32)memory_value - 1);
 | 
			
		||||
            WaitThread(std::move(thread), address);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    case ArbitrationType::DecrementAndWaitIfLessThanWithTimeout: {
 | 
			
		||||
        s32 memory_value = Memory::Read32(address);
 | 
			
		||||
        s32 memory_value = kernel.memory.Read32(address);
 | 
			
		||||
        if (memory_value < value) {
 | 
			
		||||
            // Only change the memory value if the thread should wait
 | 
			
		||||
            Memory::Write32(address, (s32)memory_value - 1);
 | 
			
		||||
            kernel.memory.Write32(address, (s32)memory_value - 1);
 | 
			
		||||
            thread->wakeup_callback = timeout_callback;
 | 
			
		||||
            thread->WakeAfterDelay(nanoseconds);
 | 
			
		||||
            WaitThread(std::move(thread), address);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,8 @@ private:
 | 
			
		|||
    explicit AddressArbiter(KernelSystem& kernel);
 | 
			
		||||
    ~AddressArbiter() override;
 | 
			
		||||
 | 
			
		||||
    KernelSystem& kernel;
 | 
			
		||||
 | 
			
		||||
    /// Puts the thread to wait on the specified arbitration address under this address arbiter.
 | 
			
		||||
    void WaitThread(SharedPtr<Thread> thread, VAddr wait_address);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -352,7 +352,7 @@ ResultCode SVC::ConnectToPort(Handle* out_handle, VAddr port_name_address) {
 | 
			
		|||
 | 
			
		||||
    static constexpr std::size_t PortNameMaxLength = 11;
 | 
			
		||||
    // Read 1 char beyond the max allowed port name to detect names that are too long.
 | 
			
		||||
    std::string port_name = Memory::ReadCString(port_name_address, PortNameMaxLength + 1);
 | 
			
		||||
    std::string port_name = memory.ReadCString(port_name_address, PortNameMaxLength + 1);
 | 
			
		||||
    if (port_name.size() > PortNameMaxLength)
 | 
			
		||||
        return ERR_PORT_NAME_TOO_LONG;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +467,7 @@ ResultCode SVC::WaitSynchronizationN(s32* out, VAddr handles_address, s32 handle
 | 
			
		|||
    std::vector<ObjectPtr> objects(handle_count);
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < handle_count; ++i) {
 | 
			
		||||
        Handle handle = Memory::Read32(handles_address + i * sizeof(Handle));
 | 
			
		||||
        Handle handle = memory.Read32(handles_address + i * sizeof(Handle));
 | 
			
		||||
        auto object = kernel.GetCurrentProcess()->handle_table.Get<WaitObject>(handle);
 | 
			
		||||
        if (object == nullptr)
 | 
			
		||||
            return ERR_INVALID_HANDLE;
 | 
			
		||||
| 
						 | 
				
			
			@ -636,7 +636,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co
 | 
			
		|||
    SharedPtr<Process> current_process = kernel.GetCurrentProcess();
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < handle_count; ++i) {
 | 
			
		||||
        Handle handle = Memory::Read32(handles_address + i * sizeof(Handle));
 | 
			
		||||
        Handle handle = memory.Read32(handles_address + i * sizeof(Handle));
 | 
			
		||||
        auto object = current_process->handle_table.Get<WaitObject>(handle);
 | 
			
		||||
        if (object == nullptr)
 | 
			
		||||
            return ERR_INVALID_HANDLE;
 | 
			
		||||
| 
						 | 
				
			
			@ -646,7 +646,7 @@ ResultCode SVC::ReplyAndReceive(s32* index, VAddr handles_address, s32 handle_co
 | 
			
		|||
    // We are also sending a command reply.
 | 
			
		||||
    // Do not send a reply if the command id in the command buffer is 0xFFFF.
 | 
			
		||||
    Thread* thread = kernel.GetThreadManager().GetCurrentThread();
 | 
			
		||||
    u32 cmd_buff_header = Memory::Read32(thread->GetCommandBufferAddress());
 | 
			
		||||
    u32 cmd_buff_header = memory.Read32(thread->GetCommandBufferAddress());
 | 
			
		||||
    IPC::Header header{cmd_buff_header};
 | 
			
		||||
    if (reply_target != 0 && header.command_id != 0xFFFF) {
 | 
			
		||||
        auto session = current_process->handle_table.Get<ServerSession>(reply_target);
 | 
			
		||||
| 
						 | 
				
			
			@ -832,9 +832,9 @@ ResultCode SVC::GetResourceLimitCurrentValues(VAddr values, Handle resource_limi
 | 
			
		|||
        return ERR_INVALID_HANDLE;
 | 
			
		||||
 | 
			
		||||
    for (unsigned int i = 0; i < name_count; ++i) {
 | 
			
		||||
        u32 name = Memory::Read32(names + i * sizeof(u32));
 | 
			
		||||
        u32 name = memory.Read32(names + i * sizeof(u32));
 | 
			
		||||
        s64 value = resource_limit->GetCurrentResourceValue(name);
 | 
			
		||||
        Memory::Write64(values + i * sizeof(u64), value);
 | 
			
		||||
        memory.Write64(values + i * sizeof(u64), value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return RESULT_SUCCESS;
 | 
			
		||||
| 
						 | 
				
			
			@ -852,9 +852,9 @@ ResultCode SVC::GetResourceLimitLimitValues(VAddr values, Handle resource_limit_
 | 
			
		|||
        return ERR_INVALID_HANDLE;
 | 
			
		||||
 | 
			
		||||
    for (unsigned int i = 0; i < name_count; ++i) {
 | 
			
		||||
        u32 name = Memory::Read32(names + i * sizeof(u32));
 | 
			
		||||
        u32 name = memory.Read32(names + i * sizeof(u32));
 | 
			
		||||
        s64 value = resource_limit->GetMaxResourceValue(name);
 | 
			
		||||
        Memory::Write64(values + i * sizeof(u64), value);
 | 
			
		||||
        memory.Write64(values + i * sizeof(u64), value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return RESULT_SUCCESS;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue