binder_do_fd_close(9)
π 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:
binder_proc_lock(9)binder_proc_unlock(9)binder_inner_proc_lock(9)binder_inner_proc_unlock(9)binder_node_lock(9)binder_node_unlock(9)binder_node_inner_lock(9)binder_node_inner_unlock(9)binder_worklist_empty(9)binder_enqueue_work_ilocked(9)binder_enqueue_deferred_thread_work_ilocked(9)binder_enqueue_thread_work_ilocked(9)binder_enqueue_thread_work(9)binder_dequeue_work(9)binder_select_thread_ilocked(9)binder_wakeup_thread_ilocked(9)binder_inc_node_tmpref(9)binder_dec_node_tmpref(9)binder_get_ref_for_node_olocked(9)binder_inc_ref_olocked(9)binder_dec_ref_olocked(9)binder_get_node_from_ref(9)binder_free_ref(9)binder_update_ref_for_handle(9)binder_dec_ref_for_handle(9)binder_inc_ref_for_node(9)binder_thread_dec_tmpref(9)binder_proc_dec_tmpref(9)binder_get_txn_from(9)binder_get_txn_from_and_acq_inner(9)binder_free_txn_fixups(9)binder_cleanup_transaction(9)binder_get_object(9)binder_validate_ptr(9)binder_validate_fixup(9)struct binder_task_work_cb(9)binder_deferred_fd_close(9)struct binder_ptr_fixup(9)struct binder_sg_copy(9)binder_do_deferred_txn_copies(9)binder_cleanup_deferred_txn_lists(9)binder_defer_copy(9)binder_add_fixup(9)binder_can_update_transaction(9)binder_find_outdated_transaction_ilocked(9)binder_proc_transaction(9)binder_get_node_refs_for_txn(9)binder_netlink_report(9)binder_free_buf(9)binder_apply_fd_fixups(9)print_next_binder_node_ilocked(9)
genuine reminder bestie: theksys_close-during-binder_ioctlthing 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
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms