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

Commit abba3bf

Browse files
Reini Urbanrurban
Reini Urban
authored andcommitted
unexec: enable unexmacosx
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
1 parent 49dced8 commit abba3bf

13 files changed

+204
-116
lines changed

MANIFEST

+1
Original file line numberDiff line numberDiff line change
@@ -5453,6 +5453,7 @@ iperlsys.h Perl's interface to the system
54535453
keywords.c Perl_keyword(), generated by regen/keywords.pl
54545454
keywords.h The keyword numbers
54555455
l1_char_class_tab.h 256 word bit table of character classes (for handy.h)
5456+
lastfile.c For unexec from GNU emacs
54565457
lib/_charnames.pm Character names
54575458
lib/AnyDBM_File.pm Perl module to emulate dbmopen
54585459
lib/AnyDBM_File.t See if AnyDBM_File works

Makefile.SH

+5-6
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,7 @@ $make_set_make
428428

429429
# disabled for now until properly integrated
430430
case "${unexec}" in
431-
#unex*) archobjs="$archobjs ${unexec}${_o}" ;;
432-
*) ;;
431+
unex*) archobjs="$archobjs ${unexec}${_o}" ;;
433432
esac
434433

435434
case "${osname}" in
@@ -624,9 +623,9 @@ miniperl_dtrace_objs = $(miniperl_objs_nodt:%=mpdtrace/%)
624623
perllib_dtrace_objs = $(perllib_objs_nodt:%=libpdtrace/%)
625624
perlmain_dtrace_objs = maindtrace/perlmain$(OBJ_EXT)
626625
627-
miniperl_objs = $(miniperl_dtrace_objs) $(DTRACE_MINI_O)
626+
miniperl_objs = $(miniperl_dtrace_objs) $(DTRACE_MINI_O) lastfile$(OBJ_EXT)
628627
perllib_objs = $(perllib_dtrace_objs) $(DTRACE_PERLLIB_O)
629-
perlmain_objs = $(perlmain_dtrace_objs) $(DTRACE_MAIN_O)
628+
perlmain_objs = $(perlmain_dtrace_objs) $(DTRACE_MAIN_O) lastfile$(OBJ_EXT)
630629
631630
miniperl_dep = $(DTRACE_MINI_O)
632631
perllib_dep = $(DTRACE_PERLLIB_O)
@@ -637,9 +636,9 @@ perlmain_dep = $(DTRACE_MAIN_O)
637636
*)
638637
$spitshell >>$Makefile <<'!NO!SUBS!'
639638
640-
miniperl_objs = $(miniperl_objs_nodt) $(DTRACE_MINI_O)
639+
miniperl_objs = $(miniperl_objs_nodt) $(DTRACE_MINI_O) lastfile$(OBJ_EXT)
641640
perllib_objs = $(perllib_objs_nodt) $(DTRACE_PERLLIB_O)
642-
perlmain_objs = perlmain$(OBJ_EXT) $(DTRACE_MAIN_O)
641+
perlmain_objs = perlmain$(OBJ_EXT) $(DTRACE_MAIN_O) lastfile$(OBJ_EXT)
643642
644643
miniperl_dep = $(miniperl_objs)
645644
perllib_dep = $(perllib_objs)

lastfile.c

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Mark end of data space to dump as pure, for GNU Emacs.
2+
Copyright (C) 1985, 2001-2015 Free Software Foundation, Inc.
3+
4+
This file is part of GNU Emacs.
5+
6+
GNU Emacs is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
GNU Emacs is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18+
19+
20+
/* How this works:
21+
22+
Fdump_emacs dumps everything up to my_edata as text space (pure).
23+
24+
The files of Emacs are written so as to have no initialized
25+
data that can ever need to be altered except at the first startup.
26+
This is so that those words can be dumped as shareable text.
27+
28+
It is not possible to exercise such control over library files.
29+
So it is necessary to refrain from making their data areas shared.
30+
Therefore, this file is loaded following all the files of Emacs
31+
but before library files.
32+
As a result, the symbol my_edata indicates the point
33+
in data space between data coming from Emacs and data
34+
coming from libraries.
35+
*/
36+
37+
/*#include <config.h>*/
38+
39+
char my_edata[] = "End of Emacs initialized data";
40+
41+
/* Help unexec locate the end of the .bss area used by Emacs (which
42+
isn't always a separate section in NT executables). */
43+
char my_endbss[1];
44+
45+
/* The Alpha MSVC linker globally segregates all static and public bss
46+
data, so we must take both into account to determine the true extent
47+
of the bss area used by Emacs. */
48+
static char _my_endbss[1];
49+
char * my_endbss_static = _my_endbss;

perl.c

