Compare commits
6 Commits
6212aef336
...
642fc4d80d
Author | SHA1 | Date |
---|---|---|
|
642fc4d80d | |
|
c209925a3c | |
|
700f3f94cb | |
|
3eba0bd9d8 | |
|
7d9f9a7ae9 | |
|
91f3f8ee43 |
|
@ -1,2 +1,3 @@
|
||||||
add_subdirectory(glacier)
|
add_subdirectory(glacier)
|
||||||
add_subdirectory(mammoth)
|
add_subdirectory(mammoth)
|
||||||
|
add_subdirectory(yunq)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "status/error.h"
|
#include "glacier/status/error.h"
|
||||||
#include "string/string.h"
|
#include "glacier/string/string.h"
|
||||||
|
|
||||||
namespace glcr {
|
namespace glcr {
|
||||||
|
|
||||||
|
@ -11,53 +11,67 @@ class Status {
|
||||||
Status(ErrorCode code) : code_(code), message_() {}
|
Status(ErrorCode code) : code_(code), message_() {}
|
||||||
Status(ErrorCode code, StringView message) : code_(code), message_(message) {}
|
Status(ErrorCode code, StringView message) : code_(code), message_(message) {}
|
||||||
|
|
||||||
explicit operator bool() { return ok(); }
|
explicit operator bool() const { return ok(); }
|
||||||
bool ok() { return code_ == OK; }
|
bool ok() const { return code_ == OK; }
|
||||||
|
|
||||||
ErrorCode code() { return code_; }
|
ErrorCode code() const { return code_; }
|
||||||
StringView message() { return message_; }
|
StringView message() const { return message_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ErrorCode code_;
|
ErrorCode code_;
|
||||||
String message_;
|
String message_;
|
||||||
|
|
||||||
Status();
|
Status() : code_(OK) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
Status InvalidArgument(StringView message) {
|
inline Status InvalidArgument(StringView message) {
|
||||||
return Status(INVALID_ARGUMENT, message);
|
return Status(INVALID_ARGUMENT, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status NotFound(StringView message) { return Status(NOT_FOUND, message); }
|
inline Status NotFound(StringView message) {
|
||||||
|
return Status(NOT_FOUND, message);
|
||||||
|
}
|
||||||
|
|
||||||
Status PermissionDenied(StringView message) {
|
inline Status PermissionDenied(StringView message) {
|
||||||
return Status(PERMISSION_DENIED, message);
|
return Status(PERMISSION_DENIED, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status NullPtr(StringView message) { return Status(NULL_PTR, message); }
|
inline Status NullPtr(StringView message) { return Status(NULL_PTR, message); }
|
||||||
|
|
||||||
Status Empty(StringView message) { return Status(EMPTY, message); }
|
inline Status Empty(StringView message) { return Status(EMPTY, message); }
|
||||||
|
|
||||||
Status AlreadyExists(StringView message) {
|
inline Status AlreadyExists(StringView message) {
|
||||||
return Status(ALREADY_EXISTS, message);
|
return Status(ALREADY_EXISTS, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status BufferSize(StringView message) { return Status(BUFFER_SIZE, message); }
|
inline Status BufferSize(StringView message) {
|
||||||
|
return Status(BUFFER_SIZE, message);
|
||||||
|
}
|
||||||
|
|
||||||
Status FailedPrecondition(StringView message) {
|
inline Status FailedPrecondition(StringView message) {
|
||||||
return Status(FAILED_PRECONDITION, message);
|
return Status(FAILED_PRECONDITION, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Internal(StringView message) { return Status(INTERNAL, message); }
|
inline Status Internal(StringView message) { return Status(INTERNAL, message); }
|
||||||
|
|
||||||
Status Unimplemented(StringView message) {
|
inline Status Unimplemented(StringView message) {
|
||||||
return Status(UNIMPLEMENTED, message);
|
return Status(UNIMPLEMENTED, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
Status Exhausted(StringView message) { return Status(EXHAUSTED, message); }
|
inline Status Exhausted(StringView message) {
|
||||||
|
return Status(EXHAUSTED, message);
|
||||||
|
}
|
||||||
|
|
||||||
Status InvalidResponse(StringView message) {
|
inline Status InvalidResponse(StringView message) {
|
||||||
return Status(INVALID_RESPONSE, message);
|
return Status(INVALID_RESPONSE, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define RETURN_ERROR(expr) \
|
||||||
|
{ \
|
||||||
|
glcr::Status _tmp_err = expr; \
|
||||||
|
if (!_tmp_err) { \
|
||||||
|
return _tmp_err; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace glcr
|
} // namespace glcr
|
||||||
|
|
|
@ -72,6 +72,12 @@ void StrFormatValue(StringBuilder& builder, char const* const& value,
|
||||||
StrFormatInternal(builder, StringView(value));
|
StrFormatInternal(builder, StringView(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void StrFormatValue(StringBuilder& builder, const String& value,
|
||||||
|
StringView opts) {
|
||||||
|
StrFormatInternal(builder, value);
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void StrFormatValue(StringBuilder& builder, const StringView& value,
|
void StrFormatValue(StringBuilder& builder, const StringView& value,
|
||||||
StringView opts) {
|
StringView opts) {
|
||||||
|
|
|
@ -44,6 +44,9 @@ void StrFormatValue(StringBuilder& builder, char const* const& value,
|
||||||
StringView opts);
|
StringView opts);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
|
void StrFormatValue(StringBuilder& builder, const String& value,
|
||||||
|
StringView opts);
|
||||||
|
template <>
|
||||||
void StrFormatValue(StringBuilder& builder, const StringView& value,
|
void StrFormatValue(StringBuilder& builder, const StringView& value,
|
||||||
StringView opts);
|
StringView opts);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#include "file/file.h"
|
#include "file/file.h"
|
||||||
|
|
||||||
#include <glacier/string/str_split.h>
|
#include <glacier/string/str_split.h>
|
||||||
|
#include <mammoth/util/init.h>
|
||||||
#include <victoriafalls/victoriafalls.yunq.client.h>
|
#include <victoriafalls/victoriafalls.yunq.client.h>
|
||||||
#include <yellowstone/yellowstone.yunq.client.h>
|
#include <yellowstone/yellowstone.yunq.client.h>
|
||||||
#include <zcall.h>
|
#include <zcall.h>
|
||||||
#include <zglobal.h>
|
|
||||||
|
|
||||||
#include "util/debug.h"
|
#include "util/debug.h"
|
||||||
|
|
||||||
|
@ -64,7 +64,11 @@ glcr::ErrorOr<glcr::Vector<glcr::String>> ListDirectory(glcr::StringView path) {
|
||||||
GetDirectoryRequest req;
|
GetDirectoryRequest req;
|
||||||
req.set_path(path);
|
req.set_path(path);
|
||||||
Directory dir;
|
Directory dir;
|
||||||
RET_ERR(gVfsClient->GetDirectory(req, dir));
|
auto status = gVfsClient->GetDirectory(req, dir);
|
||||||
|
if (!status.ok()) {
|
||||||
|
dbgln("Error in getting directory: {}", status.message());
|
||||||
|
return status.code();
|
||||||
|
}
|
||||||
|
|
||||||
auto file_views = glcr::StrSplit(dir.filenames(), ',');
|
auto file_views = glcr::StrSplit(dir.filenames(), ',');
|
||||||
glcr::Vector<glcr::String> files;
|
glcr::Vector<glcr::String> files;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "input/keyboard.h"
|
#include "input/keyboard.h"
|
||||||
|
|
||||||
|
#include <mammoth/util/init.h>
|
||||||
#include <voyageurs/voyageurs.yunq.client.h>
|
#include <voyageurs/voyageurs.yunq.client.h>
|
||||||
#include <yellowstone/yellowstone.yunq.client.h>
|
#include <yellowstone/yellowstone.yunq.client.h>
|
||||||
#include <zglobal.h>
|
|
||||||
|
|
||||||
#include "util/debug.h"
|
#include "util/debug.h"
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,14 @@ void check(uint64_t code) {
|
||||||
(void)ZProcessExit(code);
|
(void)ZProcessExit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void check(const glcr::Status& status) {
|
||||||
|
if (status.ok()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dbgln("Crash: {}", status.message());
|
||||||
|
(void)ZProcessExit(status.code());
|
||||||
|
}
|
||||||
|
|
||||||
void crash(const char* str, uint64_t code) {
|
void crash(const char* str, uint64_t code) {
|
||||||
dbgln(str);
|
dbgln(str);
|
||||||
(void)ZProcessExit(code);
|
(void)ZProcessExit(code);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/string/str_format.h>
|
#include <glacier/string/str_format.h>
|
||||||
#include <glacier/string/string_view.h>
|
#include <glacier/string/string_view.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -16,5 +17,6 @@ void dbgln(const glcr::StringView& fmt, Args... args) {
|
||||||
// Checks that the code is ok.
|
// Checks that the code is ok.
|
||||||
// if not exits the process.
|
// if not exits the process.
|
||||||
void check(uint64_t);
|
void check(uint64_t);
|
||||||
|
void check(const glcr::Status&);
|
||||||
|
|
||||||
void crash(const char*, z_err_t);
|
void crash(const char*, z_err_t);
|
||||||
|
|
|
@ -1,7 +1,16 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <zglobal.h>
|
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
extern uint64_t gSelfProcCap;
|
||||||
|
extern uint64_t gSelfVmasCap;
|
||||||
|
|
||||||
|
extern uint64_t gInitEndpointCap;
|
||||||
|
|
||||||
|
extern uint64_t gBootDenaliVmmoCap;
|
||||||
|
extern uint64_t gBootVictoriaFallsVmmoCap;
|
||||||
|
extern uint64_t gBootPciVmmoCap;
|
||||||
|
extern uint64_t gBootFramebufferVmmoCap;
|
||||||
|
|
||||||
z_err_t ParseInitPort(uint64_t init_port_cap);
|
z_err_t ParseInitPort(uint64_t init_port_cap);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include <glacier/container/intrusive_list.h>
|
#include <glacier/container/intrusive_list.h>
|
||||||
#include <glacier/string/str_format.h>
|
#include <glacier/string/str_format.h>
|
||||||
|
#include <mammoth/util/init.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <zcall.h>
|
#include <zcall.h>
|
||||||
#include <zglobal.h>
|
|
||||||
|
|
||||||
#include "util/debug.h"
|
#include "util/debug.h"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
set(yunq_files
|
||||||
|
serialize.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(yunq STATIC
|
||||||
|
${yunq_files}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(yunq
|
||||||
|
glacier)
|
||||||
|
|
||||||
|
target_include_directories(yunq
|
||||||
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/..")
|
||||||
|
|
||||||
|
set_target_properties(yunq PROPERTIES
|
||||||
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}")
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "serialize.h"
|
||||||
|
|
||||||
|
namespace yunq {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
const uint64_t kIdentByte = 0x33441122;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
glcr::Status CheckHeader(const glcr::ByteBuffer& buffer, uint64_t offset) {
|
||||||
|
if (buffer.At<uint32_t>(offset + 0) != kIdentByte) {
|
||||||
|
return glcr::InvalidArgument("Trying to parse an invalid yunq message.");
|
||||||
|
}
|
||||||
|
// TODO: Parse core size.
|
||||||
|
// TODO: Parse extension size.
|
||||||
|
// TODO: Check CRC32
|
||||||
|
// TODO: Parse options.
|
||||||
|
return glcr::Status::Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size,
|
||||||
|
uint32_t extension_size) {
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 0, kIdentByte);
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
||||||
|
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace yunq
|
|
@ -0,0 +1,14 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
|
|
||||||
|
namespace yunq {
|
||||||
|
|
||||||
|
[[nodiscard]] glcr::Status CheckHeader(const glcr::ByteBuffer& buffer,
|
||||||
|
uint64_t offset);
|
||||||
|
|
||||||
|
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size,
|
||||||
|
uint32_t extension_size);
|
||||||
|
|
||||||
|
} // namespace yunq
|
|
@ -16,7 +16,7 @@ uint64_t main(uint64_t init_port_cap) {
|
||||||
|
|
||||||
YellowstoneClient stub(gInitEndpointCap);
|
YellowstoneClient stub(gInitEndpointCap);
|
||||||
AhciInfo ahci;
|
AhciInfo ahci;
|
||||||
RET_ERR(stub.GetAhciInfo(ahci));
|
check(stub.GetAhciInfo(ahci));
|
||||||
mmth::OwnedMemoryRegion ahci_region =
|
mmth::OwnedMemoryRegion ahci_region =
|
||||||
mmth::OwnedMemoryRegion::FromCapability(ahci.ahci_region());
|
mmth::OwnedMemoryRegion::FromCapability(ahci.ahci_region());
|
||||||
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(glcr::Move(ahci_region)));
|
ASSIGN_OR_RETURN(auto driver, AhciDriver::Init(glcr::Move(ahci_region)));
|
||||||
|
|
|
@ -12,7 +12,7 @@ glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> DenaliServer::Create(
|
||||||
return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver));
|
return glcr::UniquePtr<DenaliServer>(new DenaliServer(cap, driver));
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
|
glcr::Status DenaliServer::HandleRead(const ReadRequest& req,
|
||||||
ReadResponse& resp) {
|
ReadResponse& resp) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
||||||
|
|
||||||
|
@ -28,15 +28,15 @@ glcr::ErrorCode DenaliServer::HandleRead(const ReadRequest& req,
|
||||||
resp.set_device_id(req.device_id());
|
resp.set_device_id(req.device_id());
|
||||||
resp.set_size(req.size());
|
resp.set_size(req.size());
|
||||||
resp.set_memory(region.DuplicateCap());
|
resp.set_memory(region.DuplicateCap());
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
glcr::Status DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
ReadResponse& resp) {
|
ReadResponse& resp) {
|
||||||
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
ASSIGN_OR_RETURN(AhciDevice * device, driver_.GetDevice(req.device_id()));
|
||||||
|
|
||||||
if (req.lba().size() != req.sector_cnt().size()) {
|
if (req.lba().size() != req.sector_cnt().size()) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("LBA and Sector Cnt must be the same length.");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t sector_cnt = 0;
|
uint64_t sector_cnt = 0;
|
||||||
|
@ -60,5 +60,5 @@ glcr::ErrorCode DenaliServer::HandleReadMany(const ReadManyRequest& req,
|
||||||
resp.set_device_id(req.device_id());
|
resp.set_device_id(req.device_id());
|
||||||
resp.set_size(sector_cnt);
|
resp.set_size(sector_cnt);
|
||||||
resp.set_memory(region.DuplicateCap());
|
resp.set_memory(region.DuplicateCap());
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,8 @@ class DenaliServer : public DenaliServerBase {
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create(
|
static glcr::ErrorOr<glcr::UniquePtr<DenaliServer>> Create(
|
||||||
AhciDriver& driver);
|
AhciDriver& driver);
|
||||||
|
|
||||||
glcr::ErrorCode HandleRead(const ReadRequest& req,
|
glcr::Status HandleRead(const ReadRequest& req, ReadResponse& resp) override;
|
||||||
ReadResponse& resp) override;
|
glcr::Status HandleReadMany(const ReadManyRequest& req,
|
||||||
glcr::ErrorCode HandleReadMany(const ReadManyRequest& req,
|
|
||||||
ReadResponse& resp) override;
|
ReadResponse& resp) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,7 +18,7 @@ DenaliClient::~DenaliClient() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& response) {
|
glcr::Status DenaliClient::Read(const ReadRequest& request, ReadResponse& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -41,14 +41,14 @@ glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& res
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
@ -57,7 +57,7 @@ glcr::ErrorCode DenaliClient::Read(const ReadRequest& request, ReadResponse& res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode DenaliClient::ReadMany(const ReadManyRequest& request, ReadResponse& response) {
|
glcr::Status DenaliClient::ReadMany(const ReadManyRequest& request, ReadResponse& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -80,14 +80,14 @@ glcr::ErrorCode DenaliClient::ReadMany(const ReadManyRequest& request, ReadRespo
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
|
|
@ -20,11 +20,11 @@ class DenaliClient {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode Read(const ReadRequest& request, ReadResponse& response);
|
[[nodiscard]] glcr::Status Read(const ReadRequest& request, ReadResponse& response);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode ReadMany(const ReadManyRequest& request, ReadResponse& response);
|
[[nodiscard]] glcr::Status ReadMany(const ReadManyRequest& request, ReadResponse& response);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
// Generated file -- DO NOT MODIFY.
|
||||||
#include "denali.yunq.h"
|
#include "denali.yunq.h"
|
||||||
|
|
||||||
|
#include <yunq/serialize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -11,33 +13,19 @@ struct ExtPointer {
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
void ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status ReadRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse device_id.
|
// Parse device_id.
|
||||||
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
||||||
// Parse lba.
|
// Parse lba.
|
||||||
|
@ -45,6 +33,7 @@ void ReadRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t
|
||||||
// Parse size.
|
// Parse size.
|
||||||
set_size(bytes.At<uint64_t>(offset + header_size + (8 * 2)));
|
set_size(bytes.At<uint64_t>(offset + header_size + (8 * 2)));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -58,7 +47,7 @@ uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset)
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -75,20 +64,22 @@ uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset,
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), size());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status ReadManyRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadManyRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadManyRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse device_id.
|
// Parse device_id.
|
||||||
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
||||||
// Parse lba.
|
// Parse lba.
|
||||||
|
@ -112,6 +103,7 @@ void ReadManyRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -147,7 +139,7 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
}
|
}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -186,27 +178,29 @@ uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
}
|
}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_memory(0);
|
set_memory(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status ReadResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
||||||
|
|
||||||
set_memory(caps.At(memory_ptr));
|
set_memory(caps.At(memory_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status ReadResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse device_id.
|
// Parse device_id.
|
||||||
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
set_device_id(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
||||||
// Parse size.
|
// Parse size.
|
||||||
|
@ -214,6 +208,7 @@ void ReadResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -228,7 +223,7 @@ uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +241,7 @@ uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/container/vector.h>
|
#include <glacier/container/vector.h>
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
@ -15,8 +16,8 @@ class ReadRequest {
|
||||||
ReadRequest(const ReadRequest&) = delete;
|
ReadRequest(const ReadRequest&) = delete;
|
||||||
ReadRequest(ReadRequest&&) = delete;
|
ReadRequest(ReadRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const uint64_t& device_id() const { return device_id_; }
|
const uint64_t& device_id() const { return device_id_; }
|
||||||
|
@ -32,7 +33,7 @@ class ReadRequest {
|
||||||
uint64_t size_;
|
uint64_t size_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class ReadManyRequest {
|
class ReadManyRequest {
|
||||||
public:
|
public:
|
||||||
|
@ -41,8 +42,8 @@ class ReadManyRequest {
|
||||||
ReadManyRequest(const ReadManyRequest&) = delete;
|
ReadManyRequest(const ReadManyRequest&) = delete;
|
||||||
ReadManyRequest(ReadManyRequest&&) = delete;
|
ReadManyRequest(ReadManyRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const uint64_t& device_id() const { return device_id_; }
|
const uint64_t& device_id() const { return device_id_; }
|
||||||
|
@ -58,7 +59,7 @@ class ReadManyRequest {
|
||||||
glcr::Vector<uint64_t> sector_cnt_;
|
glcr::Vector<uint64_t> sector_cnt_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class ReadResponse {
|
class ReadResponse {
|
||||||
public:
|
public:
|
||||||
|
@ -67,8 +68,8 @@ class ReadResponse {
|
||||||
ReadResponse(const ReadResponse&) = delete;
|
ReadResponse(const ReadResponse&) = delete;
|
||||||
ReadResponse(ReadResponse&&) = delete;
|
ReadResponse(ReadResponse&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const uint64_t& device_id() const { return device_id_; }
|
const uint64_t& device_id() const { return device_id_; }
|
||||||
|
@ -84,6 +85,6 @@ class ReadResponse {
|
||||||
z_cap_t memory_;
|
z_cap_t memory_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,10 @@ void DenaliServerBase::ServerThread() {
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
glcr::ErrorCode reply_err = glcr::OK;
|
||||||
resp_cap.Reset();
|
resp_cap.Reset();
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (!err) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err.code());
|
||||||
|
dbgln("Responding Error {}", err.message());
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
@ -88,12 +89,12 @@ void DenaliServerBase::ServerThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
glcr::Status DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
const glcr::CapBuffer& req_caps,
|
const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps) {
|
glcr::CapBuffer& resp_caps) {
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
if (request.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Request Not Valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
@ -103,7 +104,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
ReadRequest yunq_request;
|
ReadRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleRead(yunq_request, yunq_response));
|
RETURN_ERROR(HandleRead(yunq_request, yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
ReadManyRequest yunq_request;
|
ReadManyRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleReadMany(yunq_request, yunq_response));
|
RETURN_ERROR(HandleReadMany(yunq_request, yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,10 +141,10 @@ glcr::ErrorCode DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::Unimplemented("Method unimplemented by server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <mammoth/proc/thread.h>
|
#include <mammoth/proc/thread.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -26,11 +27,11 @@ class DenaliServerBase {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleRead(const ReadRequest&, ReadResponse&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleRead(const ReadRequest&, ReadResponse&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleReadMany(const ReadManyRequest&, ReadResponse&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleReadMany(const ReadManyRequest&, ReadResponse&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ class DenaliServerBase {
|
||||||
friend void DenaliServerBaseThreadBootstrap(void*);
|
friend void DenaliServerBaseThreadBootstrap(void*);
|
||||||
void ServerThread();
|
void ServerThread();
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps);
|
glcr::CapBuffer& resp_caps);
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <glacier/string/str_split.h>
|
#include <glacier/string/str_split.h>
|
||||||
#include <mammoth/file/file.h>
|
#include <mammoth/file/file.h>
|
||||||
#include <mammoth/proc/process.h>
|
#include <mammoth/proc/process.h>
|
||||||
#include <zglobal.h>
|
#include <mammoth/util/init.h>
|
||||||
|
|
||||||
void Terminal::HandleCharacter(char c) {
|
void Terminal::HandleCharacter(char c) {
|
||||||
console_.WriteChar(c);
|
console_.WriteChar(c);
|
||||||
|
|
|
@ -21,7 +21,7 @@ uint64_t main(uint64_t init_port) {
|
||||||
YellowstoneClient client(gInitEndpointCap);
|
YellowstoneClient client(gInitEndpointCap);
|
||||||
|
|
||||||
FramebufferInfo framebuffer;
|
FramebufferInfo framebuffer;
|
||||||
RET_ERR(client.GetFramebufferInfo(framebuffer));
|
check(client.GetFramebufferInfo(framebuffer));
|
||||||
dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}",
|
dbgln("FB addr {x}, bpp {}, width {} , height {}, pitch {}",
|
||||||
framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(),
|
framebuffer.address_phys(), framebuffer.bpp(), framebuffer.width(),
|
||||||
framebuffer.height(), framebuffer.pitch());
|
framebuffer.height(), framebuffer.pitch());
|
||||||
|
|
|
@ -12,7 +12,11 @@ glcr::ErrorOr<glcr::SharedPtr<Ext2BlockReader>> Ext2BlockReader::Init(
|
||||||
req.set_lba(denali_info.lba_offset() + 2);
|
req.set_lba(denali_info.lba_offset() + 2);
|
||||||
req.set_size(2);
|
req.set_size(2);
|
||||||
ReadResponse resp;
|
ReadResponse resp;
|
||||||
RET_ERR(client.Read(req, resp));
|
auto status = client.Read(req, resp);
|
||||||
|
if (!status.ok()) {
|
||||||
|
dbgln("Failed to read superblock: {}", status.message());
|
||||||
|
return status.code();
|
||||||
|
}
|
||||||
mmth::OwnedMemoryRegion superblock =
|
mmth::OwnedMemoryRegion superblock =
|
||||||
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
|
|
||||||
|
@ -70,7 +74,11 @@ glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
|
||||||
req.set_lba(lba_offset_ + block_number * SectorsPerBlock());
|
req.set_lba(lba_offset_ + block_number * SectorsPerBlock());
|
||||||
req.set_size(num_blocks * SectorsPerBlock());
|
req.set_size(num_blocks * SectorsPerBlock());
|
||||||
ReadResponse resp;
|
ReadResponse resp;
|
||||||
RET_ERR(denali_.Read(req, resp));
|
auto status = denali_.Read(req, resp);
|
||||||
|
if (!status.ok()) {
|
||||||
|
dbgln("Failed to read blocks: {}", status.message());
|
||||||
|
return status.code();
|
||||||
|
}
|
||||||
return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +100,11 @@ glcr::ErrorOr<mmth::OwnedMemoryRegion> Ext2BlockReader::ReadBlocks(
|
||||||
}
|
}
|
||||||
dbgln("Read many: {x}", req.lba().size());
|
dbgln("Read many: {x}", req.lba().size());
|
||||||
ReadResponse resp;
|
ReadResponse resp;
|
||||||
RET_ERR(denali_.ReadMany(req, resp));
|
auto status = denali_.ReadMany(req, resp);
|
||||||
|
if (!status.ok()) {
|
||||||
|
dbgln("Failed to read blocks: {}", status.message());
|
||||||
|
return status.code();
|
||||||
|
}
|
||||||
return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
return mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ VFSClient::~VFSClient() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResponse& response) {
|
glcr::Status VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResponse& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -41,14 +41,14 @@ glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResp
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
@ -57,7 +57,7 @@ glcr::ErrorCode VFSClient::OpenFile(const OpenFileRequest& request, OpenFileResp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode VFSClient::GetDirectory(const GetDirectoryRequest& request, Directory& response) {
|
glcr::Status VFSClient::GetDirectory(const GetDirectoryRequest& request, Directory& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -80,14 +80,14 @@ glcr::ErrorCode VFSClient::GetDirectory(const GetDirectoryRequest& request, Dire
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
|
|
@ -20,11 +20,11 @@ class VFSClient {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode OpenFile(const OpenFileRequest& request, OpenFileResponse& response);
|
[[nodiscard]] glcr::Status OpenFile(const OpenFileRequest& request, OpenFileResponse& response);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode GetDirectory(const GetDirectoryRequest& request, Directory& response);
|
[[nodiscard]] glcr::Status GetDirectory(const GetDirectoryRequest& request, Directory& response);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
// Generated file -- DO NOT MODIFY.
|
||||||
#include "victoriafalls.yunq.h"
|
#include "victoriafalls.yunq.h"
|
||||||
|
|
||||||
|
#include <yunq/serialize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -11,38 +13,25 @@ struct ExtPointer {
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenFileRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status OpenFileRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse path.
|
// Parse path.
|
||||||
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -61,7 +50,7 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -83,27 +72,29 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_memory(0);
|
set_memory(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status OpenFileResponse::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
uint64_t memory_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
|
||||||
|
|
||||||
set_memory(caps.At(memory_ptr));
|
set_memory(caps.At(memory_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenFileResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status OpenFileResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse path.
|
// Parse path.
|
||||||
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
|
@ -113,6 +104,7 @@ void OpenFileResponse::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uin
|
||||||
// Parse memory.
|
// Parse memory.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -136,7 +128,7 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), 0);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -163,25 +155,28 @@ uint64_t OpenFileResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), next_cap++);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status GetDirectoryRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetDirectoryRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status GetDirectoryRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse path.
|
// Parse path.
|
||||||
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -200,7 +195,7 @@ uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -222,25 +217,28 @@ uint64_t GetDirectoryRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status Directory::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Directory::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status Directory::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse filenames.
|
// Parse filenames.
|
||||||
auto filenames_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto filenames_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_filenames(bytes.StringAt(offset + filenames_pointer.offset, filenames_pointer.length));
|
set_filenames(bytes.StringAt(offset + filenames_pointer.offset, filenames_pointer.length));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -259,7 +257,7 @@ uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) c
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -281,7 +279,7 @@ uint64_t Directory::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, g
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), filenames_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/container/vector.h>
|
#include <glacier/container/vector.h>
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
@ -15,8 +16,8 @@ class OpenFileRequest {
|
||||||
OpenFileRequest(const OpenFileRequest&) = delete;
|
OpenFileRequest(const OpenFileRequest&) = delete;
|
||||||
OpenFileRequest(OpenFileRequest&&) = delete;
|
OpenFileRequest(OpenFileRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& path() const { return path_; }
|
const glcr::String& path() const { return path_; }
|
||||||
|
@ -26,7 +27,7 @@ class OpenFileRequest {
|
||||||
glcr::String path_;
|
glcr::String path_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class OpenFileResponse {
|
class OpenFileResponse {
|
||||||
public:
|
public:
|
||||||
|
@ -35,8 +36,8 @@ class OpenFileResponse {
|
||||||
OpenFileResponse(const OpenFileResponse&) = delete;
|
OpenFileResponse(const OpenFileResponse&) = delete;
|
||||||
OpenFileResponse(OpenFileResponse&&) = delete;
|
OpenFileResponse(OpenFileResponse&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& path() const { return path_; }
|
const glcr::String& path() const { return path_; }
|
||||||
|
@ -52,7 +53,7 @@ class OpenFileResponse {
|
||||||
z_cap_t memory_;
|
z_cap_t memory_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class GetDirectoryRequest {
|
class GetDirectoryRequest {
|
||||||
public:
|
public:
|
||||||
|
@ -61,8 +62,8 @@ class GetDirectoryRequest {
|
||||||
GetDirectoryRequest(const GetDirectoryRequest&) = delete;
|
GetDirectoryRequest(const GetDirectoryRequest&) = delete;
|
||||||
GetDirectoryRequest(GetDirectoryRequest&&) = delete;
|
GetDirectoryRequest(GetDirectoryRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& path() const { return path_; }
|
const glcr::String& path() const { return path_; }
|
||||||
|
@ -72,7 +73,7 @@ class GetDirectoryRequest {
|
||||||
glcr::String path_;
|
glcr::String path_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class Directory {
|
class Directory {
|
||||||
public:
|
public:
|
||||||
|
@ -81,8 +82,8 @@ class Directory {
|
||||||
Directory(const Directory&) = delete;
|
Directory(const Directory&) = delete;
|
||||||
Directory(Directory&&) = delete;
|
Directory(Directory&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& filenames() const { return filenames_; }
|
const glcr::String& filenames() const { return filenames_; }
|
||||||
|
@ -92,6 +93,6 @@ class Directory {
|
||||||
glcr::String filenames_;
|
glcr::String filenames_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,10 @@ void VFSServerBase::ServerThread() {
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
glcr::ErrorCode reply_err = glcr::OK;
|
||||||
resp_cap.Reset();
|
resp_cap.Reset();
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (!err) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err.code());
|
||||||
|
dbgln("Responding Error {}", err.message());
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
@ -88,12 +89,12 @@ void VFSServerBase::ServerThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
glcr::Status VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
const glcr::CapBuffer& req_caps,
|
const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps) {
|
glcr::CapBuffer& resp_caps) {
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
if (request.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Request Not Valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
@ -103,7 +104,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
OpenFileRequest yunq_request;
|
OpenFileRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleOpenFile(yunq_request, yunq_response));
|
RETURN_ERROR(HandleOpenFile(yunq_request, yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
GetDirectoryRequest yunq_request;
|
GetDirectoryRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleGetDirectory(yunq_request, yunq_response));
|
RETURN_ERROR(HandleGetDirectory(yunq_request, yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,10 +141,10 @@ glcr::ErrorCode VFSServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::Unimplemented("Method unimplemented by server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <mammoth/proc/thread.h>
|
#include <mammoth/proc/thread.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -26,11 +27,11 @@ class VFSServerBase {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleOpenFile(const OpenFileRequest&, OpenFileResponse&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleOpenFile(const OpenFileRequest&, OpenFileResponse&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetDirectory(const GetDirectoryRequest&, Directory&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleGetDirectory(const GetDirectoryRequest&, Directory&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +41,7 @@ class VFSServerBase {
|
||||||
friend void VFSServerBaseThreadBootstrap(void*);
|
friend void VFSServerBaseThreadBootstrap(void*);
|
||||||
void ServerThread();
|
void ServerThread();
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps);
|
glcr::CapBuffer& resp_caps);
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,7 +16,7 @@ uint64_t main(uint64_t init_cap) {
|
||||||
|
|
||||||
YellowstoneClient yellowstone(gInitEndpointCap);
|
YellowstoneClient yellowstone(gInitEndpointCap);
|
||||||
DenaliInfo denali_info;
|
DenaliInfo denali_info;
|
||||||
RET_ERR(yellowstone.GetDenali(denali_info));
|
check(yellowstone.GetDenali(denali_info));
|
||||||
ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(denali_info));
|
ASSIGN_OR_RETURN(Ext2Driver ext2, Ext2Driver::Init(denali_info));
|
||||||
|
|
||||||
ASSIGN_OR_RETURN(auto server, VFSServer::Create(ext2));
|
ASSIGN_OR_RETURN(auto server, VFSServer::Create(ext2));
|
||||||
|
|
|
@ -11,13 +11,13 @@ glcr::ErrorOr<glcr::UniquePtr<VFSServer>> VFSServer::Create(
|
||||||
return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap, driver));
|
return glcr::UniquePtr<VFSServer>(new VFSServer(endpoint_cap, driver));
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
glcr::Status VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
||||||
OpenFileResponse& response) {
|
OpenFileResponse& response) {
|
||||||
auto path_tokens = glcr::StrSplit(request.path(), '/');
|
auto path_tokens = glcr::StrSplit(request.path(), '/');
|
||||||
// Require all paths to be absolute rather than relative.
|
// Require all paths to be absolute rather than relative.
|
||||||
// If the path starts with '/' then the first token will be empty.
|
// If the path starts with '/' then the first token will be empty.
|
||||||
if (path_tokens.at(0) != "") {
|
if (path_tokens.at(0) != "") {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Open file supports only absolute paths.");
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIGN_OR_RETURN(auto files, driver_.ReadDirectory(2));
|
ASSIGN_OR_RETURN(auto files, driver_.ReadDirectory(2));
|
||||||
|
@ -31,9 +31,8 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found_token) {
|
if (!found_token) {
|
||||||
dbgln("Directory '{}' not found.",
|
return glcr::NotFound(glcr::StrFormat("Directory '{}' not found.",
|
||||||
glcr::String(path_tokens.at(i)).cstr());
|
glcr::String(path_tokens.at(i))));
|
||||||
return glcr::NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +47,9 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!region) {
|
if (!region) {
|
||||||
dbgln("File '{}' not found.",
|
return glcr::NotFound(
|
||||||
glcr::String(path_tokens.at(path_tokens.size() - 1)).cstr());
|
glcr::StrFormat("File '{}' not found.",
|
||||||
|
glcr::String(path_tokens.at(path_tokens.size() - 1))));
|
||||||
}
|
}
|
||||||
|
|
||||||
response.set_path(request.path());
|
response.set_path(request.path());
|
||||||
|
@ -61,15 +61,15 @@ glcr::ErrorCode VFSServer::HandleOpenFile(const OpenFileRequest& request,
|
||||||
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
|
ASSIGN_OR_RETURN(Inode * inode, driver_.GetInode(inode_num));
|
||||||
// FIXME: This technically only sets the lower 32 bits.
|
// FIXME: This technically only sets the lower 32 bits.
|
||||||
response.set_size(inode->size);
|
response.set_size(inode->size);
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode VFSServer::HandleGetDirectory(
|
glcr::Status VFSServer::HandleGetDirectory(const GetDirectoryRequest& request,
|
||||||
const GetDirectoryRequest& request, Directory& response) {
|
Directory& response) {
|
||||||
auto path_tokens = glcr::StrSplit(request.path(), '/');
|
auto path_tokens = glcr::StrSplit(request.path(), '/');
|
||||||
|
|
||||||
if (path_tokens.at(0) != "") {
|
if (path_tokens.at(0) != "") {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Get Directory only supports absolute path.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a trailing slash we can get rid of the empty string.
|
// If there is a trailing slash we can get rid of the empty string.
|
||||||
|
@ -88,9 +88,8 @@ glcr::ErrorCode VFSServer::HandleGetDirectory(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found_token) {
|
if (!found_token) {
|
||||||
dbgln("Directory '{}' not found.",
|
return glcr::NotFound(glcr::StrFormat("Directory '{}' not found.",
|
||||||
glcr::String(path_tokens.at(i)).cstr());
|
glcr::String(path_tokens.at(i))));
|
||||||
return glcr::NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,5 +105,5 @@ glcr::ErrorCode VFSServer::HandleGetDirectory(
|
||||||
|
|
||||||
response.set_filenames(filelist.ToString());
|
response.set_filenames(filelist.ToString());
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ class VFSServer : public VFSServerBase {
|
||||||
public:
|
public:
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create(Ext2Driver& driver);
|
static glcr::ErrorOr<glcr::UniquePtr<VFSServer>> Create(Ext2Driver& driver);
|
||||||
|
|
||||||
glcr::ErrorCode HandleOpenFile(const OpenFileRequest&,
|
glcr::Status HandleOpenFile(const OpenFileRequest&,
|
||||||
OpenFileResponse&) override;
|
OpenFileResponse&) override;
|
||||||
|
|
||||||
glcr::ErrorCode HandleGetDirectory(const GetDirectoryRequest&,
|
glcr::Status HandleGetDirectory(const GetDirectoryRequest&,
|
||||||
Directory&) override;
|
Directory&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -18,7 +18,7 @@ VoyageursClient::~VoyageursClient() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request) {
|
glcr::Status VoyageursClient::RegisterKeyboardListener(const KeyboardListener& request) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -41,7 +41,7 @@ glcr::ErrorCode VoyageursClient::RegisterKeyboardListener(const KeyboardListener
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
|
|
|
@ -20,7 +20,7 @@ class VoyageursClient {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode RegisterKeyboardListener(const KeyboardListener& request);
|
[[nodiscard]] glcr::Status RegisterKeyboardListener(const KeyboardListener& request);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
// Generated file -- DO NOT MODIFY.
|
||||||
#include "voyageurs.yunq.h"
|
#include "voyageurs.yunq.h"
|
||||||
|
|
||||||
|
#include <yunq/serialize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -11,43 +13,30 @@ struct ExtPointer {
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse port_capability.
|
// Parse port_capability.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_port_capability(0);
|
set_port_capability(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status KeyboardListener::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse port_capability.
|
// Parse port_capability.
|
||||||
uint64_t port_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
uint64_t port_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_port_capability(caps.At(port_capability_ptr));
|
set_port_capability(caps.At(port_capability_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeyboardListener::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status KeyboardListener::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse port_capability.
|
// Parse port_capability.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -58,7 +47,7 @@ uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +61,7 @@ uint64_t KeyboardListener::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/container/vector.h>
|
#include <glacier/container/vector.h>
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
@ -15,8 +16,8 @@ class KeyboardListener {
|
||||||
KeyboardListener(const KeyboardListener&) = delete;
|
KeyboardListener(const KeyboardListener&) = delete;
|
||||||
KeyboardListener(KeyboardListener&&) = delete;
|
KeyboardListener(KeyboardListener&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const z_cap_t& port_capability() const { return port_capability_; }
|
const z_cap_t& port_capability() const { return port_capability_; }
|
||||||
|
@ -26,6 +27,6 @@ class KeyboardListener {
|
||||||
z_cap_t port_capability_;
|
z_cap_t port_capability_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,9 +73,10 @@ void VoyageursServerBase::ServerThread() {
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
glcr::ErrorCode reply_err = glcr::OK;
|
||||||
resp_cap.Reset();
|
resp_cap.Reset();
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (!err) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err.code());
|
||||||
|
dbgln("Responding Error {}", err.message());
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
@ -88,12 +89,12 @@ void VoyageursServerBase::ServerThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
glcr::Status VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
const glcr::CapBuffer& req_caps,
|
const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps) {
|
glcr::CapBuffer& resp_caps) {
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
if (request.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Request Not Valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
@ -103,13 +104,13 @@ glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& reque
|
||||||
|
|
||||||
|
|
||||||
KeyboardListener yunq_request;
|
KeyboardListener yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleRegisterKeyboardListener(yunq_request));
|
RETURN_ERROR(HandleRegisterKeyboardListener(yunq_request));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,10 +119,10 @@ glcr::ErrorCode VoyageursServerBase::HandleRequest(const glcr::ByteBuffer& reque
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::Unimplemented("Method unimplemented by server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <mammoth/proc/thread.h>
|
#include <mammoth/proc/thread.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ class VoyageursServerBase {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterKeyboardListener(const KeyboardListener&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleRegisterKeyboardListener(const KeyboardListener&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ class VoyageursServerBase {
|
||||||
friend void VoyageursServerBaseThreadBootstrap(void*);
|
friend void VoyageursServerBaseThreadBootstrap(void*);
|
||||||
void ServerThread();
|
void ServerThread();
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps);
|
glcr::CapBuffer& resp_caps);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,10 +8,10 @@ glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> VoyageursServer::Create(
|
||||||
new VoyageursServer(cap, keyboard_driver));
|
new VoyageursServer(cap, keyboard_driver));
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode VoyageursServer::HandleRegisterKeyboardListener(
|
glcr::Status VoyageursServer::HandleRegisterKeyboardListener(
|
||||||
const KeyboardListener& listener) {
|
const KeyboardListener& listener) {
|
||||||
keyboard_driver_.RegisterListener(listener.port_capability());
|
keyboard_driver_.RegisterListener(listener.port_capability());
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap,
|
VoyageursServer::VoyageursServer(z_cap_t voyageurs_cap,
|
||||||
|
|
|
@ -11,7 +11,7 @@ class VoyageursServer : public VoyageursServerBase {
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create(
|
static glcr::ErrorOr<glcr::UniquePtr<VoyageursServer>> Create(
|
||||||
KeyboardDriver& keyboard_driver);
|
KeyboardDriver& keyboard_driver);
|
||||||
|
|
||||||
virtual glcr::ErrorCode HandleRegisterKeyboardListener(
|
virtual glcr::Status HandleRegisterKeyboardListener(
|
||||||
const KeyboardListener& listener) override;
|
const KeyboardListener& listener) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
#include <mammoth/util/debug.h>
|
#include <mammoth/util/debug.h>
|
||||||
#include <mammoth/util/memory_region.h>
|
#include <mammoth/util/memory_region.h>
|
||||||
#include <zcall.h>
|
#include <zcall.h>
|
||||||
#include <zglobal.h>
|
|
||||||
|
|
||||||
#define GPT_DEBUG 0
|
#define GPT_DEBUG 0
|
||||||
|
|
||||||
|
@ -57,29 +56,29 @@ struct PartitionEntry {
|
||||||
GptReader::GptReader(glcr::UniquePtr<DenaliClient> denali)
|
GptReader::GptReader(glcr::UniquePtr<DenaliClient> denali)
|
||||||
: denali_(glcr::Move(denali)) {}
|
: denali_(glcr::Move(denali)) {}
|
||||||
|
|
||||||
glcr::ErrorCode GptReader::ParsePartitionTables() {
|
glcr::Status GptReader::ParsePartitionTables() {
|
||||||
ReadRequest req;
|
ReadRequest req;
|
||||||
req.set_device_id(0);
|
req.set_device_id(0);
|
||||||
req.set_lba(0);
|
req.set_lba(0);
|
||||||
req.set_size(2);
|
req.set_size(2);
|
||||||
ReadResponse resp;
|
ReadResponse resp;
|
||||||
RET_ERR(denali_->Read(req, resp));
|
RETURN_ERROR(denali_->Read(req, resp));
|
||||||
mmth::OwnedMemoryRegion lba_1_and_2 =
|
mmth::OwnedMemoryRegion lba_1_and_2 =
|
||||||
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
|
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
|
||||||
if (*mbr_sig != 0xAA55) {
|
if (*mbr_sig != 0xAA55) {
|
||||||
dbgln("Invalid MBR Sig: {x}", *mbr_sig);
|
return glcr::FailedPrecondition(
|
||||||
return glcr::FAILED_PRECONDITION;
|
glcr::StrFormat("Invalid MBR Sig: {x}", *mbr_sig));
|
||||||
}
|
}
|
||||||
MbrPartition* first_partition =
|
MbrPartition* first_partition =
|
||||||
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
|
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
|
||||||
if (first_partition->boot_indicator != 0) {
|
if (first_partition->boot_indicator != 0) {
|
||||||
dbgln("Boot indicator set: {}", first_partition->boot_indicator);
|
return glcr::FailedPrecondition(glcr::StrFormat(
|
||||||
return glcr::FAILED_PRECONDITION;
|
"Boot indicator set: {}", first_partition->boot_indicator));
|
||||||
}
|
}
|
||||||
if (first_partition->os_type != 0xEE) {
|
if (first_partition->os_type != 0xEE) {
|
||||||
dbgln("Incorrect OS type: {x}", first_partition->os_type);
|
return glcr::FailedPrecondition(
|
||||||
return glcr::FAILED_PRECONDITION;
|
glcr::StrFormat("Incorrect OS type: {x}", first_partition->os_type));
|
||||||
}
|
}
|
||||||
#if GPT_DEBUG
|
#if GPT_DEBUG
|
||||||
dbgln("LBAs: ({x}, {x})", first_partition->starting_lba,
|
dbgln("LBAs: ({x}, {x})", first_partition->starting_lba,
|
||||||
|
@ -105,7 +104,7 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
|
||||||
req.set_device_id(0);
|
req.set_device_id(0);
|
||||||
req.set_lba(header->lba_partition_entries);
|
req.set_lba(header->lba_partition_entries);
|
||||||
req.set_size(num_blocks);
|
req.set_size(num_blocks);
|
||||||
RET_ERR(denali_->Read(req, resp));
|
RETURN_ERROR(denali_->Read(req, resp));
|
||||||
mmth::OwnedMemoryRegion part_table =
|
mmth::OwnedMemoryRegion part_table =
|
||||||
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
mmth::OwnedMemoryRegion::FromCapability(resp.memory());
|
||||||
for (uint64_t i = 0; i < num_partitions; i++) {
|
for (uint64_t i = 0; i < num_partitions; i++) {
|
||||||
|
@ -130,5 +129,5 @@ glcr::ErrorCode GptReader::ParsePartitionTables() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class GptReader {
|
||||||
public:
|
public:
|
||||||
GptReader(glcr::UniquePtr<DenaliClient> denali);
|
GptReader(glcr::UniquePtr<DenaliClient> denali);
|
||||||
|
|
||||||
glcr::ErrorCode ParsePartitionTables();
|
glcr::Status ParsePartitionTables();
|
||||||
|
|
||||||
uint64_t GetPrimaryPartitionLba() { return primary_partition_lba_; }
|
uint64_t GetPrimaryPartitionLba() { return primary_partition_lba_; }
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ YellowstoneClient::~YellowstoneClient() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {
|
glcr::Status YellowstoneClient::RegisterEndpoint(const RegisterEndpointRequest& request) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -43,7 +43,7 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
|
@ -57,7 +57,7 @@ glcr::ErrorCode YellowstoneClient::RegisterEndpoint(const RegisterEndpointReques
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) {
|
glcr::Status YellowstoneClient::GetEndpoint(const GetEndpointRequest& request, Endpoint& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -80,14 +80,14 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
@ -96,7 +96,7 @@ glcr::ErrorCode YellowstoneClient::GetEndpoint(const GetEndpointRequest& request
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
glcr::Status YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -119,14 +119,14 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
@ -135,7 +135,7 @@ glcr::ErrorCode YellowstoneClient::GetAhciInfo(AhciInfo& response) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response) {
|
glcr::Status YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -158,14 +158,14 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response)
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
@ -174,7 +174,7 @@ glcr::ErrorCode YellowstoneClient::GetFramebufferInfo(FramebufferInfo& response)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneClient::GetDenali(DenaliInfo& response) {
|
glcr::Status YellowstoneClient::GetDenali(DenaliInfo& response) {
|
||||||
|
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -197,14 +197,14 @@ glcr::ErrorCode YellowstoneClient::GetDenali(DenaliInfo& response) {
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
|
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
|
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
|
|
@ -22,23 +22,23 @@ class YellowstoneClient {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode RegisterEndpoint(const RegisterEndpointRequest& request);
|
[[nodiscard]] glcr::Status RegisterEndpoint(const RegisterEndpointRequest& request);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode GetEndpoint(const GetEndpointRequest& request, Endpoint& response);
|
[[nodiscard]] glcr::Status GetEndpoint(const GetEndpointRequest& request, Endpoint& response);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode GetAhciInfo(AhciInfo& response);
|
[[nodiscard]] glcr::Status GetAhciInfo(AhciInfo& response);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode GetFramebufferInfo(FramebufferInfo& response);
|
[[nodiscard]] glcr::Status GetFramebufferInfo(FramebufferInfo& response);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode GetDenali(DenaliInfo& response);
|
[[nodiscard]] glcr::Status GetDenali(DenaliInfo& response);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
// Generated file -- DO NOT MODIFY.
|
||||||
#include "yellowstone.yunq.h"
|
#include "yellowstone.yunq.h"
|
||||||
|
|
||||||
|
#include <yunq/serialize.h>
|
||||||
|
|
||||||
|
|
||||||
namespace yellowstone {
|
namespace yellowstone {
|
||||||
|
|
||||||
|
@ -13,40 +15,26 @@ struct ExtPointer {
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
void RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse endpoint_capability.
|
// Parse endpoint_capability.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_endpoint_capability(0);
|
set_endpoint_capability(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status RegisterEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse endpoint_capability.
|
// Parse endpoint_capability.
|
||||||
uint64_t endpoint_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 1));
|
uint64_t endpoint_capability_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 1));
|
||||||
|
|
||||||
set_endpoint_capability(caps.At(endpoint_capability_ptr));
|
set_endpoint_capability(caps.At(endpoint_capability_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status RegisterEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse endpoint_name.
|
// Parse endpoint_name.
|
||||||
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
|
@ -54,6 +42,7 @@ void RegisterEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& byt
|
||||||
// Parse endpoint_capability.
|
// Parse endpoint_capability.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -75,7 +64,7 @@ uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), 0);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), 0);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -100,25 +89,28 @@ uint64_t RegisterEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), next_cap++);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), next_cap++);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status GetEndpointRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status GetEndpointRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse endpoint_name.
|
// Parse endpoint_name.
|
||||||
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
auto endpoint_name_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_endpoint_name(bytes.StringAt(offset + endpoint_name_pointer.offset, endpoint_name_pointer.length));
|
set_endpoint_name(bytes.StringAt(offset + endpoint_name_pointer.offset, endpoint_name_pointer.length));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -137,7 +129,7 @@ uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -159,30 +151,33 @@ uint64_t GetEndpointRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t
|
||||||
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), endpoint_name_ptr);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse endpoint.
|
// Parse endpoint.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_endpoint(0);
|
set_endpoint(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status Endpoint::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse endpoint.
|
// Parse endpoint.
|
||||||
uint64_t endpoint_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
uint64_t endpoint_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_endpoint(caps.At(endpoint_ptr));
|
set_endpoint(caps.At(endpoint_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Endpoint::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status Endpoint::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse endpoint.
|
// Parse endpoint.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -193,7 +188,7 @@ uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) co
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), 0);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -207,32 +202,35 @@ uint64_t Endpoint::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, gl
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 0), next_cap++);
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse ahci_region.
|
// Parse ahci_region.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_ahci_region(0);
|
set_ahci_region(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status AhciInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse ahci_region.
|
// Parse ahci_region.
|
||||||
uint64_t ahci_region_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
uint64_t ahci_region_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_ahci_region(caps.At(ahci_region_ptr));
|
set_ahci_region(caps.At(ahci_region_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AhciInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status AhciInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse ahci_region.
|
// Parse ahci_region.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
// Parse region_length.
|
// Parse region_length.
|
||||||
set_region_length(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
set_region_length(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -245,7 +243,7 @@ uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) co
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -261,20 +259,22 @@ uint64_t AhciInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, gl
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), region_length());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status FramebufferInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FramebufferInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status FramebufferInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse address_phys.
|
// Parse address_phys.
|
||||||
set_address_phys(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
set_address_phys(bytes.At<uint64_t>(offset + header_size + (8 * 0)));
|
||||||
// Parse width.
|
// Parse width.
|
||||||
|
@ -300,6 +300,7 @@ void FramebufferInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint
|
||||||
// Parse blue_mask_shift.
|
// Parse blue_mask_shift.
|
||||||
set_blue_mask_shift(bytes.At<uint64_t>(offset + header_size + (8 * 11)));
|
set_blue_mask_shift(bytes.At<uint64_t>(offset + header_size + (8 * 11)));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -331,7 +332,7 @@ uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -366,27 +367,29 @@ uint64_t FramebufferInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 11), blue_mask_shift());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
void DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse denali_endpoint.
|
// Parse denali_endpoint.
|
||||||
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
// FIXME: Implement in-buffer capabilities for inprocess serialization.
|
||||||
set_denali_endpoint(0);
|
set_denali_endpoint(0);
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status DenaliInfo::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
// Parse denali_endpoint.
|
// Parse denali_endpoint.
|
||||||
uint64_t denali_endpoint_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
uint64_t denali_endpoint_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 0));
|
||||||
|
|
||||||
set_denali_endpoint(caps.At(denali_endpoint_ptr));
|
set_denali_endpoint(caps.At(denali_endpoint_ptr));
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DenaliInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status DenaliInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
// Parse denali_endpoint.
|
// Parse denali_endpoint.
|
||||||
// Skip Cap.
|
// Skip Cap.
|
||||||
// Parse device_id.
|
// Parse device_id.
|
||||||
|
@ -394,6 +397,7 @@ void DenaliInfo::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t
|
||||||
// Parse lba_offset.
|
// Parse lba_offset.
|
||||||
set_lba_offset(bytes.At<uint64_t>(offset + header_size + (8 * 2)));
|
set_lba_offset(bytes.At<uint64_t>(offset + header_size + (8 * 2)));
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -408,7 +412,7 @@ uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset)
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +430,7 @@ uint64_t DenaliInfo::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset,
|
||||||
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 2), lba_offset());
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/container/vector.h>
|
#include <glacier/container/vector.h>
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
@ -17,8 +18,8 @@ class RegisterEndpointRequest {
|
||||||
RegisterEndpointRequest(const RegisterEndpointRequest&) = delete;
|
RegisterEndpointRequest(const RegisterEndpointRequest&) = delete;
|
||||||
RegisterEndpointRequest(RegisterEndpointRequest&&) = delete;
|
RegisterEndpointRequest(RegisterEndpointRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& endpoint_name() const { return endpoint_name_; }
|
const glcr::String& endpoint_name() const { return endpoint_name_; }
|
||||||
|
@ -31,7 +32,7 @@ class RegisterEndpointRequest {
|
||||||
z_cap_t endpoint_capability_;
|
z_cap_t endpoint_capability_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class GetEndpointRequest {
|
class GetEndpointRequest {
|
||||||
public:
|
public:
|
||||||
|
@ -40,8 +41,8 @@ class GetEndpointRequest {
|
||||||
GetEndpointRequest(const GetEndpointRequest&) = delete;
|
GetEndpointRequest(const GetEndpointRequest&) = delete;
|
||||||
GetEndpointRequest(GetEndpointRequest&&) = delete;
|
GetEndpointRequest(GetEndpointRequest&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const glcr::String& endpoint_name() const { return endpoint_name_; }
|
const glcr::String& endpoint_name() const { return endpoint_name_; }
|
||||||
|
@ -51,7 +52,7 @@ class GetEndpointRequest {
|
||||||
glcr::String endpoint_name_;
|
glcr::String endpoint_name_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class Endpoint {
|
class Endpoint {
|
||||||
public:
|
public:
|
||||||
|
@ -60,8 +61,8 @@ class Endpoint {
|
||||||
Endpoint(const Endpoint&) = delete;
|
Endpoint(const Endpoint&) = delete;
|
||||||
Endpoint(Endpoint&&) = delete;
|
Endpoint(Endpoint&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const z_cap_t& endpoint() const { return endpoint_; }
|
const z_cap_t& endpoint() const { return endpoint_; }
|
||||||
|
@ -71,7 +72,7 @@ class Endpoint {
|
||||||
z_cap_t endpoint_;
|
z_cap_t endpoint_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class AhciInfo {
|
class AhciInfo {
|
||||||
public:
|
public:
|
||||||
|
@ -80,8 +81,8 @@ class AhciInfo {
|
||||||
AhciInfo(const AhciInfo&) = delete;
|
AhciInfo(const AhciInfo&) = delete;
|
||||||
AhciInfo(AhciInfo&&) = delete;
|
AhciInfo(AhciInfo&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const z_cap_t& ahci_region() const { return ahci_region_; }
|
const z_cap_t& ahci_region() const { return ahci_region_; }
|
||||||
|
@ -94,7 +95,7 @@ class AhciInfo {
|
||||||
uint64_t region_length_;
|
uint64_t region_length_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class FramebufferInfo {
|
class FramebufferInfo {
|
||||||
public:
|
public:
|
||||||
|
@ -103,8 +104,8 @@ class FramebufferInfo {
|
||||||
FramebufferInfo(const FramebufferInfo&) = delete;
|
FramebufferInfo(const FramebufferInfo&) = delete;
|
||||||
FramebufferInfo(FramebufferInfo&&) = delete;
|
FramebufferInfo(FramebufferInfo&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const uint64_t& address_phys() const { return address_phys_; }
|
const uint64_t& address_phys() const { return address_phys_; }
|
||||||
|
@ -147,7 +148,7 @@ class FramebufferInfo {
|
||||||
uint64_t blue_mask_shift_;
|
uint64_t blue_mask_shift_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
class DenaliInfo {
|
class DenaliInfo {
|
||||||
public:
|
public:
|
||||||
|
@ -156,8 +157,8 @@ class DenaliInfo {
|
||||||
DenaliInfo(const DenaliInfo&) = delete;
|
DenaliInfo(const DenaliInfo&) = delete;
|
||||||
DenaliInfo(DenaliInfo&&) = delete;
|
DenaliInfo(DenaliInfo&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
const z_cap_t& denali_endpoint() const { return denali_endpoint_; }
|
const z_cap_t& denali_endpoint() const { return denali_endpoint_; }
|
||||||
|
@ -173,7 +174,7 @@ class DenaliInfo {
|
||||||
uint64_t lba_offset_;
|
uint64_t lba_offset_;
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,10 @@ void YellowstoneServerBase::ServerThread() {
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
glcr::ErrorCode reply_err = glcr::OK;
|
||||||
resp_cap.Reset();
|
resp_cap.Reset();
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (!err) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err.code());
|
||||||
|
dbgln("Responding Error {}", err.message());
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
@ -90,12 +91,12 @@ void YellowstoneServerBase::ServerThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
glcr::Status YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
const glcr::CapBuffer& req_caps,
|
const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps) {
|
glcr::CapBuffer& resp_caps) {
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
if (request.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Request Not Valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
@ -105,13 +106,13 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
RegisterEndpointRequest yunq_request;
|
RegisterEndpointRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleRegisterEndpoint(yunq_request));
|
RETURN_ERROR(HandleRegisterEndpoint(yunq_request));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,7 +124,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
GetEndpointRequest yunq_request;
|
GetEndpointRequest yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,7 +132,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleGetEndpoint(yunq_request, yunq_response));
|
RETURN_ERROR(HandleGetEndpoint(yunq_request, yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -148,7 +149,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleGetAhciInfo(yunq_response));
|
RETURN_ERROR(HandleGetAhciInfo(yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleGetFramebufferInfo(yunq_response));
|
RETURN_ERROR(HandleGetFramebufferInfo(yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,7 +183,7 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
RET_ERR(HandleGetDenali(yunq_response));
|
RETURN_ERROR(HandleGetDenali(yunq_response));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -191,10 +192,10 @@ glcr::ErrorCode YellowstoneServerBase::HandleRequest(const glcr::ByteBuffer& req
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::Unimplemented("Method unimplemented by server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <mammoth/proc/thread.h>
|
#include <mammoth/proc/thread.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -28,23 +29,23 @@ class YellowstoneServerBase {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleRegisterEndpoint(const RegisterEndpointRequest&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleRegisterEndpoint(const RegisterEndpointRequest&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleGetAhciInfo(AhciInfo&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleGetFramebufferInfo(FramebufferInfo&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] virtual glcr::ErrorCode HandleGetDenali(DenaliInfo&) = 0;
|
[[nodiscard]] virtual glcr::Status HandleGetDenali(DenaliInfo&) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,7 +55,7 @@ class YellowstoneServerBase {
|
||||||
friend void YellowstoneServerBaseThreadBootstrap(void*);
|
friend void YellowstoneServerBaseThreadBootstrap(void*);
|
||||||
void ServerThread();
|
void ServerThread();
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps);
|
glcr::CapBuffer& resp_caps);
|
||||||
};
|
};
|
||||||
|
|
|
@ -23,7 +23,11 @@ glcr::ErrorOr<PartitionInfo> HandleDenaliRegistration(z_cap_t endpoint_cap) {
|
||||||
GptReader reader(
|
GptReader reader(
|
||||||
glcr::UniquePtr<DenaliClient>(new DenaliClient(endpoint_cap)));
|
glcr::UniquePtr<DenaliClient>(new DenaliClient(endpoint_cap)));
|
||||||
|
|
||||||
RET_ERR(reader.ParsePartitionTables());
|
auto status = reader.ParsePartitionTables();
|
||||||
|
if (!status.ok()) {
|
||||||
|
dbgln("GPT Reader: {}", status.message());
|
||||||
|
return status.code();
|
||||||
|
}
|
||||||
|
|
||||||
return PartitionInfo{.device_id = 0,
|
return PartitionInfo{.device_id = 0,
|
||||||
.partition_lba = reader.GetPrimaryPartitionLba()};
|
.partition_lba = reader.GetPrimaryPartitionLba()};
|
||||||
|
@ -42,13 +46,13 @@ glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> YellowstoneServer::Create() {
|
||||||
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
|
YellowstoneServer::YellowstoneServer(z_cap_t endpoint_cap)
|
||||||
: YellowstoneServerBase(endpoint_cap) {}
|
: YellowstoneServerBase(endpoint_cap) {}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServer::HandleGetAhciInfo(AhciInfo& info) {
|
glcr::Status YellowstoneServer::HandleGetAhciInfo(AhciInfo& info) {
|
||||||
info.set_ahci_region(pci_reader_.GetAhciVmmo());
|
info.set_ahci_region(pci_reader_.GetAhciVmmo());
|
||||||
info.set_region_length(kPcieConfigurationSize);
|
info.set_region_length(kPcieConfigurationSize);
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
|
glcr::Status YellowstoneServer::HandleGetFramebufferInfo(
|
||||||
FramebufferInfo& info) {
|
FramebufferInfo& info) {
|
||||||
// FIXME: Don't do this for each request.
|
// FIXME: Don't do this for each request.
|
||||||
mmth::OwnedMemoryRegion region =
|
mmth::OwnedMemoryRegion region =
|
||||||
|
@ -68,22 +72,22 @@ glcr::ErrorCode YellowstoneServer::HandleGetFramebufferInfo(
|
||||||
info.set_blue_mask_size(fb->blue_mask_size);
|
info.set_blue_mask_size(fb->blue_mask_size);
|
||||||
info.set_blue_mask_shift(fb->blue_mask_shift);
|
info.set_blue_mask_shift(fb->blue_mask_shift);
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServer::HandleGetDenali(DenaliInfo& info) {
|
glcr::Status YellowstoneServer::HandleGetDenali(DenaliInfo& info) {
|
||||||
if (!endpoint_map_.Contains("denali")) {
|
if (!endpoint_map_.Contains("denali")) {
|
||||||
return glcr::NOT_FOUND;
|
return glcr::NotFound("Denali Capability Not registered");
|
||||||
}
|
}
|
||||||
z_cap_t new_denali;
|
z_cap_t new_denali;
|
||||||
check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali));
|
check(ZCapDuplicate(endpoint_map_.at("denali"), kZionPerm_All, &new_denali));
|
||||||
info.set_denali_endpoint(new_denali);
|
info.set_denali_endpoint(new_denali);
|
||||||
info.set_device_id(device_id_);
|
info.set_device_id(device_id_);
|
||||||
info.set_lba_offset(lba_offset_);
|
info.set_lba_offset(lba_offset_);
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
glcr::Status YellowstoneServer::HandleRegisterEndpoint(
|
||||||
const RegisterEndpointRequest& req) {
|
const RegisterEndpointRequest& req) {
|
||||||
dbgln("Registering {}.", req.endpoint_name().view());
|
dbgln("Registering {}.", req.endpoint_name().view());
|
||||||
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
|
check(endpoint_map_.Insert(req.endpoint_name(), req.endpoint_capability()));
|
||||||
|
@ -106,19 +110,20 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
|
||||||
} else {
|
} else {
|
||||||
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
|
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode YellowstoneServer::HandleGetEndpoint(
|
glcr::Status YellowstoneServer::HandleGetEndpoint(const GetEndpointRequest& req,
|
||||||
const GetEndpointRequest& req, Endpoint& resp) {
|
Endpoint& resp) {
|
||||||
if (!endpoint_map_.Contains(req.endpoint_name())) {
|
if (!endpoint_map_.Contains(req.endpoint_name())) {
|
||||||
return glcr::NOT_FOUND;
|
return glcr::NotFound(
|
||||||
|
glcr::StrFormat("Endpoint '{}' not found.", req.endpoint_name()));
|
||||||
}
|
}
|
||||||
z_cap_t cap = endpoint_map_.at(req.endpoint_name());
|
z_cap_t cap = endpoint_map_.at(req.endpoint_name());
|
||||||
z_cap_t new_cap;
|
z_cap_t new_cap;
|
||||||
check(ZCapDuplicate(cap, kZionPerm_All, &new_cap));
|
check(ZCapDuplicate(cap, kZionPerm_All, &new_cap));
|
||||||
resp.set_endpoint(new_cap);
|
resp.set_endpoint(new_cap);
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
|
void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
|
||||||
|
|
|
@ -16,13 +16,11 @@ class YellowstoneServer : public YellowstoneServerBase {
|
||||||
public:
|
public:
|
||||||
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
|
static glcr::ErrorOr<glcr::UniquePtr<YellowstoneServer>> Create();
|
||||||
|
|
||||||
glcr::ErrorCode HandleGetAhciInfo(AhciInfo&) override;
|
glcr::Status HandleGetAhciInfo(AhciInfo&) override;
|
||||||
glcr::ErrorCode HandleGetFramebufferInfo(FramebufferInfo&) override;
|
glcr::Status HandleGetFramebufferInfo(FramebufferInfo&) override;
|
||||||
glcr::ErrorCode HandleGetDenali(DenaliInfo&) override;
|
glcr::Status HandleGetDenali(DenaliInfo&) override;
|
||||||
glcr::ErrorCode HandleRegisterEndpoint(
|
glcr::Status HandleRegisterEndpoint(const RegisterEndpointRequest&) override;
|
||||||
const RegisterEndpointRequest&) override;
|
glcr::Status HandleGetEndpoint(const GetEndpointRequest&, Endpoint&) override;
|
||||||
glcr::ErrorCode HandleGetEndpoint(const GetEndpointRequest&,
|
|
||||||
Endpoint&) override;
|
|
||||||
|
|
||||||
void WaitDenaliRegistered();
|
void WaitDenaliRegistered();
|
||||||
void WaitVictoriaFallsRegistered();
|
void WaitVictoriaFallsRegistered();
|
||||||
|
|
|
@ -17,6 +17,8 @@ macro(yunq_gen dir include_dir name)
|
||||||
|
|
||||||
target_link_libraries(${target}
|
target_link_libraries(${target}
|
||||||
mammoth
|
mammoth
|
||||||
|
glacier
|
||||||
|
yunq
|
||||||
)
|
)
|
||||||
set_target_properties(${target} PROPERTIES
|
set_target_properties(${target} PROPERTIES
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||||
|
|
|
@ -20,11 +20,11 @@ namespace {{package.cpp_namespace()}} {
|
||||||
{% for method in interface.methods %}
|
{% for method in interface.methods %}
|
||||||
|
|
||||||
{% if method.request == None %}
|
{% if method.request == None %}
|
||||||
glcr::ErrorCode {{interface.name}}Client::{{method.name}}({{method.response}}& response) {
|
glcr::Status {{interface.name}}Client::{{method.name}}({{method.response}}& response) {
|
||||||
{% elif method.response == None %}
|
{% elif method.response == None %}
|
||||||
glcr::ErrorCode {{interface.name}}Client::{{method.name}}(const {{method.request}}& request) {
|
glcr::Status {{interface.name}}Client::{{method.name}}(const {{method.request}}& request) {
|
||||||
{% else %}
|
{% else %}
|
||||||
glcr::ErrorCode {{interface.name}}Client::{{method.name}}(const {{method.request}}& request, {{method.response}}& response) {
|
glcr::Status {{interface.name}}Client::{{method.name}}(const {{method.request}}& request, {{method.response}}& response) {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
uint64_t buffer_size = kBufferSize;
|
uint64_t buffer_size = kBufferSize;
|
||||||
uint64_t cap_size = kCapBufferSize;
|
uint64_t cap_size = kCapBufferSize;
|
||||||
|
@ -49,14 +49,14 @@ glcr::ErrorCode {{interface.name}}Client::{{method.name}}(const {{method.request
|
||||||
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr()));
|
||||||
|
|
||||||
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
if (buffer_.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_RESPONSE;
|
return glcr::InvalidResponse("Got an invalid response from server.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Response Code.
|
// Check Response Code.
|
||||||
RET_ERR(buffer_.At<uint64_t>(8));
|
RET_ERR(buffer_.At<uint64_t>(8));
|
||||||
|
|
||||||
{% if method.response != None %}
|
{% if method.response != None %}
|
||||||
response.ParseFromBytes(buffer_, 16, cap_buffer_);
|
RETURN_ERROR(response.ParseFromBytes(buffer_, 16, cap_buffer_));
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
return glcr::OK;
|
return glcr::OK;
|
||||||
|
|
|
@ -23,11 +23,11 @@ class {{interface.name}}Client {
|
||||||
|
|
||||||
{% for method in interface.methods %}
|
{% for method in interface.methods %}
|
||||||
{% if method.request == None %}
|
{% if method.request == None %}
|
||||||
[[nodiscard]] glcr::ErrorCode {{method.name}}({{method.response}}& response);
|
[[nodiscard]] glcr::Status {{method.name}}({{method.response}}& response);
|
||||||
{% elif method.response == None %}
|
{% elif method.response == None %}
|
||||||
[[nodiscard]] glcr::ErrorCode {{method.name}}(const {{method.request}}& request);
|
[[nodiscard]] glcr::Status {{method.name}}(const {{method.request}}& request);
|
||||||
{% else %}
|
{% else %}
|
||||||
[[nodiscard]] glcr::ErrorCode {{method.name}}(const {{method.request}}& request, {{method.response}}& response);
|
[[nodiscard]] glcr::Status {{method.name}}(const {{method.request}}& request, {{method.response}}& response);
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// Generated file -- DO NOT MODIFY.
|
// Generated file -- DO NOT MODIFY.
|
||||||
#include "{{file}}.h"
|
#include "{{file}}.h"
|
||||||
|
|
||||||
|
#include <yunq/serialize.h>
|
||||||
|
|
||||||
{% if package != None %}
|
{% if package != None %}
|
||||||
namespace {{package.cpp_namespace()}} {
|
namespace {{package.cpp_namespace()}} {
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -13,27 +15,11 @@ struct ExtPointer {
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
void CheckHeader(const glcr::ByteBuffer& bytes) {
|
|
||||||
// TODO: Check ident.
|
|
||||||
// TODO: Parse core size.
|
|
||||||
// TODO: Parse extension size.
|
|
||||||
// TODO: Check CRC32
|
|
||||||
// TODO: Parse options.
|
|
||||||
}
|
|
||||||
|
|
||||||
void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, uint32_t extension_size) {
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 0, 0xDEADBEEF); // TODO: Chose a more unique ident sequence.
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 4, core_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 8, extension_size);
|
|
||||||
bytes.WriteAt<uint32_t>(offset + 12, 0); // TODO: Calculate CRC32.
|
|
||||||
bytes.WriteAt<uint64_t>(offset + 16, 0); // TODO: Add options.
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
{%- for message in messages %}
|
{%- for message in messages %}
|
||||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
{%- if field.type == Type.CAPABILITY %}
|
{%- if field.type == Type.CAPABILITY %}
|
||||||
|
@ -42,10 +28,11 @@ void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
|
||||||
set_{{field.name}}(0);
|
set_{{field.name}}(0);
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
glcr::Status {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
|
||||||
ParseFromBytesInternal(bytes, offset);
|
RETURN_ERROR(ParseFromBytesInternal(bytes, offset));
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
{%- if field.type == Type.CAPABILITY %}
|
{%- if field.type == Type.CAPABILITY %}
|
||||||
|
@ -55,10 +42,11 @@ void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
|
||||||
set_{{field.name}}(caps.At({{field.name}}_ptr));
|
set_{{field.name}}(caps.At({{field.name}}_ptr));
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
glcr::Status {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
|
||||||
CheckHeader(bytes);
|
RETURN_ERROR(yunq::CheckHeader(bytes, offset));
|
||||||
|
|
||||||
{%- for field in message.fields %}
|
{%- for field in message.fields %}
|
||||||
// Parse {{field.name}}.
|
// Parse {{field.name}}.
|
||||||
|
@ -88,6 +76,7 @@ void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uin
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
|
||||||
|
@ -135,7 +124,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +175,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
// The next extension pointer is the length of the message.
|
// The next extension pointer is the length of the message.
|
||||||
WriteHeader(bytes, offset, core_size, next_extension);
|
yunq::WriteHeader(bytes, offset, core_size, next_extension);
|
||||||
|
|
||||||
return next_extension;
|
return next_extension;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <glacier/buffer/byte_buffer.h>
|
#include <glacier/buffer/byte_buffer.h>
|
||||||
#include <glacier/buffer/cap_buffer.h>
|
#include <glacier/buffer/cap_buffer.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <glacier/container/vector.h>
|
#include <glacier/container/vector.h>
|
||||||
#include <glacier/string/string.h>
|
#include <glacier/string/string.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
@ -19,8 +20,8 @@ class {{message.name}} {
|
||||||
{{message.name}}(const {{message.name}}&) = delete;
|
{{message.name}}(const {{message.name}}&) = delete;
|
||||||
{{message.name}}({{message.name}}&&) = delete;
|
{{message.name}}({{message.name}}&&) = delete;
|
||||||
|
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
[[nodiscard]] glcr::Status ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset, const glcr::CapBuffer&);
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const;
|
||||||
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
|
||||||
|
|
||||||
|
@ -44,7 +45,7 @@ class {{message.name}} {
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
// Parses everything except for caps.
|
// Parses everything except for caps.
|
||||||
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
glcr::Status ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
|
||||||
};
|
};
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,10 @@ void {{interface.name}}ServerBase::ServerThread() {
|
||||||
|
|
||||||
glcr::ErrorCode reply_err = glcr::OK;
|
glcr::ErrorCode reply_err = glcr::OK;
|
||||||
resp_cap.Reset();
|
resp_cap.Reset();
|
||||||
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
|
||||||
if (err != glcr::OK) {
|
if (!err) {
|
||||||
WriteError(resp_buffer, err);
|
WriteError(resp_buffer, err.code());
|
||||||
|
dbgln("Responding Error {}", err.message());
|
||||||
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
reply_err = static_cast<glcr::ErrorCode>(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr));
|
||||||
} else {
|
} else {
|
||||||
WriteHeader(resp_buffer, resp_length);
|
WriteHeader(resp_buffer, resp_length);
|
||||||
|
@ -90,12 +91,12 @@ void {{interface.name}}ServerBase::ServerThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
glcr::Status {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuffer& request,
|
||||||
const glcr::CapBuffer& req_caps,
|
const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps) {
|
glcr::CapBuffer& resp_caps) {
|
||||||
if (request.At<uint32_t>(0) != kSentinel) {
|
if (request.At<uint32_t>(0) != kSentinel) {
|
||||||
return glcr::INVALID_ARGUMENT;
|
return glcr::InvalidArgument("Request Not Valid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t method_select = request.At<uint64_t>(8);
|
uint64_t method_select = request.At<uint64_t>(8);
|
||||||
|
@ -106,7 +107,7 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
|
||||||
|
|
||||||
{% if method.request != None %}
|
{% if method.request != None %}
|
||||||
{{method.request}} yunq_request;
|
{{method.request}} yunq_request;
|
||||||
yunq_request.ParseFromBytes(request, kHeaderSize, req_caps);
|
RETURN_ERROR(yunq_request.ParseFromBytes(request, kHeaderSize, req_caps));
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if method.response != None %}
|
{% if method.response != None %}
|
||||||
|
@ -114,11 +115,11 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if method.request == None %}
|
{% if method.request == None %}
|
||||||
RET_ERR(Handle{{method.name}}(yunq_response));
|
RETURN_ERROR(Handle{{method.name}}(yunq_response));
|
||||||
{% elif method.response == None %}
|
{% elif method.response == None %}
|
||||||
RET_ERR(Handle{{method.name}}(yunq_request));
|
RETURN_ERROR(Handle{{method.name}}(yunq_request));
|
||||||
{% else %}
|
{% else %}
|
||||||
RET_ERR(Handle{{method.name}}(yunq_request, yunq_response));
|
RETURN_ERROR(Handle{{method.name}}(yunq_request, yunq_response));
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if method.response != None %}
|
{% if method.response != None %}
|
||||||
|
@ -130,10 +131,10 @@ glcr::ErrorCode {{interface.name}}ServerBase::HandleRequest(const glcr::ByteBuff
|
||||||
}
|
}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
default: {
|
default: {
|
||||||
return glcr::UNIMPLEMENTED;
|
return glcr::Unimplemented("Method unimplemented by server.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return glcr::OK;
|
return glcr::Status::Ok();
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glacier/status/error_or.h>
|
#include <glacier/status/error_or.h>
|
||||||
|
#include <glacier/status/status.h>
|
||||||
#include <mammoth/proc/thread.h>
|
#include <mammoth/proc/thread.h>
|
||||||
#include <ztypes.h>
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
@ -28,11 +29,11 @@ class {{interface.name}}ServerBase {
|
||||||
|
|
||||||
{% for method in interface.methods %}
|
{% for method in interface.methods %}
|
||||||
{% if method.request == None %}
|
{% if method.request == None %}
|
||||||
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}({{method.response}}&) = 0;
|
[[nodiscard]] virtual glcr::Status Handle{{method.name}}({{method.response}}&) = 0;
|
||||||
{% elif method.response == None %}
|
{% elif method.response == None %}
|
||||||
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}(const {{method.request}}&) = 0;
|
[[nodiscard]] virtual glcr::Status Handle{{method.name}}(const {{method.request}}&) = 0;
|
||||||
{% else %}
|
{% else %}
|
||||||
[[nodiscard]] virtual glcr::ErrorCode Handle{{method.name}}(const {{method.request}}&, {{method.response}}&) = 0;
|
[[nodiscard]] virtual glcr::Status Handle{{method.name}}(const {{method.request}}&, {{method.response}}&) = 0;
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ class {{interface.name}}ServerBase {
|
||||||
friend void {{interface.name}}ServerBaseThreadBootstrap(void*);
|
friend void {{interface.name}}ServerBaseThreadBootstrap(void*);
|
||||||
void ServerThread();
|
void ServerThread();
|
||||||
|
|
||||||
[[nodiscard]] glcr::ErrorCode HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
[[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps,
|
||||||
glcr::ByteBuffer& response, uint64_t& resp_length,
|
glcr::ByteBuffer& response, uint64_t& resp_length,
|
||||||
glcr::CapBuffer& resp_caps);
|
glcr::CapBuffer& resp_caps);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,6 @@ def main():
|
||||||
|
|
||||||
parser = Parser(lexemes)
|
parser = Parser(lexemes)
|
||||||
ast = parser.parse()
|
ast = parser.parse()
|
||||||
print_ast(ast)
|
|
||||||
type_check(ast)
|
type_check(ast)
|
||||||
|
|
||||||
messages = [m for m in ast if type(m) is Message]
|
messages = [m for m in ast if type(m) is Message]
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
extern uint64_t gSelfProcCap;
|
|
||||||
extern uint64_t gSelfVmasCap;
|
|
||||||
|
|
||||||
extern uint64_t gInitEndpointCap;
|
|
||||||
|
|
||||||
extern uint64_t gBootDenaliVmmoCap;
|
|
||||||
extern uint64_t gBootVictoriaFallsVmmoCap;
|
|
||||||
extern uint64_t gBootPciVmmoCap;
|
|
||||||
extern uint64_t gBootFramebufferVmmoCap;
|
|
Loading…
Reference in New Issue