/*-------cria processo ----------*/ void far criaProcesso(char nomeP[],int prior, void far (*endereco_processo)()){ /*faca na raça - slide 2 tanembaum - */ PTR_DESC_PROC aux, paux; paux = (PTR_DESC_PROC)malloc(sizeof(struct bcp)); strcpy(paux -> nomeProcesso, nomeP); paux->priori = prior; paux->estado = ativo; paux -> contexto = cria_desc(); if (FilaPrior[prior] == NULL) FilaPrior[prior]->contexto = paux->contexto; else{ FilaPrior[prior] = FilaPrior[prior]->prox; FilaPrior[prior]->prox = paux->contexto; } newprocess(endereco_processo, paux -> contexto); if(prim != NULL){ paux->next_desc = fimFila->next_desc; fimFila->next_desc = paux; fimFila = paux; } else{ prim = paux; paux->next_desc = paux; fimFila = paux; } }
void vpn_user_init (struct config_data_vpn *vpn, char *seed, int len) { int d, d1; struct config_data_vpn *p; char *q; struct msgbuf buf[2]; mp = mempool_new (0, 1, true); d = newprocess ("vpn"); if (d < 0) panic ("newprocess vpn"); d1 = msgopen ("ttyout"); if (d1 < 0) panic ("msgopen ttyout"); msgsenddesc (d, d1); msgsenddesc (d, d1); msgclose (d1); p = mempool_allocmem (mp, sizeof *p); memcpy (p, vpn, sizeof *p); q = mempool_allocmem (mp, len); memcpy (q, seed, len); setmsgbuf (&buf[0], p, sizeof *p, 0); setmsgbuf (&buf[1], q, sizeof *q, 0); if (msgsendbuf (d, 0, buf, 2)) panic ("vpn init failed"); mempool_freemem (mp, q); mempool_freemem (mp, p); msgclose (d); }
/*----------Dispara Sistema -----------*/ void far disparaSistema(){ PTR_DESC inicio; d_esc = cria_desc(); inicio = cria_desc(); newprocess(escalador, d_esc); transfer(inicio, d_esc); }
/* * Function for a thread that runs an arbitrary userlevel program by * name. * * Note: this cannot pass arguments to the program. You may wish to * change it so it can, because that will make testing much easier * in the future. * * It copies the program name because runprogram destroys the copy * it gets by passing it to vfs_open(). */ static void cmd_progthread(void *ptr, unsigned long nargs) { char **args = ptr; char progname[128]; struct array *newft; pid_t newpid; int result; assert(nargs >= 1); if (nargs > 2) { kprintf("Warning: argument passing from menu not supported\n"); } /* Hope we fit. */ assert(strlen(args[0]) < sizeof(progname)); strcpy(progname, args[0]); /* cheesy hack to get exit working */ newpid = newprocess(1); if (newpid < 0) panic("cmd_progthread: allocating new process %s", strerror(newpid)); curthread->t_pid = newpid; // no pagetable corruption here /* set up filetable */ newft = copyfiletable(1); if (newft==NULL) panic("cmd_progthread: initializing filetable for child\n"); setfiletable(newpid, newft); result = runprogram(progname); if (result) { kprintf("Running program %s failed: %s\n", args[0], strerror(result)); return; } /* NOTREACHED: runprogram only returns on error. */ }
void proc_bootstrap(void) { pid_t initpid; proctable = array_create(); proctable_lock = lock_create("proctable_lock"); if (proctable_lock==NULL) panic("proc_bootstrap: failed to initialize proctable_lock\n"); /* should always be zero */ initpid = newprocess(1); assert(initpid==1); curthread->t_pid = initpid; kprintf("proctable initialized\n"); }
static void dbgsh_thread (void *arg) { int shell, ttyin, ttyout; msgregister ("dbgsh_ttyin", dbgsh_ttyin_msghandler); msgregister ("dbgsh_ttyout", dbgsh_ttyout_msghandler); debug_msgregister (); ttyin = msgopen ("dbgsh_ttyin"); ttyout = msgopen ("dbgsh_ttyout"); for (;;) { shell = newprocess ("shell"); if (ttyin < 0 || ttyout < 0 || shell < 0) panic ("dbgsh_thread"); msgsenddesc (shell, ttyin); msgsenddesc (shell, ttyout); msgsendint (shell, 0); msgclose (shell); schedule (); } }
static boolean cmdiconhit (void) { /* 5/21/91 dmb: run the string as a process so we can handle errors nicely. 8/20/91 dmb: when the process completes, we're in another thread and can't assume that the window is around anymore, let alone that its globals are set. to handle this (crashing) situation, use new minisetwindowmessage to display the result. 10/25/91 dmb: check new process's disposewhenidleflag before running it. 10/27/91 dmb: don't dispose result value if processruncode returns false 12/12/91 dmb: extract the text handle from the dialog record's TE record to overcome the miniwindow's string-oriented architecture. Unfortunately, the text also saved in the database as a string, to this is just a band-aid, not a real fix. 2.1a6 dmb: reworked threading for thread mgr 1.1 2.1b2 dmb: pass -1 for errorrefcon instead of zero to prevent top level lexical scope from being transparent (i.e. visible to subroutines) 5.0d14 dmb: minidialog now uses full text handles, not bigstrings 5.0b17 dmb: minigetstring result is ours to consume */ Handle hscript; hdltreenode hcode; boolean fl; hdlprocessrecord hprocess; register hdlprocessrecord hp; hdlprocessthread hthread; if (quickscriptprocess != nil) { sysbeep (); return (false); } if (!langpusherrorcallback (&cmderrorroutine, (long) -1)) return (false); minigetstring (0, &hscript); fl = langbuildtree (hscript, false, &hcode); /*consumes htext*/ langpoperrorcallback (); if (!fl) /*syntax error*/ return (false); langerrorclear (); /*compilation produced no error, be sure error window is empty*/ if (!newprocess (hcode, true, &cmderrorroutine, (long) -1, &hprocess)) { langdisposetree (hcode); return (false); } hp = hprocess; /*copy into register*/ (**hp).processstartedroutine = &cmdprocesscallback; (**hp).processkilledroutine = &cmdprocesscallback; #ifndef oldthreads if (!newprocessthread (&cmdthreadmain, (tythreadmainparams) hp, &hthread)) { disposeprocess (hp); return (false); } quickscriptprocess = hp; /*can only run one of these at a time*/ return (true); #else quickscriptprocess = hp; /*can only run one of these at a time*/ if (!innewprocessthread (&hthread)) /*not in new thread -- we're done with synchonous stuff*/ return (true); if ((hthread == nil) || (**hp).fldisposewhenidle) fl = false; else fl = processruncode (hp, &val); disposeprocess (hp); if (!fl) setbooleanvalue (false, &val); hashgetvaluestring (val, bsresult); disposetmpvalue (val); minisetwindowmessage (idcommandconfig, bsresult); /*can't assume miniwindow is around anymore*/ quickscriptprocess = nil; /*clear "semaphore"*/ endprocessthread (hthread); return (false); /*if we got here, hthread was nil*/ #endif } /*cmdiconhit*/
DWORD WINAPI processConnect(void *_vArg) { // Thread's argument is cast to a XPCConnectInfo object XPCConnectInfo *connectInfo = (XPCConnectInfo *)_vArg; int iRet; // Number of bytes returned from receiving // or sending data on the socket int iPid; // Process ID of the spawn application char sSocketBuf[1024]; // Stores the raw bytes received from the // socket XPCPort aPort; // Stores the chosen socket port number // XPCClientConnection linked-list pointers XPCClientConnection *currentClient; XPCClientConnection *previousClient; try { // Receive socket data iRet = connectInfo->getSocket()->iRecieveMessage((void *)sSocketBuf, sizeof(sSocketBuf)); if (iRet == 0) { cout << "Receive Error: No Data Received of Socket" << endl; delete connectInfo; return 1; } // Cast raw data to a XPCSpawnInfo object XPCSpawnInfo *spawnData = (XPCSpawnInfo *)sSocketBuf; if (spawnData->cGetAction() == SPAWN) { // If the action from the connected process is SPAWN, an attempt is // made to spawn the requested application try { XPCProcessAttrib spawn((char *)spawnData->sGetAppName()); XPCProcess newprocess(spawn); // The process ID of the spawned application is retrieved PROCESS_INFORMATION processInfo; spawn.vGetProcessInformation(&processInfo); iPid = (long int)processInfo.dwProcessId; } catch(XPCException &ex) { // If the requested application cannot be spawned, a XPCPort // object is returned to the client with a port value of -1 // indicating an error occurred XPCPort failurePort((long int)-1); iRet = connectInfo->getSocket()->iSendMessage((void *)&failurePort,sizeof(XPCPort)); if (iRet == 0) { cerr << "Socket Send Error: Error sending failure to client" << endl; } delete connectInfo; return 1; } // Lock the domain semaphore and insert the socket message into // the XPCClientConnection linked-list connectInfo->getSem()->vLockWait(); vCClientConnectionInsert((char *)spawnData->sGetAppName(), iPid, connectInfo->getSocket()); // The semaphore is unlocked once the socket message is inserted // into the linked-list connectInfo->getSem()->vUnlock(); } else { // Since the connected process's action is REGISTER, the socket // data is cast to a XPCServerSpawn object XPCServerSpawn *serverSpawn = (XPCServerSpawn *)sSocketBuf; // Retrieve an Unused Port int iPort = iGetPort(); aPort.vSetPort(iPort); // The domain sempaphore is locked before the XPCClientConnection // linked-list is traversed connectInfo->getSem()->vLockWait(); // The linked-list is traversed until the registered application // name and process ID can be located previousClient = currentClient = firstClient; while (currentClient != NULL) { if (*currentClient == *serverSpawn) { // If the client information is found, the XPCPort // object is sent to both the client and the // server iRet = connectInfo->getSocket()->iSendMessage((void *)&aPort, sizeof(XPCPort)); if (iRet == 0) { cerr << "Error sending XPCPort to client" << endl; } // A sleep is done to insure the server receives // the socket port and binds to it before the // client has the change to connect Sleep(2000); iRet = currentClient->getSocket()->iSendMessage((void *)&aPort, sizeof(XPCPort)); if (iRet == 0) { cerr << "Error sending XPCPort to server" << endl; } // Remove the found client node from the linked-list vRemoveNode(currentClient); break; } previousClient = currentClient; currentClient = currentClient->next; } // If the client information could not be located, a XPCPort object // containing a -1 is sent to the server indicating failure if (currentClient == NULL) { XPCPort failurePort((long int)-1); iRet = connectInfo->getSocket()->iSendMessage((void *)&failurePort, sizeof(XPCPort)); if (iRet == 0) { cerr << "Error sending socket data" << endl; } } // The domain semaphore protecting the linked-list is unlocked connectInfo->getSem()->vUnlock(); } } catch(XPCException &exceptObject) { // All socket related errors are caught and displayed to the user cout << "Spawn Server Error: " << exceptObject.sGetException() << endl; return 0; } delete connectInfo; return 1; }
static void panic_init_msg (void) { panic_process = newprocess ("panic"); currentcpu->panic.shell_ready = true; }
boolean meuserselected (hdlheadrecord hnode) { /* 1/7/90 dmb: in option key case, must push/popglobals around mexpandto 3/29/91 dmb: moved option key case into it's own routine; caller checks. 2.1b2 dmb: support osa scripts by using scriptbuildtree instead of langbuildtree 3.0a dmb: we're now allowed to add the new process here for runtime too. 4.1b3 dmb: don't set newlyaddedprocess here anymore; addprocess does it. */ Handle htext; long signature; hdltreenode hcode; hdlprocessrecord hprocess; register hdlprocessrecord hp; boolean fl; #if !flruntime menudata = (hdlmenurecord) (**outlinedata).outlinerefcon; #endif if (!megetnodelangtext (hnode, &htext, &signature)) return (false); if (!langpusherrorcallback (&mescripterrorroutine, (long) hnode)) return (false); fl = scriptbuildtree (htext, signature, &hcode); langpoperrorcallback (); if (!fl) /*syntax error*/ return (false); langerrorclear (); /*compilation produced no error, be sure error window is empty*/ if (!newprocess (hcode, true, &mescripterrorroutine, (long) hnode, &hprocess)) { langdisposetree (hcode); return (false); } hp = hprocess; /*copy into register*/ #if !flruntime (**hp).processkilledroutine = &meprocesscallback; shellforcemenuadjust (); /*for menu dimming*/ #endif addprocess (hp); return (true); } /*meuserselected*/