+11-9
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
#include "nwutil.h"
4343
#endif
4444

45+
#ifdef UNEXEC
46+
#include "unexec.h"
47+
#endif
48+
4549
#ifdef DEBUG_LEAKING_SCALARS_FORK_DUMP
4650
# ifdef I_SYSUIO
4751
# include <sys/uio.h>
@@ -4054,18 +4058,16 @@ void
40544058
Perl_my_unexec(pTHX)
40554059
{
40564060
#ifdef UNEXEC
4057-
SV * prog = newSVpv(BIN_EXP, 0);
4058-
SV * file = newSVpv(PL_origfilename, 0);
4059-
int status = 1;
4060-
extern int etext;
4061-
4062-
sv_catpvs(prog, "/perl");
4061+
SV * const caret_X = get_sv("\030", 0);
4062+
SV * const prog = newSVpvn_flags(SvPVX(caret_X), SvCUR(caret_X),
4063+
SvUTF8(caret_X));
4064+
/* what to do with "-e" ? */
4065+
SV * file = newSVpv(strEQc(PL_origfilename, "-e") ? "script" : PL_origfilename, 0);
40634066
sv_catpvs(file, ".perldump");
40644067

4065-
/* unexec, etext defined in unexec.c */
4066-
unexec(SvPVX(file), SvPVX(prog), &etext, sbrk(0), 0);
4068+
unexec(SvPVX(file), SvPVX(prog));
40674069
/* unexec prints msg to stderr in case of failure */
4068-
PerlProc_exit(status);
4070+
PerlProc_exit(1);
40694071
#else
40704072
/* dump to core */
40714073
PERL_UNUSED_CONTEXT;

uconfig.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -5474,9 +5474,14 @@
54745474
*/
54755475
/*#define USE_FFI / **/
54765476

5477+
/* UNEXEC:
5478+
* This symbol defines the used unexec source.
5479+
* Defined via ccflags.
5480+
*/
5481+
54775482
#endif
54785483

54795484
/* Generated from:
5480-
* c6518b8068a349c18bad76cef97a0481d5aad4221ec5224bbcb187c9c5797c67 config_h.SH
5485+
* 474e3fec8af16b87801d5230af4b9dc8361d53ecf9a252f710a95bee5706b5cf config_h.SH
54815486
* 7de9e1790e1297fa567edf82226e1e230a8b19ff4e6b1482152d77f14fa1123f uconfig.sh
54825487
* ex: set ro: */

unexaix.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ what you give them. Help stamp out software-hoarding! */
4040
*
4141
*/
4242

43-
#include <config.h>
4443
#include "unexec.h"
45-
#include "lisp.h"
44+
#define PERLIO_NOT_STDIO 0
45+
#include "EXTERN.h"
46+
#define PERL_IN_UNEXEC_C
47+
#include "perl.h"
4648

4749
#define PERROR(file) report_error (file, new)
4850
#include <a.out.h>
@@ -96,7 +98,7 @@ report_error (const char *file, int fd)
9698
{
9799
int err = errno;
98100
if (fd)
99-
emacs_close (fd);
101+
close (fd);
100102
report_file_errno ("Cannot unexec", build_string (file), err);
101103
}
102104

@@ -108,7 +110,7 @@ static _Noreturn void ATTRIBUTE_FORMAT_PRINTF (2, 3)
108110
report_error_1 (int fd, const char *msg, ...)
109111
{
110112
va_list ap;
111-
emacs_close (fd);
113+
close (fd);
112114
va_start (ap, msg);
113115
verror (msg, ap);
114116
va_end (ap);
@@ -130,11 +132,11 @@ unexec (const char *new_name, const char *a_name)
130132
{
131133
int new = -1, a_out = -1;
132134

133-
if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
135+
if (a_name && (a_out = open (a_name, O_RDONLY, 0)) < 0)
134136
{
135137
PERROR (a_name);
136138
}
137-
if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
139+
if ((new = open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
138140
{
139141
PERROR (new_name);
140142
}
@@ -145,13 +147,13 @@ unexec (const char *new_name, const char *a_name)
145147
|| adjust_lnnoptrs (new, a_out, new_name) < 0
146148
|| unrelocate_symbols (new, a_out, a_name, new_name) < 0)
147149
{
148-
emacs_close (new);
150+
close (new);
149151
return;
150152
}
151153

152-
emacs_close (new);
154+
close (new);
153155
if (a_out >= 0)
154-
emacs_close (a_out);
156+
close (a_out);
155157
mark_x (new_name);
156158
}
157159

@@ -501,7 +503,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
501503
if (!lnnoptr || !f_hdr.f_symptr)
502504
return 0;
503505

504-
if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
506+
if ((new = open (new_name, O_RDWR, 0)) < 0)
505507
{
506508
PERROR (new_name);
507509
return -1;
@@ -531,7 +533,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
531533
}
532534
}
533535
}
534-
emacs_close (new);
536+
close (new);
535537

536538
return 0;
537539
}

