28.08.2015 Views

The Design and Implementation of the Anykernel and Rump Kernels

1F3KDce

1F3KDce

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

129<br />

void *h<strong>and</strong>le;<br />

const struct modinfo *const *mi_start, *const *mi_end;<br />

int error;<br />

if ((h<strong>and</strong>le = dlopen(fname, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {<br />

/* error branch */<br />

}<br />

mi_start = dlsym(h<strong>and</strong>le, "__start_link_set_modules");<br />

mi_end = dlsym(h<strong>and</strong>le, "__stop_link_set_modules");<br />

if (mi_start && mi_end) {<br />

error = rump_pub_module_init(mi_start,<br />

(size_t)(mi_end-mi_start));<br />

/* ... */<br />

} else {<br />

/* error: not a module */<br />

}<br />

Figure 3.16: Loading kernel modules with dlopen(). Loading is a two-part<br />

process. First, <strong>the</strong> module is loaded <strong>and</strong> linked using a call to <strong>the</strong> host’s dlopen()<br />

routine. Second, <strong>the</strong> rump kernel is informed about <strong>the</strong> newly loaded module.<br />

We stated that linking libraries with “cc -o ... -lrumpfoo” <strong>and</strong> loading <strong>the</strong>m<br />

with dlopen() before calling rump_init() are equivalent. One detail deserves<br />

discussion: weak symbols. By default, symbols in <strong>the</strong> text segment are resolved<br />

lazily, which means <strong>the</strong>y are unresolved until <strong>the</strong>y are first used. To put it ano<strong>the</strong>r<br />

way, <strong>the</strong> dynamic linker resolves a reference to afunction() only when, or ra<strong>the</strong>r<br />

if, it is called at runtime. However, lazy resolution does not apply to variables,<br />

including function pointers, which are resolved immediately when <strong>the</strong> program is<br />

initially linked. Any function pointer with <strong>the</strong> initial value pointing to a weak stub<br />

will retain <strong>the</strong> same value even if a strong version <strong>of</strong> <strong>the</strong> same symbol is later loaded<br />

with dlopen().<br />

Function pointers must be dynamically adjusted when <strong>the</strong> rump kernel is bootstrapped<br />

instead <strong>of</strong> relying on weak symbols. In a rump kernel, <strong>the</strong> system call<br />

vector was <strong>the</strong> main user <strong>of</strong> function pointers to weak symbols (<strong>the</strong> only o<strong>the</strong>r place

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!