base: remove dependency from deprecated APIs

This patch adjusts the implementation of the base library and core such
that the code no longer relies on deprecated APIs except for very few
cases, mainly to keep those deprecated APIs in tact for now.

The most prominent changes are:

- Removing the use of base/printf.h

- Removing of the log backend for printf. The 'Console' with the
  format-string parser is still there along with 'snprintf.h' because
  the latter is still used at a few places, most prominently the
  'Connection' classes.

- Removing the notion of a RAM session, which does not exist in
  Genode anymore. Still the types were preserved (by typedefs to
  PD session) to keep up compatibility. But this transition should
  come to an end now.

- Slight rennovation of core's tracing service, e.g., the use of an
  Attached_dataspace as the Argument_buffer.

- Reducing the reliance on global accessors like deprecated_env() or
  core_env(). Still there is a longish way to go to eliminate all such
  calls. A useful pattern (or at least a stop-gap solution) is to
  pass the 'Env' to the individual compilation units via init functions.

- Avoiding the use of the old 'Child_policy::resolve_session_request'
  interface that returned a 'Service' instead of a 'Route'.

Issue #1987
This commit is contained in:
Norman Feske
2019-01-30 17:53:16 +01:00
parent c629a92aa2
commit aa66b5d62f
84 changed files with 396 additions and 525 deletions

View File

@ -19,8 +19,8 @@
/* Genode includes */
#include <base/signal.h>
#include <cpu_session/cpu_session.h> /* for 'Thread_capability' type */
#include <pager/capability.h>
#include <thread/capability.h>
/* core-local includes */
#include <rpc_cap_factory.h>

View File

