binder_do_fd_close(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… binder_do_fd_close(9) β€” from the Kernel API Manual ✨

okay so bestie, we're in the kernel API manual today and the star of the show is binder_do_fd_close, a function whose whole entire job is closing a list of file descriptors β€” but like, at the right time, not just whenever. timing is everything, iykyk πŸŽ€


🌸 SYNOPSIS 🌸

void binder_do_fd_close (struct callback_head *twork );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • twork β€” the callback head for task work. it's giving "my whole identity is being a callback" and honestly? respect πŸ’…

✨ DESCRIPTION ✨

okay so here's the tea, and it's actually important: it is not safe to call ksys_close during the binder_ioctl function if there's even a chance that binder's own file descriptor might get closed. like, that's the whole reason, and it exists to meet the requirements for using fdget (go read the comments for __fget_light if you want the full lore, bestie πŸ“–).

so instead of doing the risky thing, we use task_work_add to schedule the close operation for after we've returned from binder_ioctl. slay, deferred execution, we love to see it πŸ‘‘

this function right here? it's the callback for that whole mechanism β€” and it does the actual ksys_close on the given file descriptor. so it's like the main character who shows up at the very end to actually do the thing. no cap, that's the entire vibe πŸ’–


πŸ’œ SEE ALSO πŸ’œ

kernel file ./drivers/android/binder.c β€” plus this absolutely iconic lineup of related pages:


genuine reminder bestie: the ksys_close-during-binder_ioctl thing isn't a suggestion, it's a not safe. don't do it. let task work handle it. 🫢

and that's the page!! this one lives under ./drivers/android, dated October 2026, and it's binder_do_fd_close(9) β€” go forth and close your fds responsibly, mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from