Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's something that has always been interesting about Windows NT, which has a multi-level object handle table, and does not have the rule about re-using the lowest numbered available table index. There's scope for reducing contention amongst threads in such an architecture.

Although:

1. back in application-mode code the language runtime libraries make things look like a POSIX API and maintain their own table mapping object handles to POSIX-like file descriptors, where there is the old contention over the lowest free entries; and

1. in practice the object handle table seems to mostly append, so multiple object-opening threads all contend over the end of the table.





lowest-number-reuse is also a robustness issue. If multi-threaded programs UAF or double-free a file descriptor they likely end up touching FDs owned by other parts of the program which can result in various kinds of corruption and memory-unsafety. Assigning numbers from a large domain, either randomly or from a permutation sequence, would massively reduce that probability and manifest in prompt errors instead.

I want an alternative unix ABI that doesn't guarantee lowest-reuse for this exact reason. I suppose you could (almost) just hijack the close call and replace it with a dup2 of /dev/null or something (but then you'd miss close errors).

It could be emulated in userspace with F_DUPFD. But that's costly because the kernel table is optimized for dense data, not sparse.

The rust standard library aborts the program in debug builds when it detects a double-close; at that point corruption may already have occurred but better than nothing.


> The rust standard library aborts the program in debug builds when it detects a double-close

On EBADF? Neat.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: