exo2: implement GenerateRandomBytes

This commit is contained in:
Michael Scire
2020-05-15 03:23:31 -07:00
committed by SciresM
parent 6bf283ec2e
commit fa64bf4951
6 changed files with 101 additions and 7 deletions

View File

@@ -38,4 +38,41 @@ namespace ams::secmon::smc {
return g_is_locked;
}
SmcResult LockSecurityEngineAndInvoke(SmcArguments &args, SmcHandler impl) {
/* Try to lock the SE. */
if (!TryLockSecurityEngine()) {
return SmcResult::Busy;
}
ON_SCOPE_EXIT { UnlockSecurityEngine(); };
return impl(args);
}
SmcResult LockSecurityEngineAndInvokeAsync(SmcArguments &args, SmcHandler impl, GetResultHandler result_handler) {
SmcResult result = SmcResult::Busy;
/* Try to lock the security engine. */
if (TryLockSecurityEngine()) {
/* Try to start an async operation. */
if (const u64 async_key = BeginAsyncOperation(result_handler); async_key != InvalidAsyncKey) {
/* Invoke the operation. */
result = impl(args);
/* If the operation was successful, return the key. */
if (result == SmcResult::Success) {
args.r[1] = async_key;
return SmcResult::Success;
}
/* Otherwise, cancel the async operation. */
CancelAsyncOperation(async_key);
}
/* We failed to invoke the async op, so unlock the security engine. */
UnlockSecurityEngine();
}
return result;
}
}