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

@ -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); }