Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the libstd-modifications needed for the L4Re target #43972

Merged
merged 6 commits into from
Sep 14, 2017

Conversation

TobiasSchaffner
Copy link

This commit adds the needed modifications to compile the std crate for the L4 Runtime environment (L4Re).

A target for the L4Re was introduced in commit: c151220

In many aspects implementations for linux also apply for the L4Re microkernel.

Some uncommon characteristics had to be resolved:

  • L4Re has no network funktionality
  • L4Re has a maximum stacksize of 1Mb for threads
  • L4Re has no uid or gid

Co-authored-by: Sebastian Humenda sebastian.humenda@tu-dresden.de

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.


// L4Re is not able to handle more than 1MB.
#[cfg(target_os = "l4re")]
let amt = amt.unwrap_or(1 * 1024 * 1024);
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately tidy disallows you from writing this using #[cfg] or cfg!(). See https://github.com/rust-lang/rust/blob/master/src/tools/tidy/src/pal.rs for detail.

[00:03:46] tidy error: /checkout/src/libstd/sys_common/util.rs:26: platform-specific cfg: cfg(not(target_os = "l4re"))
[00:03:46] tidy error: /checkout/src/libstd/sys_common/util.rs:30: platform-specific cfg: cfg(target_os = "l4re")

@TobiasSchaffner
Copy link
Author

TobiasSchaffner commented Aug 18, 2017

Thanks for the explanation!

@alexcrichton
Copy link
Member

I think l4re is classified as "target family is unix", but maybe with these #[cfg] annotations we should go the other way around? Is l4re "unix enough" to still warrant such a classification?

@humenda
Copy link
Contributor

humenda commented Aug 18, 2017

In the strict sense, L4(Re) is a microkernel with almost all of the components
implemented in user space; traditional Unixes have a monolithic kernel and a smaller user space. On top of the completely different API, L4Re has a POSIX(-alike) personality for backward compatibility featured by uClibc. So for most programs, L4Re looks like a normal (uClibc) Unix, just without networking. I am pretty sure that not classifying L4Re as unixoid would mean substantially more work which wouldn't really pay off. Most of the software ports to L4Re go down the Unix path, too.

@TobiasSchaffner
Copy link
Author

TobiasSchaffner commented Aug 20, 2017

Id like to add that we needed less #[cfg] annotations than any other unix family member. In many cases (for example with the set_name function in thread.rs) you need one annotation to choose one of the implementations. That leads to a number of #cfg annotations that is always needed when implementing a new target for unix.


// L4Re only supports a maximum of 1Mb per default.
#[cfg(target_os = "l4re")]
let stack_size = cmp::min(stack_size, 1024 * 1024);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we rely on pthread_create to return an error for larger stack sizes here?

Copy link
Author

Choose a reason for hiding this comment

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

It will run in an error when pthread_attr_setstacksize is called. (sys/unix/thread.rs line: 55)
Most systems do not have a fixed maximum. We tried to put it to to the point where also the minimum size is checked. Putting it to the pthread_attr_setstacksize check would in my opinion put to much complexity there.

Copy link
Member

Choose a reason for hiding this comment

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

The standard library tends to prefer to expose the underlying platform semantics as much as possible, avoiding trying to make shims and such where possible. It sounds like the default stack size on l4re should be less, but I believe we should still let the error propagate from pthread_attr_setstacksize

Copy link
Member

Choose a reason for hiding this comment

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

@humenda would it be possible to change the min_stack_size function instead of adding this clause here?

@@ -469,6 +469,7 @@ pub mod error;
pub mod ffi;
pub mod fs;
pub mod io;
#[cfg(not(target_os = "l4re"))]
Copy link
Member

Choose a reason for hiding this comment

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

This is my main hesitation for this PR, just excluding the net module. This, AFAIK, doesn't happen on any other platform.

Copy link
Author

Choose a reason for hiding this comment

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

I see your point and I know that it is unusual. As Sebastian already mentioned "L4Re looks like a normal (uClibc) Unix, just without networking". Implementing a completely new platform would lead to large amounts of redundant code while we are able to (even if it is unusual) can completely disable the net part with three statements.

Copy link
Member

Choose a reason for hiding this comment

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

It's ok to not have networking implemented, Emscripten for example doesn't implement threads. To do this, however, the shims in the sys module should all return errors on l4re instead of being compiled away.

@humenda
Copy link
Contributor

humenda commented Aug 22, 2017 via email

@arielb1 arielb1 added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 22, 2017
@alexcrichton
Copy link
Member

@humenda oh so right now the conventional design of libstd is that it doesn't tailor the top-level API available per-platform, it's always there unconditionally 100% of the time. This may change in the future, but for now it's the status quo that needs to be maintained.

It's fine to not call libc functions and instead just return errors in Rust.

@aidanhs
Copy link
Member

aidanhs commented Aug 31, 2017

Hi @TobiasSchaffner, are you able to make the changes as @alexcrichton suggests, i.e. probably just making the net module a skeleton that always errors?

@TobiasSchaffner
Copy link
Author

TobiasSchaffner commented Sep 1, 2017 via email

@humenda
Copy link
Contributor

humenda commented Sep 1, 2017 via email

humenda added a commit to TobiasSchaffner/rust that referenced this pull request Sep 6, 2017
As suggested in the discussion of PR rust-lang#43972, std should provide a uniform API to
all platforms. Since there's no networking on L4Re, this now is a module in
`sys::net` providing types and functions/methods returning an error for each
action.
@humenda
Copy link
Contributor

humenda commented Sep 6, 2017

@alexcrichton Could you please have a look at the changes?
Please note that they won't build before https://github.com/rust-lang/libc/pull/758 hasn't been merged.
Thanks!

@alexcrichton
Copy link
Member

Thanks! Want to update the libc submodule now as well?

@humenda
Copy link
Contributor

humenda commented Sep 7, 2017 via email

@alexcrichton
Copy link
Member

Looks good to me! Appears to be a rebase conflict though?

humenda and others added 5 commits September 8, 2017 14:36
*   Match definition of c_char in os/raw.rs with the libc definition

    Due to historic reasons, os/raw.rs redefines types for c_char from
    libc, but these didn't match. Now they do :).

*   Enable signal reset on exec for L4Re

    L4Re has full signal emulation and hence it needs to reset the
    signal set of the child with sigemptyset. However, gid and uid
    should *not* be set.
This commit adds the needed modifications to compile the std crate
for the L4 Runtime environment (L4Re).

A target for the L4Re was introduced in commit:
c151220

In many aspects implementations for linux also apply for the L4Re
microkernel.

Two uncommon characteristics had to be resolved:
* L4Re has no network funktionality
* L4Re has a maximum stacksize of 1Mb for threads

Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
As suggested in the discussion of PR rust-lang#43972, std should provide a uniform API to
all platforms. Since there's no networking on L4Re, this now is a module in
`sys::net` providing types and functions/methods returning an error for each
action.
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 8, 2017

📌 Commit 5d1a9d7 has been approved by alexcrichton

@@ -89,3 +91,18 @@ pub mod guard {
pub unsafe fn current() -> Option<usize> { None }
pub unsafe fn init() -> Option<usize> { None }
}

pub fn min_stack() -> usize {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of duplicating all this logic in all the various platforms, could just the default min stack size get implemented on various platforms?

@TobiasSchaffner
Copy link
Author

r? @alexcrichton

#[cfg(not(target_os = "l4re"))]
pub const default_min_stack_size: usize = 2 * 1024 * 1024;
#[cfg(target_os = "l4re")]
pub const default_min_stack_size: usize = 1024 * 1024;
Copy link
Member

Choose a reason for hiding this comment

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

Conventionally in rust constants have full uppercase names like DEFAULT_MIN_STACK_SIZE

The default min stack size value is smaller on l4re and therefore
this value has to be different depending on the platform.
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 13, 2017

📌 Commit b2b5063 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Sep 14, 2017

⌛ Testing commit b2b5063 with merge 991066932ac6e7cfb76ec0c920867134d219811b...

@bors
Copy link
Contributor

bors commented Sep 14, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

@bors: retry

  • ???

@bors
Copy link
Contributor

bors commented Sep 14, 2017

⌛ Testing commit b2b5063 with merge 84bbd14...

bors added a commit that referenced this pull request Sep 14, 2017
 Add the libstd-modifications needed for the L4Re target

This commit adds the needed modifications to compile the std crate for the L4 Runtime environment (L4Re).

A target for the L4Re was introduced in commit: c151220

In many aspects implementations for linux also apply for the L4Re microkernel.

Some uncommon characteristics had to be resolved:
 * L4Re has no network funktionality
 * L4Re has a maximum stacksize of 1Mb for threads
 * L4Re has no uid or gid

Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
@bors
Copy link
Contributor

bors commented Sep 14, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 84bbd14 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants