summaryrefslogtreecommitdiff
path: root/nt
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2024-01-02 10:28:14 +0800
committerPo Lu <luangruo@yahoo.com>2024-01-02 10:28:14 +0800
commitecf08f0621c25ad1dfadd96399e204c389ab1695 (patch)
tree401dc6c6eaac6f0d9a6a35c63e5664de62fc9e27 /nt
parent083e90dd80a16c9c573f92e0f11603267d15d82b (diff)
parentdc4e6b1329614918791bef1704009c139b929845 (diff)
downloademacs-ecf08f0621c25ad1dfadd96399e204c389ab1695.tar.gz
Merge from savannah/emacs-29
dc4e6b13296 ; Update copyright years in more files 64b37776318 ; Run set-copyright from admin.el 8e1c56ae467 ; Add 2024 to copyright years # Conflicts: # doc/misc/modus-themes.org # doc/misc/texinfo.tex # etc/NEWS # etc/refcards/ru-refcard.tex # etc/themes/modus-operandi-theme.el # etc/themes/modus-themes.el # etc/themes/modus-vivendi-theme.el # lib/alloca.in.h # lib/binary-io.h # lib/c-ctype.h # lib/c-strcasecmp.c # lib/c-strncasecmp.c # lib/careadlinkat.c # lib/cloexec.c # lib/close-stream.c # lib/diffseq.h # lib/dup2.c # lib/filemode.h # lib/fpending.c # lib/fpending.h # lib/fsusage.c # lib/getgroups.c # lib/getloadavg.c # lib/gettext.h # lib/gettime.c # lib/gettimeofday.c # lib/group-member.c # lib/malloc.c # lib/md5-stream.c # lib/md5.c # lib/md5.h # lib/memmem.c # lib/memrchr.c # lib/nanosleep.c # lib/save-cwd.h # lib/sha1.c # lib/sig2str.c # lib/stdlib.in.h # lib/strtoimax.c # lib/strtol.c # lib/strtoll.c # lib/time_r.c # lib/xalloc-oversized.h # lisp/auth-source-pass.el # lisp/emacs-lisp/lisp-mnt.el # lisp/emacs-lisp/timer.el # lisp/info-look.el # lisp/jit-lock.el # lisp/loadhist.el # lisp/mail/rmail.el # lisp/net/ntlm.el # lisp/net/webjump.el # lisp/progmodes/asm-mode.el # lisp/progmodes/project.el # lisp/progmodes/sh-script.el # lisp/textmodes/flyspell.el # lisp/textmodes/reftex-toc.el # lisp/textmodes/reftex.el # lisp/textmodes/tex-mode.el # lisp/url/url-gw.el # m4/alloca.m4 # m4/clock_time.m4 # m4/d-type.m4 # m4/dirent_h.m4 # m4/dup2.m4 # m4/euidaccess.m4 # m4/fchmodat.m4 # m4/filemode.m4 # m4/fsusage.m4 # m4/getgroups.m4 # m4/getloadavg.m4 # m4/getrandom.m4 # m4/gettime.m4 # m4/gettimeofday.m4 # m4/gnulib-common.m4 # m4/group-member.m4 # m4/inttypes.m4 # m4/malloc.m4 # m4/manywarnings.m4 # m4/mempcpy.m4 # m4/memrchr.m4 # m4/mkostemp.m4 # m4/mktime.m4 # m4/nproc.m4 # m4/nstrftime.m4 # m4/pathmax.m4 # m4/pipe2.m4 # m4/pselect.m4 # m4/pthread_sigmask.m4 # m4/readlink.m4 # m4/realloc.m4 # m4/sig2str.m4 # m4/ssize_t.m4 # m4/stat-time.m4 # m4/stddef_h.m4 # m4/stdint.m4 # m4/stdio_h.m4 # m4/stdlib_h.m4 # m4/stpcpy.m4 # m4/strnlen.m4 # m4/strtoimax.m4 # m4/strtoll.m4 # m4/time_h.m4 # m4/timegm.m4 # m4/timer_time.m4 # m4/timespec.m4 # m4/unistd_h.m4 # m4/warnings.m4 # nt/configure.bat # nt/preprep.c # test/lisp/register-tests.el
Diffstat (limited to 'nt')
-rw-r--r--nt/ChangeLog.12
-rw-r--r--nt/INSTALL2
-rw-r--r--nt/INSTALL.W642
-rw-r--r--nt/Makefile.in2
-rw-r--r--nt/README2
-rw-r--r--nt/README.W322
-rw-r--r--nt/addpm.c2
-rw-r--r--nt/cmdproxy.c2
-rwxr-xr-xnt/configure.bat26
-rw-r--r--nt/ddeclient.c2
-rw-r--r--nt/epaths.nt2
-rw-r--r--nt/gnulib-cfg.mk2
-rw-r--r--nt/icons/README6
-rw-r--r--nt/inc/grp.h2
-rw-r--r--nt/inc/inttypes.h2
-rw-r--r--nt/inc/langinfo.h2
-rw-r--r--nt/inc/ms-w32.h2
-rw-r--r--nt/inc/nl_types.h2
-rw-r--r--nt/inc/stdint.h2
-rw-r--r--nt/inc/sys/resource.h2
-rw-r--r--nt/inc/sys/socket.h2
-rw-r--r--nt/inc/sys/stat.h2
-rw-r--r--nt/inc/sys/wait.h2
-rw-r--r--nt/preprep.c830
-rw-r--r--nt/runemacs.c2
25 files changed, 881 insertions, 25 deletions
diff --git a/nt/ChangeLog.1 b/nt/ChangeLog.1
index 1e54afd7a1d..0a3f96c01eb 100644
--- a/nt/ChangeLog.1
+++ b/nt/ChangeLog.1
@@ -3548,7 +3548,7 @@
;; add-log-time-zone-rule: t
;; End:
- Copyright (C) 1995-1999, 2001-2023 Free Software Foundation, Inc.
+ Copyright (C) 1995-1999, 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/INSTALL b/nt/INSTALL
index 3b465ba494c..77626f8a343 100644
--- a/nt/INSTALL
+++ b/nt/INSTALL
@@ -1,7 +1,7 @@
Building and Installing Emacs on MS-Windows
using the MSYS and MinGW tools
- Copyright (C) 2013-2023 Free Software Foundation, Inc.
+ Copyright (C) 2013-2024 Free Software Foundation, Inc.
See the end of the file for license conditions.
The MSYS/MinGW build described here is supported on versions of
diff --git a/nt/INSTALL.W64 b/nt/INSTALL.W64
index fe5f74e3209..2aa05ea0062 100644
--- a/nt/INSTALL.W64
+++ b/nt/INSTALL.W64
@@ -1,7 +1,7 @@
Building and Installing Emacs on 64-bit MS-Windows
using MSYS2 and MinGW-w64
- Copyright (c) 2015-2023 Free Software Foundation, Inc.
+ Copyright (c) 2015-2024 Free Software Foundation, Inc.
See the end of the file for license conditions.
This document describes how to compile a 64-bit GNU Emacs using MSYS2
diff --git a/nt/Makefile.in b/nt/Makefile.in
index 0c3192a63e6..865e3d807e8 100644
--- a/nt/Makefile.in
+++ b/nt/Makefile.in
@@ -1,6 +1,6 @@
### @configure_input@
-# Copyright (C) 2013-2023 Free Software Foundation, Inc.
+# Copyright (C) 2013-2024 Free Software Foundation, Inc.
# This file is part of GNU Emacs.
diff --git a/nt/README b/nt/README
index 118ead25fce..694e8854446 100644
--- a/nt/README
+++ b/nt/README
@@ -1,6 +1,6 @@
Emacs for Windows NT/2000 and Windows 95/98/ME
- Copyright (C) 2001-2023 Free Software Foundation, Inc.
+ Copyright (C) 2001-2024 Free Software Foundation, Inc.
See the end of the file for license conditions.
This directory contains support for compiling and running GNU Emacs on
diff --git a/nt/README.W32 b/nt/README.W32
index da1ede1ea4d..98657246f67 100644
--- a/nt/README.W32
+++ b/nt/README.W32
@@ -1,4 +1,4 @@
-Copyright (C) 2001-2023 Free Software Foundation, Inc.
+Copyright (C) 2001-2024 Free Software Foundation, Inc.
See the end of the file for license conditions.
Emacs version 30.0.50 for MS-Windows
diff --git a/nt/addpm.c b/nt/addpm.c
index 1f137144aac..6aee45d8149 100644
--- a/nt/addpm.c
+++ b/nt/addpm.c
@@ -1,5 +1,5 @@
/* Add entries to the GNU Emacs Program Manager folder.
- Copyright (C) 1995, 2001-2023 Free Software Foundation, Inc.
+ Copyright (C) 1995, 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/cmdproxy.c b/nt/cmdproxy.c
index d669fa1a391..0500b653bb2 100644
--- a/nt/cmdproxy.c
+++ b/nt/cmdproxy.c
@@ -1,5 +1,5 @@
/* Proxy shell designed for use with Emacs on Windows 95 and NT.
- Copyright (C) 1997, 2001-2023 Free Software Foundation, Inc.
+ Copyright (C) 1997, 2001-2024 Free Software Foundation, Inc.
Accepts subset of Unix sh(1) command-line options, for compatibility
with elisp code written for Unix. When possible, executes external
diff --git a/nt/configure.bat b/nt/configure.bat
new file mode 100755
index 00000000000..6e2ebe5357e
--- /dev/null
+++ b/nt/configure.bat
@@ -0,0 +1,26 @@
+@echo off
+rem ----------------------------------------------------------------------
+rem This was the old configuration script for MS Windows operating systems
+rem Copyright (C) 1999-2024 Free Software Foundation, Inc.
+
+rem This file is part of GNU Emacs.
+
+rem GNU Emacs is free software: you can redistribute it and/or modify
+rem it under the terms of the GNU General Public License as published by
+rem the Free Software Foundation, either version 3 of the License, or
+rem (at your option) any later version.
+
+rem GNU Emacs is distributed in the hope that it will be useful,
+rem but WITHOUT ANY WARRANTY; without even the implied warranty of
+rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+rem GNU General Public License for more details.
+
+rem You should have received a copy of the GNU General Public License
+rem along with GNU Emacs. If not, see https://www.gnu.org/licenses/.
+
+rem ----------------------------------------------------------------------
+echo ****************************************************************
+echo *** THIS METHOD OF BUILDING EMACS IS NO LONGER SUPPORTED. **
+echo *** INSTEAD, FOLLOW THE INSTRUCTIONS IN THE FILE INSTALL. **
+echo *** IN THE SAME DIRECTORY AS THIS BATCH FILE. **
+echo ****************************************************************
diff --git a/nt/ddeclient.c b/nt/ddeclient.c
index 1fbd2da4c13..2862cb30d71 100644
--- a/nt/ddeclient.c
+++ b/nt/ddeclient.c
@@ -1,5 +1,5 @@
/* Simple client interface to DDE servers.
- Copyright (C) 1998, 2001-2023 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/epaths.nt b/nt/epaths.nt
index 6069004cd13..143b6110a1c 100644
--- a/nt/epaths.nt
+++ b/nt/epaths.nt
@@ -12,7 +12,7 @@
the host system (e.g., i686-pc-mingw32), and @SRC@ by the root of
the Emacs source tree used to build Emacs. */
/*
-Copyright (C) 1993, 1995, 1997, 1999, 2001-2023 Free Software
+Copyright (C) 1993, 1995, 1997, 1999, 2001-2024 Free Software
Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/gnulib-cfg.mk b/nt/gnulib-cfg.mk
index fe29e942d80..5b1c2c88ba5 100644
--- a/nt/gnulib-cfg.mk
+++ b/nt/gnulib-cfg.mk
@@ -1,6 +1,6 @@
# Configurations for ../lib/gnulib.mk.
#
-# Copyright 2017-2023 Free Software Foundation, Inc.
+# Copyright 2017-2024 Free Software Foundation, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
diff --git a/nt/icons/README b/nt/icons/README
index dbb28fcfee1..9787d8b6017 100644
--- a/nt/icons/README
+++ b/nt/icons/README
@@ -2,13 +2,13 @@ COPYRIGHT AND LICENSE INFORMATION FOR IMAGE FILES
File: emacs.ico
Author: Kentaro Ohkouchi <nanasess@fsm.ne.jp>
-Copyright (C) 2008-2023 Free Software Foundation, Inc.
+Copyright (C) 2008-2024 Free Software Foundation, Inc.
License: GNU General Public License version 3 or later
File: emacs22.ico
Author: Andrew Zhilin
-Copyright (C) 2005-2023 Free Software Foundation, Inc.
+Copyright (C) 2005-2024 Free Software Foundation, Inc.
License: GNU General Public License version 3 or later (see COPYING)
@@ -17,7 +17,7 @@ Files: gnu2a32.ico gnu2a32t.ico gnu2b48.ico gnu2b48t.ico
gnu5w32.ico gnu5w32t.ico gnu6w48.ico gnu6w48t.ico
gnu7.ico gnu8.ico gnu9.ico
Author: Rob Davenport <rgd at bigfoot.com>
-Copyright (C) 1999, 2001-2023 Free Software Foundation, Inc.
+Copyright (C) 1999, 2001-2024 Free Software Foundation, Inc.
License: GNU General Public License version 3 or later (see COPYING)
<http://users.adelphia.net/~rob.davenport/gnuicons.html>
diff --git a/nt/inc/grp.h b/nt/inc/grp.h
index 1a5f0276ca1..695d28b4292 100644
--- a/nt/inc/grp.h
+++ b/nt/inc/grp.h
@@ -1,6 +1,6 @@
/* Replacement grp.h file for building GNU Emacs on Windows.
-Copyright (C) 2003-2023 Free Software Foundation, Inc.
+Copyright (C) 2003-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/inttypes.h b/nt/inc/inttypes.h
index 657bd960758..a8552b99b18 100644
--- a/nt/inc/inttypes.h
+++ b/nt/inc/inttypes.h
@@ -1,6 +1,6 @@
/* Replacement inttypes.h file for building GNU Emacs on Windows with MSVC.
-Copyright (C) 2011-2023 Free Software Foundation, Inc.
+Copyright (C) 2011-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/langinfo.h b/nt/inc/langinfo.h
index 86d925bd13f..0315e52d576 100644
--- a/nt/inc/langinfo.h
+++ b/nt/inc/langinfo.h
@@ -1,6 +1,6 @@
/* Replacement langinfo.h file for building GNU Emacs on Windows.
-Copyright (C) 2006-2023 Free Software Foundation, Inc.
+Copyright (C) 2006-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/ms-w32.h b/nt/inc/ms-w32.h
index c57549c96e7..cea0b072723 100644
--- a/nt/inc/ms-w32.h
+++ b/nt/inc/ms-w32.h
@@ -1,6 +1,6 @@
/* System description file for Windows NT.
-Copyright (C) 1993-1995, 2001-2023 Free Software Foundation, Inc.
+Copyright (C) 1993-1995, 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/nl_types.h b/nt/inc/nl_types.h
index 17debcc5b64..541a82c5cc1 100644
--- a/nt/inc/nl_types.h
+++ b/nt/inc/nl_types.h
@@ -1,6 +1,6 @@
/* Replacement nl_types.h file for building GNU Emacs on Windows.
-Copyright (C) 2006-2023 Free Software Foundation, Inc.
+Copyright (C) 2006-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/stdint.h b/nt/inc/stdint.h
index c9b667f5759..194d6104fdb 100644
--- a/nt/inc/stdint.h
+++ b/nt/inc/stdint.h
@@ -1,6 +1,6 @@
/* Replacement stdint.h file for building GNU Emacs on Windows.
-Copyright (C) 2011-2023 Free Software Foundation, Inc.
+Copyright (C) 2011-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/sys/resource.h b/nt/inc/sys/resource.h
index 72d855e6a82..b64f95ee660 100644
--- a/nt/inc/sys/resource.h
+++ b/nt/inc/sys/resource.h
@@ -1,6 +1,6 @@
/* A limited emulation of sys/resource.h.
-Copyright (C) 2016-2023 Free Software Foundation, Inc.
+Copyright (C) 2016-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/sys/socket.h b/nt/inc/sys/socket.h
index 43a24797b4c..5ecec24d04b 100644
--- a/nt/inc/sys/socket.h
+++ b/nt/inc/sys/socket.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1995, 2001-2023 Free Software Foundation, Inc.
+/* Copyright (C) 1995, 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/sys/stat.h b/nt/inc/sys/stat.h
index 0eb178dc0c9..cdd19ceeff4 100644
--- a/nt/inc/sys/stat.h
+++ b/nt/inc/sys/stat.h
@@ -1,7 +1,7 @@
/* sys/stat.h supplied with MSVCRT uses too narrow data types for
inode and user/group id, so we replace them with our own.
-Copyright (C) 2008-2023 Free Software Foundation, Inc.
+Copyright (C) 2008-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/inc/sys/wait.h b/nt/inc/sys/wait.h
index 6f49c055fb7..23d17444bbc 100644
--- a/nt/inc/sys/wait.h
+++ b/nt/inc/sys/wait.h
@@ -1,6 +1,6 @@
/* A limited emulation of sys/wait.h on Posix systems.
-Copyright (C) 2012-2023 Free Software Foundation, Inc.
+Copyright (C) 2012-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.
diff --git a/nt/preprep.c b/nt/preprep.c
new file mode 100644
index 00000000000..d1c4f2136cc
--- /dev/null
+++ b/nt/preprep.c
@@ -0,0 +1,830 @@
+/* Pre-process emacs.exe for profiling by MSVC.
+ Copyright (C) 1999, 2001-2024 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or (at
+your option) any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+
+ Andrew Innes <andrewi@harlequin.co.uk> 16-Jan-1999
+ based on code from addsection.c
+*/
+
+#define DEFER_MS_W32_H
+#include <config.h>
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <time.h>
+#if defined(__GNUC__) && !defined(MINGW_W64)
+#define _ANONYMOUS_UNION
+#define _ANONYMOUS_STRUCT
+#endif
+#include <windows.h>
+
+/* Include relevant definitions from IMAGEHLP.H, which can be found
+ in \\win32sdk\mstools\samples\image\include\imagehlp.h. */
+
+PIMAGE_NT_HEADERS (__stdcall * pfnCheckSumMappedFile) (LPVOID BaseAddress,
+ DWORD_PTR FileLength,
+ PDWORD_PTR HeaderSum,
+ PDWORD_PTR CheckSum);
+
+#undef min
+#undef max
+#define min(x, y) (((x) < (y)) ? (x) : (y))
+#define max(x, y) (((x) > (y)) ? (x) : (y))
+
+
+/* File handling. */
+
+typedef struct file_data {
+ const char *name;
+ unsigned long size;
+ HANDLE file;
+ HANDLE file_mapping;
+ unsigned char *file_base;
+} file_data;
+
+int
+open_input_file (file_data *p_file, const char *filename)
+{
+ HANDLE file;
+ HANDLE file_mapping;
+ void *file_base;
+ unsigned long size, upper_size;
+
+ file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ if (file == INVALID_HANDLE_VALUE)
+ return FALSE;
+
+ size = GetFileSize (file, &upper_size);
+ file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY,
+ 0, size, NULL);
+ if (!file_mapping)
+ return FALSE;
+
+ file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size);
+ if (file_base == 0)
+ return FALSE;
+
+ p_file->name = filename;
+ p_file->size = size;
+ p_file->file = file;
+ p_file->file_mapping = file_mapping;
+ p_file->file_base = file_base;
+
+ return TRUE;
+}
+
+int
+open_output_file (file_data *p_file, const char *filename, unsigned long size)
+{
+ HANDLE file;
+ HANDLE file_mapping;
+ void *file_base;
+
+ file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
+ if (file == INVALID_HANDLE_VALUE)
+ return FALSE;
+
+ file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE,
+ 0, size, NULL);
+ if (!file_mapping)
+ return FALSE;
+
+ file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
+ if (file_base == 0)
+ return FALSE;
+
+ p_file->name = filename;
+ p_file->size = size;
+ p_file->file = file;
+ p_file->file_mapping = file_mapping;
+ p_file->file_base = file_base;
+
+ return TRUE;
+}
+
+int
+open_inout_file (file_data *p_file, const char *filename)
+{
+ HANDLE file;
+ HANDLE file_mapping;
+ void *file_base;
+ unsigned long size, upper_size;
+
+ file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+ if (file == INVALID_HANDLE_VALUE)
+ return FALSE;
+
+ size = GetFileSize (file, &upper_size);
+ file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE,
+ 0, size, NULL);
+ if (!file_mapping)
+ return FALSE;
+
+ file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
+ if (file_base == 0)
+ return FALSE;
+
+ p_file->name = filename;
+ p_file->size = size;
+ p_file->file = file;
+ p_file->file_mapping = file_mapping;
+ p_file->file_base = file_base;
+
+ return TRUE;
+}
+
+/* Close the system structures associated with the given file. */
+void
+close_file_data (file_data *p_file)
+{
+ UnmapViewOfFile (p_file->file_base);
+ CloseHandle (p_file->file_mapping);
+ /* For the case of output files, set final size. */
+ SetFilePointer (p_file->file, p_file->size, NULL, FILE_BEGIN);
+ SetEndOfFile (p_file->file);
+ CloseHandle (p_file->file);
+}
+
+
+/* Routines to manipulate NT executable file sections. */
+
+unsigned long
+get_unrounded_section_size (PIMAGE_SECTION_HEADER p_section)
+{
+ /* The true section size, before rounding, for an initialized data or
+ code section. (Supposedly some linkers swap the meaning of these
+ two values.) */
+ return min (p_section->SizeOfRawData,
+ p_section->Misc.VirtualSize);
+}
+
+/* Return pointer to section header for named section. */
+IMAGE_SECTION_HEADER *
+find_section (const char *name, IMAGE_NT_HEADERS *nt_header)
+{
+ PIMAGE_SECTION_HEADER section;
+ int i;
+
+ section = IMAGE_FIRST_SECTION (nt_header);
+
+ for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
+ {
+ if (strcmp (section->Name, name) == 0)
+ return section;
+ section++;
+ }
+ return NULL;
+}
+
+/* Return pointer to section header for section containing the given
+ relative virtual address. */
+IMAGE_SECTION_HEADER *
+rva_to_section (DWORD_PTR rva, IMAGE_NT_HEADERS * nt_header)
+{
+ PIMAGE_SECTION_HEADER section;
+ int i;
+
+ section = IMAGE_FIRST_SECTION (nt_header);
+
+ for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
+ {
+ /* Some linkers (eg. the NT SDK linker I believe) swapped the
+ meaning of these two values - or rather, they ignored
+ VirtualSize entirely and always set it to zero. This affects
+ some very old exes (eg. gzip dated Dec 1993). Since
+ w32_executable_type relies on this function to work reliably,
+ we need to cope with this. */
+ DWORD_PTR real_size = max (section->SizeOfRawData,
+ section->Misc.VirtualSize);
+ if (rva >= section->VirtualAddress
+ && rva < section->VirtualAddress + real_size)
+ return section;
+ section++;
+ }
+ return NULL;
+}
+
+/* Return pointer to section header for section containing the given
+ offset in its raw data area. */
+IMAGE_SECTION_HEADER *
+offset_to_section (DWORD_PTR offset, IMAGE_NT_HEADERS * nt_header)
+{
+ PIMAGE_SECTION_HEADER section;
+ int i;
+
+ section = IMAGE_FIRST_SECTION (nt_header);
+
+ for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
+ {
+ if (offset >= section->PointerToRawData
+ && offset < section->PointerToRawData + section->SizeOfRawData)
+ return section;
+ section++;
+ }
+ return NULL;
+}
+
+/* Return offset to an object in dst, given offset in src. We assume
+ there is at least one section in both src and dst images, and that
+ the some sections may have been added to dst (after sections in src). */
+static DWORD_PTR
+relocate_offset (DWORD_PTR offset,
+ IMAGE_NT_HEADERS * src_nt_header,
+ IMAGE_NT_HEADERS * dst_nt_header)
+{
+ PIMAGE_SECTION_HEADER src_section = IMAGE_FIRST_SECTION (src_nt_header);
+ PIMAGE_SECTION_HEADER dst_section = IMAGE_FIRST_SECTION (dst_nt_header);
+ int i = 0;
+
+ while (offset >= src_section->PointerToRawData)
+ {
+ if (offset < src_section->PointerToRawData + src_section->SizeOfRawData)
+ break;
+ i++;
+ if (i == src_nt_header->FileHeader.NumberOfSections)
+ {
+ /* Handle offsets after the last section. */
+ dst_section = IMAGE_FIRST_SECTION (dst_nt_header);
+ dst_section += dst_nt_header->FileHeader.NumberOfSections - 1;
+ while (dst_section->PointerToRawData == 0)
+ dst_section--;
+ while (src_section->PointerToRawData == 0)
+ src_section--;
+ return offset
+ + (dst_section->PointerToRawData + dst_section->SizeOfRawData)
+ - (src_section->PointerToRawData + src_section->SizeOfRawData);
+ }
+ src_section++;
+ dst_section++;
+ }
+ return offset +
+ (dst_section->PointerToRawData - src_section->PointerToRawData);
+}
+
+#define OFFSET_TO_RVA(offset, section) \
+ ((section)->VirtualAddress + ((DWORD_PTR)(offset) - (section)->PointerToRawData))
+
+#define RVA_TO_OFFSET(rva, section) \
+ ((section)->PointerToRawData + ((DWORD_PTR)(rva) - (section)->VirtualAddress))
+
+#define RVA_TO_SECTION_OFFSET(rva, section) \
+ ((DWORD_PTR)(rva) - (section)->VirtualAddress)
+
+#define RVA_TO_PTR(var,section,filedata) \
+ ((void *)((unsigned char *)(RVA_TO_OFFSET(var,section) + (filedata)->file_base)))
+
+/* Convert address in executing image to RVA. */
+#define PTR_TO_RVA(ptr) ((DWORD_PTR)(ptr) - (DWORD_PTR) GetModuleHandle (NULL))
+
+#define PTR_TO_OFFSET(ptr, pfile_data) \
+ ((unsigned const char *)(ptr) - (pfile_data)->file_base)
+
+#define OFFSET_TO_PTR(offset, pfile_data) \
+ ((pfile_data)->file_base + (DWORD_PTR)(offset))
+
+#define ROUND_UP(p, align) \
+ (((DWORD_PTR)(p) + (align)-1) & ~((DWORD_PTR)(align)-1))
+#define ROUND_DOWN(p, align) ((DWORD_PTR)(p) & ~((DWORD_PTR)(align)-1))
+
+
+/* The MSVC prep program generates a ._xe file from .exe, where relevant
+ function calls etc have been patched to go through thunks (generated
+ by prep) that record timing/call information. Because the thunks
+ need to make references to functions imported from profile.dll, the
+ import table must be expanded; the end result is that all the
+ sections following .rdata are relocated to higher RVAs (add a final
+ code section is added holding all the thunks). The .reloc section is
+ also expanded, so that the thunks themselves are relocatable.
+
+ It is this relocation which kills emacs._xe, because the dumped heap
+ pointers aren't relocated, because there is no relocation data for
+ either the relevant global/static variables or the heap section
+ itself, both of which contain pointers into the heap. [Note that
+ static variables which aren't initialized during linking may become
+ initialized with heap pointers, or even pointers to other static
+ variables, because of dumping.]
+
+ We could potentially generate the relocation data ourselves by making
+ two versions of temacs, one with an extra dummy section before
+ EMHEAP to offset it, and then compare the dumped executables from
+ both. That is a lot of work though, and it doesn't solve the problem
+ of dumped pointers to static variables, which also can be relocated.
+
+ A better solution is to pre-process emacs.exe so that the .rdata and
+ .reloc sections are moved to the end of the section table, and thus
+ prep won't relocate anything else. (Of course, we leave "dead"
+ copies of these two sections in place, so that the virtual address of
+ everything else is unaffected.) Relocating the .reloc data is
+ trivial - we just update the IMAGE_BASE_RELOCATION address in the
+ header (the data itself doesn't change). Relocating the import table
+ is more complicated though, because the calls to imported functions
+ must be patched up. That requires us to selectively apply the base
+ relocations when we encounter references to imported functions (or
+ variables) in other sections, but at least the base relocations are
+ easy to parse. */
+
+static void
+copy_executable_and_move_sections (file_data *p_infile,
+ file_data *p_outfile)
+{
+ unsigned char *dst;
+ PIMAGE_DOS_HEADER dos_header;
+ PIMAGE_NT_HEADERS nt_header;
+ PIMAGE_NT_HEADERS dst_nt_header;
+ PIMAGE_SECTION_HEADER section;
+ PIMAGE_SECTION_HEADER dst_section;
+ PIMAGE_SECTION_HEADER import_section;
+ PIMAGE_SECTION_HEADER reloc_section;
+ PIMAGE_DATA_DIRECTORY import_dir;
+ PIMAGE_DATA_DIRECTORY reloc_dir;
+ DWORD_PTR import_delta_rva;
+ DWORD_PTR reloc_delta_rva;
+ DWORD_PTR offset;
+ int i;
+
+#define COPY_CHUNK(message, src, size) \
+ do { \
+ unsigned const char *s = (void *)(src); \
+ unsigned long count = (size); \
+ printf ("%s\n", (message)); \
+ printf ("\t0x%08x Offset in input file.\n", s - p_infile->file_base); \
+ printf ("\t0x%08x Offset in output file.\n", dst - p_outfile->file_base); \
+ printf ("\t0x%08x Size in bytes.\n", count); \
+ memcpy (dst, s, count); \
+ dst += count; \
+ } while (0)
+
+#define DST_TO_OFFSET() PTR_TO_OFFSET (dst, p_outfile)
+#define ROUND_UP_DST_AND_ZERO(align) \
+ do { \
+ unsigned char *newdst = p_outfile->file_base \
+ + ROUND_UP (DST_TO_OFFSET (), (align)); \
+ /* Zero the alignment slop; it may actually initialize real data. */ \
+ memset (dst, 0, newdst - dst); \
+ dst = newdst; \
+ } while (0)
+
+ /* Copy the source image sequentially, ie. section by section after
+ copying the headers and section table, to simplify the process of
+ relocating the .rdata and .reloc section table entries (which might
+ force the raw section data to be relocated).
+
+ Note that dst is updated implicitly by each COPY_CHUNK. */
+
+ dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base;
+ nt_header = (PIMAGE_NT_HEADERS) (((unsigned char *) dos_header) +
+ dos_header->e_lfanew);
+ section = IMAGE_FIRST_SECTION (nt_header);
+
+ import_dir = &nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
+ import_section = rva_to_section (import_dir->VirtualAddress, nt_header);
+
+ reloc_dir = &nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
+ reloc_section = rva_to_section (reloc_dir->VirtualAddress, nt_header);
+ if (!reloc_section)
+ {
+ printf ("No relocation data, cannot prepare for profile prepping.\n");
+ exit (1);
+ }
+
+ dst = (unsigned char *) p_outfile->file_base;
+
+ COPY_CHUNK ("Copying DOS header...", dos_header,
+ (DWORD_PTR) nt_header - (DWORD_PTR) dos_header);
+ dst_nt_header = (PIMAGE_NT_HEADERS) dst;
+ COPY_CHUNK ("Copying NT header...", nt_header,
+ (DWORD_PTR) section - (DWORD_PTR) nt_header);
+ dst_section = (PIMAGE_SECTION_HEADER) dst;
+ COPY_CHUNK ("Copying section table...", section,
+ nt_header->FileHeader.NumberOfSections * sizeof (*section));
+
+ /* Leave room for extra section table entries; filled in below. */
+ dst += 2 * sizeof (*section);
+
+ /* Align the first section's raw data area, and set the header size
+ field accordingly. */
+ ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
+ dst_nt_header->OptionalHeader.SizeOfHeaders = DST_TO_OFFSET ();
+
+ for (i = 0; i < nt_header->FileHeader.NumberOfSections;
+ i++, section++, dst_section++)
+ {
+ char msg[100];
+ sprintf (msg, "Copying raw data for %s...", section->Name);
+
+ /* "Blank out" the two sections being relocated. */
+ if (section == import_section || section == reloc_section)
+ {
+ dst_section->Name[0] = 'X';
+ dst_section->Misc.VirtualSize =
+ ROUND_UP (dst_section->Misc.VirtualSize,
+ dst_nt_header->OptionalHeader.SectionAlignment);
+ dst_section->PointerToRawData = 0;
+ dst_section->SizeOfRawData = 0;
+ dst_section->Characteristics &= ~IMAGE_SCN_CNT_INITIALIZED_DATA;
+ dst_section->Characteristics |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;
+ dst_section->Characteristics &= ~IMAGE_SCN_MEM_WRITE;
+ continue;
+ }
+
+ /* Update the file-relative offset for this section's raw data (if
+ it has any) in case things have been relocated; we will update
+ the other offsets below once we know where everything is. */
+ if (dst_section->PointerToRawData)
+ dst_section->PointerToRawData = DST_TO_OFFSET ();
+
+ /* Copy the original raw data. */
+ COPY_CHUNK
+ (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile),
+ section->SizeOfRawData);
+
+ /* Round up the raw data size to the new alignment. */
+ dst_section->SizeOfRawData =
+ ROUND_UP (dst_section->SizeOfRawData,
+ dst_nt_header->OptionalHeader.FileAlignment);
+
+ /* Align the next section's raw data area. */
+ ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
+ }
+
+ /* Add the extra section entries, copying the raw data we skipped
+ earlier. We'll patch up the data itself below. */
+ if (import_section != NULL)
+ {
+ dst_nt_header->FileHeader.NumberOfSections++;
+ dst_nt_header->OptionalHeader.SizeOfImage +=
+ ROUND_UP (import_section->Misc.VirtualSize,
+ dst_nt_header->OptionalHeader.SectionAlignment);
+ *dst_section = *import_section;
+ dst_section->VirtualAddress =
+ dst_section[-1].VirtualAddress
+ + ROUND_UP (dst_section[-1].Misc.VirtualSize,
+ dst_nt_header->OptionalHeader.SectionAlignment);
+ dst_section->PointerToRawData = DST_TO_OFFSET ();
+ /* Remember delta applied to import section. */
+ import_delta_rva = dst_section->VirtualAddress - import_section->VirtualAddress;
+ COPY_CHUNK
+ ("Relocating import directory",
+ OFFSET_TO_PTR (import_section->PointerToRawData, p_infile),
+ import_section->SizeOfRawData);
+ ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
+ dst_section++;
+ }
+ if (reloc_section != NULL)
+ {
+ dst_nt_header->FileHeader.NumberOfSections++;
+ dst_nt_header->OptionalHeader.SizeOfImage +=
+ ROUND_UP (reloc_section->Misc.VirtualSize,
+ dst_nt_header->OptionalHeader.SectionAlignment);
+ *dst_section = *reloc_section;
+ dst_section->VirtualAddress =
+ dst_section[-1].VirtualAddress
+ + ROUND_UP (dst_section[-1].Misc.VirtualSize,
+ dst_nt_header->OptionalHeader.SectionAlignment);
+ dst_section->PointerToRawData = DST_TO_OFFSET ();
+ /* Remember delta applied to reloc section. */
+ reloc_delta_rva = dst_section->VirtualAddress - reloc_section->VirtualAddress;
+ COPY_CHUNK
+ ("Relocating base relocations directory",
+ OFFSET_TO_PTR (reloc_section->PointerToRawData, p_infile),
+ reloc_section->SizeOfRawData);
+ ROUND_UP_DST_AND_ZERO (dst_nt_header->OptionalHeader.FileAlignment);
+ reloc_dir = &dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
+ reloc_dir->VirtualAddress += reloc_delta_rva;
+ dst_section++;
+ }
+
+ /* Copy remainder of source image. */
+ section--;
+ offset = ROUND_UP (section->PointerToRawData + section->SizeOfRawData,
+ nt_header->OptionalHeader.FileAlignment);
+ COPY_CHUNK
+ ("Copying remainder of executable...",
+ OFFSET_TO_PTR (offset, p_infile),
+ p_infile->size - offset);
+
+ /* Final size for new image. */
+ p_outfile->size = DST_TO_OFFSET ();
+
+ /* Now patch up remaining file-relative offsets. */
+ printf ("Patching up raw data offsets...\n");
+
+ section = IMAGE_FIRST_SECTION (nt_header);
+ dst_section = IMAGE_FIRST_SECTION (dst_nt_header);
+
+#define ADJUST_OFFSET(var) \
+ do { \
+ if ((var) != 0) \
+ (var) = relocate_offset ((var), nt_header, dst_nt_header); \
+ } while (0)
+
+#define ADJUST_IMPORT_RVA(var) \
+ do { \
+ if ((var) != 0) \
+ *((DWORD_PTR *)&(var)) += import_delta_rva; \
+ } while (0)
+
+ dst_nt_header->OptionalHeader.SizeOfInitializedData = 0;
+ dst_nt_header->OptionalHeader.SizeOfUninitializedData = 0;
+ for (i = 0; i < dst_nt_header->FileHeader.NumberOfSections; i++)
+ {
+ /* Recompute data sizes for completeness. */
+ if (dst_section[i].Characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA)
+ dst_nt_header->OptionalHeader.SizeOfInitializedData +=
+ ROUND_UP (dst_section[i].Misc.VirtualSize, dst_nt_header->OptionalHeader.FileAlignment);
+ else if (dst_section[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
+ dst_nt_header->OptionalHeader.SizeOfUninitializedData +=
+ ROUND_UP (dst_section[i].Misc.VirtualSize, dst_nt_header->OptionalHeader.FileAlignment);
+
+ ADJUST_OFFSET (dst_section[i].PointerToLinenumbers);
+ }
+
+ ADJUST_OFFSET (dst_nt_header->FileHeader.PointerToSymbolTable);
+
+ /* Update offsets in debug directory entries. Note that the debug
+ directory may be in the same section as the import table, so its
+ RVA may need to be adjusted too. */
+ {
+ PIMAGE_DATA_DIRECTORY debug_dir =
+ &dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DEBUG];
+ PIMAGE_DEBUG_DIRECTORY debug_entry;
+
+ /* Update debug_dir if part of import_section. */
+ if (rva_to_section (debug_dir->VirtualAddress, nt_header) == import_section)
+ debug_dir->VirtualAddress += import_delta_rva;
+
+ section = rva_to_section (debug_dir->VirtualAddress, dst_nt_header);
+ if (section)
+ {
+ int size;
+
+ debug_entry = RVA_TO_PTR (debug_dir->VirtualAddress, section, p_outfile);
+ size = debug_dir->Size / sizeof (IMAGE_DEBUG_DIRECTORY);
+
+ for (i = 0; i < size; i++, debug_entry++)
+ {
+ /* The debug data itself is normally not part of any
+ section, but stored after all the raw section data. So
+ let relocate_offset do the work. */
+ ADJUST_OFFSET (debug_entry->PointerToRawData);
+ ADJUST_IMPORT_RVA (debug_entry->AddressOfRawData);
+ }
+ }
+ }
+
+ /* Update RVAs in import directory entries. */
+ {
+ PIMAGE_IMPORT_DESCRIPTOR imports;
+ PIMAGE_THUNK_DATA import_thunks;
+
+ import_dir = &dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT];
+ import_dir->VirtualAddress += import_delta_rva;
+
+ section = rva_to_section (import_dir->VirtualAddress, dst_nt_header);
+ imports = RVA_TO_PTR (import_dir->VirtualAddress, section, p_outfile);
+
+ for ( ; imports->Name != 0; imports++)
+ {
+ ADJUST_IMPORT_RVA (imports->OriginalFirstThunk);
+ ADJUST_IMPORT_RVA (imports->FirstThunk);
+ ADJUST_IMPORT_RVA (imports->Name);
+
+ for (import_thunks = RVA_TO_PTR (imports->OriginalFirstThunk, section, p_outfile);
+ import_thunks->u1.Function != 0;
+ import_thunks++)
+ if ((import_thunks->u1.Ordinal >> 31) == 0)
+ ADJUST_IMPORT_RVA (import_thunks->u1.Ordinal);
+
+ for (import_thunks = RVA_TO_PTR (imports->FirstThunk, section, p_outfile);
+ import_thunks->u1.Function != 0;
+ import_thunks++)
+ if ((import_thunks->u1.Ordinal >> 31) == 0)
+ ADJUST_IMPORT_RVA (import_thunks->u1.Ordinal);
+ }
+
+ import_dir = &dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT];
+ import_dir->VirtualAddress += import_delta_rva;
+ }
+
+ /* Fix up references to the import section. */
+ printf ("Applying fixups to import references...\n");
+
+ {
+ IMAGE_BASE_RELOCATION *relocs, *block, *start_block, *end_block;
+ DWORD_PTR import_start = import_section->VirtualAddress + dst_nt_header->OptionalHeader.ImageBase;
+ DWORD_PTR import_end = import_start + import_section->Misc.VirtualSize;
+ DWORD_PTR len_import_relocs;
+ DWORD_PTR len_remaining_relocs;
+ int seen_high = 0;
+ WORD * high_word;
+ void * holder;
+
+ reloc_dir = &dst_nt_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC];
+ reloc_section = rva_to_section (reloc_dir->VirtualAddress, dst_nt_header);
+ relocs = RVA_TO_PTR (reloc_dir->VirtualAddress, reloc_section, p_outfile);
+
+ /* Move the base relocations for the import section, if there are
+ any; the profiler needs to be able to patch RVAs in the import
+ section itself. */
+ for (block = relocs, start_block = 0;
+ (DWORD_PTR) block - (DWORD_PTR) relocs < reloc_dir->Size;
+ block = (void *)((DWORD_PTR) block + block->SizeOfBlock))
+ {
+ if (block->VirtualAddress >= import_section->VirtualAddress + import_section->Misc.VirtualSize)
+ {
+ end_block = block;
+ break;
+ }
+ if (block->VirtualAddress >= import_section->VirtualAddress)
+ {
+ if (start_block == 0)
+ start_block = block;
+ block->VirtualAddress += import_delta_rva;
+ }
+ }
+ if (start_block)
+ {
+ len_import_relocs = (DWORD_PTR) end_block - (DWORD_PTR) start_block;
+ len_remaining_relocs = (DWORD_PTR) relocs + reloc_dir->Size - (DWORD_PTR) end_block;
+ holder = malloc (len_import_relocs);
+ if (holder == 0)
+ abort ();
+ memcpy (holder, start_block, len_import_relocs);
+ memcpy (start_block, end_block, len_remaining_relocs);
+ memcpy ((char *) start_block + len_remaining_relocs, holder, len_import_relocs);
+ free (holder);
+ }
+
+ /* Walk up the list of base relocations, checking for references
+ to the old import section location, and patching them to
+ reference the new location. */
+ for (block = relocs;
+ (DWORD_PTR) block - (DWORD_PTR) relocs < reloc_dir->Size;
+ block = (void *)((DWORD_PTR) block + block->SizeOfBlock))
+ {
+ DWORD_PTR page_rva = block->VirtualAddress;
+ DWORD_PTR page_offset;
+ union {
+ WORD word;
+ DWORD_PTR dword;
+ } * ploc;
+ WORD *fixup;
+
+ section = rva_to_section (page_rva, dst_nt_header);
+ /* Don't apply fixups to the blanked sections. */
+ if (section->Name[0] == 'X')
+ continue;
+
+ for (fixup = (WORD *) &block[1];
+ (DWORD_PTR) fixup - (DWORD_PTR) block < block->SizeOfBlock;
+ fixup++)
+ {
+ page_offset = (*fixup) & 0xfff;
+ ploc = RVA_TO_PTR (page_rva + page_offset, section, p_outfile);
+
+ /* Unless our assumption is wrong, all low word fixups
+ should immediately follow a high fixup. */
+ if (seen_high && ((*fixup) >> 12) != IMAGE_REL_BASED_LOW)
+ abort ();
+
+ switch ((*fixup) >> 12)
+ {
+ case IMAGE_REL_BASED_ABSOLUTE:
+ break;
+ case IMAGE_REL_BASED_HIGH:
+ /* We must assume that high and low fixups occur in
+ pairs, specifically a low fixup immediately follows a
+ high fixup (normally separated by two bytes). We
+ have to process the two fixups together, to find out
+ the full pointer value and decide whether to apply
+ the fixup. */
+ seen_high = 1;
+ high_word = &ploc->word;
+ break;
+ case IMAGE_REL_BASED_LOW:
+ offset = (*high_word << 16) + ploc->word;
+ if (offset >= import_start && offset < import_end)
+ {
+ (*high_word) += import_delta_rva >> 16;
+ ploc->dword += import_delta_rva & 0xffff;
+ }
+ seen_high = 0;
+ break;
+ case IMAGE_REL_BASED_HIGHLOW:
+ /* Docs imply two words in big-endian order, so perhaps
+ this is only used on big-endian platforms, in which
+ case the obvious code will work. */
+ if (ploc->dword >= import_start && ploc->dword < import_end)
+ ploc->dword += import_delta_rva;
+ break;
+ case IMAGE_REL_BASED_HIGHADJ:
+ /* Docs don't say, but I guess this is the equivalent
+ for little-endian platforms. */
+ if (ploc->dword >= import_start && ploc->dword < import_end)
+ ploc->dword += import_delta_rva;
+ break;
+ case IMAGE_REL_BASED_MIPS_JMPADDR:
+ /* Don't know how to handle this; MIPS support has been
+ dropped from NT4 anyway. */
+ abort ();
+ break;
+#ifdef IMAGE_REL_BASED_SECTION
+ case IMAGE_REL_BASED_SECTION:
+ case IMAGE_REL_BASED_REL32:
+ /* Docs don't say what these values mean. */
+#endif
+ default:
+ abort ();
+ }
+ }
+ }
+ }
+}
+
+
+int
+main (int argc, char **argv)
+{
+ PIMAGE_DOS_HEADER dos_header;
+ PIMAGE_NT_HEADERS nt_header;
+ file_data in_file, out_file;
+ char out_filename[MAX_PATH], in_filename[MAX_PATH];
+
+ strcpy (in_filename, argv[1]);
+ strcpy (out_filename, argv[2]);
+
+ printf ("Preparing %s for profile prepping\n", out_filename);
+
+ /* Open the original (dumped) executable file for reference. */
+ if (!open_input_file (&in_file, in_filename))
+ {
+ printf ("Failed to open %s (%d)...bailing.\n",
+ in_filename, GetLastError ());
+ exit (1);
+ }
+
+ /* Create a new image that can be prepped; we don't expect the size to
+ change because we are only adding two new section table entries,
+ which should fit in the alignment slop. */
+ if (!open_output_file (&out_file, out_filename, in_file.size))
+ {
+ printf ("Failed to open %s (%d)...bailing.\n",
+ out_filename, GetLastError ());
+ exit (1);
+ }
+
+ copy_executable_and_move_sections (&in_file, &out_file);
+
+ /* Patch up header fields; profiler is picky about this. */
+ {
+ HANDLE hImagehelp = LoadLibrary ("imagehlp.dll");
+ DWORD_PTR headersum;
+ DWORD_PTR checksum;
+
+ dos_header = (PIMAGE_DOS_HEADER) out_file.file_base;
+ nt_header = (PIMAGE_NT_HEADERS) ((char *) dos_header + dos_header->e_lfanew);
+
+ nt_header->OptionalHeader.CheckSum = 0;
+// nt_header->FileHeader.TimeDateStamp = time (NULL);
+// dos_header->e_cp = size / 512;
+// nt_header->OptionalHeader.SizeOfImage = size;
+
+ pfnCheckSumMappedFile = (void *) GetProcAddress (hImagehelp, "CheckSumMappedFile");
+ if (pfnCheckSumMappedFile)
+ {
+// nt_header->FileHeader.TimeDateStamp = time (NULL);
+ pfnCheckSumMappedFile (out_file.file_base,
+ out_file.size,
+ &headersum,
+ &checksum);
+ nt_header->OptionalHeader.CheckSum = checksum;
+ }
+ FreeLibrary (hImagehelp);
+ }
+
+ close_file_data (&out_file);
+ close_file_data (&in_file);
+
+ return 0;
+}
+
+/* eof */
diff --git a/nt/runemacs.c b/nt/runemacs.c
index 9226bb50745..4188a1fa9a4 100644
--- a/nt/runemacs.c
+++ b/nt/runemacs.c
@@ -1,6 +1,6 @@
/* runemacs --- Simple program to start Emacs with its console window hidden.
-Copyright (C) 2001-2023 Free Software Foundation, Inc.
+Copyright (C) 2001-2024 Free Software Foundation, Inc.
This file is part of GNU Emacs.