MCPcopy Create free account
hub / github.com/F-Stack/f-stack / kern_poll

Function kern_poll

freebsd/kern/sys_generic.c:1421–1522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1419}
1420
1421int
1422kern_poll(struct thread *td, struct pollfd *ufds, u_int nfds,
1423 struct timespec *tsp, sigset_t *uset)
1424{
1425 struct pollfd *kfds;
1426 struct pollfd stackfds[32];
1427 sbintime_t sbt, precision, tmp;
1428 time_t over;
1429 struct timespec ts;
1430 int error;
1431
1432 precision = 0;
1433 if (tsp != NULL) {
1434 if (tsp->tv_sec < 0)
1435 return (EINVAL);
1436 if (tsp->tv_nsec < 0 || tsp->tv_nsec >= 1000000000)
1437 return (EINVAL);
1438 if (tsp->tv_sec == 0 && tsp->tv_nsec == 0)
1439 sbt = 0;
1440 else {
1441 ts = *tsp;
1442 if (ts.tv_sec > INT32_MAX / 2) {
1443 over = ts.tv_sec - INT32_MAX / 2;
1444 ts.tv_sec -= over;
1445 } else
1446 over = 0;
1447 tmp = tstosbt(ts);
1448 precision = tmp;
1449 precision >>= tc_precexp;
1450 if (TIMESEL(&sbt, tmp))
1451 sbt += tc_tick_sbt;
1452 sbt += tmp;
1453 }
1454 } else
1455 sbt = -1;
1456
1457 /*
1458 * This is kinda bogus. We have fd limits, but that is not
1459 * really related to the size of the pollfd array. Make sure
1460 * we let the process use at least FD_SETSIZE entries and at
1461 * least enough for the system-wide limits. We want to be reasonably
1462 * safe, but not overly restrictive.
1463 */
1464 if (nfds > maxfilesperproc && nfds > FD_SETSIZE)
1465 return (EINVAL);
1466 if (nfds > nitems(stackfds))
1467 kfds = mallocarray(nfds, sizeof(*kfds), M_TEMP, M_WAITOK);
1468 else
1469 kfds = stackfds;
1470 error = copyin(ufds, kfds, nfds * sizeof(*kfds));
1471 if (error)
1472 goto done;
1473
1474#ifndef FSTACK
1475 if (uset != NULL) {
1476 error = kern_sigprocmask(td, SIG_SETMASK, uset,
1477 &td->td_oldsigmask, 0);
1478 if (error)

Callers 3

sys_pollFunction · 0.85
sys_ppollFunction · 0.85
ff_pollFunction · 0.85

Calls 11

tstosbtFunction · 0.85
kern_sigprocmaskFunction · 0.85
seltdinitFunction · 0.85
pollscanFunction · 0.85
seltdwaitFunction · 0.85
pollrescanFunction · 0.85
seltdclearFunction · 0.85
polloutFunction · 0.85
mallocarrayFunction · 0.70
freeFunction · 0.70
copyinFunction · 0.50

Tested by

no test coverage detected