Skip to content

Store user pointers as address-only types instead of platform pointers#1053

Merged
jaybosamiya-ms merged 8 commits into
microsoft:mainfrom
jstarks:generic_ptr
Jul 21, 2026
Merged

Store user pointers as address-only types instead of platform pointers#1053
jaybosamiya-ms merged 8 commits into
microsoft:mainfrom
jstarks:generic_ptr

Conversation

@jstarks

@jstarks jstarks commented Jul 20, 2026

Copy link
Copy Markdown
Member

This PR changes how the Linux shim represents user pointers, so that Platform is no longer viral across types that merely hold a pointer value.

Previously, litebox_shim_linux and litebox_common_linux stored user pointers using the platform's associated pointer types (Platform::RawConstPointer/RawMutPointer). Because those types are parameterized by the platform, every struct, enum, and signature that carried a user pointer had to carry a Platform (or RawPointerProvider) parameter -- even when it never dereferenced anything. This is the main obstacle to eventually dropping litebox_platform_multiplex from the shim in favor of explicit Platform generic bounds.

This PR introduces address-only UserPtr<T>/UserPtrMut<T> (transparent usize wrappers) in litebox_common_linux and uses them everywhere a user pointer is stored. The platform only re-enters at the handful of sites that actually access memory: the access methods take the platform as an explicit witness (e.g. ptr.read_at_offset::<Platform>(..)), converting back to the real platform pointer via to_platform_ptr. As a result, Platform shows up only where memory is genuinely read or written, which is both clearer and the setup needed to make the shim generic over the platform.

Behavior is unchanged; this is purely a representation refactor.

This PR changes how the Linux shim represents user pointers, so that
`Platform` is no longer viral across types that merely hold a pointer
value.

Previously, litebox_shim_linux and litebox_common_linux stored user
pointers using the platform's associated pointer types
(`Platform::RawConstPointer`/`RawMutPointer`). Because those types are
parameterized by the platform, every struct, enum, and signature that
carried a user pointer had to carry a `Platform` (or
`RawPointerProvider`) parameter -- even when it never dereferenced
anything. This is the main obstacle to eventually dropping
litebox_platform_multiplex from the shim in favor of explicit `Platform`
generic bounds.

This PR introduces address-only `UserPtr<T>`/`UserPtrMut<T>` (transparent
`usize` wrappers) in litebox_common_linux and uses them everywhere a user
pointer is stored. The platform only re-enters at the handful of sites
that actually access memory: the access methods take the platform as an
explicit witness (e.g. `ptr.read_at_offset::<Platform>(..)`), converting
back to the real platform pointer via `to_platform_ptr`. As a result,
`Platform` shows up only where memory is genuinely read or written, which
is both clearer and the setup needed to make the shim generic over the
platform.

Behavior is unchanged; this is purely a representation refactor.

@jaybosamiya-ms jaybosamiya-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks John! Overall looks good to me, just a few minor nits to fix up before merging

Comment thread litebox_common_linux/src/lib.rs Outdated
Comment thread litebox_common_linux/src/user_pointers.rs
Comment thread litebox_shim_linux/src/syscalls/misc.rs Outdated
Comment thread litebox_shim_linux/src/syscalls/process.rs Outdated
Comment thread litebox_shim_optee/src/syscalls/mm.rs Outdated
@jaybosamiya-ms

Copy link
Copy Markdown
Member

Also, since semver-checks CI bot does not fire on branches from forks, here's its output as of bac25fe (basically expected tweaks):

click to unfold
--- failure auto_trait_impl_removed: auto trait no longer implemented ---

Description:
A public type has stopped implementing one or more auto traits. This can break downstream code that depends on the traits being implemented.
        ref: https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/auto_trait_impl_removed.ron

Failed in:
  type UserMsgHdr is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1847
  type UserMsgHdr is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1847
  type IoReadVec is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  type IoReadVec is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  type IoReadVec is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  type IoReadVec is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  type UserMmsgHdr is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1876
  type UserMmsgHdr is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1876
  type IoWriteVec is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:351
  type IoWriteVec is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:351
  type SigSetPack is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1840
  type SigSetPack is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1840
  type IoctlArg is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:718
  type IoctlArg is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:718
  type ArchPrctlArg is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1069
  type ArchPrctlArg is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1069
  type FcntlArg is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:581
  type FcntlArg is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:581
  type TimeParam is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2997
  type TimeParam is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2997
  type FutexArgs is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1683
  type FutexArgs is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1683
  type PrctlArg is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1763
  type PrctlArg is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1763
  type SyscallRequest is no longer Send, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1938
  type SyscallRequest is no longer Sync, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1938

--- failure method_requires_different_generic_type_params: method now requires a different number of generic type parameters ---

Description:
A method now requires a different number of generic type parameters than it used to. Uses of this method that supplied the previous number of generic types will be broken.
        ref: https://doc.rust-lang.org/reference/items/generics.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/method_requires_different_generic_type_params.ron

Failed in:
  litebox_common_linux::TimeParam::read takes 1 generic types instead of 0, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:3028
  litebox_common_linux::TimeParam::write takes 1 generic types instead of 0, in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:3057

--- failure type_allows_fewer_generic_type_params: type now allows fewer generic type parameters ---

Description:
A type now allows fewer generic type parameters than it used to. Uses of this type that supplied all previously-supported generic types will be broken.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-parameter-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/type_allows_fewer_generic_type_params.ron

Failed in:
  Struct UserMsgHdr allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1847
  Struct IoReadVec allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  Struct IoReadVec allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:359
  Struct UserMmsgHdr allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1876
  Struct IoWriteVec allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:351
  Struct SigSetPack allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1840
  Enum IoctlArg allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:718
  Enum ArchPrctlArg allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1069
  Enum FcntlArg allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:581
  Enum TimeParam allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:2997
  Enum FutexArgs allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1683
  Enum PrctlArg allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1763
  Enum SyscallRequest allows 1 -> 0 generic types in /home/runner/work/litebox/litebox/litebox_common_linux/src/lib.rs:1938

@jaybosamiya-ms jaybosamiya-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed fixes for the minor nits; lgtm

@jaybosamiya-ms
jaybosamiya-ms enabled auto-merge July 21, 2026 00:56
@jaybosamiya-ms
jaybosamiya-ms added this pull request to the merge queue Jul 21, 2026
Merged via the queue into microsoft:main with commit c8e374e Jul 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants