Env::Get Cap does not find object

From TUDOS-Wiki
Jump to navigationJump to search

Problem

I start my application with a Lua script such as:

 require("L4");
 
 local ld      = L4.default_loader;
 local channel = ld:new_channel();
 
 ld:start({caps = {magic_session_name = channel}}, "rom/my_magic_application");

In my program I try to obtain this channel:

 int main()
 {
   L4::Cap<void> chan = L4Re::Env::env()->get_cap<void>("magic_session_name");
   assert(chan.is_valid());
   [..]
 }

The assertion fails.

Explanation

Object capabilities such as magic_session_cap specified in the Lua script are pushed onto the program's initial stack by the loader. They reside in a list of type l4re_env_cap_entry_t, which is defined in l4re/env/env.h as:

 typedef struct l4re_env_cap_entry_t
 {
   l4_cap_idx_t cap;
   l4_umword_t  flags;
   char name[16];
   [..]
 } l4re_env_cap_entry_t;

L4Re::Env::env()->get_cap() later runs through this list to find the required entries. As we see, there are only 16 characters reserved for the cap entry's name. Longer names get truncated to this length.

Lesson learned

Only use at most 16 characters to name objects that shall appear in your program's initial name space.