ams: support building unit test programs on windows/linux/macos
This commit is contained in:
@@ -18,10 +18,11 @@
|
||||
|
||||
namespace ams::os {
|
||||
|
||||
void InitializeForStratosphereInternal();
|
||||
void Initialize();
|
||||
|
||||
}
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
extern "C" {
|
||||
|
||||
/* Provide libnx address space allocation shim. */
|
||||
@@ -30,6 +31,7 @@ extern "C" {
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace ams::hos {
|
||||
|
||||
@@ -53,13 +55,15 @@ namespace ams::hos {
|
||||
|
||||
void InitializeForStratosphere() {
|
||||
/* Initialize the global os resource managers. This *must* be done before anything else in stratosphere. */
|
||||
os::InitializeForStratosphereInternal();
|
||||
os::Initialize();
|
||||
|
||||
/* Initialize hos::Version API. */
|
||||
hos::InitializeVersionInternal(CanAllowTemporaryApproximateVersion());
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
/* Check that we're running under mesosphere. */
|
||||
AMS_ABORT_UNLESS(IsUnitTestProgramForSetVersion() || svc::IsKernelMesosphere());
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace ams::hos {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
Result GetApproximateExosphereApiInfo(exosphere::ApiInfo *out) {
|
||||
u64 exosphere_cfg;
|
||||
|
||||
@@ -43,20 +44,28 @@ namespace ams::hos {
|
||||
*out = { exosphere_cfg };
|
||||
return ResultSuccess();
|
||||
}
|
||||
#endif
|
||||
|
||||
exosphere::ApiInfo GetExosphereApiInfo(bool allow_approximate) {
|
||||
exosphere::ApiInfo info;
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
while (true) {
|
||||
if (R_SUCCEEDED(GetExosphereApiInfo(std::addressof(info)))) {
|
||||
return info;
|
||||
break;
|
||||
}
|
||||
|
||||
if (allow_approximate && R_SUCCEEDED(GetApproximateExosphereApiInfo(std::addressof(info)))) {
|
||||
return info;
|
||||
break;
|
||||
}
|
||||
|
||||
svc::SleepThread(TimeSpan::FromMilliSeconds(25).GetNanoSeconds());
|
||||
}
|
||||
#else
|
||||
AMS_UNUSED(allow_approximate);
|
||||
R_ABORT_UNLESS(GetExosphereApiInfo(std::addressof(info)));
|
||||
#endif
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,6 +127,8 @@ namespace ams::hos {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
/* Set the version for libnx. */
|
||||
{
|
||||
const u32 major = (static_cast<u32>(current) >> 24) & 0xFF;
|
||||
@@ -125,6 +136,7 @@ namespace ams::hos {
|
||||
const u32 micro = (static_cast<u32>(current) >> 8) & 0xFF;
|
||||
hosversionSet((BIT(31)) | (MAKEHOSVERSION(major, minor, micro)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
::ams::hos::Version GetVersion() {
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace ams::hos {
|
||||
|
||||
namespace {
|
||||
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
settings::FirmwareVersion GetSettingsFirmwareVersion() {
|
||||
/* Mount the system version title. */
|
||||
R_ABORT_UNLESS(ams::fs::MountSystemData("sysver", ncm::SystemDataId::SystemVersion));
|
||||
@@ -35,12 +36,14 @@ namespace ams::hos {
|
||||
|
||||
return firmware_version;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void InitializeVersionInternal(bool allow_approximate);
|
||||
|
||||
void SetNonApproximateVersionInternal() {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
/* Get the settings . */
|
||||
const auto firmware_version = GetSettingsFirmwareVersion();
|
||||
|
||||
@@ -49,6 +52,7 @@ namespace ams::hos {
|
||||
|
||||
/* Update our own version value. */
|
||||
InitializeVersionInternal(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
namespace ams::hos {
|
||||
|
||||
WEAK_SYMBOL bool IsUnitTestProgramForSetVersion() {
|
||||
#if defined(ATMOSPHERE_OS_HORIZON)
|
||||
return false;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user