Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Fixes #13 -- added sysctls #17

Merged
merged 22 commits into from
Jun 10, 2018
Merged

Fixes #13 -- added sysctls #17

merged 22 commits into from
Jun 10, 2018

Conversation

alex
Copy link
Member

@alex alex commented May 26, 2018

Currently just has stubs for everything, not yet ready for review, using the WIP branch as a forcing function to review what I've written :-)

@alex alex force-pushed the sysctl-register branch 2 times, most recently from d20506a to 5ffa181 Compare May 27, 2018 12:00
@alex alex force-pushed the sysctl-register branch 3 times, most recently from fe3c89e to 7eedce3 Compare May 30, 2018 22:12
@alex
Copy link
Member Author

alex commented May 31, 2018

Good news... it compiles... and doesn't explode?

Bad news:

ubuntu@ip-172-26-12-143 ~/l/example-sysctl> cat /proc/sys/rust/example/a 
cat: /proc/sys/rust/example/a: Bad address

At this point I think this could use a second pair of eyes :-)

@alex alex requested a review from geofft May 31, 2018 00:08
@geofft
Copy link
Collaborator

geofft commented May 31, 2018

I believe the buffers passed to your handler are kernelspace at that point, no? i.e. procfs has already done a read/write with userspace buffers.

@alex
Copy link
Member Author

alex commented May 31, 2018

@alex alex force-pushed the sysctl-register branch from 0096607 to 9bfb1ab Compare May 31, 2018 01:09
@alex
Copy link
Member Author

alex commented May 31, 2018

Well, that was embarassing! It works now though... sort of... if I do cat /proc/sys/rust/example/a it just slowly prints 0 over and over again... I have clearly not understood the proc_handler API.

@alex
Copy link
Member Author

alex commented May 31, 2018

It works now!

@alex
Copy link
Member Author

alex commented May 31, 2018

I'll hoist some of the seperable parts of this (build.rs, error.rs, etc.) into their own PRs to reduce the size here.

@alex alex force-pushed the sysctl-register branch 2 times, most recently from 79bb4e7 to 2d1fabe Compare June 1, 2018 04:07
@alex
Copy link
Member Author

alex commented Jun 1, 2018

Ok, I think this is as minimized as I can reasonably go.

Copy link
Collaborator

@geofft geofft left a comment

Choose a reason for hiding this comment

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

LGTM after:

  • the UB fix from sysctl-register fixes #46, also confirming that my comments about concurrency safety are right
  • is it correct to increment ppos if the write failed or partially failed? (It probably does not matter much)

A couple more questions:

  • I guess we're boxing things because we need them to have a stable address and we can't have a self-referential struct? It'd be nice to figure out a way to avoid this, but that doesn't block landing this
  • Does it make sense for UserSlicePtr to implement core::fmt::Read / core::fmt::Write? (Probably not because they work with str and not [u8]?)
  • Does it make sense to make trait SysctlStorage symmetric in the two functions and have it take a UserSlicePtrReader? We already know that anything over a page is unreasonable so we can avoid an allocation.
  • Should we handle ppos being nonzero on a write?

@alex
Copy link
Member Author

alex commented Jun 10, 2018

a) Yes, box for stable address.

b) It might make sense; I think Vec<u8> implements those types, doesn't it? Seperate PR.

c) Maybe? This seems simpler :-)

d) Does something special need to be done on ppos != 0? Write at an offset into buffer? I don't think the C code I was referencing does anything with ppos besides what I do.

alex and others added 9 commits June 10, 2018 17:54
`pointer::add` and `pointer::offset` turn into a `getelementptr
inbounds`, which is UB if it does not point to a valid object or one
past a valid object (i.e., it enables compiler optimizations that make
that assumption).  Raw pointers to userspace are not pointers to valid
objects.

`pointer::wrapping_add` and `pointer::wrapping_offset` turn into a
`getelementptr`, which is always defined (and so they're both safe).
@alex alex force-pushed the sysctl-register branch from c2adbdd to 2cc3f5f Compare June 10, 2018 17:54
@alex alex merged commit cf3212c into master Jun 10, 2018
@alex alex deleted the sysctl-register branch June 10, 2018 18:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants