mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-05-13 06:34:23 -04:00
kern: add KProcess::Initialize (for non-kip processes)
This commit is contained in:
parent
8759cb4da3
commit
51311a7332
10 changed files with 232 additions and 8 deletions
|
@ -34,6 +34,14 @@ namespace ams::kern {
|
|||
return this->SetCapabilities(caps, num_caps, page_table);
|
||||
}
|
||||
|
||||
Result KCapabilities::Initialize(svc::KUserPointer<const u32 *> user_caps, s32 num_caps, KProcessPageTable *page_table) {
|
||||
/* We're initializing a user process. */
|
||||
/* Most fields have already been cleared by our constructor. */
|
||||
|
||||
/* Parse the user capabilities array. */
|
||||
return this->SetCapabilities(user_caps, num_caps, page_table);
|
||||
}
|
||||
|
||||
Result KCapabilities::SetCorePriorityCapability(const util::BitPack32 cap) {
|
||||
/* We can't set core/priority if we've already set them. */
|
||||
R_UNLESS(this->core_mask == 0, svc::ResultInvalidArgument());
|
||||
|
@ -258,4 +266,35 @@ namespace ams::kern {
|
|||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result KCapabilities::SetCapabilities(svc::KUserPointer<const u32 *> user_caps, s32 num_caps, KProcessPageTable *page_table) {
|
||||
u32 set_flags = 0, set_svc = 0;
|
||||
|
||||
for (s32 i = 0; i < num_caps; i++) {
|
||||
/* Read the cap from userspace. */
|
||||
u32 cap0;
|
||||
R_TRY(user_caps.CopyArrayElementTo(std::addressof(cap0), i));
|
||||
|
||||
const util::BitPack32 cap = { cap0 };
|
||||
if (GetCapabilityType(cap) == CapabilityType::MapRange) {
|
||||
/* Check that the pair cap exists. */
|
||||
R_UNLESS((++i) < num_caps, svc::ResultInvalidCombination());
|
||||
|
||||
/* Read the second cap from userspace. */
|
||||
u32 cap1;
|
||||
R_TRY(user_caps.CopyArrayElementTo(std::addressof(cap1), i));
|
||||
|
||||
/* Check the pair cap is a map range cap. */
|
||||
const util::BitPack32 size_cap = { cap1 };
|
||||
R_UNLESS(GetCapabilityType(size_cap) == CapabilityType::MapRange, svc::ResultInvalidCombination());
|
||||
|
||||
/* Map the range. */
|
||||
R_TRY(this->MapRange(cap, size_cap, page_table));
|
||||
} else {
|
||||
R_TRY(this->SetCapability(cap, set_flags, set_svc, page_table));
|
||||
}
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue