base-linux: coding style

This commit is contained in:
Norman Feske
2020-11-17 10:55:49 +01:00
committed by Christian Helmuth
parent dc016cbd5c
commit 0dcb526ae5
39 changed files with 832 additions and 799 deletions

View File

@ -79,6 +79,7 @@ inline int lx_iopl(int level)
} }
#endif #endif
/************************************************** /**************************************************
** Functions used by core's io mem session code ** ** Functions used by core's io mem session code **
**************************************************/ **************************************************/
@ -261,5 +262,4 @@ inline int lx_read(int fd, void *buf, Genode::size_t count)
return lx_syscall(SYS_read, fd, buf, count); return lx_syscall(SYS_read, fd, buf, count);
} }
#endif /* _CORE__INCLUDE__CORE_LINUX_SYSCALLS_H_ */ #endif /* _CORE__INCLUDE__CORE_LINUX_SYSCALLS_H_ */

View File

@ -28,107 +28,116 @@
#include <base/internal/capability_space_tpl.h> #include <base/internal/capability_space_tpl.h>
namespace Genode { namespace Genode {
class Dataspace_owner;
/** class Dataspace_component;
* Deriving classes can own a dataspace to implement conditional behavior
*/
class Dataspace_owner : Interface { };
class Dataspace_component : public Rpc_object<Linux_dataspace>
{
private:
Filename _fname { }; /* filename for mmap */
size_t const _size; /* size of dataspace in bytes */
addr_t const _addr; /* meaningless on linux */
Native_capability _cap; /* capability / file descriptor */
bool const _writable; /* false if read-only */
/* Holds the dataspace owner if a distinction between owner and
* others is necessary on the dataspace, otherwise it is 0 */
Dataspace_owner const * const _owner;
static Filename _file_name(const char *args);
size_t _file_size();
/*
* Noncopyable
*/
Dataspace_component(Dataspace_component const &);
Dataspace_component &operator = (Dataspace_component const &);
static Native_capability _fd_to_cap(int const fd)
{
return Capability_space::import(Rpc_destination(Lx_sd{fd}), Rpc_obj_key());
}
public:
/**
* Constructor
*/
Dataspace_component(size_t size, addr_t addr,
Cache_attribute, bool writable,
Dataspace_owner * owner)
: _size(size), _addr(addr), _cap(), _writable(writable),
_owner(owner) { }
/**
* Default constructor returns invalid dataspace
*/
Dataspace_component()
: _size(0), _addr(0), _cap(), _writable(false), _owner(nullptr) { }
/**
* This constructor is only provided for compatibility
* reasons and should not be used.
*/
Dataspace_component(size_t size, addr_t, addr_t phys_addr,
Cache_attribute, bool writable, Dataspace_owner *_owner);
/**
* This constructor is especially used for ROM dataspaces
*
* \param args session parameters containing 'filename' key/value
*/
Dataspace_component(const char *args);
/**
* Assign file descriptor to dataspace
*
* The file descriptor assigned to the dataspace will be enable
* processes outside of core to mmap the dataspace.
*/
void fd(int fd) { _cap = _fd_to_cap(fd); }
/**
* Check if dataspace is owned by a specified object
*/
bool owner(Dataspace_owner const &o) const { return _owner == &o; }
/**
* Detach dataspace from all rm sessions.
*/
void detach_from_rm_sessions() { }
/*************************
** Dataspace interface **
*************************/
size_t size() override { return _size; }
addr_t phys_addr() override { return _addr; }
bool writable() override { return _writable; }
/****************************************
** Linux-specific dataspace interface **
****************************************/
Filename fname() override { return _fname; }
Untyped_capability fd() override { return _cap; }
};
} }
/**
* Deriving classes can own a dataspace to implement conditional behavior
*/
class Genode::Dataspace_owner : Interface { };
class Genode::Dataspace_component : public Rpc_object<Linux_dataspace>
{
private:
Filename _fname { }; /* filename for mmap */
size_t const _size; /* size of dataspace in bytes */
addr_t const _addr; /* meaningless on linux */
Native_capability _cap; /* capability / file descriptor */
bool const _writable; /* false if read-only */
/*
* Holds the dataspace owner if a distinction between owner and
* others is necessary on the dataspace, otherwise it is 0
*/
Dataspace_owner const * const _owner;
static Filename _file_name(const char *args);
size_t _file_size();
/*
* Noncopyable
*/
Dataspace_component(Dataspace_component const &);
Dataspace_component &operator = (Dataspace_component const &);
static Native_capability _fd_to_cap(int const fd)
{
return Capability_space::import(Rpc_destination(Lx_sd{fd}), Rpc_obj_key());
}
public:
/**
* Constructor
*/
Dataspace_component(size_t size, addr_t addr,
Cache_attribute, bool writable,
Dataspace_owner * owner)
:
_size(size), _addr(addr), _cap(), _writable(writable), _owner(owner)
{ }
/**
* Default constructor creates invalid dataspace
*/
Dataspace_component()
:
_size(0), _addr(0), _cap(), _writable(false), _owner(nullptr)
{ }
/**
* This constructor is only provided for compatibility
* reasons and should not be used.
*/
Dataspace_component(size_t size, addr_t, addr_t phys_addr,
Cache_attribute, bool writable, Dataspace_owner *_owner);
/**
* This constructor is especially used for ROM dataspaces
*
* \param args session parameters containing 'filename' key/value
*/
Dataspace_component(const char *args);
/**
* Assign file descriptor to dataspace
*
* The file descriptor assigned to the dataspace will be enable
* processes outside of core to mmap the dataspace.
*/
void fd(int fd) { _cap = _fd_to_cap(fd); }
/**
* Check if dataspace is owned by a specified object
*/
bool owner(Dataspace_owner const &o) const { return _owner == &o; }
/**
* Detach dataspace from all rm sessions.
*/
void detach_from_rm_sessions() { }
/*************************
** Dataspace interface **
*************************/
size_t size() override { return _size; }
addr_t phys_addr() override { return _addr; }
bool writable() override { return _writable; }
/****************************************
** Linux-specific dataspace interface **
****************************************/
Filename fname() override { return _fname; }
Untyped_capability fd() override { return _cap; }
};
#endif /* _CORE__INCLUDE__DATASPACE_COMPONENT_H_ */ #endif /* _CORE__INCLUDE__DATASPACE_COMPONENT_H_ */

View File

@ -22,53 +22,52 @@
/* core includes */ /* core includes */
#include <dataspace_component.h> #include <dataspace_component.h>
namespace Genode { namespace Genode { class Io_mem_session_component; }
class Io_mem_session_component : public Rpc_object<Io_mem_session>
{
private:
Range_allocator &_io_mem_alloc;
Dataspace_component _ds;
Rpc_entrypoint &_ds_ep;
Io_mem_dataspace_capability _ds_cap;
size_t get_arg_size(const char *);
addr_t get_arg_phys(const char *);
Cache_attribute get_arg_wc(const char *);
public:
/**
* Constructor
*
* \param io_mem_alloc MMIO region allocator
* \param ram_alloc RAM allocator that will be checked for
* region collisions
* \param ds_ep entry point to manage the dataspace
* corresponding the io_mem session
* \param args session construction arguments, in
* particular MMIO region base, size and
* caching demands
*/
Io_mem_session_component(Range_allocator &io_mem_alloc,
Range_allocator &ram_alloc,
Rpc_entrypoint &ds_ep,
const char *args);
/**
* Destructor
*/
~Io_mem_session_component() { }
/***************************** class Genode::Io_mem_session_component : public Rpc_object<Io_mem_session>
** Io-mem session interface ** {
*****************************/ private:
Io_mem_dataspace_capability dataspace() override; Range_allocator &_io_mem_alloc;
}; Dataspace_component _ds;
} Rpc_entrypoint &_ds_ep;
Io_mem_dataspace_capability _ds_cap;
size_t get_arg_size(const char *);
addr_t get_arg_phys(const char *);
Cache_attribute get_arg_wc(const char *);
public:
/**
* Constructor
*
* \param io_mem_alloc MMIO region allocator
* \param ram_alloc RAM allocator that will be checked for
* region collisions
* \param ds_ep entry point to manage the dataspace
* corresponding the io_mem session
* \param args session construction arguments, in
* particular MMIO region base, size and
* caching demands
*/
Io_mem_session_component(Range_allocator &io_mem_alloc,
Range_allocator &ram_alloc,
Rpc_entrypoint &ds_ep,
const char *args);
/**
* Destructor
*/
~Io_mem_session_component() { }
/*****************************
** Io-mem session interface **
*****************************/
Io_mem_dataspace_capability dataspace() override;
};
#endif /* _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_ */ #endif /* _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_ */

View File

@ -16,19 +16,16 @@
#include <base/thread.h> #include <base/thread.h>
namespace Genode namespace Genode { class Irq_object; };
{
class Irq_object;
};
class Genode::Irq_object : public Thread_deprecated<4096> class Genode::Irq_object : public Thread_deprecated<4096>
{ {
private: private:
Genode::Signal_context_capability _sig_cap; Signal_context_capability _sig_cap;
Genode::Blockade _sync_ack { }; Blockade _sync_ack { };
Genode::Blockade _sync_bootup { }; Blockade _sync_bootup { };
unsigned const _irq; unsigned const _irq;
int _fd; int _fd;

View File

@ -20,9 +20,8 @@
#include <irq_session/irq_session.h> #include <irq_session/irq_session.h>
#include <irq_object.h> #include <irq_object.h>
namespace Genode { namespace Genode { class Irq_session_component; }
class Irq_session_component;
}
class Genode::Irq_session_component : public Rpc_object<Irq_session>, class Genode::Irq_session_component : public Rpc_object<Irq_session>,
private List<Irq_session_component>::Element private List<Irq_session_component>::Element
@ -30,8 +29,10 @@ class Genode::Irq_session_component : public Rpc_object<Irq_session>,
private: private:
friend class List<Irq_session_component>; friend class List<Irq_session_component>;
unsigned _irq_number; unsigned _irq_number;
Genode::Irq_object _irq_object;
Irq_object _irq_object;
public: public:

View File

@ -20,7 +20,6 @@
#include <linux_native_cpu/linux_native_cpu.h> #include <linux_native_cpu/linux_native_cpu.h>
namespace Genode { namespace Genode {
class Cpu_session_component; class Cpu_session_component;
class Native_cpu_component; class Native_cpu_component;
} }
@ -37,6 +36,7 @@ class Genode::Native_cpu_component : public Rpc_object<Linux_native_cpu,
public: public:
Native_cpu_component(Cpu_session_component &, char const *); Native_cpu_component(Cpu_session_component &, char const *);
~Native_cpu_component(); ~Native_cpu_component();
void thread_id(Thread_capability, int, int) override; void thread_id(Thread_capability, int, int) override;

View File

@ -18,7 +18,6 @@
#include <linux_native_pd/linux_native_pd.h> #include <linux_native_pd/linux_native_pd.h>
namespace Genode { namespace Genode {
class Dataspace_component; class Dataspace_component;
class Pd_session_component; class Pd_session_component;
class Native_pd_component; class Native_pd_component;
@ -26,7 +25,7 @@ namespace Genode {
class Genode::Native_pd_component : public Rpc_object<Linux_native_pd, class Genode::Native_pd_component : public Rpc_object<Linux_native_pd,
Native_pd_component> Native_pd_component>
{ {
private: private:

View File

@ -3,8 +3,6 @@
* \author Norman Feske * \author Norman Feske
* \author Christian Helmuth * \author Christian Helmuth
* \date 2006-04-28 * \date 2006-04-28
*
* Linux dummies
*/ */
/* /*
@ -26,36 +24,40 @@
#include <rpc_cap_factory.h> #include <rpc_cap_factory.h>
namespace Genode { namespace Genode {
struct Pager_object;
struct Pager_object struct Pager_entrypoint;
{
Thread_capability _thread_cap { };
Signal_context_capability _sigh { };
virtual ~Pager_object() { }
void exception_handler(Signal_context_capability sigh) { _sigh = sigh; }
/**
* Remember thread cap so that rm_session can tell thread that
* rm_client is gone.
*/
Thread_capability thread_cap() const { return _thread_cap; }
void thread_cap(Thread_capability cap) { _thread_cap = cap; }
};
struct Pager_entrypoint
{
Pager_entrypoint(Rpc_cap_factory &) { }
template <typename FUNC>
auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) {
return f(nullptr); }
Pager_capability manage(Pager_object &) { return Pager_capability(); }
void dissolve(Pager_object &) { }
};
} }
struct Genode::Pager_object
{
Thread_capability _thread_cap { };
Signal_context_capability _sigh { };
virtual ~Pager_object() { }
void exception_handler(Signal_context_capability sigh) { _sigh = sigh; }
/**
* Remember thread cap so that rm_session can tell thread that
* rm_client is gone.
*/
Thread_capability thread_cap() const { return _thread_cap; }
void thread_cap(Thread_capability cap) { _thread_cap = cap; }
};
struct Genode::Pager_entrypoint
{
Pager_entrypoint(Rpc_cap_factory &) { }
template <typename FUNC>
auto apply(Pager_capability, FUNC f) -> decltype(f(nullptr)) {
return f(nullptr); }
Pager_capability manage(Pager_object &) { return Pager_capability(); }
void dissolve(Pager_object &) { }
};
#endif /* _CORE__INCLUDE__PAGER_H_ */ #endif /* _CORE__INCLUDE__PAGER_H_ */

View File

@ -15,16 +15,17 @@
#ifndef _CORE__INCLUDE__PLATFORM_H_ #ifndef _CORE__INCLUDE__PLATFORM_H_
#define _CORE__INCLUDE__PLATFORM_H_ #define _CORE__INCLUDE__PLATFORM_H_
/* Genode includes */
#include <base/allocator_avl.h> #include <base/allocator_avl.h>
#include <base/lock_guard.h> #include <util/arg_string.h>
/* core-local includes */
#include <platform_generic.h> #include <platform_generic.h>
#include <platform_pd.h> #include <platform_pd.h>
#include <platform_thread.h> #include <platform_thread.h>
#include <synced_range_allocator.h> #include <synced_range_allocator.h>
#include <assertion.h> #include <assertion.h>
#include <util/arg_string.h>
/** /**
* List of Unix environment variables, initialized by the startup code * List of Unix environment variables, initialized by the startup code
@ -37,9 +38,11 @@ extern char **lx_environ;
*/ */
static unsigned long ram_quota_from_env() static unsigned long ram_quota_from_env()
{ {
using namespace Genode;
for (char **curr = lx_environ; curr && *curr; curr++) { for (char **curr = lx_environ; curr && *curr; curr++) {
Genode::Arg arg = Genode::Arg_string::find_arg(*curr, "GENODE_RAM_QUOTA"); Arg arg = Arg_string::find_arg(*curr, "GENODE_RAM_QUOTA");
if (arg.valid()) if (arg.valid())
return arg.ulong_value(~0); return arg.ulong_value(~0);
} }
@ -47,113 +50,109 @@ static unsigned long ram_quota_from_env()
return ~0; return ~0;
} }
namespace Genode {
using namespace Genode; class Genode::Platform : public Platform_generic
{
private:
class Platform : public Platform_generic /**
{ * Allocator for core-internal meta data
private: */
Synced_range_allocator<Allocator_avl> _core_mem_alloc;
/** Rom_fs _dummy_rom_fs { };
* Allocator for core-internal meta data
*/
Synced_range_allocator<Allocator_avl> _core_mem_alloc;
Rom_fs _dummy_rom_fs { }; struct Dummy_allocator : Range_allocator
{
void free(void *, size_t) override { ASSERT_NEVER_CALLED; }
bool need_size_for_free() const override { ASSERT_NEVER_CALLED; }
size_t consumed() const override { ASSERT_NEVER_CALLED; }
size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; }
int add_range (addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
int remove_range(addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
void free(void *) override { ASSERT_NEVER_CALLED; }
size_t avail() const override { ASSERT_NEVER_CALLED; }
bool valid_addr(addr_t ) const override { ASSERT_NEVER_CALLED; }
bool alloc(size_t, void **) override { ASSERT_NEVER_CALLED; }
struct Dummy_allocator : Range_allocator Alloc_return alloc_aligned(size_t, void **, int, addr_t, addr_t) override
{ ASSERT_NEVER_CALLED; }
Alloc_return alloc_addr(size_t, addr_t) override
{ ASSERT_NEVER_CALLED; }
} _dummy_alloc { };
/**
* Allocator for pseudo physical memory
*/
struct Pseudo_ram_allocator : Range_allocator
{
bool alloc(size_t, void **out_addr) override
{ {
void free(void *, size_t) override { ASSERT_NEVER_CALLED; } *out_addr = 0;
bool need_size_for_free() const override { ASSERT_NEVER_CALLED; } return true;
size_t consumed() const override { ASSERT_NEVER_CALLED; } }
size_t overhead(size_t) const override { ASSERT_NEVER_CALLED; }
int add_range (addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
int remove_range(addr_t, size_t ) override { ASSERT_NEVER_CALLED; }
void free(void *) override { ASSERT_NEVER_CALLED; }
size_t avail() const override { ASSERT_NEVER_CALLED; }
bool valid_addr(addr_t ) const override { ASSERT_NEVER_CALLED; }
bool alloc(size_t, void **) override { ASSERT_NEVER_CALLED; }
Alloc_return alloc_aligned(size_t, void **, int, addr_t, addr_t) override Alloc_return alloc_aligned(size_t, void **out_addr, int,
{ ASSERT_NEVER_CALLED; } addr_t, addr_t) override
Alloc_return alloc_addr(size_t, addr_t) override
{ ASSERT_NEVER_CALLED; }
} _dummy_alloc { };
/**
* Allocator for pseudo physical memory
*/
struct Pseudo_ram_allocator : Range_allocator
{ {
bool alloc(size_t, void **out_addr) override *out_addr = 0;
{ return Alloc_return::OK;
*out_addr = 0; }
return true;
}
Alloc_return alloc_aligned(size_t, void **out_addr, int, Alloc_return alloc_addr(size_t, addr_t) override
addr_t, addr_t) override {
{ return Alloc_return::OK;
*out_addr = 0; }
return Alloc_return::OK;
}
Alloc_return alloc_addr(size_t, addr_t) override int add_range(addr_t, size_t) override { return 0; }
{ int remove_range(addr_t, size_t) override { return 0; }
return Alloc_return::OK; void free(void *) override { }
} void free(void *, size_t) override { }
size_t avail() const override { return ram_quota_from_env(); }
bool valid_addr(addr_t) const override { return true; }
size_t overhead(size_t) const override { return 0; }
bool need_size_for_free() const override { return true; }
int add_range(addr_t, size_t) override { return 0; } } _ram_alloc { };
int remove_range(addr_t, size_t) override { return 0; }
void free(void *) override { }
void free(void *, size_t) override { }
size_t avail() const override { return ram_quota_from_env(); }
bool valid_addr(addr_t) const override { return true; }
size_t overhead(size_t) const override { return 0; }
bool need_size_for_free() const override { return true; }
} _ram_alloc { }; public:
public: /**
* Constructor
/** */
* Constructor Platform();
*/
Platform();
/******************************** /********************************
** Generic platform interface ** ** Generic platform interface **
********************************/ ********************************/
Range_allocator &core_mem_alloc() override { return _core_mem_alloc; } Range_allocator &core_mem_alloc() override { return _core_mem_alloc; }
Range_allocator &ram_alloc() override { return _ram_alloc; } Range_allocator &ram_alloc() override { return _ram_alloc; }
Range_allocator &io_mem_alloc() override { return _dummy_alloc; } Range_allocator &io_mem_alloc() override { return _dummy_alloc; }
Range_allocator &io_port_alloc() override { return _dummy_alloc; } Range_allocator &io_port_alloc() override { return _dummy_alloc; }
Range_allocator &irq_alloc() override { return _dummy_alloc; } Range_allocator &irq_alloc() override { return _dummy_alloc; }
Range_allocator &region_alloc() override { return _dummy_alloc; } Range_allocator &region_alloc() override { return _dummy_alloc; }
addr_t vm_start() const override { return 0; } addr_t vm_start() const override { return 0; }
size_t vm_size() const override { return 0; } size_t vm_size() const override { return 0; }
Rom_fs &rom_fs() override { return _dummy_rom_fs; } Rom_fs &rom_fs() override { return _dummy_rom_fs; }
/* /*
* On Linux, the maximum number of capabilities is primarily * On Linux, the maximum number of capabilities is primarily
* constrained by the limited number of file descriptors within * constrained by the limited number of file descriptors within
* core. Each dataspace and and each thread consumes one * core. Each dataspace and and each thread consumes one
* descriptor. However, all capabilies managed by the same * descriptor. However, all capabilies managed by the same
* entrypoint share the same file descriptor such that the fd * entrypoint share the same file descriptor such that the fd
* limit would be an overly pessimistic upper bound. * limit would be an overly pessimistic upper bound.
* *
* Hence, we define the limit somewhat arbitrary on Linux and * Hence, we define the limit somewhat arbitrary on Linux and
* accept that scenarios may break when reaching core's fd limit. * accept that scenarios may break when reaching core's fd limit.
*/ */
size_t max_caps() const override { return 10000; } size_t max_caps() const override { return 10000; }
void wait_for_exit() override; void wait_for_exit() override;
}; };
}
#endif /* _CORE__INCLUDE__PLATFORM_H_ */ #endif /* _CORE__INCLUDE__PLATFORM_H_ */

View File

@ -2,8 +2,6 @@
* \brief Linux protection domain facility * \brief Linux protection domain facility
* \author Norman Feske * \author Norman Feske
* \date 2006-06-13 * \date 2006-06-13
*
* Pretty dumb.
*/ */
/* /*
@ -24,6 +22,7 @@ namespace Genode {
struct Platform_thread; struct Platform_thread;
} }
struct Genode::Platform_pd struct Genode::Platform_pd
{ {
Platform_pd(Allocator &, char const *) { } Platform_pd(Allocator &, char const *) { }

View File

@ -2,8 +2,6 @@
* \brief Linux thread facility * \brief Linux thread facility
* \author Norman Feske * \author Norman Feske
* \date 2006-06-13 * \date 2006-06-13
*
* Pretty dumb.
*/ */
/* /*
@ -25,135 +23,133 @@
/* core includes */ /* core includes */
#include <pager.h> #include <pager.h>
namespace Genode { namespace Genode { class Platform_thread; }
class Platform_thread;
/* /*
* We hold all Platform_thread objects in a list in order to be able to * We hold all Platform_thread objects in a list in order to be able to
* reflect SIGCHLD as exception signals. When a SIGCHILD occurs, we * reflect SIGCHLD as exception signals. When a SIGCHILD occurs, we
* determine the PID of the terminated child process via 'wait4'. We use * determine the PID of the terminated child process via 'wait4'. We use
* the list to find the 'Platform_thread' matching the TID, wherei, in * the list to find the 'Platform_thread' matching the TID, wherei, in
* turn, we find the exception handler's 'Signal_context_capability'. * turn, we find the exception handler's 'Signal_context_capability'.
*/ */
class Platform_thread : public List<Platform_thread>::Element class Genode::Platform_thread : public List<Platform_thread>::Element
{ {
private: private:
struct Registry struct Registry
{ {
Mutex _mutex { }; Mutex _mutex { };
List<Platform_thread> _list { }; List<Platform_thread> _list { };
void insert(Platform_thread *thread); void insert(Platform_thread *thread);
void remove(Platform_thread *thread); void remove(Platform_thread *thread);
/**
* Trigger exception handler for 'Platform_thread' with matching PID.
*/
void submit_exception(unsigned long pid);
};
/** /**
* Return singleton instance of 'Platform_thread::Registry' * Trigger exception handler for 'Platform_thread' with matching PID.
*/ */
static Registry &_registry(); void submit_exception(unsigned long pid);
};
unsigned long _tid = -1; /**
unsigned long _pid = -1; * Return singleton instance of 'Platform_thread::Registry'
char _name[32] { }; */
static Registry &_registry();
/* unsigned long _tid = -1;
* Dummy pager object that is solely used for storing the unsigned long _pid = -1;
* 'Signal_context_capability' for the thread's exception handler. char _name[32] { };
*/
Pager_object _pager { };
public: /*
* Dummy pager object that is solely used for storing the
* 'Signal_context_capability' for the thread's exception handler.
*/
Pager_object _pager { };
/** public:
* Constructor
*/
Platform_thread(size_t, const char *name, unsigned priority,
Affinity::Location, addr_t);
~Platform_thread(); /**
* Constructor
*/
Platform_thread(size_t, const char *name, unsigned priority,
Affinity::Location, addr_t);
/** ~Platform_thread();
* Pause this thread
*/
void pause();
/** /**
* Enable/disable single stepping * Pause this thread
*/ */
void single_step(bool) { } void pause();
/** /**
* Resume this thread * Enable/disable single stepping
*/ */
void resume(); void single_step(bool) { }
/** /**
* Dummy implementation of platform-thread interface * Resume this thread
*/ */
Pager_object &pager() { return _pager; } void resume();
void pager(Pager_object &) { }
int start(void *, void *) { return 0; }
Thread_state state() /**
{ * Dummy implementation of platform-thread interface
warning("Not implemented"); */
throw Cpu_thread::State_access_failed(); Pager_object &pager() { return _pager; }
} void pager(Pager_object &) { }
int start(void *, void *) { return 0; }
void state(Thread_state) Thread_state state()
{ {
warning("Not implemented"); warning("Not implemented");
throw Cpu_thread::State_access_failed(); throw Cpu_thread::State_access_failed();
} }
const char *name() { return _name; } void state(Thread_state)
{
warning("Not implemented");
throw Cpu_thread::State_access_failed();
}
/** const char *name() { return _name; }
* Set the executing CPU for this thread
*
* SMP is currently not directly supported on Genode/Linux
* (but indirectly by the Linux kernel).
*/
void affinity(Affinity::Location) { }
/** /**
* Request the affinity of this thread * Set the executing CPU for this thread
*/ *
Affinity::Location affinity() const { return Affinity::Location(); } * SMP is currently not directly supported on Genode/Linux
* (but indirectly by the Linux kernel).
*/
void affinity(Affinity::Location) { }
/** /**
* Register process ID and thread ID of thread * Request the affinity of this thread
*/ */
void thread_id(int pid, int tid) { _pid = pid, _tid = tid; } Affinity::Location affinity() const { return Affinity::Location(); }
/** /**
* Notify Genode::Signal handler about sigchld * Register process ID and thread ID of thread
*/ */
static void submit_exception(int pid) void thread_id(int pid, int tid) { _pid = pid, _tid = tid; }
{
_registry().submit_exception(pid);
}
/** /**
* Set CPU quota of the thread to 'quota' * Notify Genode::Signal handler about sigchld
*/ */
void quota(size_t const) { /* not supported*/ } static void submit_exception(int pid)
{
_registry().submit_exception(pid);
}
/** /**
* Return execution time consumed by the thread * Set CPU quota of the thread to 'quota'
*/ */
Trace::Execution_time execution_time() const { return { 0, 0 }; } void quota(size_t const) { /* not supported*/ }
unsigned long pager_object_badge() const { return 0; } /**
}; * Return execution time consumed by the thread
} */
Trace::Execution_time execution_time() const { return { 0, 0 }; }
unsigned long pager_object_badge() const { return 0; }
};
#endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */ #endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */

View File

@ -2,8 +2,6 @@
* \brief Core-specific instance of the region-map interface * \brief Core-specific instance of the region-map interface
* \author Christian Helmuth * \author Christian Helmuth
* \date 2006-07-17 * \date 2006-07-17
*
* Dummies for Linux platform
*/ */
/* /*
@ -75,8 +73,8 @@ struct Genode::Rm_client : Pager_object
{ {
Rm_client(Cpu_session_capability, Thread_capability, Rm_client(Cpu_session_capability, Thread_capability,
Region_map_component &, unsigned long, Region_map_component &, unsigned long,
Affinity::Location, Cpu_session::Name const&, Affinity::Location, Cpu_session::Name const &,
Session_label const&) Session_label const &)
{ } { }
}; };

View File

@ -39,10 +39,10 @@ using namespace Genode;
*/ */
struct Execve_args struct Execve_args
{ {
char const *filename; char const *filename;
char * const *argv; char * const *argv;
char * const *envp; char * const *envp;
Lx_sd const parent_sd; Lx_sd const parent_sd;
Execve_args(char const *filename, Execve_args(char const *filename,
char * const *argv, char * const *argv,

View File

@ -27,7 +27,6 @@
/* Linux includes */ /* Linux includes */
#include <core_linux_syscalls.h> #include <core_linux_syscalls.h>
using namespace Genode; using namespace Genode;
@ -88,7 +87,8 @@ static void sigchld_handler(int)
Platform::Platform() Platform::Platform()
: _core_mem_alloc(nullptr) :
_core_mem_alloc(nullptr)
{ {
/* make 'mmap' behave deterministically */ /* make 'mmap' behave deterministically */
lx_disable_aslr(); lx_disable_aslr();

View File

@ -38,7 +38,7 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args)
Linux_dataspace::Filename fname; Linux_dataspace::Filename fname;
if (label.last_element().length() > sizeof(fname.buf)) { if (label.last_element().length() > sizeof(fname.buf)) {
Genode::error("file name too long: ", label.last_element()); error("file name too long: ", label.last_element());
throw Service_denied(); throw Service_denied();
} }
@ -52,7 +52,7 @@ Linux_dataspace::Filename Dataspace_component::_file_name(const char *args)
} }
Genode::size_t Dataspace_component::_file_size() size_t Dataspace_component::_file_size()
{ {
struct stat64 s; struct stat64 s;
if (lx_stat(_fname.buf, &s) < 0) throw Service_denied(); if (lx_stat(_fname.buf, &s) < 0) throw Service_denied();
@ -62,17 +62,21 @@ Genode::size_t Dataspace_component::_file_size()
Dataspace_component::Dataspace_component(const char *args) Dataspace_component::Dataspace_component(const char *args)
: _fname(_file_name(args)), :
_size(_file_size()), _fname(_file_name(args)),
_addr(0), _size(_file_size()),
_cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), _addr(0),
_writable(false), _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))),
_owner(0) { } _writable(false),
_owner(0)
{ }
Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr, Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr,
Cache_attribute, bool, Dataspace_owner *_owner) : Cache_attribute, bool, Dataspace_owner *_owner)
_size(size), _addr(phys_addr), _cap(), _writable(false), _owner(_owner) :
_size(size), _addr(phys_addr), _cap(), _writable(false), _owner(_owner)
{ {
warning("Should only be used for IOMEM and not within Linux."); warning("Should only be used for IOMEM and not within Linux.");
_fname.buf[0] = 0; _fname.buf[0] = 0;
} }

View File

@ -11,48 +11,56 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
/* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <linux_dataspace/client.h> #include <linux_dataspace/client.h>
#include <base/internal/page_size.h>
#include <core_linux_syscalls.h>
#include <io_mem_session_component.h> #include <io_mem_session_component.h>
/* base-internal includes */
#include <base/internal/page_size.h>
/* core-local includes */
#include <core_linux_syscalls.h>
using namespace Genode; using namespace Genode;
size_t Io_mem_session_component::get_arg_size(const char *) size_t Io_mem_session_component::get_arg_size(const char *)
{ {
warning(__func__, " not implemented"); warning(__func__, " not implemented");
return 0; return 0;
} }
addr_t Io_mem_session_component::get_arg_phys(const char *) addr_t Io_mem_session_component::get_arg_phys(const char *)
{ {
warning(__func__, " not implemented"); warning(__func__, " not implemented");
return 0; return 0;
} }
Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc, Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc,
Range_allocator &, Range_allocator &,
Rpc_entrypoint &ds_ep, Rpc_entrypoint &ds_ep,
const char *args) : const char *args)
_io_mem_alloc(io_mem_alloc), :
_ds(0, 0, 0, UNCACHED, true, 0), _io_mem_alloc(io_mem_alloc),
_ds_ep(ds_ep), _ds(0, 0, 0, UNCACHED, true, 0),
_ds_cap(Io_mem_dataspace_capability()) _ds_ep(ds_ep),
_ds_cap(Io_mem_dataspace_capability())
{ {
warning("no io_mem support on Linux (args=\"", args, "\")"); } warning("no io_mem support on Linux (args=\"", args, "\")");
}
Cache_attribute Io_mem_session_component::get_arg_wc(const char *) Cache_attribute Io_mem_session_component::get_arg_wc(const char *)
{ {
warning(__func__, " not implemented"); warning(__func__, " not implemented");
return UNCACHED; return UNCACHED;
} }
Io_mem_dataspace_capability Io_mem_session_component::dataspace() Io_mem_dataspace_capability Io_mem_session_component::dataspace()
{ {
return Io_mem_dataspace_capability(); return Io_mem_dataspace_capability();
} }

View File

@ -11,17 +11,18 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
#include <util/string.h>
#include <util/arg_string.h>
#include <root/root.h>
#include <io_port_session_component.h> #include <io_port_session_component.h>
using namespace Genode;
Genode::Io_port_session_component::Io_port_session_component(Genode::Range_allocator &io_port_alloc, const char *)
: _io_port_alloc(io_port_alloc) Io_port_session_component::Io_port_session_component(Range_allocator &io_port_alloc,
const char *)
:
_io_port_alloc(io_port_alloc)
{ {
Genode::warning("IO PORTS are not supported on base linux"); warning("I/O port access is not supported on base linux");
} }
Genode::Io_port_session_component::~Io_port_session_component()
{} Io_port_session_component::~Io_port_session_component() { }

View File

@ -1,7 +1,7 @@
/* /*
* \brief IRQ session implementation for base-linux * \brief IRQ session implementation for base-linux
* \author Johannes Kliemann * \author Johannes Kliemann
* \date 2018-03-14 * \date 2018-03-14
* *
*/ */
@ -13,68 +13,76 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
/* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <base/thread.h> #include <base/thread.h>
#include <irq_session_component.h> #include <irq_session_component.h>
/* core-local includes */
#include <core_linux_syscalls.h> #include <core_linux_syscalls.h>
Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &, const char *) using namespace Genode;
Irq_session_component::Irq_session_component(Range_allocator &, const char *)
: :
_irq_number(0), _irq_number(0), _irq_object(_irq_number)
_irq_object(_irq_number)
{ } { }
Genode::Irq_session_component::~Irq_session_component()
Irq_session_component::~Irq_session_component()
{ {
warning(__func__, " not implemented"); warning(__func__, " not implemented");
} }
void Genode::Irq_session_component::ack_irq()
{ }
void Genode::Irq_session_component::sigh(Genode::Signal_context_capability) void Irq_session_component::ack_irq() { }
{ }
Genode::Irq_session::Info Genode::Irq_session_component::info()
void Irq_session_component::sigh(Signal_context_capability) { }
Irq_session::Info Irq_session_component::info()
{ {
return { .type = Genode::Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; return { .type = Irq_session::Info::Type::INVALID, .address = 0, .value = 0 };
} }
Genode::Irq_object::Irq_object(unsigned irq) :
Irq_object::Irq_object(unsigned irq)
:
Thread_deprecated<4096>("irq"), Thread_deprecated<4096>("irq"),
_sig_cap(Signal_context_capability()), _sig_cap(Signal_context_capability()), _irq(irq), _fd(-1)
_irq(irq),
_fd(-1)
{ {
Genode::warning(__func__, " not implemented"); warning(__func__, " not implemented");
}
bool Genode::Irq_object::_associate()
{
Genode::warning(__func__, " not implemented");
return false;
}
void Genode::Irq_object::entry()
{
Genode::warning(__func__, " not implemented");
}
void Genode::Irq_object::ack_irq()
{
Genode::warning(__func__, " not implemented");
}
void Genode::Irq_object::start()
{
Genode::warning(__func__, " not implemented");
}
void Genode::Irq_object::sigh(Signal_context_capability)
{
Genode::warning(__func__, " not implemented");
} }
bool Irq_object::_associate()
{
warning(__func__, " not implemented");
return false;
}
void Irq_object::entry()
{
warning(__func__, " not implemented");
}
void Irq_object::ack_irq()
{
warning(__func__, " not implemented");
}
void Irq_object::start()
{
warning(__func__, " not implemented");
}
void Irq_object::sigh(Signal_context_capability)
{
warning(__func__, " not implemented");
}

View File

@ -16,22 +16,11 @@
#include <base/service.h> #include <base/service.h>
/* core includes */ /* core includes */
#include <core_env.h>
#include <platform.h>
#include <platform_services.h> #include <platform_services.h>
#include <io_port_root.h>
#include <core_linux_syscalls.h>
/** void Genode::platform_add_local_services(Rpc_entrypoint &,
* Add x86 specific ioport service Sliced_heap &,
*/ Registry<Service> &,
Trace::Source_registry &)
namespace Genode { }
{
void platform_add_local_services(Rpc_entrypoint &,
Sliced_heap &,
Registry<Service> &,
Trace::Source_registry &)
{ }
}

View File

@ -61,16 +61,20 @@ Genode::size_t Dataspace_component::_file_size()
Dataspace_component::Dataspace_component(const char *args) Dataspace_component::Dataspace_component(const char *args)
: _fname(_file_name(args)), :
_size(_file_size()), _fname(_file_name(args)),
_addr(0), _size(_file_size()),
_cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))), _addr(0),
_writable(false), _cap(_fd_to_cap(lx_open(_fname.buf, O_RDONLY | LX_O_CLOEXEC, S_IRUSR | S_IXUSR))),
_owner(0) { } _writable(false),
_owner(0)
{ }
Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr, Dataspace_component::Dataspace_component(size_t size, addr_t, addr_t phys_addr,
Cache_attribute, bool writable, Dataspace_owner *_owner) : Cache_attribute, bool writable, Dataspace_owner *_owner)
_size(size), _addr(phys_addr), _cap(), _writable(writable), _owner(_owner) :
_size(size), _addr(phys_addr), _cap(), _writable(writable), _owner(_owner)
{ {
_fname.buf[0] = 0; _fname.buf[0] = 0;
} }

View File

@ -11,17 +11,18 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
/* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <linux_dataspace/client.h> #include <linux_dataspace/client.h>
#include <base/internal/page_size.h> #include <base/internal/page_size.h>
#include <core_linux_syscalls.h>
#include <io_mem_session_component.h> #include <io_mem_session_component.h>
/* core-local includes */
#include <core_linux_syscalls.h>
using namespace Genode; using namespace Genode;
size_t Io_mem_session_component::get_arg_size(const char *args) size_t Io_mem_session_component::get_arg_size(const char *args)
{ {
size_t const size = Arg_string::find_arg(args, "size").ulong_value(0); size_t const size = Arg_string::find_arg(args, "size").ulong_value(0);
@ -38,9 +39,10 @@ addr_t Io_mem_session_component::get_arg_phys(const char *args)
return Arg_string::find_arg(args, "base").ulong_value(0); return Arg_string::find_arg(args, "base").ulong_value(0);
} }
Cache_attribute Io_mem_session_component::get_arg_wc(const char *args) Cache_attribute Io_mem_session_component::get_arg_wc(const char *args)
{ {
Arg a = Arg_string::find_arg("wc", args); Arg const a = Arg_string::find_arg("wc", args);
if (a.valid() && a.bool_value(0)) { if (a.valid() && a.bool_value(0)) {
return WRITE_COMBINED; return WRITE_COMBINED;
} else { } else {
@ -58,10 +60,10 @@ Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc
_ds_ep(ds_ep), _ds_ep(ds_ep),
_ds_cap(Io_mem_dataspace_capability()) _ds_cap(Io_mem_dataspace_capability())
{ {
int _fd = -1; int _fd = lx_open("/dev/hwio", O_RDWR | O_SYNC);
_fd = lx_open("/dev/hwio", O_RDWR | O_SYNC);
lx_ioctl_iomem(_fd, (unsigned long)get_arg_phys(args), get_arg_size(args)); lx_ioctl_iomem(_fd, (unsigned long)get_arg_phys(args), get_arg_size(args));
if (_fd > 0) { if (_fd > 0) {
_ds.fd(_fd); _ds.fd(_fd);
} else { } else {
@ -72,7 +74,8 @@ Io_mem_session_component::Io_mem_session_component(Range_allocator &io_mem_alloc
_ds_cap = static_cap_cast<Io_mem_dataspace>(static_cap_cast<Dataspace>(_ds_ep.manage(&_ds))); _ds_cap = static_cap_cast<Io_mem_dataspace>(static_cap_cast<Dataspace>(_ds_ep.manage(&_ds)));
} }
Io_mem_dataspace_capability Io_mem_session_component::dataspace() Io_mem_dataspace_capability Io_mem_session_component::dataspace()
{ {
return _ds_cap; return _ds_cap;
} }

View File

@ -11,19 +11,20 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
#include <util/string.h>
#include <util/arg_string.h> #include <util/arg_string.h>
#include <root/root.h>
#include <io_port_session_component.h> #include <io_port_session_component.h>
using namespace Genode;
Genode::Io_port_session_component::Io_port_session_component(Genode::Range_allocator &io_port_alloc, const char *args)
: _io_port_alloc(io_port_alloc) Io_port_session_component::Io_port_session_component(Range_allocator &io_port_alloc,
const char *args)
:
_io_port_alloc(io_port_alloc)
{ {
/* parse for port properties */ /* parse for port properties */
_base = Arg_string::find_arg(args, "io_port_base").ulong_value(0); _base = Arg_string::find_arg(args, "io_port_base").ulong_value(0);
_size = Arg_string::find_arg(args, "io_port_size").ulong_value(0); _size = Arg_string::find_arg(args, "io_port_size").ulong_value(0);
} }
Genode::Io_port_session_component::~Io_port_session_component() Io_port_session_component::~Io_port_session_component() { }
{}

View File

@ -1,8 +1,7 @@
/* /*
* \brief IRQ session implementation for base-linux * \brief IRQ session implementation for base-linux
* \author Johannes Kliemann * \author Johannes Kliemann
* \date 2018-03-14 * \date 2018-03-14
*
*/ */
/* /*
@ -13,15 +12,19 @@
* under the terms of the GNU Affero General Public License version 3. * under the terms of the GNU Affero General Public License version 3.
*/ */
/* Genode includes */
#include <base/log.h> #include <base/log.h>
#include <base/thread.h> #include <base/thread.h>
/* core-local includes */
#include <irq_session_component.h> #include <irq_session_component.h>
#include <irq_object.h> #include <irq_object.h>
#include <core_linux_syscalls.h> #include <core_linux_syscalls.h>
Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &, const char *args) using namespace Genode;
Irq_session_component::Irq_session_component(Range_allocator &, const char *args)
: :
_irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)), _irq_number(Arg_string::find_arg(args, "irq_number").long_value(-1)),
_irq_object(_irq_number) _irq_object(_irq_number)
@ -29,90 +32,93 @@ Genode::Irq_session_component::Irq_session_component(Genode::Range_allocator &,
_irq_object.start(); _irq_object.start();
} }
Genode::Irq_session_component::~Irq_session_component()
Irq_session_component::~Irq_session_component()
{ {
warning(__func__, " not implemented"); warning(__func__, " not implemented");
} }
void Genode::Irq_session_component::ack_irq()
void Irq_session_component::ack_irq()
{ {
_irq_object.ack_irq(); _irq_object.ack_irq();
} }
void Genode::Irq_session_component::sigh(Genode::Signal_context_capability cap)
void Irq_session_component::sigh(Signal_context_capability cap)
{ {
_irq_object.sigh(cap); _irq_object.sigh(cap);
} }
Genode::Irq_session::Info Genode::Irq_session_component::info()
Irq_session::Info Irq_session_component::info()
{ {
return { .type = Genode::Irq_session::Info::Type::INVALID, .address = 0, .value = 0 }; return { .type = Irq_session::Info::Type::INVALID, .address = 0, .value = 0 };
} }
Genode::Irq_object::Irq_object(unsigned irq) : Irq_object::Irq_object(unsigned irq)
:
Thread_deprecated<4096>("irq"), Thread_deprecated<4096>("irq"),
_sig_cap(Signal_context_capability()), _sig_cap(Signal_context_capability()), _irq(irq), _fd(-1)
_irq(irq),
_fd(-1)
{ } { }
bool Genode::Irq_object::_associate()
bool Irq_object::_associate()
{ {
_fd = lx_open("/dev/hwio", O_RDWR | O_SYNC); _fd = lx_open("/dev/hwio", O_RDWR | O_SYNC);
if (_fd < 0){ if (_fd < 0){
Genode::error("failed to open /dev/hwio"); error("failed to open /dev/hwio");
return false; return false;
} }
if (lx_ioctl_irq(_fd, _irq) < 0){ if (lx_ioctl_irq(_fd, _irq) < 0){
Genode::error("failed to request irq"); error("failed to request irq");
return false; return false;
} }
return true; return true;
} }
void Genode::Irq_object::entry()
void Irq_object::entry()
{ {
if (!_associate()) { if (!_associate())
error("failed to register IRQ ", _irq); error("failed to register IRQ ", _irq);
}
_sync_bootup.wakeup(); _sync_bootup.wakeup();
_sync_ack.block(); _sync_ack.block();
while (true) { while (true) {
if (lx_read(_fd, 0, 0) < 0) { if (lx_read(_fd, 0, 0) < 0)
Genode::warning("failed to read on /dev/hwio"); warning("failed to read on /dev/hwio");
}
if(!_sig_cap.valid()){ if(!_sig_cap.valid())
continue; continue;
}
Genode::Signal_transmitter(_sig_cap).submit(1); Signal_transmitter(_sig_cap).submit(1);
_sync_ack.block(); _sync_ack.block();
} }
} }
void Genode::Irq_object::ack_irq()
void Irq_object::ack_irq()
{ {
_sync_ack.wakeup(); _sync_ack.wakeup();
} }
void Genode::Irq_object::start()
void Irq_object::start()
{ {
Genode::Thread::start(); Thread::start();
_sync_bootup.block(); _sync_bootup.block();
} }
void Genode::Irq_object::sigh(Signal_context_capability cap)
void Irq_object::sigh(Signal_context_capability cap)
{ {
_sig_cap = cap; _sig_cap = cap;
} }

View File

@ -20,25 +20,19 @@
#include <platform.h> #include <platform.h>
#include <platform_services.h> #include <platform_services.h>
#include <io_port_root.h> #include <io_port_root.h>
#include <core_linux_syscalls.h> #include <core_linux_syscalls.h>
/** void Genode::platform_add_local_services(Rpc_entrypoint &,
* Add x86 specific ioport service Sliced_heap &md,
*/ Registry<Service> &reg,
namespace Genode Trace::Source_registry &)
{ {
void platform_add_local_services(Rpc_entrypoint &, if (!lx_iopl(3)) {
Sliced_heap &md, static Io_port_root io_port_root(*core_env().pd_session(),
Registry<Service> &reg, platform().io_port_alloc(), md);
Trace::Source_registry &)
{
if (!lx_iopl(3)) {
static Io_port_root io_port_root(*core_env().pd_session(),
platform().io_port_alloc(), md);
static Core_service<Io_port_session_component> static Core_service<Io_port_session_component>
io_port_ls(reg, io_port_root);
} io_port_ls(reg, io_port_root);
} }
} }

View File

@ -92,18 +92,16 @@ struct Stack_area_ram_allocator : Genode::Ram_allocator
/** /**
* Return single instance of the stack-area RM and RAM session * Return single instance of the stack-area RM and RAM session
*/ */
namespace Genode {
Region_map *env_stack_area_region_map; Genode::Region_map *Genode::env_stack_area_region_map;
Ram_allocator *env_stack_area_ram_allocator; Genode::Ram_allocator *Genode::env_stack_area_ram_allocator;
void init_stack_area() void Genode::init_stack_area()
{ {
static Stack_area_region_map rm_inst; static Stack_area_region_map rm_inst;
env_stack_area_region_map = &rm_inst; env_stack_area_region_map = &rm_inst;
static Stack_area_ram_allocator ram_inst; static Stack_area_ram_allocator ram_inst;
env_stack_area_ram_allocator = &ram_inst; env_stack_area_ram_allocator = &ram_inst;
}
} }

View File

@ -4,7 +4,7 @@
* \author Stefan Kalkowski * \author Stefan Kalkowski
* \date 2011-05-22 * \date 2011-05-22
* *
* A typed capability is a capability tied to one specifiec RPC interface * A typed capability is a capability tied to one specifiec RPC interface.
*/ */
/* /*

View File

@ -24,7 +24,6 @@
#include <base/internal/expanding_parent_client.h> #include <base/internal/expanding_parent_client.h>
namespace Genode { namespace Genode {
class Local_session; class Local_session;
class Local_parent; class Local_parent;
} }

View File

@ -21,6 +21,7 @@
namespace Genode { struct Native_thread; } namespace Genode { struct Native_thread; }
class Genode::Native_thread class Genode::Native_thread
{ {
private: private:

View File

@ -37,8 +37,9 @@ class Genode::Region_map_mmap : public Region_map, public Dataspace
private: private:
Region_registry _rmap { }; Region_registry _rmap { };
bool const _sub_rm; /* false if region map is root */
size_t const _size; bool const _sub_rm; /* false if region map is root */
size_t const _size;
/** /**
* Base offset of the RM session * Base offset of the RM session

View File

@ -19,30 +19,30 @@
#include <base/rpc_client.h> #include <base/rpc_client.h>
#include <util/string.h> #include <util/string.h>
namespace Genode { namespace Genode { struct Linux_dataspace_client; }
struct Linux_dataspace_client : Rpc_client<Linux_dataspace>
{
explicit Linux_dataspace_client(Dataspace_capability ds)
: Rpc_client<Linux_dataspace>(static_cap_cast<Linux_dataspace>(ds)) { }
/********************************* struct Genode::Linux_dataspace_client : Rpc_client<Linux_dataspace>
** Generic dataspace interface ** {
*********************************/ explicit Linux_dataspace_client(Dataspace_capability ds)
: Rpc_client<Linux_dataspace>(static_cap_cast<Linux_dataspace>(ds)) { }
size_t size() override { return call<Rpc_size>(); }
addr_t phys_addr() override { return call<Rpc_phys_addr>(); }
bool writable() override { return call<Rpc_writable>(); }
/**************************************** /*********************************
** Linux-specific dataspace interface ** ** Generic dataspace interface **
****************************************/ *********************************/
Filename fname() override { return call<Rpc_fname>(); } size_t size() override { return call<Rpc_size>(); }
Untyped_capability fd() override { return call<Rpc_fd>(); } addr_t phys_addr() override { return call<Rpc_phys_addr>(); }
}; bool writable() override { return call<Rpc_writable>(); }
}
/****************************************
** Linux-specific dataspace interface **
****************************************/
Filename fname() override { return call<Rpc_fname>(); }
Untyped_capability fd() override { return call<Rpc_fd>(); }
};
#endif /* _INCLUDE__LINUX_DATASPACE__CLIENT_H_ */ #endif /* _INCLUDE__LINUX_DATASPACE__CLIENT_H_ */

View File

@ -19,37 +19,37 @@
#include <base/ipc.h> #include <base/ipc.h>
#include <base/rpc.h> #include <base/rpc.h>
namespace Genode { namespace Genode { struct Linux_dataspace; }
struct Linux_dataspace : Dataspace
{
enum { FNAME_LEN = 64 };
struct Filename { char buf[FNAME_LEN]; };
virtual ~Linux_dataspace() { }
/**
* Request name of file that represents the dataspace on Linux
*
* This function is used for calling execve on files passed as ROM
* dataspaces.
*/
virtual Filename fname() = 0;
/**
* Request file descriptor of the dataspace
*/
virtual Untyped_capability fd() = 0;
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_fname, Filename, fname); struct Genode::Linux_dataspace : Dataspace
GENODE_RPC(Rpc_fd, Untyped_capability, fd); {
GENODE_RPC_INTERFACE_INHERIT(Dataspace, Rpc_fname, Rpc_fd); enum { FNAME_LEN = 64 };
}; struct Filename { char buf[FNAME_LEN]; };
}
virtual ~Linux_dataspace() { }
/**
* Request name of file that represents the dataspace on Linux
*
* This function is used for calling execve on files passed as ROM
* dataspaces.
*/
virtual Filename fname() = 0;
/**
* Request file descriptor of the dataspace
*/
virtual Untyped_capability fd() = 0;
/*********************
** RPC declaration **
*********************/
GENODE_RPC(Rpc_fname, Filename, fname);
GENODE_RPC(Rpc_fd, Untyped_capability, fd);
GENODE_RPC_INTERFACE_INHERIT(Dataspace, Rpc_fname, Rpc_fd);
};
#endif /* _INCLUDE__LINUX_DATASPACE__LINUX_DATASPACE_H_ */ #endif /* _INCLUDE__LINUX_DATASPACE__LINUX_DATASPACE_H_ */

View File

@ -19,6 +19,7 @@
namespace Genode { struct Linux_native_cpu_client; } namespace Genode { struct Linux_native_cpu_client; }
struct Genode::Linux_native_cpu_client : Rpc_client<Linux_native_cpu> struct Genode::Linux_native_cpu_client : Rpc_client<Linux_native_cpu>
{ {
explicit Linux_native_cpu_client(Capability<Native_cpu> cap) explicit Linux_native_cpu_client(Capability<Native_cpu> cap)

View File

@ -19,6 +19,7 @@
namespace Genode { struct Linux_native_pd_client; } namespace Genode { struct Linux_native_pd_client; }
struct Genode::Linux_native_pd_client : Rpc_client<Linux_native_pd> struct Genode::Linux_native_pd_client : Rpc_client<Linux_native_pd>
{ {
explicit Linux_native_pd_client(Capability<Native_pd> cap) explicit Linux_native_pd_client(Capability<Native_pd> cap)

View File

@ -21,7 +21,6 @@
#include <linux_syscalls.h> #include <linux_syscalls.h>
#include <base/internal/elf.h> #include <base/internal/elf.h>
using namespace Genode; using namespace Genode;

View File

@ -27,10 +27,15 @@ using namespace Genode;
extern char _binary_seccomp_bpf_policy_bin_start[]; extern char _binary_seccomp_bpf_policy_bin_start[];
extern char _binary_seccomp_bpf_policy_bin_end[]; extern char _binary_seccomp_bpf_policy_bin_end[];
struct bpf_program {
Genode::uint16_t blk_cnt; namespace Genode {
Genode::uint64_t* blks;
}; struct Bpf_program
{
uint16_t blk_cnt;
uint64_t *blks;
};
}
void Genode::binary_ready_hook_for_platform() void Genode::binary_ready_hook_for_platform()
{ {
@ -40,19 +45,22 @@ void Genode::binary_ready_hook_for_platform()
} }
for (char* i = _binary_seccomp_bpf_policy_bin_start; for (char* i = _binary_seccomp_bpf_policy_bin_start;
i < _binary_seccomp_bpf_policy_bin_end - sizeof(Genode::uint32_t); i++) { i < _binary_seccomp_bpf_policy_bin_end - sizeof(uint32_t); i++) {
Genode::uint32_t* v = reinterpret_cast<Genode::uint32_t*>(i);
uint32_t *v = reinterpret_cast<uint32_t *>(i);
if (*v == 0xCAFEAFFE) { if (*v == 0xCAFEAFFE) {
*v = lx_getpid(); *v = lx_getpid();
} }
} }
bpf_program program; Bpf_program program {
program.blk_cnt = (_binary_seccomp_bpf_policy_bin_end - .blk_cnt = (uint16_t)((_binary_seccomp_bpf_policy_bin_end -
_binary_seccomp_bpf_policy_bin_start) / _binary_seccomp_bpf_policy_bin_start) /
sizeof(Genode::uint64_t); sizeof(uint64_t)),
program.blks = (Genode::uint64_t*)_binary_seccomp_bpf_policy_bin_start; .blks = (uint64_t *)_binary_seccomp_bpf_policy_bin_start
Genode::uint64_t flags = SECCOMP_FILTER_FLAG_TSYNC; };
uint64_t flags = SECCOMP_FILTER_FLAG_TSYNC;
auto ret = lx_seccomp(SECCOMP_SET_MODE_FILTER, flags, &program); auto ret = lx_seccomp(SECCOMP_SET_MODE_FILTER, flags, &program);
if (ret != 0) { if (ret != 0) {
error("SECCOMP_SET_MODE_FILTER failed ", ret); error("SECCOMP_SET_MODE_FILTER failed ", ret);

View File

@ -19,8 +19,10 @@
using namespace Genode; using namespace Genode;
class Capability_invalid : public Genode::Exception {}; class Capability_invalid : public Genode::Exception {};
/** /**
* Return pointer to locally implemented region map * Return pointer to locally implemented region map
* *

View File

@ -79,37 +79,45 @@ static Genode::Env *_env_ptr;
namespace Genode { namespace Genode {
extern void bootstrap_component(); extern void bootstrap_component();
extern void call_global_static_constructors(); extern void call_global_static_constructors();
/* struct Thread_meta_data_created;
* This function is normally provided by the cxx library, which is not struct Thread_meta_data_adopted;
* used for lx_hybrid programs. For lx_hybrid programs, the exception
* handling is initialized by the host system's regular startup code.
*
* However, we conveniently use this function to get hold of the
* component's environment and initialize the default log output.
*/
void init_exception_handling(Env &env)
{
_env_ptr = &env;
init_log(env.parent());
}
} }
/*
* This function is normally provided by the cxx library, which is not
* used for lx_hybrid programs. For lx_hybrid programs, the exception
* handling is initialized by the host system's regular startup code.
*
* However, we conveniently use this function to get hold of the
* component's environment and initialize the default log output.
*/
void Genode::init_exception_handling(Env &env)
{
_env_ptr = &env;
init_log(env.parent());
}
/* /*
* Static constructors are handled by the Linux startup code - so implement * Static constructors are handled by the Linux startup code - so implement
* this as empty function. * this as empty function.
*/ */
void Genode::call_global_static_constructors() { } void Genode::call_global_static_constructors() { }
Genode::size_t Component::stack_size() __attribute__((weak)); Genode::size_t Component::stack_size() __attribute__((weak));
Genode::size_t Component::stack_size() Genode::size_t Component::stack_size()
{ {
return 16UL * 1024 * sizeof(Genode::addr_t); return 16UL * 1024 * sizeof(Genode::addr_t);
} }
/* /*
* Hybrid components are not allowed to implement legacy main(). This enables * Hybrid components are not allowed to implement legacy main(). This enables
* us to hook in and bootstrap components as usual. * us to hook in and bootstrap components as usual.
@ -184,165 +192,164 @@ static pthread_key_t tls_key()
} }
namespace Genode { /**
* Meta data tied to the thread via the pthread TLS mechanism
*/
struct Genode::Native_thread::Meta_data
{
/**
* Linux-specific thread meta data
*
* For non-hybrid programs, this information is located at the
* 'Stack'. But the POSIX threads of hybrid programs have no 'Stack'
* object. So we have to keep the meta data here.
*/
Native_thread native_thread { };
/** /**
* Meta data tied to the thread via the pthread TLS mechanism * Filled out by 'thread_start' function in the stack of the new
* thread
*/ */
struct Native_thread::Meta_data Thread &thread_base;
/**
* POSIX thread handle
*/
pthread_t pt { };
/**
* Constructor
*
* \param thread associated 'Thread' object
*/
Meta_data(Thread *thread) : thread_base(*thread)
{ {
/** native_thread.meta_data = this;
* Linux-specific thread meta data }
*
* For non-hybrid programs, this information is located at the
* 'Stack'. But the POSIX threads of hybrid programs have no 'Stack'
* object. So we have to keep the meta data here.
*/
Native_thread native_thread { };
/** virtual ~Meta_data() { }
* Filled out by 'thread_start' function in the stack of the new
* thread
*/
Thread &thread_base;
/** /**
* POSIX thread handle * Used to block the constructor until the new thread has initialized
*/ * 'id'
pthread_t pt { }; */
virtual void wait_for_construction() = 0;
virtual void constructed() = 0;
/** /**
* Constructor * Used to block the new thread until 'start' is called
* */
* \param thread associated 'Thread' object virtual void wait_for_start() = 0;
*/ virtual void started() = 0;
Meta_data(Thread *thread) : thread_base(*thread)
{
native_thread.meta_data = this;
}
virtual ~Meta_data() { } /**
* Used to block the 'join()' function until the 'entry()' is done
*/
virtual void wait_for_join() = 0;
virtual void joined() = 0;
};
/**
* Thread meta data for a thread created by Genode
*/
class Genode::Thread_meta_data_created : public Native_thread::Meta_data
{
private:
/** /**
* Used to block the constructor until the new thread has initialized * Used to block the constructor until the new thread has initialized
* 'id' * 'id'
*/ */
virtual void wait_for_construction() = 0; Blockade _construct_lock { };
virtual void constructed() = 0;
/** /**
* Used to block the new thread until 'start' is called * Used to block the new thread until 'start' is called
*/ */
virtual void wait_for_start() = 0; Blockade _start_lock { };
virtual void started() = 0;
/** /**
* Used to block the 'join()' function until the 'entry()' is done * Used to block the 'join()' function until the 'entry()' is done
*/ */
virtual void wait_for_join() = 0; Blockade _join_lock { };
virtual void joined() = 0;
};
/** public:
* Thread meta data for a thread created by Genode
*/
class Thread_meta_data_created : public Native_thread::Meta_data
{
private:
/** Thread_meta_data_created(Thread *thread)
* Used to block the constructor until the new thread has initialized : Native_thread::Meta_data(thread) { }
* 'id'
*/
Blockade _construct_lock { };
/** void wait_for_construction() override
* Used to block the new thread until 'start' is called {
*/ _construct_lock.block();
Blockade _start_lock { }; }
/** void constructed() override
* Used to block the 'join()' function until the 'entry()' is done {
*/ _construct_lock.wakeup();
Blockade _join_lock { }; }
public: void wait_for_start() override
{
_start_lock.block();
}
Thread_meta_data_created(Thread *thread) void started() override
: Native_thread::Meta_data(thread) { } {
_start_lock.wakeup();
}
void wait_for_construction() override void wait_for_join() override
{ {
_construct_lock.block(); _join_lock.block();
} }
void constructed() override void joined() override
{ {
_construct_lock.wakeup(); _join_lock.wakeup();
} }
};
void wait_for_start() override
{
_start_lock.block();
}
void started() override /**
{ * Thread meta data for an adopted thread
_start_lock.wakeup(); */
} class Genode::Thread_meta_data_adopted : public Native_thread::Meta_data
{
public:
void wait_for_join() override Thread_meta_data_adopted(Thread *thread)
{ : Native_thread::Meta_data(thread) { }
_join_lock.block();
}
void joined() override void wait_for_construction() override
{ {
_join_lock.wakeup(); error("wait_for_construction() called for an adopted thread");
} }
};
/** void constructed() override
* Thread meta data for an adopted thread {
*/ error("constructed() called for an adopted thread");
class Thread_meta_data_adopted : public Native_thread::Meta_data }
{
public:
Thread_meta_data_adopted(Thread *thread) void wait_for_start() override
: Native_thread::Meta_data(thread) { } {
error("wait_for_start() called for an adopted thread");
}
void wait_for_construction() override void started() override
{ {
error("wait_for_construction() called for an adopted thread"); error("started() called for an adopted thread");
} }
void constructed() override void wait_for_join() override
{ {
error("constructed() called for an adopted thread"); error("wait_for_join() called for an adopted thread");
} }
void wait_for_start() override void joined() override
{ {
error("wait_for_start() called for an adopted thread"); error("joined() called for an adopted thread");
} }
};
void started() override
{
error("started() called for an adopted thread");
}
void wait_for_join() override
{
error("wait_for_join() called for an adopted thread");
}
void joined() override
{
error("joined() called for an adopted thread");
}
};
}
static void adopt_thread(Native_thread::Meta_data *meta_data) static void adopt_thread(Native_thread::Meta_data *meta_data)