@ -49,6 +49,8 @@ static inline Genode::Socket_pair create_server_socket_pair(long id)
{
Genode::Socket_pair socket_pair;
using Genode::raw;
/*
* Main thread uses 'Ipc_server' for 'sleep_forever()' only. No need for
* binding.
@ -63,7 +65,7 @@ static inline Genode::Socket_pair create_server_socket_pair(long id)
*/
socket_pair.server_sd = lx_socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (socket_pair.server_sd < 0) {
PRAW("Error: Could not create server-side socket (ret=%d)", socket_pair.server_sd);
raw("Error: Could not create server-side socket (ret=", socket_pair.server_sd, ")");
class Server_socket_failed { };
throw Server_socket_failed();
}
@ -73,7 +75,7 @@ static inline Genode::Socket_pair create_server_socket_pair(long id)
int const bind_ret = lx_bind(socket_pair.server_sd, (sockaddr *)&addr, sizeof(addr));
if (bind_ret < 0) {
PRAW("Error: Could not bind server socket (ret=%d)", bind_ret);
raw("Error: Could not bind server socket (ret=", bind_ret, ")");
class Bind_failed { };
throw Bind_failed();
}
@ -83,14 +85,14 @@ static inline Genode::Socket_pair create_server_socket_pair(long id)
*/
socket_pair.client_sd = lx_socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (socket_pair.client_sd < 0) {
PRAW("Error: Could not create client-side socket (ret=%d)", socket_pair.client_sd);
raw("Error: Could not create client-side socket (ret=", socket_pair.client_sd, ")");
class Client_socket_failed { };
throw Client_socket_failed();
}
int const conn_ret = lx_connect(socket_pair.client_sd, (sockaddr *)&addr, sizeof(addr));
if (conn_ret < 0) {
PRAW("Error: Could not connect client-side socket (ret=%d)", conn_ret);
raw("Error: Could not connect client-side socket (ret=", conn_ret, ")");
class Connect_failed { };
throw Connect_failed();
}

View File

@ -13,7 +13,7 @@
/* Genode includes */
#include <rm_session/rm_session.h>
#include <ram_session/ram_session.h>
#include <base/ram_allocator.h>
#include <base/thread.h>
/* base-internal includes */

View File

@ -33,7 +33,8 @@ struct Genode::Local_pd_session : Expanding_pd_session_client
Region_map_mmap _stack_area { true, stack_area_virtual_size() };
Region_map_mmap _linker_area { true, Pd_session::LINKER_AREA_SIZE };
Local_pd_session(Pd_session_capability pd) : Expanding_pd_session_client(pd) { }
Local_pd_session(Parent &parent, Pd_session_capability pd)
: Expanding_pd_session_client(parent, pd) { }
Capability<Region_map> address_space()
{

View File

@ -55,29 +55,30 @@ class Genode::Platform_env_base : public Env_deprecated
* in 'Platform_env_base' because the procedure differs between
* core and non-core components.
*/
Local_pd_session _local_pd_session { _pd_session_cap };
Local_pd_session _local_pd_session;
public:
/**
* Constructor
*/
Platform_env_base(Cpu_session_capability cpu_cap,
Platform_env_base(Parent &parent,
Cpu_session_capability cpu_cap,
Pd_session_capability pd_cap)
:
_cpu_session_cap(cpu_cap),
_cpu_session_client(cpu_cap, Parent::Env::cpu()),
_cpu_session_client(parent, cpu_cap, Parent::Env::cpu()),
_region_map_mmap(false),
_pd_session_cap(pd_cap),
_local_pd_session(_pd_session_cap)
_local_pd_session(parent, _pd_session_cap)
{ }
/**
* Constructor used by 'Core_env'
*/
Platform_env_base()
Platform_env_base(Parent &parent)
:
Platform_env_base(Cpu_session_capability(), Pd_session_capability())
Platform_env_base(parent, Cpu_session_capability(), Pd_session_capability())
{ }
@ -85,8 +86,6 @@ class Genode::Platform_env_base : public Env_deprecated
** Env_deprecated interface **
******************************/
Ram_session *ram_session() override { return &_local_pd_session; }
Ram_session_capability ram_session_cap() override { return _pd_session_cap; }
Region_map *rm_session() override { return &_region_map_mmap; }
Cpu_session *cpu_session() override { return &_cpu_session_client; }
Cpu_session_capability cpu_session_cap() override { return _cpu_session_cap; }
@ -134,8 +133,9 @@ class Genode::Platform_env : public Platform_env_base
** Env_deprecated interface **
******************************/
Parent *parent() override { return &_parent(); }
Heap *heap() override { return &_heap; }
Parent *parent() override { return &_parent(); }
Allocator *heap() override { return &_heap; }
};
#endif /* _INCLUDE__BASE__INTERNAL__PLATFORM_ENV_H_ */

View File

@ -19,6 +19,7 @@
#include <base/env.h>
#include <region_map/region_map.h>
#include <dataspace/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/local_capability.h>

View File

@ -160,7 +160,7 @@ static int lookup_tid_by_client_socket(int sd)
unsigned tid = 0;
if (Genode::ascii_to(name.sun_path + prefix_len.len, tid) == 0) {
PRAW("Error: could not parse tid number");
raw("Error: could not parse tid number");
return -1;
}
return tid;
@ -354,7 +354,8 @@ static inline void lx_reply(int reply_socket, Rpc_exception_code exception_code,
}
if (ret < 0)
PRAW("[%d] lx_sendmsg failed with %d in lx_reply() reply_socket=%d", lx_gettid(), ret, reply_socket);
raw("[", lx_gettid, "] lx_sendmsg failed with ", ret, " "
"in lx_reply() reply_socket=", reply_socket);
}
@ -388,7 +389,7 @@ Rpc_exception_code Genode::ipc_call(Native_capability dst,
int ret = lx_socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0, sd);
if (ret < 0) {
PRAW("[%d] lx_socketpair failed with %d", lx_getpid(), ret);
raw("[", lx_gettid(), "] lx_socketpair failed with ", ret);
throw Genode::Ipc_error();
}
}
@ -438,7 +439,7 @@ Rpc_exception_code Genode::ipc_call(Native_capability dst,
throw Genode::Blocking_canceled();
if (recv_ret < 0) {
PRAW("[%d] lx_recvmsg failed with %d in lx_call()", lx_getpid(), recv_ret);
raw("[", lx_getpid(), "] lx_recvmsg failed with ", recv_ret, " in lx_call()");
throw Genode::Ipc_error();
}
@ -496,8 +497,8 @@ Genode::Rpc_request Genode::ipc_reply_wait(Reply_capability const &last_caller,
continue;
if (ret < 0) {
PRAW("lx_recvmsg failed with %d in ipc_reply_wait, sd=%d",
ret, native_thread.socket_pair.server_sd);
raw("lx_recvmsg failed with ", ret, " in ipc_reply_wait, sd=",
native_thread.socket_pair.server_sd);
continue;
}
@ -528,8 +529,8 @@ Ipc_server::Ipc_server()
Native_thread &native_thread = Thread::myself()->native_thread();
if (native_thread.is_ipc_server) {
PRAW("[%d] unexpected multiple instantiation of Ipc_server by one thread",
lx_gettid());
Genode::raw("[", lx_gettid(), "] "
" unexpected multiple instantiation of Ipc_server by one thread");
struct Ipc_server_multiple_instance { };
throw Ipc_server_multiple_instance();
}

View File

@ -154,14 +154,15 @@ Local_parent &Platform_env::_parent()
Platform_env::Platform_env()
:
Platform_env_base(static_cap_cast<Cpu_session>(_parent().session_cap(Parent::Env::cpu())),
Platform_env_base(_parent(),
static_cap_cast<Cpu_session>(_parent().session_cap(Parent::Env::cpu())),
static_cap_cast<Pd_session> (_parent().session_cap(Parent::Env::pd()))),
_heap(Platform_env_base::ram_session(), Platform_env_base::rm_session())
_heap(Platform_env_base::pd_session(), Platform_env_base::rm_session())
{
_attach_stack_area();
env_stack_area_region_map = &_local_pd_session._stack_area;
env_stack_area_ram_allocator = ram_session();
env_stack_area_ram_allocator = Platform_env_base::pd_session();
/* register TID and PID of the main thread at core */
Linux_native_cpu_client native_cpu(cpu_session()->native_cpu());

View File

@ -41,13 +41,13 @@ Region_map_client::attach(Dataspace_capability ds, size_t size,
Region_map::Local_addr local_addr,
bool executable, bool writeable)
{
return _local(*this)->attach(ds, size, offset, use_local_addr,
return _local(rpc_cap())->attach(ds, size, offset, use_local_addr,
local_addr, executable, writeable);
}
void Region_map_client::detach(Local_addr local_addr) {
return _local(*this)->detach(local_addr); }
return _local(rpc_cap())->detach(local_addr); }
void Region_map_client::fault_handler(Signal_context_capability /*handler*/)
@ -61,9 +61,9 @@ void Region_map_client::fault_handler(Signal_context_capability /*handler*/)
}
Region_map::State Region_map_client::state() { return _local(*this)->state(); }
Region_map::State Region_map_client::state() { return _local(rpc_cap())->state(); }
Dataspace_capability Region_map_client::dataspace() {
return _local(*this) ? _local(*this)->dataspace() : Dataspace_capability(); }
return _local(rpc_cap()) ? _local(rpc_cap())->dataspace() : Dataspace_capability(); }

View File

@ -36,8 +36,8 @@ Rm_session_client::Rm_session_client(Capability<Rm_session> session)
Capability<Region_map> Rm_session_client::create(size_t size) {
return _local(*this)->create(size); }
return _local(rpc_cap())->create(size); }
void Rm_session_client::destroy(Capability<Region_map> cap) {
_local(*this)->destroy(cap); }
_local(rpc_cap())->destroy(cap); }

View File

@ -32,20 +32,6 @@ char **lx_environ;
*/
int main_thread_futex_counter __attribute__((aligned(sizeof(addr_t))));
/**
* Genode console hook
*/
extern "C" int stdout_write(char const *);
/*
* Core lacks the hook, so provide a base-linux specific weak implementation
*/
extern "C" __attribute__((weak)) int stdout_write(char const *s)
{
raw(s);
return Genode::strlen(s);
}
/**
* Signal handler for exceptions like segmentation faults
*/
@ -62,17 +48,7 @@ void exception_signal_handler(int signum)
default: /* unexpected signal */ return;
}
/*
* We can't use Genode::printf() as the exception may have occurred in the
* Genode console library itself, which uses a mutex. Therefore, we use
* Genode::snprintf() and call the console hook directly to minimize
* overlaps with other code paths.
*/
static char msg[128];
snprintf(msg, sizeof(msg),
ESC_ERR "%s (signum=%d), see Linux kernel log for details" ESC_END "\n",
reason, signum);
stdout_write(msg);
raw(reason, " (signum=", signum, "), see Linux kernel log for details");
/*
* We reset the signal handler to SIG_DFL and trigger exception again,

View File

@ -20,6 +20,7 @@
#include <base/log.h>
#include <linux_native_cpu/client.h>
#include <cpu_thread/client.h>
#include <deprecated/env.h>
/* base-internal includes */
#include <base/internal/stack.h>

View File

@ -86,8 +86,16 @@ namespace Genode {
* 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 init_exception_handling(Env &env) { _env_ptr = &env; }
void init_exception_handling(Env &env)
{
_env_ptr = &env;
init_log(env.parent());
}
}
/*

View File

@ -34,7 +34,6 @@
/* Genode includes */
#include <util/string.h>
#include <base/printf.h>
#include <base/snprintf.h>
#include <base/log.h>

View File

@ -20,6 +20,7 @@
/* Linux includes */
#include <stdlib.h>
#include <stdio.h>
using namespace Genode;
@ -28,7 +29,7 @@ struct Testapp_testclass
{
Testapp_testclass()
{
Genode::log("Global static constructor of Genode application called");
printf("[init -> test-lx_hybrid_ctors] Global static constructor of Genode application called.\n");
}
void dummy() { }