commit 1a155fb7a2b4ca3780be755801dcde3ce94a8034 from: int16h date: Thu Dec 4 10:42:31 2025 UTC Added defensive code to write_full() to detect and break out of the infinite loop if write() returns 0 (stdio); other mods while debugging file/mem I/O commit - 6b515a6f644d1aebf0f99f296c2a4e6187d8233a commit + 1a155fb7a2b4ca3780be755801dcde3ce94a8034 blob - 99d5b8f9b1bde5657388a930e544eb64fc6fd3cc blob + e1232717e513b49db1caca7bdad5e844f28b3c19 --- changelog.md +++ changelog.md @@ -51,6 +51,8 @@ - Console/PTY stability: delayed fallback disablement until both ttyd and ptyctl register; auto-activate the first PTY on alloc/open and switch off supervisor/fallback; reset the console line buffer on PTY changes to drop stale input; guarded console-injected `[signal N]` stanzas behind `LENIX_DEBUG` to avoid shells seeing `[signal` as commands; tightened shell PTY activation in init with warnings on bad PTY IDs. - libc safety: `strlen`/`strcmp`/`strncmp` now tolerate NULL inputs to avoid release-only crashes; ramdiskd/vfs startup page faults fixed by guarding unused helpers and sizing/alignment of BSS. - Misc: Debug-only helpers wrapped with `LENIX_DEBUG` (blockd, ramdiskd, pci) and marked padding as used to satisfy `-Werror`; added a serial log for VFS register success for visibility in non-debug boots. +- VFS debug gating: all `[vfs]` logging is now guarded by `LENIX_VFS_DEBUG` instead of `LENIX_DEBUG`, with common macros (`VFS_PUTS/VFS_PRINTF`) to silence output in release builds. +- IPC wait backoff: VFS/service client request loops still yield while spinning; earlier backoff tweaks were reverted to the original budgets to avoid long stalls during boot. # 2025-12-03 blob - 803cf48ec6ef9859c61249e42edb31df2fa0f677 blob + ab71e8cb79bdd5e5edf61e1a1ecde7537bc17431 --- kernel/ipc/service_client.c +++ kernel/ipc/service_client.c @@ -141,7 +141,6 @@ ipc_service_request_issue_timeout(struct ipc_service_c uint8_t tmp_req[IPC_MAILBOX_MAX_PAYLOAD]; uint64_t spins = 0; uint64_t spin_limit = 10000000; /* Default iteration budget */ - size_t resp_bytes = 0; if (spin_limit_override != 0) spin_limit = spin_limit_override; @@ -212,7 +211,6 @@ ipc_service_request_issue_timeout(struct ipc_service_c if (slot->response_len > resp_len) slot->response_len = resp_len; service_memcpy(resp, slot->response_buf, slot->response_len); - resp_bytes = slot->response_len; slot->in_use = false; slot->ready = false; @@ -225,7 +223,7 @@ ipc_service_request_issue_timeout(struct ipc_service_c preq->in_use = false; spinlock_unlock(&pending_requests_lock); if (out_resp_len != NULL) - *out_resp_len = resp_bytes; + *out_resp_len = slot->response_len; return 0; } blob - aa9cd56c4697c6f50249b6d50f01c3419ae3fc4d blob + 194bde48e75e5bede694aa4f98a25fbb2397c487 --- kernel/ipc/vfs_service.c +++ kernel/ipc/vfs_service.c @@ -233,7 +233,7 @@ vfs_request_issue(const struct ipc_vfs_request *req, * while still allowing adequate time for VFS server to respond. * Matches block_service.c spin limits (1M iterations). */ - uint64_t spin_limit = 1000000; + uint64_t spin_limit = 1000000; /* Default iteration budget */ #ifdef LENIX_DEBUG uint64_t t_start, t_alloc, t_send, t_wait, t_end; t_start = __builtin_ia32_rdtsc(); blob - e54e7b1630be5ae6733b3f5c617b303662168be7 blob + 8cd5ae9b1ee21e8f2e0519524f0c33fc322e93a0 --- kernel/kmain.c +++ kernel/kmain.c @@ -255,23 +255,23 @@ kmain_post_mm(void) boot_log_result("ramdiskd", rc == 0); } - rc = user_pci_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing pci-daemon...", rc == 0); - #endif - if (rc == 0) { - rc = user_pci_server_launch(); - boot_log_result("pci-server", rc == 0); - } + // rc = user_pci_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing pci-daemon...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_pci_server_launch(); + // boot_log_result("pci-server", rc == 0); + // } - rc = user_virtio_blk_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing virtio-blk driver...", rc == 0); - #endif - if (rc == 0) { - rc = user_virtio_blk_server_launch(); - boot_log_result("virtio-blk driver", rc == 0); - } + // rc = user_virtio_blk_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing virtio-blk driver...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_virtio_blk_server_launch(); + // boot_log_result("virtio-blk driver", rc == 0); + // } rc = user_fs_server_prepare(); #ifdef LENIX_DEBUG @@ -282,14 +282,14 @@ kmain_post_mm(void) boot_log_result("fs-server", rc == 0); } - rc = user_tmpfs_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing tmpfs-server...", rc == 0); - #endif - if (rc == 0) { - rc = user_tmpfs_server_launch(); - boot_log_result("tmpfs-server", rc == 0); - } + // rc = user_tmpfs_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing tmpfs-server...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_tmpfs_server_launch(); + // boot_log_result("tmpfs-server", rc == 0); + // } rc = user_vfs_server_prepare(); #ifdef LENIX_DEBUG @@ -300,32 +300,32 @@ kmain_post_mm(void) boot_log_result("vfs", rc == 0); } - rc = user_netd_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing netd...", rc == 0); - #endif - if (rc == 0) { - rc = user_netd_server_launch(); - boot_log_result("netd", rc == 0); - } + // rc = user_netd_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing netd...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_netd_server_launch(); + // boot_log_result("netd", rc == 0); + // } - rc = user_sock_udp_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing sock.udp...", rc == 0); - #endif - if (rc == 0) { - rc = user_sock_udp_server_launch(); - boot_log_result("sock.udp", rc == 0); - } + // rc = user_sock_udp_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing sock.udp...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_sock_udp_server_launch(); + // boot_log_result("sock.udp", rc == 0); + // } - rc = user_sock_tcp_server_prepare(); - #ifdef LENIX_DEBUG - boot_log_result("Preparing sock.tcp...", rc == 0); - #endif - if (rc == 0) { - rc = user_sock_tcp_server_launch(); - boot_log_result("sock.tcp", rc == 0); - } + // rc = user_sock_tcp_server_prepare(); + // #ifdef LENIX_DEBUG + // boot_log_result("Preparing sock.tcp...", rc == 0); + // #endif + // if (rc == 0) { + // rc = user_sock_tcp_server_launch(); + // boot_log_result("sock.tcp", rc == 0); + // } rc = user_tty_server_prepare(); #ifdef LENIX_DEBUG blob - c0abe7ee359ef924c65b3cbf54d103ccf3cd6e88 blob + 7df4d909c3c886b430584adb030621bdffc8bb35 --- servers/fs/vfs/main.c +++ servers/fs/vfs/main.c @@ -1577,20 +1577,22 @@ vfs_respond_read(const struct ipc_vfs_request *req) memset(&resp, 0, sizeof(resp)); ipc_vfs_response_reset(&resp, IPC_VFS_RESP_READ, req->token); - #ifdef LENIX_DEBUG + #ifdef LENIX_VFS_DEBUG printf("[vfs] READ handler entry: req_handle=%u req_len=%u\n", req->body.read.handle, req->body.read.length); #endif handle = vfs_handle_lookup(req->body.read.handle); if (handle == NULL) { + #ifdef LENIX_VFS_DEBUG printf("[vfs] READ: handle lookup failed\n"); + #endif resp.body.read.status = VFS_EBADF; resp.body.read.data_len = 0; vfs_send_response(&resp); return; } - #ifdef LENIX_DEBUG + #ifdef LENIX_VFS_DEBUG printf("[vfs] READ: handle found, fs_fd=%d VFS_READAHEAD_ENABLE=%d\n", handle->fs_fd, VFS_READAHEAD_ENABLE); #endif @@ -1605,7 +1607,7 @@ vfs_respond_read(const struct ipc_vfs_request *req) size_t copied = 0; int64_t pos = handle->logical_offset; - #ifdef LENIX_DEBUG + #ifdef LENIX_VFS_DEBUG printf("[vfs] read: use_readahead=%d is_device=%d refcount=%u pos=%lld req_len=%zu\n", use_readahead, handle->is_device, handle->refcount, (long long)pos, requested_len); #endif @@ -1747,7 +1749,7 @@ done: handle->logical_offset = pos; resp.body.read.status = (int32_t)copied; /* Status = bytes read, not error code */ resp.body.read.data_len = (uint32_t)copied; - #ifdef LENIX_DEBUG + #ifdef LENIX_VFS_DEBUG printf("[vfs] read done: copied=%zu new_pos=%lld\n", copied, (long long)pos); #endif vfs_send_response(&resp); blob - 8572afd9da188b0a2056b87c8508d4c08b701a3e blob + c1a56a587f3cd72c86a0968d0f7896416cb37627 --- user/runtime/src/stdio.c +++ user/runtime/src/stdio.c @@ -11,6 +11,13 @@ write_full(int fd, const char *buf, size_t len) ssize_t w = write(fd, buf, len); if (w < 0) return -1; + if (w == 0) { + /* write() returned 0 - no progress possible. + * This should never happen for regular files/pipes, + * but handle defensively to avoid infinite loop. */ + errno = EIO; + return -1; + } buf += (size_t)w; len -= (size_t)w; }