Native access to Genode environment
Add a 'GenodeEnv' type and a 'componentConstructHook' to the system module. The 'componentConstructHook' allows for detection of POSIX style programs that exit implicitly or native Genode components that initialize to serve RPC requests and OS signals. This hook takes a 'GenodeEnv' argument so that the environment interface is passed cleanly to application code after globals are initialized. This is an typed pointer to a C++ object, procedures for accessing the environment will be available from a Nimble library and not included in the standard library. The standard library has an internal pointer to the environment object but this is not for external use, the undocumented global environment pointer has been removed.
This commit is contained in:
parent
bf394ed1a1
commit
22f714585b
10 changed files with 107 additions and 37 deletions
|
|
@ -1498,11 +1498,21 @@ when defined(nimdoc):
|
|||
## macro, use the `error <manual.html#error-pragma>`_ or `fatal
|
||||
## <manual.html#fatal-pragma>`_ pragmas.
|
||||
|
||||
|
||||
elif defined(genode):
|
||||
proc quit*(errorcode: int = QuitSuccess) {.magic: "Exit", noreturn,
|
||||
importcpp: "genodeEnv->parent().exit(@); Genode::sleep_forever()",
|
||||
header: "<base/sleep.h>".}
|
||||
include genode/env
|
||||
|
||||
var systemEnv {.exportc: runtimeEnvSym.}: GenodeEnvPtr
|
||||
|
||||
type GenodeEnv* = GenodeEnvPtr
|
||||
## Opaque type representing Genode environment.
|
||||
|
||||
proc quit*(env: GenodeEnv; errorcode: int) {.magic: "Exit", noreturn,
|
||||
importcpp: "#->parent().exit(@); Genode::sleep_forever()", header: "<base/sleep.h>".}
|
||||
|
||||
proc quit*(errorcode: int = QuitSuccess) =
|
||||
systemEnv.quit(errorCode)
|
||||
|
||||
|
||||
|
||||
elif defined(nodejs):
|
||||
proc quit*(errorcode: int = QuitSuccess) {.magic: "Exit",
|
||||
|
|
@ -4215,3 +4225,22 @@ when not defined(js):
|
|||
type
|
||||
ForLoopStmt* {.compilerProc.} = object ## special type that marks a macro
|
||||
## as a `for-loop macro`:idx:
|
||||
|
||||
when defined(genode):
|
||||
var componentConstructHook*: proc (env: GenodeEnv) {.nimcall.}
|
||||
## Hook into the Genode component bootstrap process.
|
||||
## This hook is called after all globals are initialized.
|
||||
## When this hook is set the component will not automatically exit,
|
||||
## call ``quit`` explicitly to do so. This is the only available method
|
||||
## of accessing the initial Genode environment.
|
||||
|
||||
proc nim_component_construct(env: GenodeEnv) {.exportc.} =
|
||||
## Procedure called during ``Component::construct`` by the loader.
|
||||
if componentConstructHook.isNil:
|
||||
env.quit(programResult)
|
||||
# No native Genode application initialization,
|
||||
# exit as would POSIX.
|
||||
else:
|
||||
componentConstructHook(env)
|
||||
# Perform application initialization
|
||||
# and return to thread entrypoint.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue