Something went wrong. Try again.
An experimental port of NetBSD, FreeBSD, OpenBSD, and XNU to unkernel unkernel.dev
Something went wrong. Try again.
1.3 kB · 39 lines
12345678910111213141516171819202122232425262728293031323334353637383940-- SPDX-License-Identifier: GPL-2.0-or-later-- Copyright (C) 2026 unkernel contributorsmodule Unkernel ( Options, Kernel, Termination(..), ExecResult , options, withMemory, withDistro, boot, exec, stop, withKernel ) where
import Preludeimport Control.Promise (Promise, toAffE)import Effect (Effect)import Effect.Aff (Aff, bracket)
foreign import data Options :: Typeforeign import data Kernel :: Type
data Termination = Exited Int | Signaled Int
type ExecResult = { stdout :: String, stderr :: String, termination :: Termination }
foreign import options :: Optionsforeign import withMemory :: Int -> Options -> Optionsforeign import withDistro :: String -> Options -> Optionsforeign import bootImpl :: Options -> Effect (Promise Kernel)foreign import stopImpl :: Kernel -> Effect (Promise Unit)foreign import execImpl :: (Int -> Termination) -> (Int -> Termination) -> String -> Array String -> Kernel -> Effect (Promise ExecResult)
boot :: Options -> Aff Kernelboot opts = bootImpl opts # toAffE
stop :: Kernel -> Aff Unitstop vm = stopImpl vm # toAffE
exec :: String -> Array String -> Kernel -> Aff ExecResultexec file args vm = execImpl Exited Signaled file args vm # toAffE
withKernel :: forall a. (Kernel -> Aff a) -> Options -> Aff awithKernel run opts = bracket (boot opts) stop run