os/packet_stream: avoid global env

Pass an explicit Region_map reference to stream constructors.

Issue #1987
Issue #2034
This commit is contained in:
Emery Hemingway 2016-07-22 10:05:52 +02:00 committed by Norman Feske
parent ce3170f3f7
commit 9bae4823a0
18 changed files with 61 additions and 44 deletions

View File

@ -37,10 +37,11 @@ class Block::Session_client : public Genode::Rpc_client<Session>
* 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>(session),
_tx(call<Rpc_tx_cap>(), tx_buffer_alloc)
_tx(call<Rpc_tx_cap>(), rm, tx_buffer_alloc)
{ }

View File

@ -47,7 +47,7 @@ struct Block::Connection : Genode::Connection<Session>, Session_client
const char *label = "")
:
Genode::Connection<Session>(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>, Session_client
const char *label = "")
:
Genode::Connection<Session>(_session(*Genode::env()->parent(), label, tx_buf_size)),
Session_client(cap(), tx_block_alloc)
Session_client(cap(), *tx_block_alloc, *Genode::env()->rm_session())
{ }
};

View File

@ -38,7 +38,7 @@ class Block::Session_rpc_object : public Genode::Rpc_object<Session, Session_rpc
*/
Session_rpc_object(Genode::Dataspace_capability tx_ds,
Genode::Rpc_entrypoint &ep)
: _tx(tx_ds, ep) { }
: _tx(tx_ds, *Genode::env()->rm_session(), ep) { }
/**
* Return capability to packet-stream channel

View File

@ -37,10 +37,11 @@ class File_system::Session_client : public Genode::Rpc_client<Session>
* 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>(session),
_tx(call<Rpc_tx_cap>(), &tx_buffer_alloc)
_tx(call<Rpc_tx_cap>(), rm, tx_buffer_alloc)
{ }

View File

@ -76,7 +76,7 @@ struct File_system::Connection_base : Genode::Connection<Session>, Session_clien
:
Genode::Connection<Session>(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>, Session_clien
:
Genode::Connection<Session>(_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())
{ }
};

View File

@ -37,7 +37,7 @@ class File_system::Session_rpc_object : public Genode::Rpc_object<Session, Sessi
*/
Session_rpc_object(Genode::Dataspace_capability tx_ds,
Genode::Rpc_entrypoint &ep)
: _tx(tx_ds, ep) { }
: _tx(tx_ds, *Genode::env()->rm_session(), ep) { }
/**
* Return capability to packet-stream channel

View File

@ -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<Session>
* 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>(session),
_tx(call<Rpc_tx_cap>(), tx_buffer_alloc),
_rx(call<Rpc_rx_cap>())
_tx(call<Rpc_tx_cap>(), rm, tx_buffer_alloc),
_rx(call<Rpc_rx_cap>(),rm )
{ }

View File

@ -55,7 +55,7 @@ struct Nic::Connection : Genode::Connection<Session>, Session_client
:
Genode::Connection<Session>(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>, Session_client
:
Genode::Connection<Session>(_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())
{ }
};

View File

@ -46,7 +46,8 @@ class Nic::Session_rpc_object : public Genode::Rpc_object<Session, Session_rpc_o
Genode::Range_allocator *rx_buffer_alloc,
Genode::Rpc_entrypoint &ep)
:
_tx(tx_ds, ep), _rx(rx_ds, rx_buffer_alloc, ep) { }
_tx(tx_ds, *Genode::env()->rm_session(), ep),
_rx(rx_ds, *Genode::env()->rm_session(), *rx_buffer_alloc, ep) { }
Genode::Capability<Tx> _tx_cap() { return _tx.cap(); }
Genode::Capability<Rx> _rx_cap() { return _rx.cap(); }

View File

@ -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_queue> _submit_transmitter;
Packet_descriptor_receiver<Ack_queue> _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>(_submit_queue_local_base(),

View File

@ -42,9 +42,11 @@ class Packet_stream_rx::Client : public Genode::Rpc_client<CHANNEL>
/**
* Constructor
*/
Client(Genode::Capability<CHANNEL> channel_cap) :
Client(Genode::Capability<CHANNEL> channel_cap,
Genode::Region_map &rm)
:
Genode::Rpc_client<CHANNEL>(channel_cap),
_sink(Base::template call<Rpc_dataspace>())
_sink(Base::template call<Rpc_dataspace>(), rm)
{
/* wire data-flow signals for the packet receiver */
_sink.register_sigh_ack_avail(Base::template call<Rpc_ack_avail>());

View File

@ -45,9 +45,10 @@ class Packet_stream_rx::Rpc_object : public Genode::Rpc_object<CHANNEL, Rpc_obje
* interface
*/
Rpc_object(Genode::Dataspace_capability ds,
Genode::Range_allocator *buffer_alloc,
Genode::Region_map &rm,
Genode::Range_allocator &buffer_alloc,
Genode::Rpc_entrypoint &ep)
: _ep(ep), _cap(_ep.manage(this)), _source(buffer_alloc, ds),
: _ep(ep), _cap(_ep.manage(this)), _source(ds, rm, buffer_alloc),
/* init signal handlers with default handlers of source */
_sigh_ready_to_submit(_source.sigh_ready_to_submit()),

View File

@ -49,10 +49,11 @@ class Packet_stream_tx::Client : public Genode::Rpc_client<CHANNEL>
* transmission buffer
*/
Client(Genode::Capability<CHANNEL> channel_cap,
Genode::Range_allocator *buffer_alloc)
Genode::Region_map &rm,
Genode::Range_allocator &buffer_alloc)
:
Genode::Rpc_client<CHANNEL>(channel_cap),
_source(buffer_alloc, Base::template call<Rpc_dataspace>())
_source(Base::template call<Rpc_dataspace>(), rm, buffer_alloc)
{
/* wire data-flow signals for the packet transmitter */
_source.register_sigh_packet_avail(Base::template call<Rpc_packet_avail>());

View File

@ -43,9 +43,10 @@ class Packet_stream_tx::Rpc_object : public Genode::Rpc_object<CHANNEL, Rpc_obje
* interface
*/
Rpc_object(Genode::Dataspace_capability ds,
Genode::Region_map &rm,
Genode::Rpc_entrypoint &ep)
:
_ep(ep), _cap(_ep.manage(this)), _sink(ds),
_ep(ep), _cap(_ep.manage(this)), _sink(ds, rm),
/* init signal handlers with default handlers of sink */
_sigh_ready_to_ack(_sink.sigh_ready_to_ack()),

View File

@ -41,11 +41,12 @@ class Usb::Session_client : public Genode::Rpc_client<Session>
* 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>(session),
_tx(call<Rpc_tx_cap>(), tx_buffer_alloc)
_tx(call<Rpc_tx_cap>(), rm, tx_buffer_alloc)
{
if (state_change.valid())
sigh_state_change(state_change);

View File

@ -46,7 +46,7 @@ struct Usb::Connection : Genode::Connection<Session>, Session_client
Genode::Signal_context_capability())
:
Genode::Connection<Session>(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>, Session_client
Genode::Signal_context_capability())
:
Genode::Connection<Session>(_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)
{ }
};

View File

@ -37,7 +37,7 @@ class Usb::Session_rpc_object : public Genode::Rpc_object<Session, Session_rpc_o
*/
Session_rpc_object(Genode::Dataspace_capability tx_ds,
Genode::Rpc_entrypoint &ep)
: _tx(tx_ds, ep) { }
: _tx(tx_ds, *Genode::env()->rm_session(), ep) { }
/**
* Return capability to packet-stream channel

View File

@ -144,7 +144,8 @@ class Source : private Genode::Thread_deprecated<STACK_SIZE>,
/* init bulk buffer allocator, storing its meta data on the heap */
Thread_deprecated("source"),
Genode::Allocator_avl(Genode::env()->heap()),
Packet_stream_source<Test_packet_stream_policy>(this, ds_cap),
Packet_stream_source<Test_packet_stream_policy>(
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<STACK_SIZE>,
Sink(Genode::Dataspace_capability ds_cap)
:
Thread_deprecated("sink"),
Packet_stream_sink<Test_packet_stream_policy>(ds_cap),
Packet_stream_sink<Test_packet_stream_policy>(
ds_cap, *Genode::env()->rm_session()),
_operation(OP_NONE),
_lock(Genode::Lock::LOCKED),
_cnt(0)