MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / waitpid

Method waitpid

source/kernel/ksystem.cpp:361–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361U32 KSystem::waitpid(KThread* thread, S32 pid, U32 statusAddress, U32 options) {
362 KProcessPtr process;
363 U32 result = 0;
364 KMemory* memory = thread->memory;
365
366 BOXEDWINE_CRITICAL_SECTION_WITH_CONDITION(processesCond);
367
368 while (!process) {
369 if (pid>0) {
370 process = KSystem::processes[pid];
371 if (!process) {
372 return -K_ECHILD;
373 }
374 if (!process->isStopped() && !process->isTerminated()) {
375 process = 0;
376 }
377 } else {
378 if (pid==0)
379 pid = thread->process->groupId;
380 for (auto& n : KSystem::processes) {
381 KProcessPtr p = n.value;
382 if (p && (p->isStopped() || p->isTerminated())) {
383 if (pid == -1) {
384 if (p->parentId == thread->process->id) {
385 process = p;
386 break;
387 }
388 } else {
389 if (p->groupId == (U32)(-pid)) {
390 process = p;
391 break;
392 }
393 }
394 }
395 }
396 }
397 if (!process) {
398 if (options & 1) { // WNOHANG
399 return 0;
400 } else {
401 BOXEDWINE_CONDITION_WAIT(processesCond);
402#ifdef BOXEDWINE_MULTI_THREADED
403 if (KThread::currentThread()->terminating) {
404 return -K_EINTR;
405 }
406 if (KThread::currentThread()->startSignal) {
407 KThread::currentThread()->startSignal = false;
408 return -K_CONTINUE;
409 }
410#endif
411 }
412 }
413 }
414 if (statusAddress!=0) {
415 int s = 0;
416 if (process->isStopped()) {
417 s |= 0x7f;
418 s|=((process->signaled & 0xFF)<< 8);

Callers

nothing calls this directly

Calls 3

isStoppedMethod · 0.80
isTerminatedMethod · 0.80
writedMethod · 0.45

Tested by

no test coverage detected