Skip to content

on Linux, empty program panics if procfs is not mounted #22642

Closed

Description

@dwrensha

The program pub main(){} fails if procfs is not mounted:

thread '<unnamed>' panicked at 'failed to get thread attributes', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84

It seems that the problem is a call to pthread_getattr_np() which tries to read /proc/self/maps and fails.

$ rustc --version
rustc 1.0.0-nightly (522d09dfe 2015-02-19) (built 2015-02-21)

Activity

  1. changed the title [-]empty program panics on Linux if procfs is not mounted[/-] [+]on Linux, empty program panics if procfs is not mounted[/+] on Feb 21, 2015
  2. dwrensha commented on Feb 22, 2015

    @dwrensha
    ContributorAuthor

    I found that I can work around this by defining my own entry point:

    #![feature(start, std_misc)]
    
    #[start]
    fn start(argc: isize, argv: *const *const u8) -> isize {
        unsafe { ::std::rt::args::init(argc, argv); }
        // ...                                                                                            
        return 0;
    }
    
  3. alexcrichton commented on Feb 23, 2015

    @alexcrichton
    Member

    Hm this is somewhat worrisome. It seems overly restrictive, but on the other hand it looks like the failure in question is our detection of the stack start of the main thread in setting up the first guard page. I forget how reliable it is that linux sets up a guard page for us, and it would be tough to remove for now at least.

  4. kentonv commented on Feb 23, 2015

    @kentonv

    @alexcrichton could the code skip guard page creation when /proc is unavailable (as detected by pthread_getattr_np failing)? That seems better than failing to work at all, doesn't it?

  5. alexcrichton commented on Feb 23, 2015

    @alexcrichton
    Member

    Perhaps yes, I'd want to have a chance to look more into it though.

  6. psmit commented on Jul 15, 2015

    @psmit

    Has there been any update regarding this issue? For an AI competition we want to isolate our processes and not mounting proc inside the chroot has served well for any other languages. Is there a workaround possible in code or compilation flags?

  7. dwrensha commented on Jul 16, 2015

    @dwrensha
    ContributorAuthor

    @phsmit: You can work around the problem in code by defining your own entry point with the #[start] attribute.

    Unfortunately, that's not an adequate solution in all situations, e.g. if you want to run rustc or cargo in a sandboxed environment.

  8. added a commit that references this issue on Jul 21, 2015
    d68b152
  9. added a commit that references this issue on Jul 21, 2015
    ee2d3bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.O-linuxOperating system: Linux

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions