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

Segfault upon stack overflow in child thread. #7490

Closed
vicuna opened this issue Feb 21, 2017 · 4 comments
Closed

Segfault upon stack overflow in child thread. #7490

vicuna opened this issue Feb 21, 2017 · 4 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Feb 21, 2017

Original bug ID: 7490
Reporter: wintersteiger
Assigned to: @mshinwell
Status: assigned (set by @mshinwell on 2017-02-24T14:39:24Z)
Resolution: open
Priority: normal
Severity: crash
Platform: amd64
OS: Ubuntu
OS Version: 16.04
Version: 4.04.0
Category: threads
Monitored by: @gasche

Bug description

This works as expected:

let rec thread_fun _ =
try
thread_fun ()
with
Stack_overflow -> Printf.printf "caught exn\n"

let _ = thread_fun () ; ()

But when thread_fun is called like so:

let _ =
Thread.join (Thread.create thread_fun ()) ;
()

then it segfaults.

Steps to reproduce

Compile with ocamlopt -thread unix.cmxa threads.cmxa stackoverflow.ml -o stackoverflow
Run ./stackoverflow

Additional information

Problem originally encountered in FStar, see here: FStarLang/FStar#870

@vicuna
Copy link
Author

vicuna commented Feb 23, 2017

Comment author: @mshinwell

I will have a look at this

@vicuna
Copy link
Author

vicuna commented Feb 23, 2017

Comment author: @mshinwell

Pierre and I are working on a fix.

@vicuna
Copy link
Author

vicuna commented Feb 24, 2017

Comment author: @mshinwell

Please see #1062

@xavierleroy
Copy link
Contributor

Fixed by #8670 .

samoht added a commit to samoht/index that referenced this issue Nov 20, 2019
To avoid allocating on the stack, keep the runtime lock so that OCaml objects
are not moved around.

This is needed because thread stack are very small on musl<1.1.21 (80k).

Allocating a buffer of 64k bytes on the stack means that the stack overflow
detection (`caml_c_call`) won't have enough space to allocate 32k and will
segfault: see ocaml/ocaml#7490 for a similar bug
report.

`caml_c_call` has been properly fixed in behttps://github.com/ocaml/ocaml/pull/8670
and it also has been changed to only allocate 4k -- also solving our initial
issue with too small thread stacks (as 64+8<80).

Many thanks to @sadiqj for helping with debugging the issue.

Co-authored-by: Frédéric Bour <fred@tarides.com>
gs0510 pushed a commit to gs0510/index that referenced this issue Dec 6, 2019
To avoid allocating on the stack, keep the runtime lock so that OCaml objects
are not moved around.

This is needed because thread stack are very small on musl<1.1.21 (80k).

Allocating a buffer of 64k bytes on the stack means that the stack overflow
detection (`caml_c_call`) won't have enough space to allocate 32k and will
segfault: see ocaml/ocaml#7490 for a similar bug
report.

`caml_c_call` has been properly fixed in behttps://github.com/ocaml/ocaml/pull/8670
and it also has been changed to only allocate 4k -- also solving our initial
issue with too small thread stacks (as 64+8<80).

Many thanks to @sadiqj for helping with debugging the issue.

Co-authored-by: Frédéric Bour <fred@tarides.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants