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

Function kern_close_range

freebsd/kern/kern_descrip.c:1369–1418  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1367}
1368
1369int
1370kern_close_range(struct thread *td, u_int lowfd, u_int highfd)
1371{
1372 struct filedesc *fdp;
1373 const struct fdescenttbl *fdt;
1374 struct file *fp;
1375 int fd;
1376
1377 /*
1378 * Check this prior to clamping; closefrom(3) with only fd 0, 1, and 2
1379 * open should not be a usage error. From a close_range() perspective,
1380 * close_range(3, ~0U, 0) in the same scenario should also likely not
1381 * be a usage error as all fd above 3 are in-fact already closed.
1382 */
1383 if (highfd < lowfd) {
1384 return (EINVAL);
1385 }
1386
1387 fdp = td->td_proc->p_fd;
1388 FILEDESC_XLOCK(fdp);
1389 #pragma GCC diagnostic ignored "-Wcast-qual"
1390 fdt = atomic_load_ptr(&fdp->fd_files);
1391 #pragma GCC diagnostic error "-Wcast-qual"
1392 highfd = MIN(highfd, fdt->fdt_nfiles - 1);
1393 fd = lowfd;
1394 if (__predict_false(fd > highfd)) {
1395 goto out_locked;
1396 }
1397 for (;;) {
1398 fp = fdt->fdt_ofiles[fd].fde_file;
1399 if (fp == NULL) {
1400 if (fd == highfd)
1401 goto out_locked;
1402 } else {
1403 fdfree(fdp, fd);
1404 (void) closefp(fdp, fd, fp, td, true, true);
1405 if (fd == highfd)
1406 goto out_unlocked;
1407 FILEDESC_XLOCK(fdp);
1408 #pragma GCC diagnostic ignored "-Wcast-qual"
1409 fdt = atomic_load_ptr(&fdp->fd_files);
1410 #pragma GCC diagnostic error "-Wcast-qual"
1411 }
1412 fd++;
1413 }
1414out_locked:
1415 FILEDESC_XUNLOCK(fdp);
1416out_unlocked:
1417 return (0);
1418}
1419
1420#ifndef _SYS_SYSPROTO_H_
1421struct close_range_args {

Callers 2

sys_close_rangeFunction · 0.85
freebsd12_closefromFunction · 0.85

Calls 2

fdfreeFunction · 0.85
closefpFunction · 0.85

Tested by

no test coverage detected