base*, os: get rid of all env() calls

Issue #1987
This commit is contained in:
Martin Stein 2017-02-24 17:06:42 +01:00 committed by Christian Helmuth
parent 9b8fcb5fd0
commit daaddbd584
5 changed files with 58 additions and 41 deletions

View File

@ -49,13 +49,14 @@ void Thread::_init_platform_thread(size_t weight, Type type)
{
/* if no cpu session is given, use it from the environment */
if (!_cpu_session)
_cpu_session = env()->cpu_session();
_cpu_session = env_deprecated()->cpu_session();
if (type == NORMAL)
{
/* create thread at core */
_thread_cap = _cpu_session->create_thread(env()->pd_session_cap(), name(),
Location(), Weight(weight));
_thread_cap = _cpu_session->create_thread(env_deprecated()->pd_session_cap(),
name(), Location(),
Weight(weight));
/* assign thread to protection domain */
if (!_thread_cap.valid())
@ -65,7 +66,7 @@ void Thread::_init_platform_thread(size_t weight, Type type)
}
/* adjust values whose computation differs for a main thread */
native_thread().kcap = Fiasco::MAIN_THREAD_CAP;
_thread_cap = env()->parent()->main_thread_cap();
_thread_cap = env_deprecated()->parent()->main_thread_cap();
if (!_thread_cap.valid())
throw Cpu_session::Thread_creation_failed();

View File

@ -14,8 +14,7 @@
*/
/* Genode includes */
#include <base/env.h>
#include <base/log.h>
#include <base/component.h>
#include <log_session/connection.h>
#include <foc/capability_space.h>
@ -25,14 +24,18 @@
using namespace Genode;
using namespace Fiasco;
int main(int argc, char **argv)
struct Main { Main(Env &env); };
Main::Main(Env &env)
{
log("--- capability integrity test ---");
enum { COUNT = 1000 };
Cap_index* idx = cap_idx_alloc()->alloc_range(COUNT);
Fiasco::l4_cap_idx_t tid = Capability_space::kcap(env()->ram_session_cap());
Fiasco::l4_cap_idx_t tid = Capability_space::kcap(env.ram_session_cap());
/* try the first 1000 local name IDs */
for (int local_name = 0; local_name < COUNT; local_name++, idx++) {
@ -50,5 +53,8 @@ int main(int argc, char **argv)
}
log("--- finished capability integrity test ---");
return 0;
env.parent().exit(0);
}
void Component::construct(Env &env) { static Main main(env); }

View File

@ -12,14 +12,14 @@
*/
/* Genode includes */
#include <base/log.h>
#include <base/env.h>
#include <base/sleep.h>
#include <base/heap.h>
#include <base/component.h>
#include <base/thread.h>
#include <util/misc_math.h>
#include <rm_session/connection.h>
#include <region_map/client.h>
using namespace Genode;
static void blob() __attribute__((used));
static void blob()
@ -34,22 +34,26 @@ static void blob()
: : : );
}
extern unsigned long blob_beg;
extern unsigned long blob_end;
int main()
struct Main
{
using namespace Genode;
Heap heap;
Main(Env &env);
};
Main::Main(Env &env) : heap(env.ram(), env.rm())
{
/* activate for early printf in Rm_session_mmap::attach() etc. */
if (0) Thread::trace("FOO");
/* induce initial heap expansion to remove RM noise */
if (1) {
void *addr(env()->heap()->alloc(0x100000));
env()->heap()->free(addr, 0);
void *addr;
heap.alloc(0x100000, &addr);
heap.free(addr, 0);
}
addr_t beg((addr_t)&blob_beg);
@ -61,47 +65,50 @@ int main()
/* RAM dataspace attachment overlapping binary */
try {
Ram_dataspace_capability ds(env()->ram_session()->alloc(size));
Ram_dataspace_capability ds(env.ram().alloc(size));
log("before RAM dataspace attach");
env()->rm_session()->attach_at(ds, beg);
env.rm().attach_at(ds, beg);
error("after RAM dataspace attach -- ERROR");
sleep_forever();
env.parent().exit(-1);
} catch (Region_map::Region_conflict) {
log("OK caught Region_conflict exception");
}
/* empty managed dataspace overlapping binary */
try {
Rm_connection rm_connection;
Rm_connection rm_connection(env);
Region_map_client rm(rm_connection.create(size));
Dataspace_capability ds(rm.dataspace());
log("before sub-RM dataspace attach");
env()->rm_session()->attach_at(ds, beg);
env.rm().attach_at(ds, beg);
error("after sub-RM dataspace attach -- ERROR");
sleep_forever();
env.parent().exit(-1);
} catch (Region_map::Region_conflict) {
log("OK caught Region_conflict exception");
}
/* sparsely populated managed dataspace in free VM area */
try {
Rm_connection rm_connection;
Rm_connection rm_connection(env);
Region_map_client rm(rm_connection.create(0x100000));
rm.attach_at(env()->ram_session()->alloc(0x1000), 0x1000);
rm.attach_at(env.ram().alloc(0x1000), 0x1000);
Dataspace_capability ds(rm.dataspace());
log("before populated sub-RM dataspace attach");
char *addr = (char *)env()->rm_session()->attach(ds) + 0x1000;
char *addr = (char *)env.rm().attach(ds) + 0x1000;
log("after populated sub-RM dataspace attach / before touch");
char const val = *addr;
*addr = 0x55;
log("after touch (", val, "/", *addr, ")");
} catch (Region_map::Region_conflict) {
error("Caught Region_conflict exception -- ERROR");
sleep_forever();
env.parent().exit(-1);
}
env.parent().exit(0);
}
void Component::construct(Env &env) { static Main main(env); }

View File

@ -11,25 +11,23 @@
* under the terms of the GNU Affero General Public License version 3.
*/
#include <base/env.h>
#include <base/log.h>
#include <base/component.h>
#include <ram_session/connection.h>
#include <timer_session/connection.h>
using namespace Genode;
static void test_linux_rmmap_bug()
static void test_linux_rmmap_bug(Env &env)
{
enum { QUOTA = 1*1024*1024, CHUNK = 0x1000, ROUNDS = 0x10 };
using namespace Genode;
log("line: ", __LINE__);
Ram_connection ram;
Ram_connection ram(env);
#if 1 /* transfer quota */
log("line: ", __LINE__);
ram.ref_account(env()->ram_session_cap());
env()->ram_session()->transfer_quota(ram.cap(), QUOTA);
ram.ref_account(env.ram_session_cap());
env.ram().transfer_quota(ram.cap(), QUOTA);
#endif
log("line: ", __LINE__);
@ -41,10 +39,14 @@ static void test_linux_rmmap_bug()
log("Done.");
}
struct Main { Main(Env &env); };
int main()
Main::Main(Env &env)
{
Genode::log("--- test-rm_session_mmap started ---");
test_linux_rmmap_bug();
test_linux_rmmap_bug(env);
}
void Component::construct(Env &env) { static Main main(env); }

View File

@ -61,9 +61,10 @@ struct Genode::Trace::Connection : Genode::Connection<Genode::Trace::Session>,
*/
Connection(size_t ram_quota, size_t arg_buffer_size, unsigned parent_levels) __attribute__((deprecated))
:
Genode::Connection<Session>(_session(*env()->parent(), ram_quota,
arg_buffer_size, parent_levels)),
Session_client(*env()->rm_session(), cap())
Genode::Connection<Session>(_session(*env_deprecated()->parent(),
ram_quota, arg_buffer_size,
parent_levels)),
Session_client(*env_deprecated()->rm_session(), cap())
{ }
};