2017-08-05 13:09:50 +00:00
|
|
|
#include <nx/SystemCallHandler.h>
|
|
|
|
#include <nx/SystemCallEntry.h>
|
2017-07-12 14:02:10 +00:00
|
|
|
|
|
|
|
nx::SystemCallHandler::SystemCallHandler() :
|
|
|
|
mIsSet(false),
|
|
|
|
mSystemCalls()
|
|
|
|
{}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
void nx::SystemCallHandler::operator=(const SystemCallHandler & other)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
mIsSet = other.mIsSet;
|
|
|
|
mSystemCalls = other.mSystemCalls;
|
2017-07-12 14:02:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
bool nx::SystemCallHandler::operator==(const SystemCallHandler & other) const
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return (mIsSet == other.mIsSet) \
|
|
|
|
&& (mSystemCalls == other.mSystemCalls);
|
2017-07-12 14:02:10 +00:00
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
bool nx::SystemCallHandler::operator!=(const SystemCallHandler & other) const
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
return !(*this == other);
|
2017-07-12 14:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nx::SystemCallHandler::importKernelCapabilityList(const fnd::List<KernelCapability>& caps)
|
|
|
|
{
|
2018-06-24 15:01:16 +00:00
|
|
|
if (caps.size() == 0)
|
2017-07-15 08:28:01 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-12 14:02:10 +00:00
|
|
|
SystemCallEntry entry;
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
uint8_t syscallUpper, syscall;
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < caps.size(); i++)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
entry.setKernelCapability(caps[i]);
|
|
|
|
syscallUpper = 24 * entry.getSystemCallUpperBits();
|
2018-03-22 05:26:22 +00:00
|
|
|
for (uint8_t j = 0; j < 24; j++)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
syscall = syscallUpper + j;
|
|
|
|
if (((entry.getSystemCallLowerBits() >> j) & 1) == 1)
|
|
|
|
{
|
|
|
|
mSystemCalls.hasElement(syscall) == false ? mSystemCalls.addElement(syscall) : throw fnd::Exception(kModuleName, "SystemCall already added");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mIsSet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::SystemCallHandler::exportKernelCapabilityList(fnd::List<KernelCapability>& caps) const
|
|
|
|
{
|
|
|
|
if (isSet() == false)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fnd::List<SystemCallEntry> entries;
|
|
|
|
for (size_t i = 0; i < kSyscallTotalEntryNum; i++)
|
|
|
|
{
|
2018-05-26 04:07:42 +00:00
|
|
|
entries[i].setSystemCallUpperBits((uint32_t)i);
|
2017-07-12 14:02:10 +00:00
|
|
|
entries[i].setSystemCallLowerBits(0);
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < mSystemCalls.size(); i++)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
if (mSystemCalls[i] > kMaxSystemCall)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Illegal SystemCall. (range: 0x00-0xBF inclusive)");
|
|
|
|
}
|
|
|
|
|
|
|
|
entries[mSystemCalls[i] / 24].setSystemCallLowerBits(entries[mSystemCalls[i] / 24].getSystemCallLowerBits() | BIT(mSystemCalls[i] % 24));
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < entries.size(); i++)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
if (entries[i].getSystemCallLowerBits() != 0)
|
|
|
|
{
|
|
|
|
caps.addElement(entries[i].getKernelCapability());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void nx::SystemCallHandler::clear()
|
|
|
|
{
|
|
|
|
mIsSet = false;
|
|
|
|
mSystemCalls.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nx::SystemCallHandler::isSet() const
|
|
|
|
{
|
|
|
|
return mIsSet;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
const fnd::List<uint8_t>& nx::SystemCallHandler::getSystemCalls() const
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
return mSystemCalls;
|
|
|
|
}
|
|
|
|
|
2018-03-22 05:26:22 +00:00
|
|
|
void nx::SystemCallHandler::setSystemCallList(const fnd::List<uint8_t>& calls)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
mSystemCalls.clear();
|
2018-06-24 15:01:16 +00:00
|
|
|
for (size_t i = 0; i < calls.size(); i++)
|
2017-07-12 14:02:10 +00:00
|
|
|
{
|
|
|
|
if (mSystemCalls[i] > kMaxSystemCall)
|
|
|
|
{
|
|
|
|
throw fnd::Exception(kModuleName, "Illegal SystemCall. (range: 0x00-0xBF inclusive)");
|
|
|
|
}
|
|
|
|
|
|
|
|
mSystemCalls.hasElement(calls[i]) == false ? mSystemCalls.addElement(calls[i]) : throw fnd::Exception(kModuleName, "SystemCall already added");
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsSet = true;
|
2018-06-24 15:01:16 +00:00
|
|
|
}
|