Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

add unexec #176

Open
rurban opened this issue Jul 4, 2016 · 5 comments
Open

add unexec #176

rurban opened this issue Jul 4, 2016 · 5 comments
Assignees

Comments

@rurban
Copy link
Member

rurban commented Jul 4, 2016

sources from emacs, and re-enable -u and dump.
with support for elf, coff, darwin, cygwin, win32/64, hpux, aix, sunos/solaris, dos.

TODO:

See feature/gh176-unexec

@rurban rurban self-assigned this Jul 4, 2016
@rurban
Copy link
Member Author

rurban commented Jul 4, 2016

With 7d2f258f586d854e7ba4f2500ee189dafd304ef4 I can successfully dump a binary cperl executable from any script, even -e. (darwin so far, the others need to be tested).
Just the initialization order is wrong, gv_fetch fails to retrieve the dynamic $^X, which is still empty.

@bulk88
Copy link
Member

bulk88 commented Jul 6, 2016

the emacs undump code for win32 is unusable by perl. emacs uses a custom malloc that allows storing and restoring the custom heap from a disk file. I also cant figure out how the emacs code is going to recreate and make valid again all the FDs from the frozen proc. XS DLLs and 3rd party DLLs need to be frozen and unfrozen too. Win32 unexec code pretty much would have to use https://msdn.microsoft.com/en-us/library/windows/desktop/ms680360%28v=vs.85%29.aspx to make a memory dump file, then reinflate it, and tweak the PEB and TEB structs to register all the Win32 heaps to the master linked list of heaps. There might also be drama in having to defeat ASLR/C stack buffer overflow sentinal patterns.

@rurban
Copy link
Member Author

rurban commented Jul 6, 2016

unexec has its own malloc, yes, to be able to access old dumped memory.

Parallel to perlcc IO in BEGIN blocks or before the dump opcode may not be replayed. This is a known limitation, and already known from perlcc. open/chdir being the worst.
I might think of adding hacks to reopen FD's, which would be easier than with B::C.

Dynamic modules are correctly loaded with unexec. The corresponding section handles this, e.g. LC_LOAD_DYLIB on darwin.
ASLR is also handled correctly by rebasing the dumped sections.

@rurban
Copy link
Member Author

rurban commented Jul 14, 2016

solaris

works for simple scripts, because it's trivial there.

$ ./miniperl -Ilib -u -e'print "ok\n"'
$ ./a.exe
ok

accessing argv/argc fails on the empty PL_argvgv symbol while dumping. init_argv_symbols/init_postdump_symbols is uninitialized for -u.

    /* init_postdump_symbols not currently designed to be called */
    /* more than once (ENV isn't cleared first, for example)     */
    /* But running with -u leaves %ENV & @ARGV undefined!    XXX */
    if (!PL_do_undump)
    init_postdump_symbols(argc,argv,env);

darwin

  • needs -Duseshrplib
  • uses unexec_malloc, which uses malloc_zone, before -u. After -u, running the dumped code it uses malloc().
  • fails with Bad address when dumping __bss DATA segments. With a static libperl.a also with __data and __common.
  • with a static libperl.a my_edata is not in .DATA, but in __common. nm disagrees with run-time.
  • works under the debugger

elf (linux)

  • dumps works fine, but run-time fails when freeing a dumped SV: parser->linestr (char*)
    via safesysfree, which should be freed with free instead. (easy to fix by only using malloc)
#3  0x00007ffff6d3d966 in malloc_printerr (action=3,
    str=0x7ffff6e2c442 "corrupted double-linked list", ptr=<optimized out>, ar_ptr=<optimized out>)
    at malloc.c:5007
#4  0x00007ffff6d3e936 in _int_free (av=0x7ffff7064b20 <main_arena>, p=<optimized out>,
    have_lock=0) at malloc.c:4006
#5  0x000000000054f011 in Perl_safesysfree (where=0xad0290) at util.c:390```

@rurban
Copy link
Member Author

rurban commented Jul 14, 2016

Run init_postdump_symbols 2x with -u:
We need the %ENV & @argv symbols during BEGIN, and we need to re-initialize in dumped binaries.

    /* init_postdump_symbols not currently designed to be called */
    /* more than once (ENV isn't cleared first, for example)     */
    /* But running with -u leaves %ENV & @ARGV undefined!    XXX */
    init_postdump_symbols(argc,argv,env);

@rurban rurban added this to the v5.26.0 milestone Jul 14, 2016
rurban pushed a commit that referenced this issue Nov 2, 2018
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Nov 25, 2018
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Mar 18, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Apr 1, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Apr 5, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Apr 5, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Apr 30, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jun 12, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jun 24, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jun 26, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jun 27, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jul 1, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jul 2, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jul 2, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jul 3, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Aug 25, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Dec 17, 2019
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jan 19, 2020
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
rurban pushed a commit that referenced this issue Jan 19, 2020
dumps and starts fine, even if we don't record the regions yet.

fails in starting at Perl_set_caret_X(), empty gv_fetchpvs() $^X symbol.
we need to change the init order, as $^X and some others need to be initialized
dynamically, similar to dynaloaded modules.

prepared the other sources also, but untested.
esp. win32 and solaris. macosx and win32 seem to be the most trickiest.
harmonize error message, esp. when failing to create the file, most likely
due to a BEGIN { chdir .. }, changed pwd.

See #176
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants