|
|
|
@ -62,14 +62,8 @@ public: |
|
|
|
template <typename T> |
|
|
|
void Push(T value); |
|
|
|
|
|
|
|
void Push(u32 value) { |
|
|
|
cmdbuf[index++] = value; |
|
|
|
} |
|
|
|
template <typename First, typename... Other> |
|
|
|
void Push(const First& first_value, const Other&... other_values) { |
|
|
|
Push(first_value); |
|
|
|
Push(other_values...); |
|
|
|
} |
|
|
|
void Push(const First& first_value, const Other&... other_values); |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief Copies the content of the given trivially copyable class to the buffer as a normal |
|
|
|
@ -77,59 +71,96 @@ public: |
|
|
|
* @note: The input class must be correctly packed/padded to fit hardware layout. |
|
|
|
*/ |
|
|
|
template <typename T> |
|
|
|
void PushRaw(const T& value) { |
|
|
|
static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); |
|
|
|
std::memcpy(cmdbuf + index, &value, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
void PushRaw(const T& value); |
|
|
|
|
|
|
|
// TODO : ensure that translate params are added after all regular params |
|
|
|
template <typename... H> |
|
|
|
void PushCopyHandles(H... handles) { |
|
|
|
Push(CopyHandleDesc(sizeof...(H))); |
|
|
|
Push(static_cast<Kernel::Handle>(handles)...); |
|
|
|
} |
|
|
|
void PushCopyHandles(H... handles); |
|
|
|
|
|
|
|
template <typename... H> |
|
|
|
void PushMoveHandles(H... handles) { |
|
|
|
Push(MoveHandleDesc(sizeof...(H))); |
|
|
|
Push(static_cast<Kernel::Handle>(handles)...); |
|
|
|
} |
|
|
|
void PushMoveHandles(H... handles); |
|
|
|
|
|
|
|
void PushCurrentPIDHandle() { |
|
|
|
Push(CallingPidDesc()); |
|
|
|
Push(u32(0)); |
|
|
|
} |
|
|
|
void PushCurrentPIDHandle(); |
|
|
|
|
|
|
|
void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { |
|
|
|
Push(StaticBufferDesc(size, buffer_id)); |
|
|
|
Push(buffer_vaddr); |
|
|
|
} |
|
|
|
void PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id); |
|
|
|
|
|
|
|
void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms) { |
|
|
|
Push(MappedBufferDesc(size, perms)); |
|
|
|
Push(buffer_vaddr); |
|
|
|
} |
|
|
|
void PushMappedBuffer(VAddr buffer_vaddr, u32 size, MappedBufferPermissions perms); |
|
|
|
}; |
|
|
|
|
|
|
|
/// Push /// |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push<u32>(u32 value) { |
|
|
|
Push(value); |
|
|
|
inline void RequestBuilder::Push(u32 value) { |
|
|
|
cmdbuf[index++] = value; |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void RequestBuilder::PushRaw(const T& value) { |
|
|
|
static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); |
|
|
|
std::memcpy(cmdbuf + index, &value, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push(u8 value) { |
|
|
|
PushRaw(value); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push(u16 value) { |
|
|
|
PushRaw(value); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push<u64>(u64 value) { |
|
|
|
inline void RequestBuilder::Push(u64 value) { |
|
|
|
Push(static_cast<u32>(value)); |
|
|
|
Push(static_cast<u32>(value >> 32)); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push<ResultCode>(ResultCode value) { |
|
|
|
inline void RequestBuilder::Push(bool value) { |
|
|
|
Push(u8(value)); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline void RequestBuilder::Push(ResultCode value) { |
|
|
|
Push(value.raw); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename First, typename... Other> |
|
|
|
void RequestBuilder::Push(const First& first_value, const Other&... other_values) { |
|
|
|
Push(first_value); |
|
|
|
Push(other_values...); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename... H> |
|
|
|
inline void RequestBuilder::PushCopyHandles(H... handles) { |
|
|
|
Push(CopyHandleDesc(sizeof...(H))); |
|
|
|
Push(static_cast<Kernel::Handle>(handles)...); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename... H> |
|
|
|
inline void RequestBuilder::PushMoveHandles(H... handles) { |
|
|
|
Push(MoveHandleDesc(sizeof...(H))); |
|
|
|
Push(static_cast<Kernel::Handle>(handles)...); |
|
|
|
} |
|
|
|
|
|
|
|
inline void RequestBuilder::PushCurrentPIDHandle() { |
|
|
|
Push(CallingPidDesc()); |
|
|
|
Push(u32(0)); |
|
|
|
} |
|
|
|
|
|
|
|
inline void RequestBuilder::PushStaticBuffer(VAddr buffer_vaddr, u32 size, u8 buffer_id) { |
|
|
|
Push(StaticBufferDesc(size, buffer_id)); |
|
|
|
Push(buffer_vaddr); |
|
|
|
} |
|
|
|
|
|
|
|
inline void RequestBuilder::PushMappedBuffer(VAddr buffer_vaddr, u32 size, |
|
|
|
MappedBufferPermissions perms) { |
|
|
|
Push(MappedBufferDesc(size, perms)); |
|
|
|
Push(buffer_vaddr); |
|
|
|
} |
|
|
|
|
|
|
|
class RequestParser : public RequestHelperBase { |
|
|
|
public: |
|
|
|
RequestParser(u32* command_buffer, Header command_header) |
|
|
|
@ -197,24 +228,60 @@ public: |
|
|
|
*/ |
|
|
|
template <typename T> |
|
|
|
void PopRaw(T& value); |
|
|
|
|
|
|
|
/** |
|
|
|
* @brief Reads the next normal parameters as a struct, by copying it into a new value |
|
|
|
* @note: The output class must be correctly packed/padded to fit hardware layout. |
|
|
|
*/ |
|
|
|
template <typename T> |
|
|
|
T PopRaw(); |
|
|
|
}; |
|
|
|
|
|
|
|
/// Pop /// |
|
|
|
|
|
|
|
template <> |
|
|
|
inline u32 RequestParser::Pop<u32>() { |
|
|
|
inline u32 RequestParser::Pop() { |
|
|
|
return cmdbuf[index++]; |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void RequestParser::PopRaw(T& value) { |
|
|
|
static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); |
|
|
|
std::memcpy(&value, cmdbuf + index, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
T RequestParser::PopRaw() { |
|
|
|
T value; |
|
|
|
PopRaw(value); |
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline u64 RequestParser::Pop<u64>() { |
|
|
|
inline u8 RequestParser::Pop() { |
|
|
|
return PopRaw<u8>(); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline u16 RequestParser::Pop() { |
|
|
|
return PopRaw<u16>(); |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline u64 RequestParser::Pop() { |
|
|
|
const u64 lsw = Pop<u32>(); |
|
|
|
const u64 msw = Pop<u32>(); |
|
|
|
return msw << 32 | lsw; |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline ResultCode RequestParser::Pop<ResultCode>() { |
|
|
|
inline bool RequestParser::Pop() { |
|
|
|
return Pop<u8>() != 0; // != 0 to remove warning C4800 |
|
|
|
} |
|
|
|
|
|
|
|
template <> |
|
|
|
inline ResultCode RequestParser::Pop() { |
|
|
|
return ResultCode{Pop<u32>()}; |
|
|
|
} |
|
|
|
|
|
|
|
@ -277,11 +344,4 @@ inline VAddr RequestParser::PopMappedBuffer(size_t* data_size, |
|
|
|
return Pop<VAddr>(); |
|
|
|
} |
|
|
|
|
|
|
|
template <typename T> |
|
|
|
void RequestParser::PopRaw(T& value) { |
|
|
|
static_assert(std::is_trivially_copyable<T>(), "Raw types should be trivially copyable"); |
|
|
|
std::memcpy(&value, cmdbuf + index, sizeof(T)); |
|
|
|
index += (sizeof(T) + 3) / 4; // round up to word length |
|
|
|
} |
|
|
|
|
|
|
|
} // namespace IPC |