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

Method futex

source/kernel/kthread.cpp:314–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312}
313
314U32 KThread::futex(U32 addr, U32 op, U32 value, U32 pTime, U32 val2, U32 val3, bool time64) {
315 U64 ramAddress = 0;
316 U32 cmd = (op & FUTEX_CMD_MASK);
317 bool isPrivate = (op & FUTEX_PRIVATE_FLAG) != 0;
318
319 if (isPrivate) {
320 ramAddress = addr;
321 } else {
322 ramAddress = (U64)memory->getRamPtr(addr, 4, false, true);
323 }
324 if (ramAddress == 0) {
325 kpanic_fmt("Could not find futex address: %0.8X", addr);
326 }
327 /*
328 * from kernel source, if I ever implement one of these I need to note pTime actually contains val2
329 if (cmd == FUTEX_REQUEUE || cmd == FUTEX_CMP_REQUEUE ||
330 cmd == FUTEX_CMP_REQUEUE_PI || cmd == FUTEX_WAKE_OP)
331 val2 = (u32)(unsigned long)utime;
332 */
333 if (cmd ==FUTEX_WAIT || cmd == FUTEX_WAIT_BITSET) {
334 //klog_fmt("%x/%x futux WAIT addr=%x op=%x val=%x ram=%x", id, process->id, addr, op, value, (U32)ramAddress);
335 struct futex* f;
336 U32 expireTime = 0xFFFFFFFF;
337
338 if (pTime != 0) {
339 if (time64) {
340 U64 seconds = memory->readq(pTime);
341 U32 nano = memory->readd(pTime + 8);
342
343 if (cmd == FUTEX_WAIT) {
344 // FUTEX_WAIT timeout is relative
345 expireTime = (U32)(seconds * 1000 + nano / 1000000);
346 } else {
347 expireTime = (U32)((seconds * 1000 + nano / 1000000) - KSystem::getSystemTimeAsMicroSeconds() / 1000);
348 }
349 } else {
350 U32 seconds = memory->readd(pTime);
351 U32 nano = memory->readd(pTime + 4);
352
353 if (cmd == FUTEX_WAIT) {
354 // FUTEX_WAIT timeout is relative
355 expireTime = seconds * 1000 + nano / 1000000;
356 } else {
357 expireTime = (U32)((seconds * 1000 + nano / 1000000) - KSystem::getSystemTimeAsMicroSeconds() / 1000);
358 }
359 }
360 expireTime += KSystem::getMilliesSinceStart();
361 }
362
363 f = getFutex(this, ramAddress);
364
365 if (!f) {
366 U32 currentValue = memory->readd(addr);
367 if (currentValue != value) {
368 //klog_fmt(" %x/%x futux addr=%x op=%x val=%x ram=%x NEW VALUE %x", id, process->id, addr, op, value, (U32)ramAddress, currentValue);
369 return -K_EWOULDBLOCK;
370 }
371

Callers 3

internalCleanupMethod · 0.95
syscall_futexFunction · 0.45
syscall_futex_time64Function · 0.45

Calls 8

kpanic_fmtFunction · 0.85
getFutexFunction · 0.85
allocFutexFunction · 0.85
freeFutexFunction · 0.85
kwarn_fmtFunction · 0.85
readqMethod · 0.80
getRamPtrMethod · 0.45
readdMethod · 0.45

Tested by

no test coverage detected