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.

117<br />

[ .... ]<br />

2194: e8 fc ff ff ff call 2195 <br />

2199: 85 db test %ebx,%ebx<br />

219b: 75 0c jne 21a9 <br />

219d: 8b 45 f4 mov 0xfffffff4(%ebp),%eax<br />

21a0: 8b 55 f8 mov 0xfffffff8(%ebp),%edx<br />

21a3: 83 c4 24 add $0x24,%esp<br />

21a6: 5b pop %ebx<br />

21a7: 5d pop %ebp<br />

21a8: c3 ret<br />

[ .... ]<br />

Figure 3.13: Compile-time optimized size<strong>of</strong>() check. <strong>The</strong> assembly <strong>of</strong> <strong>the</strong><br />

generated code compiled for i386 is presented.<br />

4. <strong>The</strong> second exception to <strong>the</strong> above is <strong>the</strong> lseek() call on 32bit architectures.<br />

<strong>The</strong> call returns a 64bit <strong>of</strong>f_t 10 with <strong>the</strong> low bits occupying one register <strong>and</strong><br />

<strong>the</strong> high bits <strong>the</strong> o<strong>the</strong>r one. Since NetBSD supports all combinations <strong>of</strong> 32bit,<br />

64bit, little endian <strong>and</strong> big endian architectures, care had to be taken to have<br />

<strong>the</strong> translation from a two-element register_t vector to a variable work for<br />

all calls on all architectures. We use a compile-time check for data type sizes<br />

<strong>and</strong> typecast accordingly. To see why <strong>the</strong> check is required, consider <strong>the</strong><br />

following. If <strong>the</strong> typecast is never done, lseek breaks on 32bit architectures.<br />

If <strong>the</strong> typecast to <strong>the</strong> return type is done for all calls, system calls returning<br />

an integer break on 64bit big-endian architectures.<br />

<strong>The</strong> above is not <strong>the</strong> only way to solve <strong>the</strong> problem. <strong>The</strong> makesyscalls.sh<br />

script detects 64bit return values <strong>and</strong> sets <strong>the</strong> SYCALL_RET_64 flag in a system<br />

call’s description. We could have hooked into <strong>the</strong> facility <strong>and</strong> created a special<br />

wrapper for lseek without <strong>the</strong> “if (size<strong>of</strong>())” clause. <strong>The</strong> compiled code<br />

is <strong>the</strong> same for both approaches (Figure 3.13), so <strong>the</strong> choice is a matter <strong>of</strong><br />

taste instead <strong>of</strong> runtime performance.<br />

10 <strong>of</strong>f_t is always 64bit on NetBSD instead <strong>of</strong> depending on <strong>the</strong> value <strong>of</strong> _FILE_OFFSET_BITS<br />

which used on for example Linux <strong>and</strong> Solaris.

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

Saved successfully!

Ooh no, something went wrong!