Skip to content

Commit 0ab5ec3

Browse files
authored
CORE: Try to avoid calling into Scheme after exit. (#366)
This disables log-trace on newer gambit when deadlock-exceptions are encountered as otherwise they get stuck in an infinite loop. However, this should reduce some of the other problems with ___cleanup() when we encounter segfaults.
1 parent 6a63dea commit 0ab5ec3

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

languages/scm.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int debug_settings = ___DEBUG_SETTINGS_INITIAL;
2929

3030
void system_init();
3131

32+
static int lambdanative_exit_call_count = -1; /* System running when 0 */
3233
void lambdanative_payload_setup()
3334
{
3435
DMSG("lambdanative_payload_setup [scm]");
@@ -39,6 +40,7 @@ void lambdanative_payload_setup()
3940
debug_settings = (debug_settings & ~___DEBUG_SETTINGS_REPL_MASK) |
4041
(___DEBUG_SETTINGS_REPL_STDIO << ___DEBUG_SETTINGS_REPL_SHIFT);
4142
setup_params.debug_settings = debug_settings;
43+
lambdanative_exit_call_count = 0;
4244
___setup(&setup_params);
4345
#if defined(ANDROID)
4446
#if (___VERSION < 409002)
@@ -52,7 +54,7 @@ void lambdanative_payload_setup()
5254
void lambdanative_payload_cleanup()
5355
{
5456
DMSG("lambdanative_payload_cleanup [scm]");
55-
___cleanup();
57+
if(lambdanative_exit_call_count++==0) ___cleanup();
5658
}
5759

5860
#ifndef STANDALONE
@@ -61,7 +63,7 @@ void scm_event(int,int,int);
6163

6264
void lambdanative_payload_event(int t, int x, int y)
6365
{
64-
scm_event(t,x,y);
66+
if( lambdanative_exit_call_count == 0 ) scm_event(t,x,y);
6567
}
6668
#endif
6769

loaders/hook/hook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void ffi_event(int t, int x, int y)
6464
}
6565
FFI_EVENT_LOCK
6666
if (!lambdanative_needsinit&&t) lambdanative_payload_event(t,x,y);
67-
if (t==EVENT_TERMINATE) { lambdanative_payload_cleanup(); exit(0); }
67+
if (t==EVENT_TERMINATE) { lambdanative_exit(0); }
6868
FFI_EVENT_UNLOCK
6969
}
7070
#endif // STANDALONE

modules/config/config.scm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4747

4848
void force_terminate()
4949
{
50-
___cleanup();
51-
exit(0);
50+
lambdanative_exit(0);
5251
}
5352

5453
end-of-c-declare

modules/ln_core/log.scm

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#|
22
LambdaNative - a cross-platform Scheme framework
3-
Copyright (c) 2009-2013, University of British Columbia
3+
Copyright (c) 2009-2020, University of British Columbia
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or
@@ -150,10 +150,17 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
150150
(string-mapconcat (reverse tmp) ": ")))
151151

152152
(define (log:exception-handler e)
153-
(log-error (thread-name (current-thread)) ": " (exception->string e))
154-
(log-trace (current-thread))
155-
(log-error "HALT")
156-
(exit))
153+
(log-error "Thread \"" (thread-name (current-thread)) "\": " (exception->string e))
154+
(cond-expand
155+
(gambit-c (log-trace (current-thread)))
156+
(else
157+
(unless (deadlock-exception? e)
158+
;; gambit ___cleanup(); re-enters with a deadlock-exception here
159+
;; while printing the trace
160+
(log-trace (current-thread)))
161+
))
162+
(log-error "HALT pid " ((c-lambda () int "getpid")))
163+
(exit 70))
157164

158165
;; catch primordial thread exceptions
159166
(current-exception-handler log:exception-handler)
@@ -174,7 +181,4 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
174181
(log-system "Application " (system-appname) " built " (system-builddatetime))
175182
(log-system "Git hash " (system-buildhash))
176183

177-
178-
179-
180184
;; eof

0 commit comments

Comments
 (0)