Skip to content

Add a generic type to ForeignPtr#2827

Merged
stevenengler merged 19 commits intoshadow:mainfrom
stevenengler:ptr-types
Apr 3, 2023
Merged

Add a generic type to ForeignPtr#2827
stevenengler merged 19 commits intoshadow:mainfrom
stevenengler:ptr-types

Conversation

@stevenengler
Copy link
Copy Markdown
Contributor

@stevenengler stevenengler commented Apr 3, 2023

Follow-up to #2813.

This makes ForeignPtr typed. There aren't many places where we need untyped pointers in Shadow, so making pointers typed should be the default. This also means that for a lot of pointers, we can define their type directly in the syscall handler. Pointer types should now be self-documenting, and it should be harder to accidentally access the pointers as the wrong type. An UntypedForeignPtr was added for compatibility with the C code.

  • added a generic type to ForeignPtr
  • added UntypedForeignPtr for C code which maps to ForeignPtr<()> in rust code
  • renamed TypedArrayForeignPtr to ForeignArrayPtr

The intermediate commits have a lot of casts between pointer types so that each commit would build and run, but the final code should have only a few pointer type conversions.

There are still some things that can be cleaned up, but I think this gets most of the code in.

@stevenengler stevenengler self-assigned this Apr 3, 2023
@github-actions github-actions bot added Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable labels Apr 3, 2023
@stevenengler stevenengler requested a review from sporksmith April 3, 2023 15:42
Copy link
Copy Markdown
Contributor

@sporksmith sporksmith left a comment

Choose a reason for hiding this comment

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

Nice!

`UntypedForeignPtr` should only be used in C code and maps to `ForeignPtr<()>`
in rust. This commit changes all existing rust uses of `ForeignPtr` to
`ForeignPtr<()>`, allowing us to start changing the generic type in the future.
Used the following command:

```
rg 'TypedArrayForeignPtr' --files-with-matches | xargs sed -i 's/TypedArrayForeignPtr/ForeignArrayPtr/g'
```
Realized a better way of preventing type inference without requiring a second
generic.
@stevenengler stevenengler enabled auto-merge April 3, 2023 17:34
@stevenengler stevenengler merged commit 0b4767d into shadow:main Apr 3, 2023
@stevenengler stevenengler deleted the ptr-types branch April 3, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Libraries Support functions like LD_PRELOAD and logging Component: Main Composing the core Shadow executable

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants