V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
qianxi0410

关于 xv6 系统调用实现的返回值疑问

  •  
  •   qianxi0410 · Mar 5, 2023 · 1767 views
    This topic created in 1157 days ago, the information mentioned may be changed or developed.

    在 xv6 中,系统调用的返回值的类型是uint64,但是出错却返回 -1 如: https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/sysproc.c#LL38-L49C2

    而用户态文件夹下定义的系统调用声明却又返回 int,如: https://github.com/mit-pdos/xv6-riscv/blob/riscv/user/user.h#L4-L24

    想请教一下大家,这是何解?

    5 replies    2023-03-05 11:17:38 +08:00
    Madcrow
        1
    Madcrow  
       Mar 5, 2023 via Android
    数都是同一个 64 位数,只是你把它看作 uint 还是 int
    qianxi0410
        3
    qianxi0410  
    OP
       Mar 5, 2023
    好像只是单纯了做了下类型转换而已,-1 最后还是-1 ,那内核为何还要定义为 uint64 ,直接定义为 int 不好吗?
    levelworm
        4
    levelworm  
       Mar 5, 2023 via Android
    我好像记得有个原因是 int 随着架构不同有可能不一样,但是 uintX 都是一样的。不过我也不确定。
    Madcrow
        5
    Madcrow  
       Mar 5, 2023 via Android
    应该是因为返回值保存在寄存器中,寄存器在 riscv64 中是 64bit
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2864 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 06:24 · PVG 14:24 · LAX 23:24 · JFK 02:24
    ♥ Do have faith in what you're doing.