View File

@ -19,21 +19,21 @@
#define STR(x) STR2(x) #define STR(x) STR2(x)
#define INCBIN(name, file) \ #define INCBIN(name, file) \
__asm__(".section .rodata\n" \ __asm__(".section .rodata\n" \
".global incbin_" STR(name) "_start\n" \ ".global incbin_" STR(name) "_start\n" \
".type incbin_" STR(name) "_start, @object\n" \ ".type incbin_" STR(name) "_start, @object\n" \
".balign 16\n" \ ".balign 16\n" \
"incbin_" STR(name) "_start:\n" \ "incbin_" STR(name) "_start:\n" \
".incbin \"" file "\"\n" \ ".incbin \"" file "\"\n" \
\ \
".global incbin_" STR(name) "_end\n" \ ".global incbin_" STR(name) "_end\n" \
".type incbin_" STR(name) "_end, @object\n" \ ".type incbin_" STR(name) "_end, @object\n" \
".balign 1\n" \ ".balign 1\n" \
"incbin_" STR(name) "_end:\n" \ "incbin_" STR(name) "_end:\n" \
".byte 0\n" \ ".byte 0\n" \
); \ ); \
extern const __attribute__((aligned(16))) void* incbin_ ## name ## _start; \ extern const __attribute__((aligned(16))) void* incbin_ ## name ## _start; \
extern const void* incbin_ ## name ## _end; \ extern const void* incbin_ ## name ## _end; \
INCBIN(seccomp_bpf_policy, "seccomp_bpf_policy.bin"); INCBIN(seccomp_bpf_policy, "seccomp_bpf_policy.bin");

View File

@ -23,7 +23,6 @@
#include <stdlib.h> #include <stdlib.h>
static Genode::Blockade *main_wait_lock() static Genode::Blockade *main_wait_lock()
{ {
static Genode::Blockade inst; static Genode::Blockade inst;