diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a74759..7332fe2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,6 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") project(AcadiaOS VERSION 0.0.1 LANGUAGES CXX ASM-ATT) -include(CTest) - set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_EXPORT_COMPILE_COMMANDS True) @@ -14,8 +12,16 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS True) set(BASE_COMPILE_FLAGS "-ffreestanding -fno-rtti -fno-exceptions -mincoming-stack-boundary=3") set(BASE_LINK_FLAGS "-nostdlib") +if (enable_testing) + include(CTest) + find_package(Catch2 3 REQUIRED) + find_program(MEMORYCHECK_COMMAND valgrind) + set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full") + add_custom_target(build_test) +endif() + add_subdirectory(zion) -add_subdirectory(lib) add_subdirectory(yunq) +add_subdirectory(lib) add_subdirectory(usr) add_subdirectory(sys) diff --git a/lib/glacier/test/CMakeLists.txt b/lib/glacier/test/CMakeLists.txt index 1396d3b..c3701f7 100644 --- a/lib/glacier/test/CMakeLists.txt +++ b/lib/glacier/test/CMakeLists.txt @@ -1,10 +1,2 @@ -find_package(Catch2 3 REQUIRED) -find_program(MEMORYCHECK_COMMAND valgrind) -set(MEMORYCHECK_COMMAND_OPTIONS "--trace-children=yes --leak-check=full") - add_subdirectory(container) -add_custom_target(build_test) -add_dependencies(build_test - glc_vec_test) - diff --git a/lib/glacier/test/container/CMakeLists.txt b/lib/glacier/test/container/CMakeLists.txt index 2fad536..f5488ab 100644 --- a/lib/glacier/test/container/CMakeLists.txt +++ b/lib/glacier/test/container/CMakeLists.txt @@ -2,3 +2,7 @@ add_executable(glc_vec_test vector.cpp) target_link_libraries(glc_vec_test glacier Catch2::Catch2WithMain) target_include_directories(glc_vec_test PRIVATE "../..") add_test(NAME glc_vec_test COMMAND $) + +add_dependencies(build_test + glc_vec_test) + diff --git a/lib/yunq/CMakeLists.txt b/lib/yunq/CMakeLists.txt index 5fd7a31..2c87371 100644 --- a/lib/yunq/CMakeLists.txt +++ b/lib/yunq/CMakeLists.txt @@ -16,3 +16,7 @@ target_include_directories(yunq set_target_properties(yunq PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}") + +if (enable_testing) + add_subdirectory(test) +endif() diff --git a/lib/yunq/test/CMakeLists.txt b/lib/yunq/test/CMakeLists.txt new file mode 100644 index 0000000..c66b271 --- /dev/null +++ b/lib/yunq/test/CMakeLists.txt @@ -0,0 +1,42 @@ +add_executable(yunq_test yunq_test.cpp) + +add_dependencies(yunq_test + example_yunq) + +target_link_libraries(yunq_test + Catch2::Catch2WithMain + example_yunq) + +target_include_directories(yunq_test PRIVATE "." "../../../zion/include") + +add_test(NAME yunq_test COMMAND $) + +add_dependencies(build_test + yunq_test) + + +# Build the yunq manualy rather than using the generator +# because we don't want to link against mammoth and overrite new. +set(target example_yunq) +add_library(example_yunq + ${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq.cpp + ) + +target_include_directories(example_yunq + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/example" + ) + +target_link_libraries(${target} + glacier + yunq + zion_stub +) + +set(PYTHON "${CMAKE_SOURCE_DIR}/yunq/venv/bin/python") +set(YUNQ "${CMAKE_SOURCE_DIR}/yunq/yunq.py") + +add_custom_command( + OUTPUT example/example.yunq.cpp + COMMAND ${PYTHON} ${YUNQ} ${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/example/example.yunq +) diff --git a/lib/yunq/test/example/example.yunq b/lib/yunq/test/example/example.yunq new file mode 100644 index 0000000..eaf2a9f --- /dev/null +++ b/lib/yunq/test/example/example.yunq @@ -0,0 +1,5 @@ +package ex; + +message Basic { + u64 field; +} diff --git a/lib/yunq/test/example/example.yunq.cpp b/lib/yunq/test/example/example.yunq.cpp new file mode 100644 index 0000000..7b5733e --- /dev/null +++ b/lib/yunq/test/example/example.yunq.cpp @@ -0,0 +1,58 @@ +// Generated file -- DO NOT MODIFY. +#include "example.yunq.h" + +#include +#include + + +namespace ex { + +namespace { + +const uint64_t header_size = 24; // 4x uint32, 1x uint64 + +struct ExtPointer { + uint32_t offset; + uint32_t length; +}; + +} // namespace +glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message) { + RETURN_ERROR(ParseFromBytesInternal(message)); + return glcr::Status::Ok(); +} + +glcr::Status Basic::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { + RETURN_ERROR(ParseFromBytesInternal(message)); + return glcr::Status::Ok(); +} + +glcr::Status Basic::ParseFromBytesInternal(const yunq::MessageView& message) { + RETURN_ERROR(message.CheckHeader()); + // Parse field. + ASSIGN_OR_RETURN(field_, message.ReadField(0)); + + return glcr::Status::Ok(); +} + +uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { + yunq::Serializer serializer(bytes, offset, 1); + return SerializeInternal(serializer); +} + +uint64_t Basic::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { + yunq::Serializer serializer(bytes, offset, 1, caps); + return SerializeInternal(serializer); +} + +uint64_t Basic::SerializeInternal(yunq::Serializer& serializer) const { + // Write field. + serializer.WriteField(0, field_); + + serializer.WriteHeader(); + + return serializer.size(); +} + + +} // namepace ex diff --git a/lib/yunq/test/example/example.yunq.h b/lib/yunq/test/example/example.yunq.h new file mode 100644 index 0000000..bbaab36 --- /dev/null +++ b/lib/yunq/test/example/example.yunq.h @@ -0,0 +1,43 @@ +// Generated file - DO NOT MODIFY +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace ex { + +class Basic { + public: + Basic() {} + // Delete copy and move until implemented. + Basic(const Basic&) = delete; + Basic(Basic&&) = default; + Basic& operator=(Basic&&) = default; + + [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message); + [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&); + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; + uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; + + const uint64_t& field() const { return field_; } + uint64_t& mutable_field() { return field_; } + void set_field(const uint64_t& value) { field_ = value; } + + private: + uint64_t field_; + + // Parses everything except for caps. + glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); + + uint64_t SerializeInternal(yunq::Serializer& serializer) const; +}; + + +} // namepace ex diff --git a/lib/yunq/test/yunq_test.cpp b/lib/yunq/test/yunq_test.cpp new file mode 100644 index 0000000..126fdef --- /dev/null +++ b/lib/yunq/test/yunq_test.cpp @@ -0,0 +1,23 @@ +#include + +#include "example/example.yunq.h" + +TEST_CASE("Basic Setter/Getter", "[yunq]") { + ex::Basic b; + b.set_field(1); + REQUIRE(b.field() == 1); +} + +TEST_CASE("Basic serialization", "[yunq]") { + ex::Basic a; + a.set_field(1); + + glcr::ByteBuffer buf(1024); + a.SerializeToBytes(buf, 0); + + ex::Basic b; + yunq::MessageView v(buf, 0); + REQUIRE(b.ParseFromBytes(v).ok() == true); + + REQUIRE(b.field() == 1); +} diff --git a/sys/denali/lib/denali/denali.yunq.client.cpp b/sys/denali/lib/denali/denali.yunq.client.cpp deleted file mode 100644 index 09e6f6a..0000000 --- a/sys/denali/lib/denali/denali.yunq.client.cpp +++ /dev/null @@ -1,100 +0,0 @@ -// Generated file - DO NOT MODIFY -#include "denali.yunq.client.h" - -#include -#include -#include -#include - - - - -DenaliClient::~DenaliClient() { - if (endpoint_ != 0) { - check(ZCapRelease(endpoint_)); - } -} - - - - -glcr::Status DenaliClient::Read(const ReadRequest& request, ReadResponse& response) { - - uint64_t buffer_size = kBufferSize; - uint64_t cap_size = kCapBufferSize; - - const uint32_t kSentinel = 0xBEEFDEAD; - buffer_.WriteAt(0, kSentinel); - buffer_.WriteAt(8, 0); - - cap_buffer_.Reset(); - - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); - - - buffer_.WriteAt(4, 16 + length); - - z_cap_t reply_port_cap; - RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); - - // FIXME: Add a way to zero out the first buffer. - RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); - - if (buffer_.At(0) != kSentinel) { - return glcr::InvalidResponse("Got an invalid response from server."); - } - - // Check Response Code. - RET_ERR(buffer_.At(8)); - - - yunq::MessageView resp_view(buffer_, 16); - RETURN_ERROR(response.ParseFromBytes(resp_view, cap_buffer_)); - - - return glcr::OK; -} - - - - -glcr::Status DenaliClient::ReadMany(const ReadManyRequest& request, ReadResponse& response) { - - uint64_t buffer_size = kBufferSize; - uint64_t cap_size = kCapBufferSize; - - const uint32_t kSentinel = 0xBEEFDEAD; - buffer_.WriteAt(0, kSentinel); - buffer_.WriteAt(8, 1); - - cap_buffer_.Reset(); - - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); - - - buffer_.WriteAt(4, 16 + length); - - z_cap_t reply_port_cap; - RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); - - // FIXME: Add a way to zero out the first buffer. - RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); - - if (buffer_.At(0) != kSentinel) { - return glcr::InvalidResponse("Got an invalid response from server."); - } - - // Check Response Code. - RET_ERR(buffer_.At(8)); - - - yunq::MessageView resp_view(buffer_, 16); - RETURN_ERROR(response.ParseFromBytes(resp_view, cap_buffer_)); - - - return glcr::OK; -} - - - - diff --git a/sys/denali/lib/denali/denali.yunq.cpp b/sys/denali/lib/denali/denali.yunq.cpp deleted file mode 100644 index de259cc..0000000 --- a/sys/denali/lib/denali/denali.yunq.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// Generated file -- DO NOT MODIFY. -#include "denali.yunq.h" - -#include -#include - - -namespace { - -const uint64_t header_size = 24; // 4x uint32, 1x uint64 - -struct ExtPointer { - uint32_t offset; - uint32_t length; -}; - -} // namespace -glcr::Status DiskBlock::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status DiskBlock::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status DiskBlock::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse lba. - ASSIGN_OR_RETURN(lba_, message.ReadField(0)); - // Parse size. - ASSIGN_OR_RETURN(size_, message.ReadField(1)); - - return glcr::Status::Ok(); -} - -uint64_t DiskBlock::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 2); - return SerializeInternal(serializer); -} - -uint64_t DiskBlock::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 2, caps); - return SerializeInternal(serializer); -} - -uint64_t DiskBlock::SerializeInternal(yunq::Serializer& serializer) const { - // Write lba. - serializer.WriteField(0, lba_); - // Write size. - serializer.WriteField(1, size_); - - serializer.WriteHeader(); - - return serializer.size(); -} -glcr::Status ReadRequest::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status ReadRequest::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status ReadRequest::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse device_id. - ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); - // Parse block. - message.ReadMessage(1, block_); - - return glcr::Status::Ok(); -} - -uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 2); - return SerializeInternal(serializer); -} - -uint64_t ReadRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 2, caps); - return SerializeInternal(serializer); -} - -uint64_t ReadRequest::SerializeInternal(yunq::Serializer& serializer) const { - // Write device_id. - serializer.WriteField(0, device_id_); - // Write block. - serializer.WriteMessage(1, block_); - - serializer.WriteHeader(); - - return serializer.size(); -} -glcr::Status ReadManyRequest::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status ReadManyRequest::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status ReadManyRequest::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse device_id. - ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); - // Parse blocks. - message.ReadRepeatedMessage(1, blocks_); - - - return glcr::Status::Ok(); -} - -uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 2); - return SerializeInternal(serializer); -} - -uint64_t ReadManyRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 2, caps); - return SerializeInternal(serializer); -} - -uint64_t ReadManyRequest::SerializeInternal(yunq::Serializer& serializer) const { - // Write device_id. - serializer.WriteField(0, device_id_); - // Write blocks. - serializer.WriteRepeatedMessage(1, blocks_); - - serializer.WriteHeader(); - - return serializer.size(); -} -glcr::Status ReadResponse::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - // Parse memory. - ASSIGN_OR_RETURN(memory_, message.ReadCapability(2)); - return glcr::Status::Ok(); -} - -glcr::Status ReadResponse::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - // Parse memory. - ASSIGN_OR_RETURN(memory_, message.ReadCapability(2, caps)); - return glcr::Status::Ok(); -} - -glcr::Status ReadResponse::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse device_id. - ASSIGN_OR_RETURN(device_id_, message.ReadField(0)); - // Parse size. - ASSIGN_OR_RETURN(size_, message.ReadField(1)); - // Parse memory. - - return glcr::Status::Ok(); -} - -uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 3); - return SerializeInternal(serializer); -} - -uint64_t ReadResponse::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 3, caps); - return SerializeInternal(serializer); -} - -uint64_t ReadResponse::SerializeInternal(yunq::Serializer& serializer) const { - // Write device_id. - serializer.WriteField(0, device_id_); - // Write size. - serializer.WriteField(1, size_); - // Write memory. - serializer.WriteCapability(2, memory_); - - serializer.WriteHeader(); - - return serializer.size(); -} - diff --git a/sys/denali/lib/denali/denali.yunq.server.cpp b/sys/denali/lib/denali/denali.yunq.server.cpp deleted file mode 100644 index 4fe21f5..0000000 --- a/sys/denali/lib/denali/denali.yunq.server.cpp +++ /dev/null @@ -1,152 +0,0 @@ -// Generated file -- DO NOT MODIFY. -#include "denali.yunq.server.h" - -#include -#include - - -namespace { - -const uint32_t kSentinel = 0xBEEFDEAD; -const uint32_t kHeaderSize = 0x10; - -void WriteError(glcr::ByteBuffer& buffer, glcr::ErrorCode err) { - buffer.WriteAt(0, kSentinel); - buffer.WriteAt(4, kHeaderSize); - buffer.WriteAt(8, err); -} - -void WriteHeader(glcr::ByteBuffer& buffer, uint64_t message_length) { - buffer.WriteAt(0, kSentinel); - buffer.WriteAt(4, kHeaderSize + message_length); - buffer.WriteAt(8, glcr::OK); -} - -} // namespace - - - -void DenaliServerBaseThreadBootstrap(void* server_base) { - ((DenaliServerBase*)server_base)->ServerThread(); -} - -DenaliServerBase::~DenaliServerBase() { - if (endpoint_ != 0) { - check(ZCapRelease(endpoint_)); - } -} - -glcr::ErrorOr DenaliServerBase::CreateClientCap() { - uint64_t client_cap; - RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap)); - return client_cap; -} - -glcr::ErrorOr DenaliServerBase::CreateClient() { - uint64_t client_cap; - RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap)); - return DenaliClient(client_cap); -} - -Thread DenaliServerBase::RunServer() { - return Thread(DenaliServerBaseThreadBootstrap, this); -} - -void DenaliServerBase::ServerThread() { - glcr::ByteBuffer recv_buffer(0x1000); - glcr::CapBuffer recv_cap(0x10); - glcr::ByteBuffer resp_buffer(0x1000); - glcr::CapBuffer resp_cap(0x10); - z_cap_t reply_port_cap; - - while (true) { - uint64_t recv_cap_size = 0x10; - uint64_t recv_buf_size = 0x1000; - recv_cap.Reset(); - glcr::ErrorCode recv_err = static_cast(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap)); - if (recv_err != glcr::OK) { - dbgln("Error in receive: {x}", recv_err); - continue; - } - - uint64_t resp_length = 0; - - glcr::ErrorCode reply_err = glcr::OK; - resp_cap.Reset(); - glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); - if (!err) { - WriteError(resp_buffer, err.code()); - dbgln("Responding Error {}", err.message()); - reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); - } else { - WriteHeader(resp_buffer, resp_length); - reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); - } - if (reply_err != glcr::OK) { - dbgln("Error in reply: {x}", reply_err); - } - } - -} - -glcr::Status DenaliServerBase::HandleRequest(const glcr::ByteBuffer& request, - const glcr::CapBuffer& req_caps, - glcr::ByteBuffer& response, uint64_t& resp_length, - glcr::CapBuffer& resp_caps) { - if (request.At(0) != kSentinel) { - return glcr::InvalidArgument("Request Not Valid"); - } - - uint64_t method_select = request.At(8); - - switch(method_select) { - case 0: { - - - ReadRequest yunq_request; - yunq::MessageView request_view(request, kHeaderSize); - RETURN_ERROR(yunq_request.ParseFromBytes(request_view, req_caps)); - - - - ReadResponse yunq_response; - - - - RETURN_ERROR(HandleRead(yunq_request, yunq_response)); - - - - resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); - - break; - } - case 1: { - - - ReadManyRequest yunq_request; - yunq::MessageView request_view(request, kHeaderSize); - RETURN_ERROR(yunq_request.ParseFromBytes(request_view, req_caps)); - - - - ReadResponse yunq_response; - - - - RETURN_ERROR(HandleReadMany(yunq_request, yunq_response)); - - - - resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); - - break; - } - default: { - return glcr::Unimplemented("Method unimplemented by server."); - } - } - return glcr::Status::Ok(); -} - - diff --git a/yunq/CMakeLists.txt b/yunq/CMakeLists.txt index 271476d..df824b8 100644 --- a/yunq/CMakeLists.txt +++ b/yunq/CMakeLists.txt @@ -19,6 +19,7 @@ macro(yunq_gen dir include_dir name) mammoth glacier yunq + zion_stub ) set_target_properties(${target} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}" diff --git a/yunq/example/example.yunq b/yunq/example/example.yunq deleted file mode 100644 index f286199..0000000 --- a/yunq/example/example.yunq +++ /dev/null @@ -1,16 +0,0 @@ -package srv.file; - -interface VFS { - method open (OpenFileRequest) -> (File); -} - -message OpenFileRequest { - string path; - repeated u64 options; -} - -message File { - string path; - u64 attrs; - capability mem_cap; -} diff --git a/yunq/example/example.yunq.client.cpp b/yunq/example/example.yunq.client.cpp deleted file mode 100644 index 406e895..0000000 --- a/yunq/example/example.yunq.client.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// Generated file - DO NOT MODIFY -#include "example.yunq.client.h" - -#include -#include -#include -#include - - -namespace srv::file { - - - -VFSClient::~VFSClient() { - if (endpoint_ != 0) { - check(ZCapRelease(endpoint_)); - } -} - - - - -glcr::Status VFSClient::open(const OpenFileRequest& request, File& response) { - - uint64_t buffer_size = kBufferSize; - uint64_t cap_size = kCapBufferSize; - - const uint32_t kSentinel = 0xBEEFDEAD; - buffer_.WriteAt(0, kSentinel); - buffer_.WriteAt(8, 0); - - cap_buffer_.Reset(); - - uint64_t length = request.SerializeToBytes(buffer_, /*offset=*/16, cap_buffer_); - - - buffer_.WriteAt(4, 16 + length); - - z_cap_t reply_port_cap; - RET_ERR(ZEndpointSend(endpoint_, 16 + length, buffer_.RawPtr(), cap_buffer_.UsedSlots(), cap_buffer_.RawPtr(), &reply_port_cap)); - - // FIXME: Add a way to zero out the first buffer. - RET_ERR(ZReplyPortRecv(reply_port_cap, &buffer_size, buffer_.RawPtr(), &cap_size, cap_buffer_.RawPtr())); - - if (buffer_.At(0) != kSentinel) { - return glcr::InvalidResponse("Got an invalid response from server."); - } - - // Check Response Code. - RET_ERR(buffer_.At(8)); - - - yunq::MessageView resp_view(buffer_, 16); - RETURN_ERROR(response.ParseFromBytes(resp_view, cap_buffer_)); - - - return glcr::OK; -} - - - - - -} // namepace srv::file diff --git a/yunq/example/example.yunq.client.h b/yunq/example/example.yunq.client.h deleted file mode 100644 index 826d920..0000000 --- a/yunq/example/example.yunq.client.h +++ /dev/null @@ -1,37 +0,0 @@ -// Generated file - DO NOT MODIFY -#pragma once - -#include -#include -#include -#include - -#include "example.yunq.h" - - -namespace srv::file { - -class VFSClient { - public: - VFSClient(z_cap_t VFS_cap) : endpoint_(VFS_cap) {} - VFSClient(const VFSClient&) = delete; - VFSClient(VFSClient&& other) : endpoint_(other.endpoint_) {other.endpoint_ = 0;}; - ~VFSClient(); - - z_cap_t Capability() { return endpoint_; } - - - - [[nodiscard]] glcr::Status open(const OpenFileRequest& request, File& response); - - - private: - z_cap_t endpoint_; - uint64_t kBufferSize = 0x1000; - glcr::ByteBuffer buffer_{kBufferSize}; - uint64_t kCapBufferSize = 0x10; - glcr::CapBuffer cap_buffer_{kCapBufferSize}; -}; - - -} // namepace srv::file diff --git a/yunq/example/example.yunq.cpp b/yunq/example/example.yunq.cpp deleted file mode 100644 index 4033cfc..0000000 --- a/yunq/example/example.yunq.cpp +++ /dev/null @@ -1,110 +0,0 @@ -// Generated file -- DO NOT MODIFY. -#include "example.yunq.h" - -#include -#include - - -namespace srv::file { - -namespace { - -const uint64_t header_size = 24; // 4x uint32, 1x uint64 - -struct ExtPointer { - uint32_t offset; - uint32_t length; -}; - -} // namespace -glcr::Status OpenFileRequest::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status OpenFileRequest::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - return glcr::Status::Ok(); -} - -glcr::Status OpenFileRequest::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse path. - ASSIGN_OR_RETURN(path_, message.ReadField(0)); - // Parse options. - ASSIGN_OR_RETURN(options_, message.ReadRepeated(1)); - - - return glcr::Status::Ok(); -} - -uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 2); - return SerializeInternal(serializer); -} - -uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 2, caps); - return SerializeInternal(serializer); -} - -uint64_t OpenFileRequest::SerializeInternal(yunq::Serializer& serializer) const { - // Write path. - serializer.WriteField(0, path_); - // Write options. - serializer.WriteRepeated(1, options_); - - serializer.WriteHeader(); - - return serializer.size(); -} -glcr::Status File::ParseFromBytes(const yunq::MessageView& message) { - RETURN_ERROR(ParseFromBytesInternal(message)); - // Parse mem_cap. - ASSIGN_OR_RETURN(mem_cap_, message.ReadCapability(2)); - return glcr::Status::Ok(); -} - -glcr::Status File::ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer& caps) { - RETURN_ERROR(ParseFromBytesInternal(message)); - // Parse mem_cap. - ASSIGN_OR_RETURN(mem_cap_, message.ReadCapability(2, caps)); - return glcr::Status::Ok(); -} - -glcr::Status File::ParseFromBytesInternal(const yunq::MessageView& message) { - RETURN_ERROR(message.CheckHeader()); - // Parse path. - ASSIGN_OR_RETURN(path_, message.ReadField(0)); - // Parse attrs. - ASSIGN_OR_RETURN(attrs_, message.ReadField(1)); - // Parse mem_cap. - - return glcr::Status::Ok(); -} - -uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const { - yunq::Serializer serializer(bytes, offset, 3); - return SerializeInternal(serializer); -} - -uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset, glcr::CapBuffer& caps) const { - yunq::Serializer serializer(bytes, offset, 3, caps); - return SerializeInternal(serializer); -} - -uint64_t File::SerializeInternal(yunq::Serializer& serializer) const { - // Write path. - serializer.WriteField(0, path_); - // Write attrs. - serializer.WriteField(1, attrs_); - // Write mem_cap. - serializer.WriteCapability(2, mem_cap_); - - serializer.WriteHeader(); - - return serializer.size(); -} - - -} // namepace srv::file diff --git a/yunq/example/example.yunq.h b/yunq/example/example.yunq.h deleted file mode 100644 index 112ddab..0000000 --- a/yunq/example/example.yunq.h +++ /dev/null @@ -1,71 +0,0 @@ -// Generated file - DO NOT MODIFY -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace srv::file { - -class OpenFileRequest { - public: - OpenFileRequest() {} - // Delete copy and move until implemented. - OpenFileRequest(const OpenFileRequest&) = delete; - OpenFileRequest(OpenFileRequest&&) = delete; - - [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message); - [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&); - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - const glcr::String& path() const { return path_; } - void set_path(const glcr::String& value) { path_ = value; } - const glcr::Vector& options() const { return options_; } - void add_options(const uint64_t& value) { options_.PushBack(value); } - - private: - glcr::String path_; - glcr::Vector options_; - - // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); - - uint64_t SerializeInternal(yunq::Serializer& serializer) const; -}; -class File { - public: - File() {} - // Delete copy and move until implemented. - File(const File&) = delete; - File(File&&) = delete; - - [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message); - [[nodiscard]] glcr::Status ParseFromBytes(const yunq::MessageView& message, const glcr::CapBuffer&); - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset) const; - uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const; - const glcr::String& path() const { return path_; } - void set_path(const glcr::String& value) { path_ = value; } - const uint64_t& attrs() const { return attrs_; } - void set_attrs(const uint64_t& value) { attrs_ = value; } - const z_cap_t& mem_cap() const { return mem_cap_; } - void set_mem_cap(const z_cap_t& value) { mem_cap_ = value; } - - private: - glcr::String path_; - uint64_t attrs_; - z_cap_t mem_cap_; - - // Parses everything except for caps. - glcr::Status ParseFromBytesInternal(const yunq::MessageView& message); - - uint64_t SerializeInternal(yunq::Serializer& serializer) const; -}; - - -} // namepace srv::file diff --git a/yunq/example/example.yunq.server.cpp b/yunq/example/example.yunq.server.cpp deleted file mode 100644 index 5c3b84c..0000000 --- a/yunq/example/example.yunq.server.cpp +++ /dev/null @@ -1,135 +0,0 @@ -// Generated file -- DO NOT MODIFY. -#include "example.yunq.server.h" - -#include -#include - - -namespace srv::file { - -namespace { - -const uint32_t kSentinel = 0xBEEFDEAD; -const uint32_t kHeaderSize = 0x10; - -void WriteError(glcr::ByteBuffer& buffer, glcr::ErrorCode err) { - buffer.WriteAt(0, kSentinel); - buffer.WriteAt(4, kHeaderSize); - buffer.WriteAt(8, err); -} - -void WriteHeader(glcr::ByteBuffer& buffer, uint64_t message_length) { - buffer.WriteAt(0, kSentinel); - buffer.WriteAt(4, kHeaderSize + message_length); - buffer.WriteAt(8, glcr::OK); -} - -} // namespace - - - -void VFSServerBaseThreadBootstrap(void* server_base) { - ((VFSServerBase*)server_base)->ServerThread(); -} - -VFSServerBase::~VFSServerBase() { - if (endpoint_ != 0) { - check(ZCapRelease(endpoint_)); - } -} - -glcr::ErrorOr VFSServerBase::CreateClientCap() { - uint64_t client_cap; - RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap)); - return client_cap; -} - -glcr::ErrorOr VFSServerBase::CreateClient() { - uint64_t client_cap; - RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap)); - return VFSClient(client_cap); -} - -Thread VFSServerBase::RunServer() { - return Thread(VFSServerBaseThreadBootstrap, this); -} - -void VFSServerBase::ServerThread() { - glcr::ByteBuffer recv_buffer(0x1000); - glcr::CapBuffer recv_cap(0x10); - glcr::ByteBuffer resp_buffer(0x1000); - glcr::CapBuffer resp_cap(0x10); - z_cap_t reply_port_cap; - - while (true) { - uint64_t recv_cap_size = 0x10; - uint64_t recv_buf_size = 0x1000; - recv_cap.Reset(); - glcr::ErrorCode recv_err = static_cast(ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap)); - if (recv_err != glcr::OK) { - dbgln("Error in receive: {x}", recv_err); - continue; - } - - uint64_t resp_length = 0; - - glcr::ErrorCode reply_err = glcr::OK; - resp_cap.Reset(); - glcr::Status err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap); - if (!err) { - WriteError(resp_buffer, err.code()); - dbgln("Responding Error {}", err.message()); - reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize, resp_buffer.RawPtr(), 0, nullptr)); - } else { - WriteHeader(resp_buffer, resp_length); - reply_err = static_cast(ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr())); - } - if (reply_err != glcr::OK) { - dbgln("Error in reply: {x}", reply_err); - } - } - -} - -glcr::Status VFSServerBase::HandleRequest(const glcr::ByteBuffer& request, - const glcr::CapBuffer& req_caps, - glcr::ByteBuffer& response, uint64_t& resp_length, - glcr::CapBuffer& resp_caps) { - if (request.At(0) != kSentinel) { - return glcr::InvalidArgument("Request Not Valid"); - } - - uint64_t method_select = request.At(8); - - switch(method_select) { - case 0: { - - - OpenFileRequest yunq_request; - yunq::MessageView request_view(request, kHeaderSize); - RETURN_ERROR(yunq_request.ParseFromBytes(request_view, req_caps)); - - - - File yunq_response; - - - - RETURN_ERROR(Handleopen(yunq_request, yunq_response)); - - - - resp_length = yunq_response.SerializeToBytes(response, kHeaderSize, resp_caps); - - break; - } - default: { - return glcr::Unimplemented("Method unimplemented by server."); - } - } - return glcr::Status::Ok(); -} - - - -} // namepace srv::file diff --git a/yunq/example/example.yunq.server.h b/yunq/example/example.yunq.server.h deleted file mode 100644 index 646e669..0000000 --- a/yunq/example/example.yunq.server.h +++ /dev/null @@ -1,50 +0,0 @@ -// Generated File -- DO NOT MODIFY. -#pragma once - -#include -#include -#include -#include - -#include "example.yunq.h" -#include "example.yunq.client.h" - - -namespace srv::file { - - - - -class VFSServerBase { - public: - VFSServerBase(z_cap_t VFS_cap) : endpoint_(VFS_cap) {} - VFSServerBase(const VFSServerBase&) = delete; - VFSServerBase(VFSServerBase&&) = delete; - virtual ~VFSServerBase(); - - glcr::ErrorOr CreateClientCap(); - glcr::ErrorOr CreateClient(); - - [[nodiscard]] Thread RunServer(); - - - - [[nodiscard]] virtual glcr::Status Handleopen(const OpenFileRequest&, File&) = 0; - - - - private: - z_cap_t endpoint_; - - friend void VFSServerBaseThreadBootstrap(void*); - void ServerThread(); - - [[nodiscard]] glcr::Status HandleRequest(const glcr::ByteBuffer& request, const glcr::CapBuffer& req_caps, - glcr::ByteBuffer& response, uint64_t& resp_length, - glcr::CapBuffer& resp_caps); -}; - - - - -} // namepace srv::file diff --git a/zion/CMakeLists.txt b/zion/CMakeLists.txt index 2e63927..e42ee29 100644 --- a/zion/CMakeLists.txt +++ b/zion/CMakeLists.txt @@ -99,7 +99,3 @@ add_library(zion_stub STATIC target_include_directories(zion_stub PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) - -set_target_properties(zion_stub - PROPERTIES - COMPILE_FLAGS "${_Z_COMPILE_FLAGS}")