refactor: remove UserPtr and UserConstPtr usages#107
refactor: remove UserPtr and UserConstPtr usages#107Ticonderoga2017 wants to merge 1 commit intoStarry-OS:mainfrom
Conversation
|
Good job 👍 |
AsakuraMizu
left a comment
There was a problem hiding this comment.
Sorry, there were too many files, and I haven't had time to look at a few of them myself.
There was a problem hiding this comment.
Pull request overview
This pull request refactors the codebase to remove custom UserPtr and UserConstPtr types in favor of a unified memory access interface from starry_vm. The changes introduce VmPtr/VmMutPtr primitives and helper functions like vm_read_slice, vm_write_slice, and vm_load_until_nul for safer user-space memory operations.
Key Changes:
- Replaced all
UserPtr/UserConstPtrusages with raw pointers andstarry_vmprimitives - Updated system call signatures to accept raw pointers instead of custom wrapper types
- Refactored
CMsgBuilderto work with raw pointers and returnResultfrom constructor - Simplified syscall dispatcher by replacing
.into()calls withas _casts
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| api/src/mm.rs | Removed UserPtr/UserConstPtr implementations; kept VmBytes/VmBytesMut wrappers and vm_load_string helper |
| api/src/vfs/dev/event.rs | Converted event device ioctls to use vm_write_slice and allocate temporary buffers |
| api/src/syscall/net/socket.rs | Updated socket syscalls to use raw pointers with VmPtr/VmMutPtr traits |
| api/src/syscall/net/opt.rs | Refactored getsockopt/setsockopt to use vm_read/vm_write with temporary variables |
| api/src/syscall/net/name.rs | Simplified getsockname/getpeername to use raw pointers |
| api/src/syscall/net/io.rs | Updated sendmsg/recvmsg to use vm_read_uninit and addr_of_mut for field access |
| api/src/syscall/net/cmsg.rs | Refactored CMsgBuilder to use raw pointers and made constructor fallible |
| api/src/syscall/mod.rs | Replaced .into() conversions with as _ casts throughout syscall dispatcher |
| api/src/syscall/ipc/shm.rs | Updated shmctl to use vm_read/vm_write with nullable pointer handling |
| api/src/syscall/io_mpx/select.rs | Converted select/pselect6 to read/write local copies and use nullable pattern |
| api/src/syscall/io_mpx/poll.rs | Updated poll/ppoll to use local Vec buffers with vm_read/vm_write |
| api/src/syscall/io_mpx/epoll.rs | Converted epoll functions to use temporary buffers and vm_write |
| api/src/syscall/fs/memfd.rs | Changed memfd_create signature to use raw pointer |
| api/src/syscall/fs/io.rs | Updated truncate to use vm_load_string |
| api/src/syscall/fs/fd_ops.rs | Modified fcntl to use vm_read_uninit/vm_write for flock64 |
| api/src/socket.rs | Updated SocketAddrExt trait to use raw pointers; refactored read/write methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| nullable!(sigmask.get_as_ref())?.copied(), | ||
| || match block_on(future::timeout( | ||
| let mut buf = vec![epoll_event { events: 0, data: 0 }; maxevents as usize]; | ||
| let sig = match sigmask.nullable() { |
| ) | ||
| } | ||
| })?; | ||
| for (i, ev) in buf.iter().take(n as usize).enumerate() { |
| }; | ||
| do_poll(fds, timeout, None) | ||
| let ret = do_poll(&mut local, timeout, None)?; | ||
| for (i, it) in local.iter().enumerate() { |
There was a problem hiding this comment.
Use vm_write_slice. Please apply the same fix to other instances.
| let sigmask = match sigmask.nullable() { | ||
| Some(p) => { | ||
| let sig = unsafe { p.vm_read_uninit()?.assume_init() }; | ||
| check_sigset_size(sig.sigsetsize)?; |
| Some(p) => { | ||
| let sig = unsafe { p.vm_read_uninit()?.assume_init() }; | ||
| check_sigset_size(sig.sigsetsize)?; | ||
| match sig.set.nullable() { |
There was a problem hiding this comment.
Use Option::map. Please apply the same fix to other instances.
| let mut bits = vec![0u8; size]; | ||
| if ty == 0 { | ||
| Ok(copy_bytes(self.ev_bits.as_bytes(), bits)) | ||
| let written = copy_bytes(self.ev_bits.as_bytes(), &mut bits); |
There was a problem hiding this comment.
Maybe we can use vm_write_slice instead to avoid extra copy?
| let mut bits = vec![0u8; size]; | ||
| let n = | ||
| copy_bytes(self.inner.lock().key_state.as_bytes(), &mut bits); | ||
| vm_write_slice(arg as *mut u8, &bits[..n])?; |
| } | ||
| Ok(bits.len().min(ty.bits_count().div_ceil(8))) | ||
| let written = bits.len().min(ty.bits_count().div_ceil(8)); | ||
| vm_write_slice(arg as *mut u8, &bits[..written])?; |
#39
Description
UserPtr/UserConstPtrand their supporting memory validation functions to implement a unified user-space memory access interface.VmPtr/VmMutPtr,vm_read_slice,vm_write_slice, andvm_load_until_nulfromstarry_vm, covering scenarios such as read/write operations and string loading.axioframework'sRead/WriteandIoBuf/IoBufMutmodels, avoiding inconsistencies caused by custom pointer types.