[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 5/5] First version of REPL Ctrl-C trampoline for Woe32
From: |
Bruno Haible |
Subject: |
Re: [PATCH 5/5] First version of REPL Ctrl-C trampoline for Woe32 |
Date: |
Sat, 27 Mar 2021 16:15:16 +0100 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-203-generic; KDE/5.18.0; x86_64; ; ) |
José E. Marchesi wrote:
> I am CCing Bruno. He may have some ideas about this.
Yes I have a couple of ideas about this.
1) Move the 3 methods Throw, RaiseInThread, DontOptimize out of the class
ThreadAbort. We don't like C++. Use plain C syntax whereever possible.
(You don't need a C++ class in order to use 'throw' and 'catch'.
You can use them in plain static functions in a .cpp file.)
2) Once this is done, the only use of class ThreadAbort is in the functions
Throw and pk_tramp_cmd_exec. What happens here is unwinding the stack.
Unwinding a stack that contains C++ function invocations can only be
done with 'throw' and 'catch'. But poke is a C program; it does not
contain C++. (This is on purpose.) For C programs, 'longjmp' and 'setjmp'
are the equivalent. So, rewrite the Throw and pk_tramp_cmd_exec to use
a jmp_buf instead. (This does not need to be the same jmp_buf as in
pk-repl.c. Better do the simplifications one by one.)
Does the Ctrl-C handling still work? I hope so. Then:
3) The RaiseInThread function is a dirty hack, but it is the way to do it.
GNU libsigsegv does a similar hack. The hairy part is to get the stack
alignment right.
Why does this actually work? At the point where pk_tramp_cmd_exec returns,
callee-saved registers need to have certain values. The RaiseInThread
functions dealt with the program counter and stack pointer; the longjmp
restored the remaining register values.
4) Now try to eliminate one of the two jmp_bufs. We have one already
in pk_repl.c. Use that with setjmp/longjmp on platforms where sigsetjmp/
siglongjmp does not exist.
5) If and only if the approaches above don't work, I would suggest to use
the 'ansi-c++-opt' module instead of AC_PROG_CXX. Then poke can be
built on Unix systems without a C++ compiler.
Bruno
- Re: [PATCH 2/5] Improve portability (particularly for Woe32), (continued)
[PATCH 4/5] Disable the GC at exit if GC_remove_roots absent, Georgiy Tugai, 2021/03/25
[PATCH 3/5] Allow Poke to be built relocatable, Georgiy Tugai, 2021/03/25
[PATCH 5/5] First version of REPL Ctrl-C trampoline for Woe32, Georgiy Tugai, 2021/03/25
Re: [PATCH 1/5] Rename CHAR, IN, VOID, ERROR to avoid collision, Jose E. Marchesi, 2021/03/26