Skip to content

Commit

Permalink
libc: implement read and write by async_read and async_write
Browse files Browse the repository at this point in the history
  • Loading branch information
atopia authored and chelmuth committed Sep 6, 2024
1 parent 6ff558d commit 39838ce
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 123 deletions.
15 changes: 14 additions & 1 deletion repos/libports/src/lib/libc/internal/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Genode { class Env; }
namespace Libc {

using namespace Genode;

class File_descriptor;

using Absolute_path = Genode::Path<PATH_MAX>;
Expand Down Expand Up @@ -78,6 +78,19 @@ namespace Libc {
virtual bool supports_unlink(const char *path);
virtual bool supports_mmap();

/*
* Asynchronous helper methods
*/
struct Async_read_state {
bool complete_read { false };
};
virtual bool async_read(File_descriptor *, void *, ::size_t, ::off_t, ssize_t &, int &, Async_read_state &);

struct Async_write_state {
size_t bytes_written { 0 };
};
virtual bool async_write(File_descriptor *, const void *, ::size_t, ::off_t, ssize_t &, int &, Async_write_state &);

/*
* Should be overwritten for plugins that require the Genode environment
*/
Expand Down
6 changes: 6 additions & 0 deletions repos/libports/src/lib/libc/internal/vfs_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ class Libc::Vfs_plugin final : public Plugin
bool supports_unlink(const char *) override { return true; }
bool supports_mmap() override { return true; }

/*
* Helper functions to use in the context of a monitor job
*/
bool async_read(File_descriptor *, void *, ::size_t, ::off_t, ssize_t &, int &, Async_read_state &) override;
bool async_write(File_descriptor *, const void *, ::size_t, ::off_t, ssize_t &, int &, Async_write_state &) override;

/* kernel-specific API without monitor */
File_descriptor *open_from_kernel(const char *, int, int libc_fd);
int close_from_kernel(File_descriptor *);
Expand Down
23 changes: 23 additions & 0 deletions repos/libports/src/lib/libc/plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <internal/init.h>
#include <internal/resume.h>

#include <errno.h>

using namespace Libc;


Expand Down Expand Up @@ -140,6 +142,27 @@ bool Plugin::supports_mmap()
}


/*
* Asynchronous helper functions
*/
bool Plugin::async_read(File_descriptor *, void *, ::size_t, ::off_t, ssize_t &retval, int &error, Async_read_state &)
{
error = EBADF;
retval = -1;

return true;
}


bool Plugin::async_write(File_descriptor *, const void *, ::size_t, ::off_t, ssize_t &retval, int &error, Async_write_state &)
{
error = EBADF;
retval = -1;

return true;
}


/**
* Generate dummy member function of Plugin class
*/
Expand Down
Loading

0 comments on commit 39838ce

Please sign in to comment.