mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-24 03:06:17 +00:00
kern: add version bounds checking
This commit is contained in:
parent
56ec55f3c4
commit
47f2e93a42
5 changed files with 79 additions and 4 deletions
|
@ -354,6 +354,10 @@ namespace ams::kern {
|
|||
constexpr bool CanForceDebug() const {
|
||||
return this->debug_capabilities.Get<DebugFlags::ForceDebug>();
|
||||
}
|
||||
|
||||
constexpr u32 GetIntendedKernelMajorVersion() const { return this->intended_kernel_version.Get<KernelVersion::MajorVersion>(); }
|
||||
constexpr u32 GetIntendedKernelMinorVersion() const { return this->intended_kernel_version.Get<KernelVersion::MinorVersion>(); }
|
||||
constexpr u32 GetIntendedKernelVersion() const { return ams::svc::EncodeKernelVersion(this->GetIntendedKernelMajorVersion(), this->GetIntendedKernelMinorVersion()); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -27,8 +27,10 @@ namespace ams::kern {
|
|||
/* Initial processes may use any user priority they like. */
|
||||
this->priority_mask = ~0xFul;
|
||||
|
||||
/* TODO: Here, Nintendo sets the kernel version to (current kernel version). */
|
||||
/* How should we handle this? Not a MESOSPHERE_TODO because it's not critical. */
|
||||
/* Here, Nintendo sets the kernel version to the current kernel version. */
|
||||
/* We will follow suit and set the version to the highest supported kernel version. */
|
||||
this->intended_kernel_version.Set<KernelVersion::MajorVersion>(ams::svc::SupportedKernelMajorVersion);
|
||||
this->intended_kernel_version.Set<KernelVersion::MinorVersion>(ams::svc::SupportedKernelMinorVersion);
|
||||
|
||||
/* Parse the capabilities array. */
|
||||
return this->SetCapabilities(caps, num_caps, page_table);
|
||||
|
|
|
@ -146,8 +146,11 @@ namespace ams::kern {
|
|||
}
|
||||
|
||||
Result KProcess::Initialize(const ams::svc::CreateProcessParameter ¶ms) {
|
||||
/* TODO: Validate intended kernel version. */
|
||||
/* How should we do this? */
|
||||
/* Validate that the intended kernel version is high enough for us to support. */
|
||||
R_UNLESS(this->capabilities.GetIntendedKernelVersion() >= ams::svc::RequiredKernelVersion, svc::ResultInvalidCombination());
|
||||
|
||||
/* Validate that the intended kernel version isn't too high for us to support. */
|
||||
R_UNLESS(this->capabilities.GetIntendedKernelVersion() <= ams::svc::SupportedKernelVersion, svc::ResultInvalidCombination());
|
||||
|
||||
/* Create and clear the process local region. */
|
||||
R_TRY(this->CreateThreadLocalRegion(std::addressof(this->plr_address)));
|
||||
|
|
|
@ -21,4 +21,5 @@
|
|||
|
||||
#include <vapours/svc/svc_types.hpp>
|
||||
#include <vapours/svc/svc_definitions.hpp>
|
||||
#include <vapours/svc/svc_version.hpp>
|
||||
#include <vapours/svc/ipc/svc_message_buffer.hpp>
|
||||
|
|
65
libraries/libvapours/include/vapours/svc/svc_version.hpp
Normal file
65
libraries/libvapours/include/vapours/svc/svc_version.hpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020 Atmosphère-NX
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <vapours/svc/svc_common.hpp>
|
||||
#include <vapours/svc/svc_select_hardware_constants.hpp>
|
||||
#include <vapours/util/util_bitpack.hpp>
|
||||
|
||||
namespace ams::svc {
|
||||
|
||||
constexpr inline u32 ConvertToSvcMajorVersion(u32 sdk) { return sdk + 4; }
|
||||
constexpr inline u32 ConvertToSdkMajorVersion(u32 svc) { return svc - 4; }
|
||||
|
||||
constexpr inline u32 ConvertToSvcMinorVersion(u32 sdk) { return sdk; }
|
||||
constexpr inline u32 ConvertToSdkMinorVersion(u32 svc) { return svc; }
|
||||
|
||||
struct KernelVersion {
|
||||
using MinorVersion = util::BitPack32::Field<0, 4>;
|
||||
using MajorVersion = util::BitPack32::Field<MinorVersion::Next, 13>;
|
||||
};
|
||||
|
||||
constexpr inline u32 EncodeKernelVersion(u32 major, u32 minor) {
|
||||
util::BitPack32 pack = {};
|
||||
pack.Set<KernelVersion::MinorVersion>(minor);
|
||||
pack.Set<KernelVersion::MajorVersion>(major);
|
||||
return pack.value;
|
||||
}
|
||||
|
||||
constexpr inline u32 GetKernelMajorVersion(u32 encoded) {
|
||||
const util::BitPack32 pack = { encoded };
|
||||
return pack.Get<KernelVersion::MajorVersion>();
|
||||
}
|
||||
|
||||
constexpr inline u32 GetKernelMinorVersion(u32 encoded) {
|
||||
const util::BitPack32 pack = { encoded };
|
||||
return pack.Get<KernelVersion::MinorVersion>();
|
||||
}
|
||||
|
||||
/* Nintendo doesn't support programs targeting SVC versions < 3.0. */
|
||||
constexpr inline u32 RequiredKernelMajorVersion = 3;
|
||||
constexpr inline u32 RequiredKernelMinorVersion = 0;
|
||||
|
||||
constexpr inline u32 RequiredKernelVersion = EncodeKernelVersion(RequiredKernelMajorVersion, RequiredKernelMinorVersion);
|
||||
|
||||
/* This is the highest SVC version supported by Atmosphere, to be updated on new kernel releases. */
|
||||
/* NOTE: Official kernel versions have SVC major = SDK major + 4, SVC minor = SDK minor. */
|
||||
constexpr inline u32 SupportedKernelMajorVersion = ConvertToSvcMajorVersion(10);
|
||||
constexpr inline u32 SupportedKernelMinorVersion = ConvertToSvcMinorVersion( 4);
|
||||
|
||||
constexpr inline u32 SupportedKernelVersion = EncodeKernelVersion(SupportedKernelMajorVersion, SupportedKernelMinorVersion);
|
||||
|
||||
}
|
Loading…
Reference in a new issue