summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel/svc/svc_cache.cpp
blob: 42167d35b147fa8fc1da96c861110674c3d6631d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#include "core/core.h"
#include "core/hle/kernel/k_process.h"
#include "core/hle/kernel/svc.h"
#include "core/hle/kernel/svc_results.h"
#include "core/hle/kernel/svc_types.h"

namespace Kernel::Svc {

Result FlushProcessDataCache32(Core::System& system, Handle process_handle, u64 address, u64 size) {
    // Validate address/size.
    R_UNLESS(size > 0, ResultInvalidSize);
    R_UNLESS(address == static_cast<uintptr_t>(address), ResultInvalidCurrentMemory);
    R_UNLESS(size == static_cast<size_t>(size), ResultInvalidCurrentMemory);

    // Get the process from its handle.
    KScopedAutoObject process =
        system.Kernel().CurrentProcess()->GetHandleTable().GetObject<KProcess>(process_handle);
    R_UNLESS(process.IsNotNull(), ResultInvalidHandle);

    // Verify the region is within range.
    auto& page_table = process->PageTable();
    R_UNLESS(page_table.Contains(address, size), ResultInvalidCurrentMemory);

    // Perform the operation.
    R_RETURN(system.Memory().FlushDataCache(*process, address, size));
}

} // namespace Kernel::Svc