sys provides safer wrappers around Magnolia's low-level sysproc and
syscall built-ins.
Instead of handling multiple raw return shapes at every call site, sys
normalizes results into consistent objects and helper predicates.
sys := import('sys')
Returns true when result is a successful syscall-style result.
Accepted success tags:
:ok:success
if sys.ok?(res) -> println('call succeeded')
Returns true when result is an error result (type = :error).
if sys.error?(res) -> println('call failed')
Resolves a procedure symbol from a shared library.
Success shape:
{
type: :ok
proc: <proc>
library: <string>
symbol: <string>
}
Error shape:
{
type: :error
error: <string>
library: <string>
symbol: <string>
detail: <value>
}
pidProc := sys.resolve('kernel32.dll', 'GetCurrentProcessId')
if pidProc.type = :error -> println(pidProc.error)
Calls a resolved procedure or address and normalizes malformed payloads.
Success shape:
{
type: :ok
r1: <int>
r2: <int>
errno?: <int>
}
Error shape:
{
type: :error
error: <string>
detail?: <value>
}
resolved := sys.resolve('kernel32.dll', 'GetCurrentProcessId')
if resolved.type = :ok -> {
res := sys.call(resolved.proc)
if sys.ok?(res) -> println('PID: ' + string(res.r1))
}
Convenience API that runs resolve(...) then call(...).
res := sys.resolveAndCall('kernel32.dll', 'GetCurrentProcessId')
Returns result.r1 if successful; otherwise returns fallback.
pid := sys.valueOr(res, -1)
sys := import('sys')
fn currentPID {
res := sys.resolveAndCall('kernel32.dll', 'GetCurrentProcessId')
sys.valueOr(res, -1)
}
println('PID: ' + string(currentPID()))
- Keep direct
sysprocandsyscallusage inside wrapper code when possible. - Validate argument types and pointers before native calls.
- For memory helpers and concurrency primitives, see the
godocumentation.