|
UP
EROS Web Developer Documentation Programmer's Guide |
Capability Support in High-Level LanguagesD R A F T This note describes the support mechanisms provided to enable C and C++ programs to manipulate capabilities. All of the current EROS libraries are built using these conventions. 1. IntroductionHigher level languages such as C and C++. do not directly support capabilities as a standard datatype. While it is possible to extend these languages, such an extension represents a significant departure from the runtime expectations of existing programs. Instead, the current EROS programming environment has adopted a compromise using a combination of preprocessor facilities and compiler extensions. 1.1 Slot ReferencesThe EROS capability support mechanism provides a data type for capability slot references. Every capability resides in a slot, and a slot reference names that slot. Two capability slot types are provided:
Both types of slot references can be passed as arguments to library routines, but procedures are not permitted to return them as results or to copy one slot reference to another. 1.2 The Key Cache LibraryThe key cache library provides an optional tool for managing large numbers of capabilities. EROS processes have 31 effective capability registers (capability register zero cannot be modified). For many applications this is ample. Other applications must support a larger number of capabilities. The Key Cache Library transparently multiplexes this larger number of capability slots onto the available capability registers, allowing the application to be written as though a large number of capabilities were directly available. Because the EROS runtime libraries are written using the capability slot data type, they transparently take advantage of the key cache if it is present. 2. C and C++ InterfaceThe C/C++ interface for capability slots involves three declarations and three new procedure calls. 2.1 Slot DeclarationsThe declarations are:
2.2 ProceduresThe three new procedures are KCALL, KRETURN, and KSEND. Where the CALL, RETURN, and SEND procedures use a low-level message format, the KCALL, KRETURN, and KSEND procedures provide the binding layer between slot references and the capability registers in order for the invocation to succeed. KCALL, KSEND, and KRETURN resolve the slots to registers and then invoke the lower-level primitives. 3. Typical UsageC and C++ code that wishes to use this interface should first include #include <domain/keyslot.h>
For native EROS applications, some of the key registers will initially contain values placed there by the constructor. Most applications will therefore wish to include the following declarations in the main source code file: DEF_SLOT(constituents, 1); /* process constituents node */ DEF_SLOT(self, 2); /* domain key to this process */ DEF_SLOT(proccre, 3); /* our process creator */ DEF_SLOT(mybank, 4); /* our space bank */ DEF_SLOT(mysched, 5); /* our schedule capability */ DEF_SLOT(caller, 31); /* resume key to our caller */ Applications that wish to accept capability arguments as part of their invocations may also wish to declare: DEF_SLOT(arg1); /* process constituents node */ DEF_SLOT(arg2); /* domain key to this process */ DEF_SLOT(arg3); /* our process creator */
As an example of TEMP_SLOT, consider the
uint32_t lwp_start(KeySlot lwp /* a domain key */)
{
uint32_t result;
TEMP_SLOT(lwp_fault);
KMessage km;
result = process_make_waiting(lwp, lwp_fault /* OUT */);
if (result != RC_OK)
return result;
km.snd_len = 0;
km.snd_slot0 = KR_ZERO;
km.snd_slot1 = KR_ZERO;
km.snd_slot2 = KR_ZERO;
km.snd_slot3 = KR_ZERO;
km.snd_code = RC_OK;
km.snd_invSlot = lwp_fault;
KSEND(&km);
return RC_OK;
}
4. Special SituationsA special situation arises in the case where a program is converting itself into another program by replacing its address space. The recipient program usually will have embedded assumptions about which of its initial capabilities are in what registers. These assumptions must be satisfied by the original program before invoking the target program. This can be accomplished by means of the BIND_SLOT call:
It is therefore possible to achieve explicit placement of capabilities in desired registers by appropriate calls to BIND_SLOT.
Copyright 1998 by Jonathan Shapiro. All rights reserved. For terms of redistribution, see the EROS License Agreement |