L4Re Operating System Framework
Interface and Usage Documentation
|
Ned's job is to bootstrap the system running on L4Re.
The main thing to do here is to coordinate the startup of services and applications as well as to provide the communication channels for them. The central facility in Ned is the Lua (http://www.lua.org) script interpreter with the L4Re and ELF-loader bindings.
The boot process is based on the execution of one or more Lua scripts that create communication channels (IPC gates), instantiate other L4Re objects, organize capabilities to these objects in sets, and start application processes with access to those objects (or based on those objects).
For starting applications, Ned depends on the services of Moe, the Root-Task or another loader, which must provide data spaces and region maps. Ned also uses the 'rom' capability as source for Lua scripts and at least the 'l4re' binary (the runtime environment core) running in each application.
Each application Ned starts is equipped with an L4Re::Env environment that provides information about all the initial objects made accessible to this application.
Ned provides various bindings for L4Re abstractions. These bindings are located in the 'L4' package (require
"L4"
).
Capabilities are handled as normal values in Lua. They can be stored in normal variables or Lua compound structures (tables). A capability in Lua possesses additional information about the access rights that shall be transfered to other tasks when the capability is transfered. To support implementation of the Principle of Least Privilege, minimal rights are assigned by default. Extended rights can be added using the method mode
("...") (short m
("...")) that returns a new reference to the capability with the given rights.
mode
method.The capabilities in Lua also carry dynamic type information about the referenced objects. They thereby provide type-specific operations on the objects, such as the create
operation on a generic factory or the query
and register
operations on a name space.
The initial objects provided to Ned itself are accessible via the table L4.Env
. The default (usually unnamed) capabilities are accessible as factory
, log
, mem_alloc
, parent
, rm
, and scheduler
in the L4.Env
table.
Protocols
The protocol constants are defined by default in the L4 package's table L4.Proto
. The definition is not complete and only covers what is usually needed to configure and start applications. The protocols are for example used as first argument to the Factory:create
method.
Rights
The rights of a Lua capability can be defined in two ways via the :mode()
interface. Either via a string representation of the rights or via an integer value. An example for the former is :mode("rsnc")
while the latter equivalent is :mode(L4.Rights.r | L4.Rights.s | L4.Rights.n | L4.Rights.c)
. The following listing shows the integer constants. The constant names can be used in the string parameter to :mode()
.
Debugging Flags
Debugging flags used for the applications L4Re core:
Loader Flags
Flags for configuring the loading process of an application.
The central facility for starting a new task with Ned is the class L4.Loader
. This class provides interfaces for conveniently configuring and starting programs. It provides three operations:
new_channel()
Returns a new IPC gate that can be used to connect two applications start()
and startv()
Start a new application process and return a process objectThe new_channel()
call is used to provide a service application with a communication channel to bind its initial service to. The concrete behavior of the object and the number of IPC gates required by a server depends on the server implementation. The channel can the be passed to client applications as well or can be used for operations within the script itself.
start()
and startv()
always require at least two arguments. The first one is a table that contains information about the initial objects an application shall get. The second argument is a string, which for start()
is the program name plus a white-space-separated list of program arguments (argv). For startv()
the second argument is just the program binary name – which may contain spaces –, and the program arguments are provided as separate string arguments following the binary name (allowing spaces in arguments, too). The last optional argument is a table containing the POSIX environment variables for the program.
The Loader class uses reasonable defaults for most of the initial objects. However, you can override any initial object with some user-defined values. The main elements of the initial object table are:
factory
The factory used by the new process to create new kernel objects, such as threads etc. This must be a capability to an object implementing the L4::Factory protocol and defaults to the factory object provided to Ned. mem
The memory allocator provided to the application and used by Ned allocates data spaces for the process. This defaults to Ned's memory allocator object (see L4Re::Mem_alloc). rm_fab
The generic factory object used to allocate the region-map object for the process. (defaults to Ned's memory allocator). log_fab
The generic factory to create the L4Re::Log object for the application's output (defaults to Ned's memory allocator). The create
method of the log_fab
object is called with log_tag
and log_color
, from this table, as arguments. log_tag
The string used for tagging log output of this process (defaults to the program name) (see log_fab
). log_color
The color used for the log tag (defaults to "white"). scheduler
The scheduler object used for the process' threads (defaults to Ned's own scheduler). caps
The table with application-specific named capabilities (default is an empty table). If the table does not contain a capability with the name 'rom', the 'rom' capability from Ned's initial caps is inserted into the table.The start()
and startv()
calls return a task object that supports a number of operations.
state()
returns a string with the current task state: "running" or "zombie" if the task has terminated. If the task was alreay reaped ( wait()
returned) or if kill()
was called, then the function will return nil
. exit_code()
returns the exit code if the task has terminated or nil
if it was either killed or has been reaped. kill()
forcefully terminates the task. Returns "killed" if the task was terminated or the exit code if the task was already gone. Returns nil
if the task was already reaped. exit_handler(function)
registers a Lua function that is invoked when the task terminates. If the task has already terminated, the function is called immediately. Returns true
if the callback is pending, otherwise false
. The callback function gets the exit code (nil
if killed) of the task as its only parameter. The return value of the function is ignored. Only one callback can be registered. wait()
suspends execution until the task has terminated. It's better to use exit_handler()
instead. While the Lua code executes wait()
, no exit_handler()
will be dispatched.Ned can react on the termination of child tasks. The preferred mechanism is to register an exit_handler()
for a task:
If the task did already terminate then the callback is invoked immediately. It is also possible to suspend execution of the Ned script until a task has terminated:
This method should be used with caution, though. The Ned script will wait until the child task has terminated. Neither will any of the registered exit_handler()
will be called during this time, nor will the remote command interface be able to execute commands either.
Applications can enrich the kernel debugger with information using the API defined in l4/sys/debugger. In order to do so, the developer has to assign access to the kernel debugger kernel object to the application. This can be done like this:
Ned can be used in interactive mode by connecting the small ned-prompt helper tool to the command capability. Add the following code snippet at the end of your ned script:
The script hands in ned's own log capability to ned-prompt
. This ensures that input and output of ned and the prompt appear on the same console.
ned-prompt
needs to be added to your modules list.
Ned's command line syntax is:
[--exit|--wait-and-exit] [--execute|-e STATEMENT] <lua script> [options passed to lua script]
Ned interprets the first non-option argument <lua script>
as the Lua script which it should load and run. All arguments following the first non-option argument are passed as arguments to the Lua script via Lua's global arg
table.
Exit Options: exit, wait-and-exit (must be first if used)
exit*: terminates the application after the script has run through even if there are still tasks running. wait
for tasks at the end of the script to ensure they do not die forcefully.
exit-and-wait**: terminates the application after the script has run through and all tasks started by ned have signaled their exit.
Execute Statement Option: execute, e
Execute the Lua statement STATEMENT
.