| 359 | } |
| 360 | |
| 361 | U32 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); |
nothing calls this directly
no test coverage detected