Commit Graph

1628 Commits

Author SHA1 Message Date
github-actions[bot] 9cdfa1ef0e
Update translated documentation (#1788) 2026-02-15 00:12:01 +08:00
LoGin 41c6ab33d9
feat: add dunitest user-mode unit testing framework (#1787)
- Introduce dunitest framework with Rust runner and C++ test suites
- Add Makefile target`test-dunit-local`for local test execution
- Include documentation and DADK configuration for integration

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-15 00:06:48 +08:00
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
github-actions[bot] 5413b69e28
Update translated documentation (#1784) 2026-02-11 13:24:48 +08:00
LoGin 0482f02e1b
feat: enhance nix config and bootstrap (#1775)
- Upgrade Docker image version from v1.21 to v1.22 across dev container and CI
workflows
- Add .nix-gc-root to .gitignore
- Enhance nix configuration with Chinese mirrors, auto GC root, and system QEMU
support
- Update bootstrap script with improved nix installation and configuration
options
- Update DADK dependency to v0.6.1

Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 13:16:55 +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
LoGin ee5f736d49
chore: remove NovaShell and dog from DADK config (#1782)
Signed-off-by: longjin <longjin@DragonOS.org>
2026-02-11 11:46:38 +08:00
Yuming Jiang b2b8aace07
feat(agents): 统一的 agent 配置管理方案。 (#1670)
* feat(agents/skills): 为 agents 添加 skill-creator 技能

* feat(agents): 实现初版 Gvisor bug 修复 Skill

* docs(agents):添加 `.agent` 文件夹的文档

* chore(agents):使用软链接将 skills 文件夹链接到不同agent

* refactor: 调整 README 文档

* feat: 添加对 copilot 的 skills 引用支持

* feat(agents): 更新 “gvisor 分析”的 SKILL.md 文档并将示例拆分为单独文档

* feat: v0.2.0 gvisor 分析报告 skills

- 合并单测试用例分析和多测试用例分析的工作流

* docs(agents/gvisor-anly): 补充步骤七完整内容并更新示例

- 补充 SKILL.md 步骤七的详细内容(根因分析表格和修复方案的生成规则)
- 更新 EXAMPLES.md 中的处理流程,使其符合新的 7 步工作流
- 区分单个测试(跳过概览步骤)和多个测试(完整 7 步)的处理路径

Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
2026-02-11 11:24:30 +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
github-actions[bot] 4d123d114c
Update translated documentation (#1779) 2026-02-10 13:33:10 +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
火花 03c943ae77
feat(app): 添加runcell应用程序 (#1761)
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
2026-02-03 23:52:25 +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 269251c190
chore(busybox): 设置默认密码算法为sha512 (#1760)
Signed-off-by: xboHodx <xbohodx2024@gmail.com>
2026-02-03 11:29:46 +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
Vitus 832c04a23f
feat(nix): 添加nix alias,formatter,以及更好的提示与原make命令集成 (#1661)
* - chore:加了一条一键启动的命令

* chore(nix): 添加nixfmt格式化器并整合devShell配置

  - 添加treefmt-nix和nixfmt-rfc-style作为项目formatter
  - 将tools/nix-dev-shell的devShell配置合并到根目录flake.nix
  - 新增rust-toolchain到devShell的buildInputs
  - 格式化所有.nix文件并排除.direnv目录
  - 移除已废弃的tools/nix-dev-shell目录

* fix

* fix

* fix:构建完后直接退出
fix:  qemu 参数分开写的不支持问题

* fix

* fix

* fix:delete result

* remove 快速启动 hint

* Update Makefile

---------

Co-authored-by: Samuel Dai <samuka007@dragonos.org>
2026-01-28 00:17:18 +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
aLinChe 7e30cc7de9
fix: inittab error for fat fs(#1710)
Signed-off-by: aLinChe <1129332011@qq.com>
2026-01-27 16:01:26 +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