The svLapCreate() system call creates a new local
access point for the actor designated by the actor capability (KnCap
).
The svLapBind() system call binds the LAP descriptor pointed to by lapdesc with the symbolic name pointed to by name.
The svLapDelete() system call deletes the local access point whose descriptor is pointed to by lapdesc.
The following example demonstrates a POSIX application that uses these restricted microkernel calls. To launch the example, type:
rsh <target_name> lap <lapserver>
This example applies to supervisor actors only. It is a POSIX application, running in privileged mode.
(file: progov/lap.c) #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <chorus.h> #include <spawn.h> #include <lap/chLap.h> #include <exec/chExec.h> KnCap actorCap; KnLapDesc lapDesc; char* lapArgument; KnTimeVal timeval; void lapHandler(char* message, char* cookie) { int res; res = actorSelf(&actorCap); if (res != K_OK) { printf("actorSelf failed, returns %d\n",res); exit(1); } printf("LAP handler is running \n"); printf(" thread LI = %d, actor UI = 0x%x 0x%x\n", threadSelf(), actorCap.ui.uiHead, actorCap.ui.uiTail); printf(" Argument = %s, cookie = %s\n",message, cookie); } int main(int argc, char** argv, char** envp) { int res; KnActorPrivilege actorP; char* cookie = "Chorus"; char* spawn_args[4]; res = actorPrivilege(K_MYACTOR, &actorP, NULL); if (res != K_OK) { printf("Cannot get actor privilege, error %d\n", res); exit(1); } if (argc == 1) { printf("Must be run with one argument: LAP name\n"); exit(1); } if (argc == 2) { /* * This is the Server process. * connect a LAP handler, * bind a symbolic name to the LAP (name given as argv[1]) * spawn a client actor (give LAP symbolic name in argument) * wait one minute for Lap invocation */ /* * Spawn the client process */ if (actorP != K_SUPACTOR) { printf("This program must be run in supervisor mode\n"); exit(1); } spawn_args[0] = argv[0]; spawn_args[1] = argv[1]; spawn_args[2] = "ARGH"; spawn_args[3] = NULL; res = posix_spawnp(NULL, spawn_args[0], NULL, NULL, spawn_args, NULL); if (res < 0) { printf("Cannot spawn client actor, error %d\n", res); exit(1); } /* * Create the LAP */ res = svLapCreate(K_MYACTOR, (KnLapHdl) lapHandler, cookie, K_LAP_SETJMP, &lapDesc); if (res != K_OK) { printf("svLapCreate failed, returns %d\n",res); exit(1); } /* * Bind a symbolic name */ res = svLapBind(&lapDesc, argv[1], 0); if (res != K_OK) { printf("svLapBind failed, returns %d\n",res); exit(1); } /* * Wait one minute * Other client processes can be run from the console: * rsh target lap lap-name lap-argument * */ timeval.tmSec = 60; timeval.tmNSec = 0; (void) threadDelay(&timeVal); /* * Unbind the LAP name and Delete the LAP */ res = svLapUnbind(argv[1]); if (res != K_OK) { printf("svLapUnBind failed, returns %d\n",res); exit(1); } res = svLapDelete(&lapDesc); if (res != K_OK) { printf("svLapDelete failed, returns %d\n",res); exit(1); } printf("Server actor is leaving ...\n"); } else { /* * This is the Client Actor: * argv[1] is the LAP name, argv[2] is the LAP argument. * Get the LAP descriptor and invoke the LAP handler. */ res = actorSelf(&actorCap); if (res != K_OK) { printf("actorSelf failed ! Return code = %d\n",res); exit(1); } printf("Client actor is running, thread li = %d, " "actor UI = 0x%x 0x%x\n", threadSelf(), actorCap.ui.uiHead, actorCap.ui.uiTail); /* * Get the LAP descriptor knowing its name */ res = lapResolve(&lapDesc, argv[1], 0); if (res != K_OK) { printf("lapResolve failed, returns %d\n", res); exit(1); } /* * Invoke the LAP handler */ res = lapInvoke(&lapDesc, argv[2]); if (res != K_OK) { printf("lapInvoke failed, returns %d\n", res); exit(1); } printf("Client actor is leaving ...\n"); } return 0; }
In the previous example, the main thread:
Checks if it is running as a supervisor process.
Spawns another copy of itself using posix_spawn().
Creates a Local Access Point and connects a LAP handler, which prints the unique identifier of the current thread (Actor UI + thread LI), the LAP argument and the LAP cookie.
Binds a symbolic name received as the first argument.
Waits one minute for LAP invocations.
Frees the LAP and its name.
Terminates.
The spawned actor:
Receives two arguments: the symbolic LAP name and the argument to be passed to the LAP handler.
Retrieves the LAP descriptor.
Invokes the LAP handler.
Terminates.