Compare commits

...

4 Commits

8 changed files with 151 additions and 52 deletions

View File

@ -4,7 +4,7 @@ interface VFS {
message OpenFileRequest {
string path;
u64 options;
repeated u64 options;
}
message File {

View File

@ -28,23 +28,30 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
} // namespace
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse path.
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
// Parse options.
set_options(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
ParseFromBytesInternal(bytes, offset);
}
void OpenFileRequest::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
ParseFromBytesInternal(bytes, offset);
}
void OpenFileRequest::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse path.
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
// Parse options.
set_options(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
auto options_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 1));
options_.Resize(options_pointer.length);
for (uint64_t i = offset + options_pointer.offset;
i < offset + options_pointer.offset + (sizeof(uint64_t) * options_pointer.length);
i += sizeof(uint64_t)) {
options_.PushBack(bytes.At<uint64_t>(i));
}
}
uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
@ -62,7 +69,18 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
// Write options.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), options());
ExtPointer options_ptr{
.offset = next_extension,
.length = (uint32_t)(options().size() * sizeof(uint64_t)),
};
next_extension += options_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), options_ptr);
for (uint64_t i = 0; i < options().size(); i++) {
uint32_t ext_offset = offset + options_ptr.offset + (i * sizeof(uint64_t));
bytes.WriteAt<uint64_t>(ext_offset, options().at(i));
}
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
@ -86,7 +104,18 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 0), path_ptr);
// Write options.
bytes.WriteAt<uint64_t>(offset + header_size + (8 * 1), options());
ExtPointer options_ptr{
.offset = next_extension,
.length = (uint32_t)(options().size() * sizeof(uint64_t)),
};
next_extension += options_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * 1), options_ptr);
for (uint64_t i = 0; i < options().size(); i++) {
uint32_t ext_offset = offset + options_ptr.offset + (i * sizeof(uint64_t));
bytes.WriteAt<uint64_t>(ext_offset, options().at(i));
}
// The next extension pointer is the length of the message.
WriteHeader(bytes, offset, core_size, next_extension);
@ -94,19 +123,21 @@ uint64_t OpenFileRequest::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t off
return next_extension;
}
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse path.
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
set_path(bytes.StringAt(offset + path_pointer.offset, path_pointer.length));
// Parse attrs.
set_attrs(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
ParseFromBytesInternal(bytes, offset);
// Parse mem_cap.
// FIXME: Implement in-buffer capabilities for inprocess serialization.
set_mem_cap(0);
}
void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
ParseFromBytesInternal(bytes, offset);
// Parse mem_cap.
uint64_t mem_cap_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
set_mem_cap(caps.At(mem_cap_ptr));
}
void File::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
// Parse path.
auto path_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * 0));
@ -115,9 +146,8 @@ void File::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const
// Parse attrs.
set_attrs(bytes.At<uint64_t>(offset + header_size + (8 * 1)));
// Parse mem_cap.
uint64_t mem_cap_ptr = bytes.At<uint64_t>(offset + header_size + (8 * 2));
// Skip Cap.
set_mem_cap(caps.At(mem_cap_ptr));
}
uint64_t File::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {

View File

@ -3,6 +3,7 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <ztypes.h>
class OpenFileRequest {
@ -15,16 +16,18 @@ class OpenFileRequest {
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
void 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, glcr::CapBuffer&) const;
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
glcr::String path() const { return path_; }
void set_path(const glcr::String& value) { path_ = value; }
uint64_t options() const { return options_; }
void set_options(const uint64_t& value) { options_ = value; }
const glcr::Vector<uint64_t>& options() const { return options_; }
void add_options(const uint64_t& value) { options_.PushBack(value); }
private:
glcr::String path_;
uint64_t options_;
glcr::Vector<uint64_t> options_;
// Parses everything except for caps.
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
};
class File {
public:
@ -36,11 +39,11 @@ class File {
void ParseFromBytes(const glcr::ByteBuffer&, uint64_t offset);
void 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, glcr::CapBuffer&) const;
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
glcr::String path() const { return path_; }
void set_path(const glcr::String& value) { path_ = value; }
void set_path(const glcr::String& value) { path_ = value; }
uint64_t attrs() const { return attrs_; }
void set_attrs(const uint64_t& value) { attrs_ = value; }
void set_attrs(const uint64_t& value) { attrs_ = value; }
z_cap_t mem_cap() const { return mem_cap_; }
void set_mem_cap(const z_cap_t& value) { mem_cap_ = value; }
@ -49,4 +52,6 @@ class File {
uint64_t attrs_;
z_cap_t mem_cap_;
// Parses everything except for caps.
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
};

View File

@ -31,8 +31,7 @@ void VFSServerBaseThreadBootstrap(void* server_base) {
glcr::ErrorOr<VFSClient> VFSServerBase::CreateClient() {
uint64_t client_cap;
// FIXME: Restrict permissions to send-only here.
RET_ERR(ZCapDuplicate(endpoint_, &client_cap));
RET_ERR(ZCapDuplicate(endpoint_, ~(kZionPerm_Read), &client_cap));
return VFSClient(client_cap);
}
@ -51,9 +50,9 @@ void VFSServerBase::ServerThread() {
uint64_t recv_cap_size = 0x10;
uint64_t recv_buf_size = 0x1000;
recv_cap.Reset();
glcr::ErrorCode recv_err = ZEndpointRecv(endpoint_, &recv_buf_size, recv_buffer.RawPtr(), &recv_cap_size, recv_cap.RawPtr(), &reply_port_cap);
glcr::ErrorCode recv_err = static_cast<glcr::ErrorCode>(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);
dbgln("Error in receive: {x}", recv_err);
continue;
}
@ -64,13 +63,13 @@ void VFSServerBase::ServerThread() {
glcr::ErrorCode err = HandleRequest(recv_buffer, recv_cap, resp_buffer, resp_length, resp_cap);
if (err != glcr::OK) {
WriteError(resp_buffer, err);
reply_err = 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 {
WriteHeader(resp_buffer, resp_length);
reply_err = ZReplyPortSend(reply_port_cap, kHeaderSize + resp_length, resp_buffer.RawPtr(), resp_cap.UsedSlots(), resp_cap.RawPtr());
reply_err = static_cast<glcr::ErrorCode>(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);
dbgln("Error in reply: {x}", reply_err);
}
}

View File

@ -30,32 +30,36 @@ void WriteHeader(glcr::ByteBuffer& bytes, uint64_t offset, uint32_t core_size, u
{%- for message in messages %}
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
ParseFromBytesInternal(bytes, offset);
{%- for field in message.fields %}
{%- if field.type == Type.CAPABILITY %}
// Parse {{field.name}}.
{%- if field.type == Type.U64 %}
set_{{field.name}}(bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}})));
{%- elif field.type == Type.I64 %}
set_{{field.name}}(bytes.At<int64_t>(offset + header_size + (8 * {{loop.index0}})));
{%- elif field.type == Type.STRING %}
auto {{field.name}}_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * {{loop.index0}}));
set_{{field.name}}(bytes.StringAt(offset + {{field.name}}_pointer.offset, {{field.name}}_pointer.length));
{%- elif field.type == Type.CAPABILITY %}
// FIXME: Implement in-buffer capabilities for inprocess serialization.
set_{{field.name}}(0);
{%- else %}
// TODO: Unimplemented parsing {{field.type}}
{%- endif %}
{%- endfor %}
}
void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t offset, const glcr::CapBuffer& caps) {
ParseFromBytesInternal(bytes, offset);
{%- for field in message.fields %}
{%- if field.type == Type.CAPABILITY %}
// Parse {{field.name}}.
uint64_t {{field.name}}_ptr = bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}}));
set_{{field.name}}(caps.At({{field.name}}_ptr));
{%- endif %}
{%- endfor %}
}
void {{message.name}}::ParseFromBytesInternal(const glcr::ByteBuffer& bytes, uint64_t offset) {
CheckHeader(bytes);
{%- for field in message.fields %}
// Parse {{field.name}}.
{%- if not field.repeated %}
{%- if field.type == Type.U64 %}
set_{{field.name}}(bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}})));
{%- elif field.type == Type.I64 %}
@ -65,13 +69,22 @@ void {{message.name}}::ParseFromBytes(const glcr::ByteBuffer& bytes, uint64_t of
set_{{field.name}}(bytes.StringAt(offset + {{field.name}}_pointer.offset, {{field.name}}_pointer.length));
{%- elif field.type == Type.CAPABILITY %}
uint64_t {{field.name}}_ptr = bytes.At<uint64_t>(offset + header_size + (8 * {{loop.index0}}));
set_{{field.name}}(caps.At({{field.name}}_ptr));
// Skip Cap.
{%- else %}
// TODO: Unimplemented parsing {{field.type}}
{%- endif %}
{%- else %}
auto {{field.name}}_pointer = bytes.At<ExtPointer>(offset + header_size + (8 * {{loop.index0}}));
{{field.name}}_.Resize({{field.name}}_pointer.length / sizeof({{field.cpp_type()}}));
for (uint64_t i = offset + {{field.name}}_pointer.offset;
i < offset + {{field.name}}_pointer.offset + {{field.name}}_pointer.length;
i += sizeof({{field.cpp_type()}})) {
{{field.name}}_.PushBack(bytes.At<{{field.cpp_type()}}>(i));
}
{% endif %}
{%- endfor %}
}
uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t offset) const {
@ -80,6 +93,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
{%- for field in message.fields %}
// Write {{field.name}}.
{%- if not field.repeated %}
{%- if field.type == Type.U64 %}
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
{%- elif field.type == Type.I64 %}
@ -101,6 +115,20 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
{%- else %}
// TODO: Unimplemented serialization {{field.type}}
{%- endif %}
{%- else %}
ExtPointer {{field.name}}_ptr{
.offset = next_extension,
.length = (uint32_t)({{field.name}}().size() * sizeof({{field.cpp_type()}})),
};
next_extension += {{field.name}}_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
for (uint64_t i = 0; i < {{field.name}}().size(); i++) {
uint32_t ext_offset = offset + {{field.name}}_ptr.offset + (i * sizeof({{field.cpp_type()}}));
bytes.WriteAt<{{field.cpp_type()}}>(ext_offset, {{field.name}}().at(i));
}
{%- endif %}
{%- endfor %}
// The next extension pointer is the length of the message.
@ -116,6 +144,7 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
{%- for field in message.fields %}
// Write {{field.name}}.
{%- if not field.repeated %}
{%- if field.type == Type.U64 %}
bytes.WriteAt<uint64_t>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}());
{%- elif field.type == Type.I64 %}
@ -137,6 +166,20 @@ uint64_t {{message.name}}::SerializeToBytes(glcr::ByteBuffer& bytes, uint64_t of
{%- else %}
// TODO: Unimplemented serialization {{field.type}}
{%- endif %}
{%- else %}
ExtPointer {{field.name}}_ptr{
.offset = next_extension,
.length = (uint32_t)({{field.name}}().size() * sizeof({{field.cpp_type()}})),
};
next_extension += {{field.name}}_ptr.length;
bytes.WriteAt<ExtPointer>(offset + header_size + (8 * {{loop.index0}}), {{field.name}}_ptr);
for (uint64_t i = 0; i < {{field.name}}().size(); i++) {
uint32_t ext_offset = offset + {{field.name}}_ptr.offset + (i * sizeof({{field.cpp_type()}}));
bytes.WriteAt<{{field.cpp_type()}}>(ext_offset, {{field.name}}().at(i));
}
{%- endif %}
{%- endfor %}
// The next extension pointer is the length of the message.

View File

@ -3,6 +3,7 @@
#include <glacier/buffer/byte_buffer.h>
#include <glacier/buffer/cap_buffer.h>
#include <glacier/container/vector.h>
#include <glacier/string/string.h>
#include <ztypes.h>
@ -21,14 +22,25 @@ class {{message.name}} {
uint64_t SerializeToBytes(glcr::ByteBuffer&, uint64_t offset, glcr::CapBuffer&) const;
{%- for field in message.fields %}
{%- if not field.repeated %}
{{field.cpp_type()}} {{field.name}}() const { return {{field.name}}_; }
void set_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_ = value; }
{%- else %}
const glcr::Vector<{{field.cpp_type()}}>& {{field.name}}() const { return {{field.name}}_; }
void add_{{field.name}}(const {{field.cpp_type()}}& value) { {{field.name}}_.PushBack(value); }
{%- endif %}
{%- endfor %}
private:
{%- for field in message.fields %}
{%- if not field.repeated %}
{{field.cpp_type()}} {{field.name}}_;
{%- else %}
glcr::Vector<{{field.cpp_type()}}> {{field.name}}_;
{%- endif %}
{%- endfor %}
// Parses everything except for caps.
void ParseFromBytesInternal(const glcr::ByteBuffer&, uint64_t offset);
};
{%- endfor %}

