Demo: NetBSD driver in Haskell
☆ NetBSD audio driver plays sound.
☆ The driver's interrupt handler
rewrited using Haskell.
☆ GC occurs in interrupt handler.
☆ Watch the movie at following.
☆ This slide: http://bit.ly/ajhc-icfp2014
Kernel developers want type
☆ Kernels are developed with C.
☆ We should design kernel with the
☆ C language is unsafe!
Kernel Bug #1: Buffer overrun
☆ Pointer to array doesn't know the
Kernel Bug #2: Page fault
☆ Page fault in user space => SEGV
☆ Page fault in kernel space => Halt!
Kernel Bug #3: Weak type
☆ Lots of (void *) and unsafe coercion.
☆ NetBSD kernel uses it 45130 times!
$ grep "void *" `find . -name "*.c"` | wc -l
☆ Kernel developers frequently use
(void *) for flexibility. It's realy BAD, but
there is no other option.
☆ Unix-like OS designed by strong type.
☆ We want to use Metasepi OS for daily
desktop usage (e.g. web browser,
programming, office suite, ... etc.)
☆ We have surveyed may functional
languages (e.g. Haskell, OCaml,
MLton, ... etc.)
Why we use jhc ?
Comparison of programs to print "hoge"
on terminal. The smaller the values, the
lesser is the dependency on POSIX, the
more suitable for system programming.
Unix-like OS needs reentrancy
☆ Why we need reentrancy?
☆ Because interrupt handler should be
☆ Why we need interrupt handler?
☆ Because preemptive multitasking
☆ Why we need the multitasking?
☆ Because Unix-like OS depends on it.
What's reentrancy ?
Reentrant code can be interrupted in the middle of its execution
and then safely called again ("re-entered") before its previous
invocations complete execution.
How do we get reentrancy in C ?
☆ C language contexts are isolated.
Root of the problem
☆ GHC's Haskell context is global and
☆ There is only one GC heap on GHC.
☆ If interrupt occurs while GC is
running, the interrupt context can't use
GC heap, because the running GC is
☆ Therefore GHC's binary isn't
How we can fix this problem
We re-define the Haskell Context.
Context-Local Heaps (CLHs)
☆ Idea: Isolate contexts by local heap
(O) Original NetBSD 6.1.2 kernel
(S) The kernel includes AC'97 and HD Audio driver snatched by Ajhc
(N) (S) + using naive GC
(B4) (S) + having GC block 16 Byte
(B5) (S) + having GC block 32 Byte
(B6) (S) + having GC block 64 Byte
Thank's for contributors !
☆ Music is "signal" created by Epopsan.
☆ John Meacham as jhc author.
☆ Can we write Unix in Haskell?
☆ => Yes!
☆ How we realize Reentrant GC?
☆ => With Context-Local Heaps (CLHs)!
☆ Can we implement CLHs in other
☆ => Yes! Of course, GHC can do it!
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.