unexcoff.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
5050
* of Dell Computer Corporation. [email protected].
5151
*/
5252

53-
#include <config.h>
5453
#include "unexec.h"
55-
#include "lisp.h"
54+
#define PERLIO_NOT_STDIO 0
55+
#include "EXTERN.h"
56+
#define PERL_IN_UNEXEC_C
57+
#include "perl.h"
5658

5759
#define PERROR(file) report_error (file, new)
5860

@@ -131,7 +133,7 @@ report_error (const char *file, int fd)
131133
{
132134
int err = errno;
133135
if (fd)
134-
emacs_close (fd);
136+
close (fd);
135137
report_file_errno ("Cannot unexec", build_string (file), err);
136138
}
137139

@@ -142,7 +144,7 @@ report_error (const char *file, int fd)
142144
static void
143145
report_error_1 (int fd, const char *msg, int a1, int a2)
144146
{
145-
emacs_close (fd);
147+
close (fd);
146148
error (msg, a1, a2);
147149
}
148150

@@ -499,7 +501,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
499501
#ifdef MSDOS
500502
if ((new = writedesc) < 0)
501503
#else
502-
if ((new = emacs_open (new_name, O_RDWR, 0)) < 0)
504+
if ((new = open (new_name, O_RDWR, 0)) < 0)
503505
#endif
504506
{
505507
PERROR (new_name);
@@ -523,7 +525,7 @@ adjust_lnnoptrs (int writedesc, int readdesc, const char *new_name)
523525
}
524526
}
525527
#ifndef MSDOS
526-
emacs_close (new);
528+
close (new);
527529
#endif
528530
return 0;
529531
}
@@ -538,11 +540,11 @@ unexec (const char *new_name, const char *a_name)
538540
{
539541
int new = -1, a_out = -1;
540542

541-
if (a_name && (a_out = emacs_open (a_name, O_RDONLY, 0)) < 0)
543+
if (a_name && (a_out = open (a_name, O_RDONLY, 0)) < 0)
542544
{
543545
PERROR (a_name);
544546
}
545-
if ((new = emacs_open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
547+
if ((new = open (new_name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
546548
{
547549
PERROR (new_name);
548550
}
@@ -553,13 +555,13 @@ unexec (const char *new_name, const char *a_name)
553555
|| adjust_lnnoptrs (new, a_out, new_name) < 0
554556
)
555557
{
556-
emacs_close (new);
558+
close (new);
557559
return;
558560
}
559561

560-
emacs_close (new);
562+
close (new);
561563
if (a_out >= 0)
562-
emacs_close (a_out);
564+
close (a_out);
563565
mark_x (new_name);
564566
}
565567

unexcw.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ GNU General Public License for more details.
1818
You should have received a copy of the GNU General Public License
1919
along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
2020

21-
#include <config.h>
2221
#include "unexec.h"
23-
#include "lisp.h"
22+
#define PERLIO_NOT_STDIO 0
23+
#include "EXTERN.h"
24+
#define PERL_IN_UNEXEC_C
25+
#include "perl.h"
2426

2527
#include <stdio.h>
2628
#include <fcntl.h>
@@ -298,9 +300,9 @@ unexec (const char *outfile, const char *infile)
298300
infile = add_exe_suffix_if_necessary (infile, infile_buffer);
299301
outfile = add_exe_suffix_if_necessary (outfile, outfile_buffer);
300302

301-
fd_in = emacs_open (infile, O_RDONLY | O_BINARY, 0);
303+
fd_in = open (infile, O_RDONLY | O_BINARY, 0);
302304
assert (fd_in >= 0);
303-
fd_out = emacs_open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755);
305+
fd_out = open (outfile, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 0755);
304306
assert (fd_out >= 0);
305307
for (;;)
306308
{
@@ -316,13 +318,13 @@ unexec (const char *outfile, const char *infile)
316318
ret2 = write (fd_out, buffer, ret);
317319
assert (ret2 == ret);
318320
}
319-
ret = emacs_close (fd_in);
321+
ret = close (fd_in);
320322
assert (ret == 0);
321323

322324
bss_sbrk_did_unexec = 1;
323325
fixup_executable (fd_out);
324326
bss_sbrk_did_unexec = 0;
325327

326-
ret = emacs_close (fd_out);
328+
ret = close (fd_out);
327329
assert (ret == 0);
328330
}

0 commit comments

Comments
 (0)