View File

@ -114,9 +114,10 @@ type_to_cppstr = {
}
class Field():
def __init__(self, fieldtype: Type, name: str):
def __init__(self, fieldtype: Type, name: str, repeated = False):
self.type = fieldtype
self.name = name
self.repeated = repeated
def cpp_type(self):
return type_to_cppstr[self.type]
@ -250,14 +251,19 @@ class Parser():
def field(self):
repeated = False
field_type_str = self.consume_identifier()
if field_type_str == "repeated":
repeated = True
field_type_str = self.consume_identifier()
if field_type_str not in type_str_dict.keys():
sys.exit("Expected type got '%s'" % field_type_str)
field_type = type_str_dict[field_type_str]
name = self.consume_identifier()
self.consume_check(LexemeType.SEMICOLON)
return Field(field_type, name)
return Field(field_type, name, repeated)
def type_check(decls: list[Decl]):
for decl in decls:

View File

@ -30,7 +30,11 @@ void dbg(const glcr::StringView& str) {
void AddProcPrefix() {
if (gScheduler != nullptr) {
auto t = gScheduler->CurrentThread();
dbg(glcr::StrFormat("[{}.{}] ", t->pid(), t->tid()));
char buffer[16];
glcr::FixedStringBuilder builder(buffer, 16);
glcr::StrFormatIntoBuffer(builder, "[{}.{}] ", t->pid(), t->tid());
dbg(builder);
}
}