]> code.delx.au - gnu-emacs/blobdiff - nt/addsection.c
Initial support for hunspell dictionaries auto-detection (Bug#13639)
[gnu-emacs] / nt / addsection.c
index 6eb2ee37038096298dc4a33daf2274654a2ddc9a..ee68ebee9b27830e28dd02e5c822a3c23cde8c90 100644 (file)
@@ -1,13 +1,12 @@
 /* Add an uninitialized data section to an executable.
-   Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005,
-      2006, 2007, 2008  Free Software Foundation, Inc.
+   Copyright (C) 1999, 2001-2013 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+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, or (at your option)
-any later version.
+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
@@ -15,9 +14,8 @@ 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; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
 
    Andrew Innes <andrewi@harlequin.co.uk>       04-Jan-1999
      based on code from unexw32.c
@@ -37,10 +35,10 @@ Boston, MA 02110-1301, USA.
    in \\win32sdk\mstools\samples\image\include\imagehlp.h. */
 
 PIMAGE_NT_HEADERS
-(__stdcall * pfnCheckSumMappedFile) (LPVOID BaseAddress,
-                                   DWORD FileLength,
-                                   LPDWORD HeaderSum,
-                                   LPDWORD CheckSum);
+(__stdcall * pfnCheckSumMappedFile) (PVOID BaseAddress,
+                                    DWORD_PTR FileLength,
+                                    PDWORD_PTR HeaderSum,
+                                    PDWORD_PTR CheckSum);
 
 #undef min
 #undef max
@@ -51,15 +49,15 @@ PIMAGE_NT_HEADERS
 /* File handling.  */
 
 typedef struct file_data {
-    char          *name;
-    unsigned long  size;
-    HANDLE         file;
-    HANDLE         file_mapping;
-    unsigned char *file_base;
+  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, char *filename)
+open_input_file (file_data *p_file, const char *filename)
 {
   HANDLE file;
   HANDLE file_mapping;
@@ -91,7 +89,7 @@ open_input_file (file_data *p_file, char *filename)
 }
 
 int
-open_output_file (file_data *p_file, char *filename, unsigned long size)
+open_output_file (file_data *p_file, const char *filename, unsigned long size)
 {
   HANDLE file;
   HANDLE file_mapping;
@@ -147,7 +145,7 @@ get_unrounded_section_size (PIMAGE_SECTION_HEADER p_section)
 
 /* Return pointer to section header for named section. */
 IMAGE_SECTION_HEADER *
-find_section (char * name, IMAGE_NT_HEADERS * nt_header)
+find_section (const char *name, IMAGE_NT_HEADERS *nt_header)
 {
   PIMAGE_SECTION_HEADER section;
   int i;
@@ -166,7 +164,7 @@ find_section (char * name, IMAGE_NT_HEADERS * nt_header)
 /* Return pointer to section header for section containing the given
    relative virtual address. */
 IMAGE_SECTION_HEADER *
-rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
+rva_to_section (DWORD_PTR rva, IMAGE_NT_HEADERS * nt_header)
 {
   PIMAGE_SECTION_HEADER section;
   int i;
@@ -181,7 +179,7 @@ rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
         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 real_size = max (section->SizeOfRawData,
+      DWORD_PTR real_size = max (section->SizeOfRawData,
                             section->Misc.VirtualSize);
       if (rva >= section->VirtualAddress
          && rva < section->VirtualAddress + real_size)
@@ -194,7 +192,7 @@ rva_to_section (DWORD rva, IMAGE_NT_HEADERS * nt_header)
 /* Return pointer to section header for section containing the given
    offset in its raw data area. */
 IMAGE_SECTION_HEADER *
-offset_to_section (DWORD offset, IMAGE_NT_HEADERS * nt_header)
+offset_to_section (DWORD_PTR offset, IMAGE_NT_HEADERS * nt_header)
 {
   PIMAGE_SECTION_HEADER section;
   int i;
@@ -214,8 +212,8 @@ offset_to_section (DWORD offset, IMAGE_NT_HEADERS * nt_header)
 /* 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
-relocate_offset (DWORD offset,
+static DWORD_PTR
+relocate_offset (DWORD_PTR offset,
                 IMAGE_NT_HEADERS * src_nt_header,
                 IMAGE_NT_HEADERS * dst_nt_header)
 {
@@ -249,32 +247,33 @@ relocate_offset (DWORD offset,
 }
 
 #define OFFSET_TO_RVA(offset, section) \
-         (section->VirtualAddress + ((DWORD)(offset) - section->PointerToRawData))
+         (section->VirtualAddress + ((DWORD_PTR)(offset) - section->PointerToRawData))
 
 #define RVA_TO_OFFSET(rva, section) \
-         (section->PointerToRawData + ((DWORD)(rva) - section->VirtualAddress))
+         (section->PointerToRawData + ((DWORD_PTR)(rva) - section->VirtualAddress))
 
 #define RVA_TO_SECTION_OFFSET(rva, section) \
-         ((DWORD)(rva) - section->VirtualAddress)
+         ((DWORD_PTR)(rva) - section->VirtualAddress)
 
 /* Convert address in executing image to RVA.  */
-#define PTR_TO_RVA(ptr) ((DWORD)(ptr) - (DWORD) GetModuleHandle (NULL))
+#define PTR_TO_RVA(ptr) ((DWORD_PTR)(ptr) - (DWORD_PTR) GetModuleHandle (NULL))
 
 #define PTR_TO_OFFSET(ptr, pfile_data) \
-          ((unsigned char *)(ptr) - (pfile_data)->file_base)
+          ((unsigned const char *)(ptr) - (pfile_data)->file_base)
 
 #define OFFSET_TO_PTR(offset, pfile_data) \
-          ((pfile_data)->file_base + (DWORD)(offset))
+          ((pfile_data)->file_base + (DWORD_PTR)(offset))
 
-#define ROUND_UP(p, align)   (((DWORD)(p) + (align)-1) & ~((align)-1))
-#define ROUND_DOWN(p, align) ((DWORD)(p) & ~((align)-1))
+#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))
 
 
 static void
 copy_executable_and_add_section (file_data *p_infile,
                                 file_data *p_outfile,
-                                char *new_section_name,
-                                DWORD new_section_size)
+                                const char *new_section_name,
+                                DWORD_PTR new_section_size)
 {
   unsigned char *dst;
   PIMAGE_DOS_HEADER dos_header;
@@ -282,13 +281,13 @@ copy_executable_and_add_section (file_data *p_infile,
   PIMAGE_NT_HEADERS dst_nt_header;
   PIMAGE_SECTION_HEADER section;
   PIMAGE_SECTION_HEADER dst_section;
-  DWORD offset;
+  DWORD_PTR offset;
   int i;
   int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0;
 
 #define COPY_CHUNK(message, src, size, verbose)                                        \
   do {                                                                         \
-    unsigned char *s = (void *)(src);                                          \
+    unsigned const char *s = (void *)(src);                                            \
     unsigned long count = (size);                                              \
     if (verbose)                                                               \
       {                                                                                \
@@ -319,17 +318,17 @@ copy_executable_and_add_section (file_data *p_infile,
      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 long) dos_header) +
+  nt_header = (PIMAGE_NT_HEADERS) (((unsigned char *) dos_header) +
                                   dos_header->e_lfanew);
   section = IMAGE_FIRST_SECTION (nt_header);
 
   dst = (unsigned char *) p_outfile->file_base;
 
   COPY_CHUNK ("Copying DOS header...", dos_header,
-             (DWORD) nt_header - (DWORD) dos_header, be_verbose);
+             (DWORD_PTR) nt_header - (DWORD_PTR) dos_header, be_verbose);
   dst_nt_header = (PIMAGE_NT_HEADERS) dst;
   COPY_CHUNK ("Copying NT header...", nt_header,
-             (DWORD) section - (DWORD) nt_header, be_verbose);
+             (DWORD_PTR) section - (DWORD_PTR) nt_header, be_verbose);
   dst_section = (PIMAGE_SECTION_HEADER) dst;
   COPY_CHUNK ("Copying section table...", section,
              nt_header->FileHeader.NumberOfSections * sizeof (*section),
@@ -511,8 +510,8 @@ main (int argc, char **argv)
   /* Patch up header fields; profiler is picky about this. */
   {
     HANDLE hImagehelp = LoadLibrary ("imagehlp.dll");
-    DWORD  headersum;
-    DWORD  checksum;
+    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);
@@ -543,5 +542,3 @@ main (int argc, char **argv)
 
 /* eof */
 
-/* arch-tag: 17e2b0aa-8c17-4bd1-b24b-1cda689245fa
-   (do not change this comment) */