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
alex merged 22 commits into
masterfrom
sysctl-register
Jun 10, 2018
Merged

Fixes #13 -- added sysctls#17
alex merged 22 commits into
masterfrom
sysctl-register

Conversation

@alex

@alex alex commented May 26, 2018

Copy link
Copy Markdown
Member

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

alex commented May 31, 2018

Copy link
Copy Markdown
Member Author

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

geofft commented May 31, 2018

Copy link
Copy Markdown
Collaborator

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

alex commented May 31, 2018

Copy link
Copy Markdown
Member Author

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

alex commented May 31, 2018

Copy link
Copy Markdown
Member Author

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

alex commented May 31, 2018

Copy link
Copy Markdown
Member Author

It works now!

@alex

alex commented May 31, 2018

Copy link
Copy Markdown
Member Author

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

alex commented Jun 1, 2018

Copy link
Copy Markdown
Member Author

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

@geofft geofft left a comment

Copy link
Copy Markdown
Collaborator

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 #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

alex commented Jun 10, 2018

Copy link
Copy Markdown
Member Author

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