process_madvise syscall needs pidfd_get_pid function to translate pidfd to pid so this patch move the function to kernel/pid.c.
Showing the changes to kernel (2 of 3 files). Show all
Unified · Split
| @@ -1474,25 +1474,6 @@ end: · 1473 unmodified lines | ||
| 1474 | 1474 | return retval; |
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | −static struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) | |
| 1478 | −{ | |
| 1479 | − struct fd f; | |
| 1480 | − struct pid *pid; | |
| 1481 | − | |
| 1482 | − f = fdget(fd); | |
| 1483 | − if (!f.file) | |
| 1484 | − return ERR_PTR(-EBADF); | |
| 1485 | − | |
| 1486 | − pid = pidfd_pid(f.file); | |
| 1487 | − if (!IS_ERR(pid)) { | |
| 1488 | − get_pid(pid); | |
| 1489 | − *flags = f.file->f_flags; | |
| 1490 | − } | |
| 1491 | − | |
| 1492 | − fdput(f); | |
| 1493 | − return pid; | |
| 1494 | −} | |
| 1495 | − | |
| 1496 | 1477 | static long kernel_waitid(int which, pid_t upid, struct waitid_info *infop, |
| 1497 | 1478 | int options, struct rusage *ru) |
| 1498 | 1479 | { |
| @@ -520,6 +520,25 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns) · 519 unmodified lines | ||
| 520 | 520 | return idr_get_next(&ns->idr, &nr); |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | +struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) | |
| 524 | +{ | |
| 525 | + struct fd f; | |
| 526 | + struct pid *pid; | |
| 527 | + | |
| 528 | + f = fdget(fd); | |
| 529 | + if (!f.file) | |
| 530 | + return ERR_PTR(-EBADF); | |
| 531 | + | |
| 532 | + pid = pidfd_pid(f.file); | |
| 533 | + if (!IS_ERR(pid)) { | |
| 534 | + get_pid(pid); | |
| 535 | + *flags = f.file->f_flags; | |
| 536 | + } | |
| 537 | + | |
| 538 | + fdput(f); | |
| 539 | + return pid; | |
| 540 | +} | |
| 541 | + | |
| 523 | 542 | /** |
| 524 | 543 | * pidfd_create() - Create a new pid file descriptor. |
| 525 | 544 | * |