kernel: POSIX compliance and robustness fixes (Round 3)
Round 3 of the audit fix plan — medium-severity POSIX compliance fixes:
- ftruncate: reject O_RDONLY fd with EBADF (write permission check)
- truncate: check vfs_check_permission for write access (EACCES)
- O_EXCL: return EEXIST when O_CREAT|O_EXCL on existing file
- O_DIRECTORY: return ENOTDIR when O_DIRECTORY on non-directory
- posix_spawn: fix _syscall2→_syscall4 to pass all 4 args (pid_out,
path, argv, envp) matching kernel handler expectations
- SYSCALL_MKDIR: accept mode argument from user space (passed through
to syscall_mkdir_impl; VFS backends don't use it yet)
- CLONE_VM: add address-space refcount table to prevent use-after-free
when thread group leader exits before threads. g_as_refcnt[] tracks
refs per addr_space value; parent and child each hold a ref; last
ref to exit destroys the AS.