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.

175<br />

Note: <strong>the</strong> categories are not mutually exclusive. For example, socket() <strong>and</strong> open()<br />

belong to several <strong>of</strong> <strong>the</strong>m. In case open() is given a filename under a configurable<br />

prefix (e.g. /rump), it will call <strong>the</strong> rump kernel to h<strong>and</strong>le <strong>the</strong> request <strong>and</strong> new rump<br />

kernel file descriptor will be returned to <strong>the</strong> application as a result.<br />

<strong>The</strong> rest <strong>of</strong> this section describes advanced rumphijack features beyond simple system<br />

call routing. Never<strong>the</strong>less, those features are commonly required for supporting<br />

many real-world applications.<br />

File Descriptor Games<br />

A rump kernel file descriptor is differentiated from a host kernel file descriptor by <strong>the</strong><br />

numerical value <strong>of</strong> <strong>the</strong> file descriptor. Before a rump kernel descriptor is returned<br />

to <strong>the</strong> application, it is <strong>of</strong>fset by a per-process configurable constant. Generally<br />

speaking, if <strong>the</strong> file descriptor parameter for a system call is greater than <strong>the</strong> <strong>of</strong>fset,<br />

it belongs to <strong>the</strong> rump kernel <strong>and</strong> <strong>the</strong> system call should be directed to <strong>the</strong> rump<br />

kernel.<br />

<strong>The</strong> default <strong>of</strong>fset was selected to be half <strong>of</strong> select()’s FD_SETSIZE <strong>and</strong> is 128.<br />

This value allows almost all applications to work, including historic ones that use<br />

select() <strong>and</strong> modern ones that use a fairly large number <strong>of</strong> file descriptors. In<br />

case <strong>the</strong> host returns a file descriptor which is equal to or greater than <strong>the</strong> process’s<br />

hijack fd <strong>of</strong>fset, rumphijack closes <strong>the</strong> fd <strong>and</strong> sets errno to ENFILE.<br />

A problem arises from <strong>the</strong> dup2() interface which does not fit <strong>the</strong> above model: in<br />

dup2 <strong>the</strong> new file descriptor number is decided by <strong>the</strong> caller. For example, a common<br />

scheme used e.g. by certain web servers is accepting a connection on a socket, forking<br />

a h<strong>and</strong>ler, <strong>and</strong> dup2’ing <strong>the</strong> accepted socket connection to stdin/stdout. <strong>The</strong> new<br />

file descriptor must belong to <strong>the</strong> same kernel as <strong>the</strong> old descriptor, but in case <strong>of</strong>

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

Saved successfully!

Ooh no, something went wrong!