Commit Graph

745 Commits

Author SHA1 Message Date
LoGin 41de8ac209
refactor(tty): enhance TTY session management and stdio initialization (#1786)
- Update TTY session checks to ensure proper session leader and controlling TTY conditions during open.
- Modify stdio initialization to prevent init process from acquiring a controlling TTY, aligning with Linux semantics.
- Add a new test case to validate behavior of tcgetpgrp without a controlling TTY.

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-13 11:35:27 +08:00
LoGin 2140513f38
feat(vfs): implement flock advisory file locking (#1785)
- Add flock syscall support with shared/exclusive locks and nonblocking mode
- Introduce open file description ID for flock owner tracking
- Add flock manager with sharded hashmap for lock state management
- Support lock inheritance across dup/fork and release on last close
- Add comprehensive test suite covering basic operations and edge cases
- Fix SCM_RIGHTS fd passing to share open file description instead of cloning

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 16:13:45 +08:00
LoGin c820bf9b8b
fix(netlink): harden route segment parsing and accept short GET payloads (#1781)
* fix(netlink): harden route segment parsing and accept short GET payloads

Prevent kernel panics on malformed netlink route messages by adding strict length
validation before reading segment body CType bytes. Add compatibility handling for
short RTM_GETLINK/RTM_GETADDR/RTM_GETROUTE payloads (rtgenmsg-sized) and keep
parsing bounded by nlmsg_len. Add a c_unitest regression test that covers truncated
and rtgen-sized netlink route requests.

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 14:45:26 +08:00
LoGin 50695ef647
fix(vfs): make dup/dup2/dup3 share open file description and move close_on_exec to per-fd (#1783)
* fix(vfs): make dup/dup2/dup3 share open file description and move close_on_exec to per-fd

   Previously, dup/dup2/dup3 used try_clone() which created independent
   File objects, violating the POSIX requirement that duplicated fds share
   the same open file description (file offset, status flags). Also,
   close_on_exec was stored inside File instead of being a per-fd attribute
   in the fd table.

   This commit:
   - Move close_on_exec from File to FileDescriptorVec as a per-fd bitmap,
     matching Linux's fdtable.close_on_exec semantics
   - Add alloc_fd_arc() to install a shared Arc<File> for dup operations
   - Make dup/dup2/dup3 share Arc<File> instead of cloning
   - Adapt all 26 call sites (open, pipe, socket, epoll, bpf, kvm, etc.)
     to pass explicit cloexec parameter to alloc_fd()
   - Fix CLONE_PIDFD to unconditionally set close-on-exec on pidfd
   - Fix pidfd_open to unconditionally set close-on-exec on pidfd
   - Fix do_dup3 to allow fd table expansion for high newfd values and
     return EBADF (not EMFILE) when newfd >= RLIMIT_NOFILE
   - Add unit tests covering shared offset, shared flags, per-fd cloexec,
     high fd dup2, dup3 EINVAL on same fd, and refcount after close

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(filesystem): propagate O_CLOEXEC flag to file descriptor allocation

- Update`create_epoll`and`perf_event_open`
to pass the O_CLOEXEC flag from file flags to`alloc_fd`
- Ensure`FileDescriptorVec`properly reserves capacity for the`cloexec`
vector when expanding

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 14:42:17 +08:00
xboHodx 8b6f23a4a3
feat(ext4): add device node support with mknod system call (#1759)
feat(ext4): add device node support with mknod system call

- Implement device inode creation with proper device number encoding in i_block
- Add mknod system call handling for character/block devices and FIFOs
- Support both old (major/minor < 256) and new format device number encoding
- Add comprehensive test suite for mknod functionality
- Fix stat system call to properly handle device nodes
- Add device number utilities compatible with Linux ext4 format

Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-11 13:08:24 +08:00
xboHodx 174b133cd9
feat(ext4): implement atomic rename and rename_exchange with POSIX semantics (#1758)
- Add atomic rename operation with proper POSIX semantics (no-op when source and
target refer to same inode, atomic replace when target exists)
- Implement rename_exchange for atomic swapping of directory entries
- Add directory entry replacement in place for atomic operations
- Add comprehensive test suite for rename operations
- Fix directory link count handling during rename operations
- Add cycle detection to prevent moving directories into their own
subdirectories
- Update VFS layer to support RENAME_EXCHANGE flag

Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-11 00:19:11 +08:00
LoGin 822726e07a
feat(net): implement netlink socket sendmsg/recvmsg and improve address handling (#1778)
* feat(net): implement netlink socket sendmsg/recvmsg and improve address handling

- Add sendmsg and recvmsg implementations for netlink sockets
- Implement NEWADDR and DELADDR operations for netlink route protocol
- Refactor get_ephemeral_iface to follow Linux-like source address selection
- Fix error propagation in netlink route message sending
- Add socket_ip_unbound_netlink_test to gvisor whitelist

Signed-off-by: longjin <longjin@DragonOS.org>

* feat(net): enhance network interface binding and loopback handling

- Add smoltcp features for increased address and route limits
- Improve error handling for address binding with specific error messages
- Enhance subnet-directed broadcast and loopback interface matching logic
- Add broadcast delivery support for UDP sockets
- Refactor netlink socket to return original message length for TRUNC flag
- Fix route addition to include local routes and proper rollback on failure
- Add batch polling for network interfaces to improve performance

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 00:05:48 +08:00
LoGin de4ee15bc8
feat: 引入RootFS清单系统并重构DADK配置 (#1776)
- 新增RootFS清单系统,支持通过ROOTFS_MANIFEST环境变量选择不同配置
- 重构DADK配置生成逻辑,移除旧的dadk-manifest.toml和rootfs.toml
- 更新构建系统以支持清单解析和动态配置生成
- 改进用户态包管理,支持按清单切换包集合
- 升级DADK到v0.6.1并更新相关工具链

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-10 13:28:34 +08:00
LoGin 3c751ec8b4
feat(netlink): add kobject uevent support and socket options (#1777)
- Add kobject uevent netlink protocol support with new socket type
- Implement socket options (SO_TYPE, SO_DOMAIN, SO_PROTOCOL, SO_SNDTIMEO,
SO_RCVTIMEO) for netlink sockets
- Fix SockAddrNl nl_family field type from AddressFamily to u16
- Add timeout handling for send and receive operations
- Improve error handling in remote_endpoint() method

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-10 13:26:21 +08:00
LoGin b768bb8efb
refactor(vfs): 将ioctl方法的private_data参数类型改为MutexGuard (#1772)
- 统一将IndexNode
trait的ioctl方法参数从&FilePrivateData改为MutexGuard<FilePrivateData>
- 在TtyDevice中提前释放锁以避免死锁
- 更新所有相关实现以适配新的参数类型

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-07 21:42:43 +08:00
Yuming Jiang 28b6ba7a21
feat: 在架构相关初始化的时候注册 tsc 时钟源。 (#1769)
- 添加 Tsc 时钟源实现。
- 优化时钟源重新选择的逻辑


Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
Co-authored-by: longjin <longjin@DragonOS.org>
2026-02-07 21:25:56 +08:00
LoGin b7c8d9d021
refactor(process): 调整进程退出时资源清理顺序 (#1771)
- 将 deactivate_task 和 set_user_vm(None) 操作移至 exit_files() 之后执行
- 在 deactivate_task 前添加 rq.update_rq_clock() 调用
- 修复因 exit_files() 可能阻塞导致 user_vm 提前清空/已退出的进程被重新加入rq引发的崩溃问题

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-07 21:24:20 +08:00
Vitus 5eeb6de512
feat(vfs): implement fallocate syscall (#1668)
* feat(vfs): implement fallocate syscall

  实现 fallocate 系统调用 (syscall 285),用于为文件分配磁盘空间。

  - 新增 sys_fallocate.rs 系统调用处理
  - 支持 mode=0 的默认分配操作,通过 vfs_truncate 扩展文件
  - 暂不支持 FALLOC_FL_KEEP_SIZE、FALLOC_FL_PUNCH_HOLE 等标志位

* - fix:add deleted_test

* - fix

* 修复关于文件大小扩展的问题,使其更符合linux语义

* fix(vfs): fallocate should only extend file, not shrink

    According to Linux fallocate(2) semantics, mode=0 should only
    extend the file size when offset+len exceeds the current file
    size. It should never shrink the file.

* fix(vfs): fallocate 溢出处理和文件类型检查修复

  - 修正文档中的错误码描述(EOPNOTSUPP → EOPNOTSUPP_OR_ENOTSUP)
  - 修复溢出处理:使用 checked_add 替代 saturating_add,溢出时正确返回 EINVAL
  - 添加文件类型检查,只支持普通文件,与 ftruncate 行为保持一致

* - 对于分配大小小于文件空间的,直接明确返回不支持

* - fix:修改一些错误码相关

* - 添加fallocate的测试
- 添加nix对c_unitest的构建,会直接打包存放在bin下面

* improve fallocate coverage and error handling

* 删除错误文件


Signed-off-by:  zhzvitus  <zhzvitus@gmail.com>
2026-02-05 21:40:37 +08:00
LoGin bdf38a8dc2
feat(kernel): 改进内核线程管理和网络命名空间轮询线程 (#1764)
* feat(kernel): 改进内核线程管理和网络命名空间轮询线程

- 新增`KernelThreadMechanism::request_stop`方法,支持请求内核线程退出
- 新增`KernelThreadMechanism::reap_zombie_kthreads`方法,用于回收僵尸内核线程
- 重构网络命名空间轮询线程为`NetnsPoller`结构,支持线程生命周期管理
- 网络命名空间销毁时自动停止轮询线程,避免资源泄漏
- 修复`ProcessControlBlock::is_kthread`方法的实现
- 优化内核线程退出时的唤醒逻辑,确保父进程能及时回收

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-05 11:24:18 +08:00
LoGin 6e8e8c6411
feat(procfs): add /proc/sys/net/ipv4/ip_local_port_range interface (#1749)
* feat(procfs): add /proc/sys/net/ipv4/ip_local_port_range interface

- Add net module to procfs sys directory with IPv4 support
- Implement ip_local_port_range file for reading/writing port range
configuration
- Update PortManager to support configurable local port range with atomic
operations
- Extend ephemeral port allocation to use configured range instead of hardcoded
values
- Add gvisor test cases for IPv4 UDP socket functionality

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-04 15:12:36 +08:00
Yuming Jiang dade7343ba
fix(driver/tsc): 修复 pmtimer 拼写错误 (#1762)
Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
2026-02-03 11:31:08 +08:00
xboHodx 6d9f280a9c
fix(ext4): 修复inode创建逻辑,支持目录创建并优化文件模式处理 (#1757)
Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-02 21:43:59 +08:00
xboHodx 3b0c2f8a99
fix(mount): 修复link方法中的inode转换问题以避免EINVAL错误 (#1756)
Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-02 21:31:44 +08:00
xboHodx a5c30c9351
fix(ntty): 修复读取缓冲区索引计算错误 (#1755)
Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-02 21:25:05 +08:00
LoGin 4dfe101f21
fix(rseq): handle signal reentrancy bug and improve error handling (#1752)
- Fix signal reentrancy bug by preventing nested SIGSEGV delivery during rseq
fault handling
- Change rseq error handling from sending SIGSEGV to disabling rseq and
returning error
- Add test case to demonstrate and verify the fix for rseq+signal reentrancy

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-02 13:18:42 +08:00
LoGin 012be249fa
refactor(dma): centralize DMA memory management and integrate with block layer (#1750)
* refactor(dma): centralize DMA memory management and integrate with block layer

- Introduce unified DMA allocator with pooling support and DmaBuffer abstraction
- Replace ad-hoc DMA allocations in block layer with DmaBuffer
- Remove duplicate DMA implementations from virtio and network drivers
- Add DMA direction and cache policy configuration options

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-02 13:17:08 +08:00
LoGin 546a9cad14
fix(process): 修复多线程exec的de_thread竞态与线程退出语义 (#1748)
* fix(process): 修复多线程exec的de_thread竞态与线程退出语义

修正PID交换时的锁顺序与notify_count语义,避免ESRCH与卡死。
完善/proc/self语义与SIGKILL线程级处理,稳定exec行为。

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-01 22:20:09 +08:00
LoGin f1e7925d97
* feat(net): add multicast support and improve UDP socket handling(#1719)
- Enable multicast features in smoltcp dependency
- Add multicast group management with proper cleanup on socket close
- Implement UDP port binding with SO_REUSEADDR/SO_REUSEPORT support
- Add multicast loopback delivery for local multicast packets
- Support IP_PKTINFO and IP_ORIGDSTADDR control messages
- Improve UDP socket binding/unbinding with interface tracking
- Add raw socket support for UDP loopback packet delivery
- Fix UDP receive filtering for multicast/broadcast addresses
- Implement proper ephemeral port allocation with atomic operations

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-01 21:06:38 +08:00
LoGin 40e536c41c
refactor(kernel): 优化UTS命名空间字符串处理 (#1745)
- 将NewUtsName内部字段从String类型改为[u8; 65]数组,减少内存分配
- 重构copy_string_to_array为copy_bytes_to_array,支持字节数组直接复制
- 修改set_hostname和set_domainname方法,直接接受字节数组参数
- 更新sys_setdomainname和sys_sethostname系统调用,使用UserBufferReader读取用户空
间数据
- 添加UTF-8边界切割测试用例

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-01 18:05:13 +08:00
LoGin 2ee9c82154
refactor(mm/sysfs): replace manual buffer copy with sysfs_emit_str and improve error handling(#1746)
- Replace unwrap() with ok_or() for safer error handling in downcast_arc
- Use sysfs_emit_str to simplify string output in show methods
- Remove redundant buffer copy operations for cleaner code

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-01 17:59:19 +08:00
xboHodx 6fc4e3707f
fix(link_test): 修复符号链接、硬链接相关系统调用 (#1709)
* fix(link): 修复do_linkat函数中的AT_SYMLINK_FOLLOW逻辑完全反转问题

* fix(vfs): 修复do_linkat函数中的硬链接创建逻辑,增加安全检查

Signed-off-by: xboHodx <xbohodx2024@gmail.com>


* fix(link): 修复do_linkat函数中的路径检查逻辑,增强跨文件系统链接的安全性

Signed-off-by: xboHodx <xbohodx2024@gmail.com>

---------

Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-01-30 14:59:48 +08:00
LoGin da1759ee20
feat(procfs): 增强procfs文件系统功能 (#1713)
* feat(procfs): 增强procfs文件系统功能

- 在meminfo文件中添加SwapTotal和SwapFree字段
- 为/proc/<pid>目录实现动态owner方法,支持实时UID/GID查询
- 在pid/stat文件中改进tty_nr字段的获取逻辑
- 在procfs模板中为DirOps、FileOps和SymOps添加owner方法支持

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-29 13:28:15 +08:00
LoGin efb0f6eaaa
feat(net): 为UDP和Raw socket添加IPv4组播支持 (#1716)
- 新增multicast模块,包含IPv4组播成员管理相关函数
- 为UDP socket实现IP_MULTICAST_IF、IP_ADD_MEMBERSHIP和IP_DROP_MEMBERSHIP选项
- 为Raw socket实现IP_MULTICAST_IF、IP_ADD_MEMBERSHIP和IP_DROP_MEMBERSHIP选项
- 在IpOption枚举中添加MULTICAST_IF选项
- 更新gvisor测试白名单,添加相关socket测试

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-28 23:36:09 +08:00
LoGin f36191f408
feat(apic): add calibration for APIC timer initial count (#1715)
* feat(apic): add calibration for APIC timer initial count

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(time): 修复next_n_us_timer_jiffies函数计算错误

- 修正了微秒转jiffies时未向上取整导致的精度问题

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(net): defer tcp shutdown FIN until tx queue drains

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(poll): use protected user buffers and always write revents

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Co-authored-by: jiangyuming <mingjiangyu1@qq.com>
Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-28 22:01:34 +08:00
LoGin c194b663ba
feat(net/socket): 新增UDP套接字选项处理与错误队列支持 (#1712)
* feat(net/socket): 新增UDP套接字选项处理与错误队列支持

- 新增timeval模块,提供通用的时间值解析与写入函数
- 重构UDP套接字选项处理逻辑,拆分为独立option模块
- 实现UDP错误队列支持,包括MSG_ERRQUEUE标志处理
- 新增多种套接字选项:SO_REUSEADDR、SO_BROADCAST、SO_LINGER等
- 支持IP和IPV6级别的选项设置与获取
- 优化接收逻辑,返回原始数据长度以支持MSG_TRUNC标志
- 统一TCP、Unix域套接字的时间值处理函数

Signed-off-by: longjin <longjin@DragonOS.org>

* feat(tests/gvisor): add socket_ip_udp_loopback_test to blocklist and update whitelist

- Added socket_ip_udp_loopback_test to the blocklist due to missing SYS_SENDMMSG support.
- Updated whitelist.txt to include socket_ip_udp_loopback_test for testing purposes.

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-27 23:30:44 +08:00
LoGin 7ce83b8afa
fix(virtio): 修复MSI-X中断处理逻辑并优化网络驱动 (#1711)
- 修复VirtIO设备中断处理逻辑,正确处理MSI-X中断
- 优化VirtIO网络驱动,移除冗余代码并改进性能
- 调整BioQueue等待方法,修复IO等待标记问题
- 更新inittab配置,移除冗余注释行

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-27 16:19:32 +08:00
xboHodx d3b796b9ba
fix(driver/tty): 修复 TTY 读取时的缓冲区偏移错误和规范模式语义问题 (#1707)
Signed-off-by: xbohodx2024 <xbohodx2024@gmail.com>
2026-01-27 14:25:37 +08:00
aLinChe 0ddf676454
fix(sh): 修复了Busybox没有正确读取/etc/passwd导致的$HOME环境变量为/或丢失的问题 (#1704)
Signed-off-by: aLinChe <1129332011@qq.com>
2026-01-26 00:51:12 +08:00
LoGin 1949188db7
feat: 完善CPU时间统计与IO等待支持 (#1701)
- 新增/proc/stat和/proc/[pid]/stat的CPU时间统计功能
- 实现IO等待统计,区分iowait与idle时间
- 扩展等待队列支持IO等待标记
- 更新TCP套接字使用IO等待接口

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-23 16:24:08 +08:00
Yuming Jiang 7543a33658
fix(ipc): 修复部分 `shm_test` 错误的测试用例 (#1674)
* fix(mm): 克隆地址空间时对于映射到 SysV 共享内存的 VMA 增加 shm map_count。

* fix(ipc): 使 shm 元数据与 Linux 对齐

- 补充 `ShmFlags::PERM_MASK` 用于获取 POSIX 权限位
    - 该掩码用于屏蔽掉非权限位的一次性标志,如 `IPC_CREAT`、`IPC_EXCL` 等。
- 使 KernelShm 能正确创建并初始化
    - 正确初始化 uid/gid/cuid/cgid,并使用 `PERM_MASK` 正确获取权限位。
    - shm_lpid 初始化为 0(因为 lpid 只记录最后一个执行 attach/detach 操作的进程 ID,而在创建时没有这样的进程)。
- 使 `shm_stat` 能够正确获取共享内存状态信息
    - 使 `shm_stat` 正确获取 shm_perm.mode。
    - 使 `shm_stat` 将 shm_{a,d,c}time 以秒为单位输出,

* fix(ipc/sys_shmget): 完善 sys_shmget 创建一个 key 已经存在的共享内存段时的错误处理

- 添加了对 size 参数的检查,确保如果 size 大于已存在段的大小,则返回错误。

* feat(ipc): 添加KernIpcPerm构造函数

* docs(ipc/shm): 优化 SysV Shm 模块部分注释,标记待实现的 ShmId 生成机制

- 统一称呼“Shm Segment”为“共享内存段”,避免混淆
- 使用 “attach” 和 “detach” 术语,避免使用中文翻译。
- 优化部分注释的表达,使其更清晰易懂
- 标记待实现的 ShmId 生成机制

* refactor(mm/ucontext): 优化 `InnerAddressSpace::munmap` 函数和其内部调用 `extract` 函数的注释

- 重构并优化 `InnerAddressSpace::munmap()` 函数的注释
    - 调整了部分代码的顺序以提升可读性
    - 优化了检查 related_vmas 循环中的注释和变量命名,使其更清晰易懂
    - 添加了循环 unmap related_vmas 的每次循环的操作的逻辑注释,帮助理解代码意图
- 优化 `LockedVMA::extract()` 函数注释,增加参数和返回值说明

* docs(mm/UserMappings): 优化 `remove_vma` 函数的注释

* refactor(mm/ucontext): 优化 LockedVMA::unmap() 临时变量命名

- 优化共享内存管理器的detach_shm函数注释,增加对副作用的说明
- 优化 unmap() 函数中变量的命名

* refactor(ipc/shm): 优化 KernIpcPerm 构造函数,简化权限信息传递

* docs(ipc/shm): 更新 KernelShm 结构体中 shm_lprid 字段的注释,明确操作者定义

* fmt

* docs(ipc/shm): 更新 KernelShm 构造函数中 lprid 填充为0 的注释

* fix(ipc): 修复 shm 路径 unwrap 崩溃

* fix(ipc): 处理 fork 中 shm 段删除竞态

* fix(ipc/shmget): sys_shmget 共享内存段状态不一致

- 添加根据 shm_id 获取实际共享内存段的错误处理,防止在 “检查” -> “获取” 过程中状态变化导致的不一致问题。

* fix(ipc/shm): 处理 shm 相关类型转换溢出

* 补充 try_clone 锁顺序说明

* clean: 清除未使用的 PosixShmPerm::new 函数

* ci: restart CI pipeline

---------

Co-authored-by: longjin <longjin@DragonOS.org>
2026-01-23 00:03:23 +08:00
LoGin f63030f3fa
refactor(arch/x86_64/ipc): 重构信号栈帧设置流程以优化锁持有时间 (#1699)
- 调整setup_frame函数中用户态数据准备与写入的顺序
- 将用户态ucontext和fpstate的生成提前至持有锁期间,避免在锁内访问用户内存
- 将数据写入用户栈的操作移至释放锁之后,减少锁的持有时间并处理可能的缺页异常

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-22 16:09:55 +08:00
LoGin a728b27356
feat(x86_64): 添加KVM时钟源支持 (#1683)
* feat(x86_64): 添加KVM时钟源支持

- 新增kvm_clock模块,支持在KVM虚拟化环境中使用pvclock作为时钟源
- 添加kvm_para和pvclock模块,提供KVM特性检测和pvclock数据结构
- 修改TSC管理器,添加从KVM设置TSC频率的方法
- 调整时钟源初始化顺序,优先使用KVM时钟源
- 修复时钟源选择和timekeeper初始化的相关问题

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
Co-authored-by: kaleidoscope416 <jiangruizhi@DragonOS.org>
2026-01-22 15:23:40 +08:00
LoGin a345616436
feat(procfs): 新增loadavg文件支持并完善负载统计 (#1695)
- 新增/proc/loadavg文件,显示系统负载、运行进程数和最后分配的PID
- 实现负载计算模块,支持1分钟、5分钟、15分钟平均负载
- 修复进程唤醒时nr_uninterruptible计数问题
- 在PID命名空间中添加last_pid跟踪

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-22 14:08:05 +08:00
LoGin 5badcbb5ae
fix(signal): 修复信号处理中的pending状态更新和等待队列中断处理 (#1697)
* fix(signal): 修复信号处理中的pending状态更新和等待队列中断处理

- 在do_signal中无信号时添加recalc_sigpending调用
- 移除多处手动设置HAS_PENDING_SIGNAL标志的代码,改用wq_wait_event_interruptible
的错误传播
- 在set_sigprocmask中屏蔽SIGKILL和SIGSTOP信号

Signed-off-by: longjin <longjin@DragonOS.org>

* fix(kernel): 修复group_exit线程级SIGKILL避免go_demo退出卡住

在 group_exit 中对线程组内每个线程发送线程级 SIGKILL(PidType::PID)
使用 SigCode::Kernel 构造内核发起的终止信号,确保语义正确
避免进程级共享 pending 仅被单线程消费导致线程组残留

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-22 14:07:10 +08:00
火花 7e8a84fb73
feat(filesystem): improve mknod support for devfs and tmpfs (#1698)
Implement proper mknod syscall support in DevFS and TmpFS by adding
  logic to create character devices, block devices, and FIFO pipes
  based on the mode parameter.

  - DevFS: Add mknod method to create device nodes
  - TmpFS: Enhance mknod to correctly set file type and device number
  - Remove ENOSYS error for block/char device creation in TmpFS

Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
2026-01-22 11:51:31 +08:00
LoGin 878033ceff
refactor(ipc): 重构信号处理逻辑,优化锁顺序并简化接口 (#1694)
* refactor(ipc): 重构信号处理逻辑,优化锁顺序并简化接口

- 在`ProcessControlBlock`中新增`dequeue_pending_signal`
方法,统一处理线程与进程共享信号队列,遵循`sighand -> sig_info`
的锁顺序以避免死锁
- 移除`ProcessSignalInfo::dequeue_signal`方法,替换为更明确的
`dequeue_thread_signal`,仅处理线程私有信号
- 简化`recalc_sigpending`方法签名,移除可选的`siginfo_guard`参数,内部统一获取锁
- 更新`do_signal`、`signalfd`、`sys_rt_sigtimedwait`
等调用点以使用新接口,消除冗余锁操作
- 在`Sighand`结构体中添加`inner_read`方法以支持上述锁顺序

Signed-off-by: longjin <longjin@DragonOS.org>

* add doc

* fix(net): 修复TCP套接字事件通知和关闭流程

- 在`incoming()`方法中增加对EPOLLHUP和EPOLLERR事件的检查
- 在关闭流程中显式释放writer并触发通知
- 在接收和发送数据成功后调用`notify()`方法更新事件状态
- 修改事件检查逻辑,使用`intersects()`替代`contains()`以支持多事件判断

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-22 00:23:21 +08:00
LoGin 50fbcf2212
feat(mm): 新增页缓存统计与监控功能 (#1692)
- 新增页缓存统计模块,跟踪文件页、脏页、回写页、映射页、共享内存页等状态
- 在/proc/meminfo中新增Cached、Dirty、Writeback、Mapped、Shmem等统计信息
- 新增/proc/vmstat文件,提供完整的虚拟内存统计信息
- 新增/proc/sys/vm/drop_caches接口,支持清理页缓存
- 在/sys/kernel/mm/pagecache下新增sysfs属性,提供页缓存统计信息
- 重构页缓存驱逐逻辑,支持更灵活的驱逐策略
- 为tmpfs共享内存页缓存添加统计支持

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 20:34:37 +08:00
LoGin 5285c1510b
feat(net): 实现SO_RCVLOWAT选项并完善socket选项处理 (#1693)
- 为UDP、TCP、Unix域socket添加SO_RCVLOWAT选项支持
- 修复SO_SNDTIMEO/SO_RCVTIMEO选项处理,支持无限超时(u64::MAX)
- 实现SO_TYPE、SO_DOMAIN、SO_PROTOCOL等基础socket选项
- 为TCP socket添加SO_REUSEADDR、SO_BROADCAST、SO_PASSCRED、SO_NO_CHECK选项
- 修复TCP缓冲区大小计算,区分SNDBUF和RCVBUF的最小值
- 改进timeval解析逻辑,支持负值和零值处理
- 添加gvisor测试白名单,支持更多socket测试用例

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 20:34:21 +08:00
LoGin 84f1fe454d
feat(net): 新增TCP/IP套接字选项支持与Cork缓冲区超时机制 (#1691)
- 新增TCP_LINGER2、IP_MULTICAST_TTL、IP_MULTICAST_LOOP、SO_OOBINLINE等套接字选项
的读写支持
- 为TCP_CORK选项实现自动超时刷新机制,防止数据在缓冲区中滞留过久
- 在TCP状态处理中区分Closed与TimeWait状态,返回更精确的错误码
- 新增相关网络常量定义,提升与Linux内核的兼容性
- 更新gvisor测试白名单,添加socket_ip_tcp_generic_loopback_test

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 15:10:05 +08:00
LoGin ff5082c1ea
fix(net/tcp): 修复TCP套接字关闭和接收逻辑 (#1690)
* fix(net/tcp): 修复TCP套接字关闭和接收逻辑

- 修复TCP套接字关闭时未处理未读数据的问题
- 修复接收逻辑中状态检查错误返回ECONNRESET的问题
- 添加cork缓冲区刷新互斥锁防止重复刷新

Signed-off-by: longjin <longjin@DragonOS.org>

* feat(net/tcp): 实现TCP keepalive和linger选项支持

- 新增TCP_KEEPIDLE、TCP_KEEPINTVL、TCP_KEEPCNT选项的读写支持
- 实现SO_LINGER选项设置,支持立即中止连接
- 修改连接关闭逻辑,当linger_abort为true时立即中止连接
- 添加相关选项的默认值和验证逻辑

Signed-off-by: longjin <longjin@DragonOS.org>

---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 13:20:30 +08:00
LoGin 1ee52548ed
feat(page_cache): 重构页缓存为异步IO模型并添加回调机制 (#1688)
* feat(page_cache): 重构页缓存为异步IO模型并添加回调机制

- 将SyncPageCacheBackend重构为AsyncPageCacheBackend,支持异步读写操作
- 在BioRequest中添加complete_callbacks字段和on_complete方法,支持完成回调
- 重构PageCache内部结构,引入PageEntry管理页面状态和异步等待
- 新增PageCacheManager提供统一的管理接口,简化外部调用
- 更新文件系统(ext4、fat、tmpfs)使用新的异步页缓存后端
- 修改块设备读写接口,使用异步BIO提交和等待机制
- 优化页面错误处理、预读、写回等流程,支持异步操作

Signed-off-by: longjin <longjin@DragonOS.org>

* refactor(filesystem): 重构页面缓存状态管理逻辑

将页面状态管理逻辑重构为循环处理模式,增加compare_exchange_state方法
提取状态解码逻辑到独立方法decode_state
优化脏页处理流程,减少锁竞争


---------

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 09:57:27 +08:00
LoGin df62bcbd8f
fix(wait): align WNOHANG/PGID wait semantics with Linux 6.6 (#1689)
- return ECHILD when no matching children exist
- handle PGID WNOHANG scanning correctly
- add WNOTHREAD wait test for thread-created child

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-21 01:04:23 +08:00
Vitus 6755a4024b
fix(syscall): 修复 ppoll 系统调用使其符合 Linux 6.6 标准 (#1671)
* fix(syscall): 修复 ppoll 系统调用使其符合 Linux 6.6 标准

  修复 gvisor ppoll 测试套件中的多个失败用例:

  1. timespec 验证
     - 添加 tv_sec < 0 检查,返回 EINVAL
     - 添加 tv_nsec 范围检查 [0, 999999999],越界返回 EINVAL
     - 修复 InvalidTimeoutNegative 和 InvalidTimeoutNotNormalized 测试

  2. sigsetsize 参数
     - 添加第 5 个参数 sigsetsize(原只有 4 个参数)
     - 验证 sigsetsize 必须等于 sizeof(SigSet)
     - 修复 InvalidMaskSize 测试

  3. 信号掩码处理
     - 使用 has_pending_not_masked_signal() 替代 signal_pending_state()
     - 确保被屏蔽的信号不会中断 ppoll,只处理未屏蔽的信号
     - 修复 SignalMaskBlocksSignal 和 SignalMaskAllowsSignal 测试

  4. 错误码转换
     - 在 poll_select_finish 中添加 ERESTART_RESTARTBLOCK → EINTR 转换
     - 移除 ppoll 中不必要的 restart block 设置

* feat(时间处理): 添加as_millis_saturating_u64方法并用于ppoll超时计算

添加PosixTimeSpec的as_millis_saturating_u64方法,处理大数值时的饱和运算
在sys_ppoll中使用新方法替代原有超时计算逻辑,避免潜在溢出问题

---------

Co-authored-by: longjin <longjin@DragonOS.org>
Signed-off-by:  zhzvitus <zhzvitus@gmail.com>
2026-01-20 15:40:54 +08:00
LoGin 62149de157
feat(ipc/signal): 重构 nanosleep 重启函数以支持进程/线程 CPU 时间等待 (#1687)
- 新增`ktime_now`和`calc_remaining`辅助函数
- 在`RestartFnNanosleep`中为`ProcessCPUTimeID`和`ThreadCPUTimeID`
实现基于等待队列的精确等待
- 在`de_thread`中清除待终止线程的退出信号,避免信号误传

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-20 15:39:54 +08:00
LoGin d252e73f6d
refactor(page_cache): 引入PageCacheBackend抽象层并重构相关文件系统 (#1686)
- 新增PageCacheBackend trait和SyncPageCacheBackend实现,用于抽象页面缓存后端操作
- 修改PageCache构造函数,支持传入自定义后端
- 重构ext4、fat、tmpfs文件系统使用新的PageCache后端机制
- 优化页面回收和预读逻辑,使用后端接口进行读写操作
- 修复页面错误处理逻辑,移除直接文件读取改用page_cache.read_pages()

Signed-off-by: longjin <longjin@DragonOS.org>
2026-01-20 02:19:53 +08:00