From 9bae4823a0172eff45370c8440eb216b971772d6 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Fri, 22 Jul 2016 10:05:52 +0200 Subject: [PATCH] os/packet_stream: avoid global env Pass an explicit Region_map reference to stream constructors. Issue #1987 Issue #2034 --- repos/os/include/block_session/client.h | 5 +-- repos/os/include/block_session/connection.h | 4 +-- repos/os/include/block_session/rpc_object.h | 2 +- repos/os/include/file_system_session/client.h | 5 +-- .../include/file_system_session/connection.h | 4 +-- .../include/file_system_session/rpc_object.h | 2 +- repos/os/include/nic_session/client.h | 9 +++--- repos/os/include/nic_session/connection.h | 4 +-- repos/os/include/nic_session/rpc_object.h | 3 +- repos/os/include/os/packet_stream.h | 31 +++++++++++-------- repos/os/include/packet_stream_rx/client.h | 6 ++-- .../os/include/packet_stream_rx/rpc_object.h | 5 +-- repos/os/include/packet_stream_tx/client.h | 5 +-- .../os/include/packet_stream_tx/rpc_object.h | 3 +- repos/os/include/usb_session/client.h | 5 +-- repos/os/include/usb_session/connection.h | 4 +-- repos/os/include/usb_session/rpc_object.h | 2 +- repos/os/src/test/packet_stream/main.cc | 6 ++-- 18 files changed, 61 insertions(+), 44 deletions(-) diff --git a/repos/os/include/block_session/client.h b/repos/os/include/block_session/client.h index 288c5a22fd..209c2103ce 100644 --- a/repos/os/include/block_session/client.h +++ b/repos/os/include/block_session/client.h @@ -37,10 +37,11 @@ class Block::Session_client : public Genode::Rpc_client * transmission buffer */ Session_client(Session_capability session, - Genode::Range_allocator *tx_buffer_alloc) + Genode::Range_allocator &tx_buffer_alloc, + Genode::Region_map &rm) : Genode::Rpc_client(session), - _tx(call(), tx_buffer_alloc) + _tx(call(), rm, tx_buffer_alloc) { } diff --git a/repos/os/include/block_session/connection.h b/repos/os/include/block_session/connection.h index 6635223447..66ada54a3d 100644 --- a/repos/os/include/block_session/connection.h +++ b/repos/os/include/block_session/connection.h @@ -47,7 +47,7 @@ struct Block::Connection : Genode::Connection, Session_client const char *label = "") : Genode::Connection(env, _session(env.parent(), label, tx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), *tx_block_alloc, env.rm()) { } /** @@ -62,7 +62,7 @@ struct Block::Connection : Genode::Connection, Session_client const char *label = "") : Genode::Connection(_session(*Genode::env()->parent(), label, tx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), *tx_block_alloc, *Genode::env()->rm_session()) { } }; diff --git a/repos/os/include/block_session/rpc_object.h b/repos/os/include/block_session/rpc_object.h index 7e00bbd947..b9f0a0a727 100644 --- a/repos/os/include/block_session/rpc_object.h +++ b/repos/os/include/block_session/rpc_object.h @@ -38,7 +38,7 @@ class Block::Session_rpc_object : public Genode::Rpc_objectrm_session(), ep) { } /** * Return capability to packet-stream channel diff --git a/repos/os/include/file_system_session/client.h b/repos/os/include/file_system_session/client.h index ffe4287a27..d37650ab2e 100644 --- a/repos/os/include/file_system_session/client.h +++ b/repos/os/include/file_system_session/client.h @@ -37,10 +37,11 @@ class File_system::Session_client : public Genode::Rpc_client * transmission buffer */ Session_client(Session_capability session, - Genode::Range_allocator &tx_buffer_alloc) + Genode::Range_allocator &tx_buffer_alloc, + Genode::Region_map &rm) : Rpc_client(session), - _tx(call(), &tx_buffer_alloc) + _tx(call(), rm, tx_buffer_alloc) { } diff --git a/repos/os/include/file_system_session/connection.h b/repos/os/include/file_system_session/connection.h index 699e1a1ff5..f54075d585 100644 --- a/repos/os/include/file_system_session/connection.h +++ b/repos/os/include/file_system_session/connection.h @@ -76,7 +76,7 @@ struct File_system::Connection_base : Genode::Connection, Session_clien : Genode::Connection(env, _session(env.parent(), label, root, writeable, tx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), tx_block_alloc, env.rm()) { } /** @@ -94,7 +94,7 @@ struct File_system::Connection_base : Genode::Connection, Session_clien : Genode::Connection(_session(*Genode::env()->parent(), label, root, writeable, tx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), tx_block_alloc, *Genode::env()->rm_session()) { } }; diff --git a/repos/os/include/file_system_session/rpc_object.h b/repos/os/include/file_system_session/rpc_object.h index be827a5739..0dbbb9c213 100644 --- a/repos/os/include/file_system_session/rpc_object.h +++ b/repos/os/include/file_system_session/rpc_object.h @@ -37,7 +37,7 @@ class File_system::Session_rpc_object : public Genode::Rpc_objectrm_session(), ep) { } /** * Return capability to packet-stream channel diff --git a/repos/os/include/nic_session/client.h b/repos/os/include/nic_session/client.h index 74701a424c..2fd275c152 100644 --- a/repos/os/include/nic_session/client.h +++ b/repos/os/include/nic_session/client.h @@ -5,7 +5,7 @@ */ /* - * Copyright (C) 2009-2013 Genode Labs GmbH + * Copyright (C) 2009-2016 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU General Public License version 2. @@ -38,11 +38,12 @@ class Nic::Session_client : public Genode::Rpc_client * transmission buffer */ Session_client(Session_capability session, - Genode::Range_allocator *tx_buffer_alloc) + Genode::Range_allocator &tx_buffer_alloc, + Genode::Region_map &rm) : Genode::Rpc_client(session), - _tx(call(), tx_buffer_alloc), - _rx(call()) + _tx(call(), rm, tx_buffer_alloc), + _rx(call(),rm ) { } diff --git a/repos/os/include/nic_session/connection.h b/repos/os/include/nic_session/connection.h index 1be5e1e405..238bde4c10 100644 --- a/repos/os/include/nic_session/connection.h +++ b/repos/os/include/nic_session/connection.h @@ -55,7 +55,7 @@ struct Nic::Connection : Genode::Connection, Session_client : Genode::Connection(env, _session(env.parent(), label, tx_buf_size, rx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), *tx_block_alloc, env.rm()) { } /** @@ -72,7 +72,7 @@ struct Nic::Connection : Genode::Connection, Session_client : Genode::Connection(_session(*Genode::env()->parent(), label, tx_buf_size, rx_buf_size)), - Session_client(cap(), tx_block_alloc) + Session_client(cap(), *tx_block_alloc, *Genode::env()->rm_session()) { } }; diff --git a/repos/os/include/nic_session/rpc_object.h b/repos/os/include/nic_session/rpc_object.h index f641495c94..0f8363f81c 100644 --- a/repos/os/include/nic_session/rpc_object.h +++ b/repos/os/include/nic_session/rpc_object.h @@ -46,7 +46,8 @@ class Nic::Session_rpc_object : public Genode::Rpc_objectrm_session(), ep), + _rx(rx_ds, *Genode::env()->rm_session(), *rx_buffer_alloc, ep) { } Genode::Capability _tx_cap() { return _tx.cap(); } Genode::Capability _rx_cap() { return _rx.cap(); } diff --git a/repos/os/include/os/packet_stream.h b/repos/os/include/os/packet_stream.h index 43d9fcffd2..a0ee717705 100644 --- a/repos/os/include/os/packet_stream.h +++ b/repos/os/include/os/packet_stream.h @@ -433,6 +433,7 @@ class Genode::Packet_stream_base protected: + Genode::Region_map &_rm; Genode::Dataspace_capability _ds_cap; void *_ds_local_base; @@ -449,13 +450,14 @@ class Genode::Packet_stream_base * \throw 'Transport_dataspace_too_small' */ Packet_stream_base(Genode::Dataspace_capability transport_ds, + Genode::Region_map &rm, Genode::size_t submit_queue_size, Genode::size_t ack_queue_size) : - _ds_cap(transport_ds), + _rm(rm), _ds_cap(transport_ds), /* map dataspace locally */ - _ds_local_base(Genode::env()->rm_session()->attach(_ds_cap)), + _ds_local_base(rm.attach(_ds_cap)), _submit_queue_offset(0), _ack_queue_offset(_submit_queue_offset + submit_queue_size), _bulk_buffer_offset(_ack_queue_offset + ack_queue_size) @@ -479,7 +481,7 @@ class Genode::Packet_stream_base */ try { /* unmap transport dataspace locally */ - Genode::env()->rm_session()->detach(_ds_local_base); + _rm.detach(_ds_local_base); } catch (...) { } } @@ -541,7 +543,7 @@ class Genode::Packet_stream_source : private Packet_stream_base typedef typename POLICY::Ack_queue Ack_queue; typedef typename POLICY::Content_type Content_type; - Genode::Range_allocator *_packet_alloc; + Genode::Range_allocator &_packet_alloc; Packet_descriptor_transmitter _submit_transmitter; Packet_descriptor_receiver _ack_receiver; @@ -558,6 +560,7 @@ class Genode::Packet_stream_source : private Packet_stream_base * * \param transport_ds dataspace used for communication buffer shared * between source and sink + * \param rm region to map buffer dataspace into * \param packet_alloc allocator for managing packet allocation within * the shared communication buffer * @@ -565,10 +568,11 @@ class Genode::Packet_stream_source : private Packet_stream_base * initialized by the constructor using dataspace-relative offsets * rather than pointers. */ - Packet_stream_source(Genode::Range_allocator *packet_alloc, - Genode::Dataspace_capability transport_ds_cap) + Packet_stream_source(Genode::Dataspace_capability transport_ds_cap, + Genode::Region_map &rm, + Genode::Range_allocator &packet_alloc) : - Packet_stream_base(transport_ds_cap, + Packet_stream_base(transport_ds_cap, rm, sizeof(Submit_queue), sizeof(Ack_queue)), _packet_alloc(packet_alloc), @@ -580,13 +584,13 @@ class Genode::Packet_stream_source : private Packet_stream_base Ack_queue::CONSUMER)) { /* initialize packet allocator */ - _packet_alloc->add_range(_bulk_buffer_offset, + _packet_alloc.add_range(_bulk_buffer_offset, _bulk_buffer_size); } ~Packet_stream_source() { - _packet_alloc->remove_range(_bulk_buffer_offset, + _packet_alloc.remove_range(_bulk_buffer_offset, _bulk_buffer_size); } @@ -643,7 +647,7 @@ class Genode::Packet_stream_source : private Packet_stream_base Packet_descriptor alloc_packet(Genode::size_t size, int align = POLICY::Packet_descriptor::PACKET_ALIGNMENT) { void *base = 0; - if (size && _packet_alloc->alloc_aligned(size, &base, align).error()) + if (size && _packet_alloc.alloc_aligned(size, &base, align).error()) throw Packet_alloc_failed(); return Packet_descriptor((Genode::off_t)base, size); @@ -706,7 +710,7 @@ class Genode::Packet_stream_source : private Packet_stream_base void release_packet(Packet_descriptor packet) { if (packet.size()) - _packet_alloc->free((void *)packet.offset(), packet.size()); + _packet_alloc.free((void *)packet.offset(), packet.size()); } void debug_print_buffers() { @@ -743,9 +747,10 @@ class Genode::Packet_stream_sink : private Packet_stream_base * \param transport_ds dataspace used for communication buffer shared between * source and sink */ - Packet_stream_sink(Genode::Dataspace_capability transport_ds) + Packet_stream_sink(Genode::Dataspace_capability transport_ds, + Genode::Region_map &rm) : - Packet_stream_base(transport_ds, sizeof(Submit_queue), sizeof(Ack_queue)), + Packet_stream_base(transport_ds, rm, sizeof(Submit_queue), sizeof(Ack_queue)), /* construct packet-descriptor queues */ _submit_receiver(construct_at(_submit_queue_local_base(), diff --git a/repos/os/include/packet_stream_rx/client.h b/repos/os/include/packet_stream_rx/client.h index 2da33904a2..908483dd78 100644 --- a/repos/os/include/packet_stream_rx/client.h +++ b/repos/os/include/packet_stream_rx/client.h @@ -42,9 +42,11 @@ class Packet_stream_rx::Client : public Genode::Rpc_client /** * Constructor */ - Client(Genode::Capability channel_cap) : + Client(Genode::Capability channel_cap, + Genode::Region_map &rm) + : Genode::Rpc_client(channel_cap), - _sink(Base::template call()) + _sink(Base::template call(), rm) { /* wire data-flow signals for the packet receiver */ _sink.register_sigh_ack_avail(Base::template call()); diff --git a/repos/os/include/packet_stream_rx/rpc_object.h b/repos/os/include/packet_stream_rx/rpc_object.h index b62741c925..e5e7a0f6aa 100644 --- a/repos/os/include/packet_stream_rx/rpc_object.h +++ b/repos/os/include/packet_stream_rx/rpc_object.h @@ -45,9 +45,10 @@ class Packet_stream_rx::Rpc_object : public Genode::Rpc_object * transmission buffer */ Client(Genode::Capability channel_cap, - Genode::Range_allocator *buffer_alloc) + Genode::Region_map &rm, + Genode::Range_allocator &buffer_alloc) : Genode::Rpc_client(channel_cap), - _source(buffer_alloc, Base::template call()) + _source(Base::template call(), rm, buffer_alloc) { /* wire data-flow signals for the packet transmitter */ _source.register_sigh_packet_avail(Base::template call()); diff --git a/repos/os/include/packet_stream_tx/rpc_object.h b/repos/os/include/packet_stream_tx/rpc_object.h index 8fd6783c45..1152a5e493 100644 --- a/repos/os/include/packet_stream_tx/rpc_object.h +++ b/repos/os/include/packet_stream_tx/rpc_object.h @@ -43,9 +43,10 @@ class Packet_stream_tx::Rpc_object : public Genode::Rpc_object * transmission buffer */ Session_client(Session_capability session, - Genode::Range_allocator *tx_buffer_alloc, + Genode::Range_allocator &tx_buffer_alloc, + Genode::Region_map &rm, Genode::Signal_context_capability state_change) : Genode::Rpc_client(session), - _tx(call(), tx_buffer_alloc) + _tx(call(), rm, tx_buffer_alloc) { if (state_change.valid()) sigh_state_change(state_change); diff --git a/repos/os/include/usb_session/connection.h b/repos/os/include/usb_session/connection.h index d38abdf335..aa8cc73753 100644 --- a/repos/os/include/usb_session/connection.h +++ b/repos/os/include/usb_session/connection.h @@ -46,7 +46,7 @@ struct Usb::Connection : Genode::Connection, Session_client Genode::Signal_context_capability()) : Genode::Connection(env, _session(env.parent(), label, tx_buf_size)), - Session_client(cap(), tx_block_alloc, sigh_state_changed) + Session_client(cap(), *tx_block_alloc, env.rm(), sigh_state_changed) { } /** @@ -63,7 +63,7 @@ struct Usb::Connection : Genode::Connection, Session_client Genode::Signal_context_capability()) : Genode::Connection(_session(*Genode::env()->parent(), label, tx_buf_size)), - Session_client(cap(), tx_block_alloc, sigh_state_changed) + Session_client(cap(), *tx_block_alloc, *Genode::env()->rm_session(), sigh_state_changed) { } }; diff --git a/repos/os/include/usb_session/rpc_object.h b/repos/os/include/usb_session/rpc_object.h index f02025e4e1..65608f2308 100644 --- a/repos/os/include/usb_session/rpc_object.h +++ b/repos/os/include/usb_session/rpc_object.h @@ -37,7 +37,7 @@ class Usb::Session_rpc_object : public Genode::Rpc_objectrm_session(), ep) { } /** * Return capability to packet-stream channel diff --git a/repos/os/src/test/packet_stream/main.cc b/repos/os/src/test/packet_stream/main.cc index 0e8c32216f..e0005207d4 100644 --- a/repos/os/src/test/packet_stream/main.cc +++ b/repos/os/src/test/packet_stream/main.cc @@ -144,7 +144,8 @@ class Source : private Genode::Thread_deprecated, /* init bulk buffer allocator, storing its meta data on the heap */ Thread_deprecated("source"), Genode::Allocator_avl(Genode::env()->heap()), - Packet_stream_source(this, ds_cap), + Packet_stream_source( + ds_cap, *Genode::env()->rm_session(), *this), _operation(OP_NONE), _lock(Genode::Lock::LOCKED), _cnt(0) @@ -225,7 +226,8 @@ class Sink : private Genode::Thread_deprecated, Sink(Genode::Dataspace_capability ds_cap) : Thread_deprecated("sink"), - Packet_stream_sink(ds_cap), + Packet_stream_sink( + ds_cap, *Genode::env()->rm_session()), _operation(OP_NONE), _lock(Genode::Lock::LOCKED), _cnt(0)