This is the mail archive of the cygwin-apps mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Ok, here's round 2. I've omitted rebase-dump-related changes for now, other than moving the db typedefs to rebase-db.[h,c] (*). (*) There's a .c because we probably need to have IMG_INFO_MAGIC and IMG_INFO_VERSION tightly coupled with rebase-db.h. So, since I already had the .c, I also moved the *_cmp() functions to rebase-db.[h,c]. It's possible load_image_info, save_image_info, and print_image_info could also be moved, but I think the needs of rebase.exe and rebase-dump.exe are different enough that I didn't bother right now. build-aux/config.guess: Add msys support. build-aux/config.sub: Add msys support. (Once again, whether to include these ^^^ changes, and fork config.*, is up to Jason). configure.ac: Specify -static-* and -D overrides, on a platform-sensitive basis, here rather than hardcoding in Makefile.in. Add strtoll.c to LIBOBJS for MSYS. imagehelper/Makefile.in: Instead of hardcoding -static-* and -D overrides here, use new platform-sensitive vars defined by configure. Makefile.in: Ditto. Also, add strtoll.c. imagehelper/rebase_main.cc: Fix bug in GetImageInfos64 call. Be explicit about CYGWIN vs MSYS. imagehelper/sections.h: Fix portability issues with stdint.h and uintptr_t. rebase.c: Handle missing inttypes.h on MSYS. Be explicit about CYGWIN vs MSYS. Move db typedefs and comparison functions to rebase-db.[c,h]. Use standard GPLv2+ text. (strtoull) [MSYS]: Declare missing function. (main) [MSYS]: Allow room for msys-1.0.dll, as with cygwin1.dll. (mkstemp) [MINGW]: Fix open flags. (load_image_info): Fix open flags (O_BINARY). Validate read() return value against requested number of bytes. (merge_image_info) [MSYS]: Skip msys-1.0.dll, as with cygwin1.dll. (parse_args) [MINGW]: Use program path to determine location of database. rebaseall.in: Add platform-specific code to handle msys shortcomings. Use standard GPLv2+ text. peflagsall.in: Ditto. peflags.c: Use standard GPLv2+ text. rebase-db.h: New file. rebase-db.c: New file. strtoll.c: New file. -- Chuck
Index: Makefile.in =================================================================== RCS file: /cvs/cygwin-apps/rebase/Makefile.in,v retrieving revision 1.6 diff -u -p -r1.6 Makefile.in --- Makefile.in 21 Jul 2011 19:10:04 -0000 1.6 +++ Makefile.in 24 Jul 2011 18:57:39 -0000 @@ -58,9 +58,10 @@ ASH = @ASH@ DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(srcdir)/imagehelper DEFS = @DEFS@ -DVERSION='"$(PACKAGE_VERSION)"' -DLIB_VERSION='"$(LIB_VERSION)"' -DSYSCONFDIR='"$(sysconfdir)"' -override CFLAGS+=-Wall -Werror -override CXXFLAGS+=-Wall -Werror -override LDFLAGS+=-static -static-libgcc +override CFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@ +override CXXFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@ +override LDFLAGS+=-static @EXTRA_LDFLAG_OVERRIDES@ +override CXX_LDFLAGS+=@EXTRA_CXX_LDFLAG_OVERRIDES@ .SUFFIXES: .SUFFIXES: .c .cc .$(O) @@ -73,7 +74,7 @@ override LDFLAGS+=-static -static-libgcc LIBIMAGEHELPER = imagehelper/libimagehelper.a -REBASE_OBJS = rebase.$(O) $(LIBOBJS) +REBASE_OBJS = rebase.$(O) rebase-db.$(O) $(LIBOBJS) REBASE_LIBS = $(LIBIMAGEHELPER) PEFLAGS_OBJS = peflags.$(O) $(LIBOBJS) @@ -85,15 +86,18 @@ SRC_DISTFILES = aclocal.m4 configure.ac build-aux/config.guess build-aux/config.sub \ build-aux/install-sh getopt.h_ getopt_long.c -all: libimagehelper rebase$(EXEEXT) peflags$(EXEEXT) rebaseall peflagsall +all: libimagehelper rebase$(EXEEXT) \ + peflags$(EXEEXT) rebaseall peflagsall libimagehelper: $(MAKE) -C imagehelper imagehelper rebase$(EXEEXT): $(REBASE_LIBS) $(REBASE_OBJS) - $(CXX) $(CXXFLAGS) $(LDFLAGS) -static-libstdc++ -o $@ $(REBASE_OBJS) $(REBASE_LIBS) + $(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_LDFLAGS) -o $@ $(REBASE_OBJS) $(REBASE_LIBS) -rebase.$(O):: rebase.c Makefile +rebase.$(O):: rebase.c rebase-db.h Makefile + +rebase-db.$(O):: rebase-db.c rebase-db.h Makefile peflags$(EXEEXT): $(PEFLAGS_OBJS) $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(PEFLAGS_OBJS) @@ -105,6 +109,8 @@ getopt.h: getopt.h_ getopt_long.$(O):: getopt_long.c getopt.h +strtoll.$(O):: strtoll.c + # Autoconf manual says "do not use AC_CONFIG_FILES to replace # bindir and friends in your shell scripts" edit = sed \ Index: configure.ac =================================================================== RCS file: /cvs/cygwin-apps/rebase/configure.ac,v retrieving revision 1.3 diff -u -p -r1.3 configure.ac --- configure.ac 28 Jun 2011 19:43:19 -0000 1.3 +++ configure.ac 24 Jul 2011 18:57:39 -0000 @@ -34,7 +34,8 @@ AC_CHECK_DECLS([cygwin_conv_path], [],[ LIBOBJS= case "$host" in - *msys* ) AC_LIBOBJ([getopt_long]) ;; + *msys* ) AC_LIBOBJ([getopt_long]) + AC_LIBOBJ([strtoll]) ;; esac AC_SUBST([LIBOBJS]) @@ -44,6 +45,24 @@ case "$host" in esac AC_SUBST(DEFAULT_OFFSET_VALUE) +case "$host" in + *msys* ) EXTRA_CFLAG_OVERRIDES= + EXTRA_LDFLAG_OVERRIDES="-static-libgcc" + EXTRA_CXX_LDFLAG_OVERRIDES= + ;; + *cygwin* ) EXTRA_CFLAG_OVERRIDES= + EXTRA_LDFLAG_OVERRIDES="-static-libgcc" + EXTRA_CXX_LDFLAG_OVERRIDES="-static-libstdc++" + ;; + *mingw* ) EXTRA_CFLAG_OVERRIDES="-D__USE_MINGW_ANSI_STDIO" + EXTRA_LDFLAG_OVERRIDES="-static-libgcc" + EXTRA_CXX_LDFLAG_OVERRIDES="-static-libstdc++" + ;; +esac +AC_SUBST(EXTRA_CFLAG_OVERRIDES) +AC_SUBST(EXTRA_LDFLAG_OVERRIDES) +AC_SUBST(EXTRA_CXX_LDFLAG_OVERRIDES) + AC_CONFIG_FILES([Makefile imagehelper/Makefile]) Index: peflags.c =================================================================== RCS file: /cvs/cygwin-apps/rebase/peflags.c,v retrieving revision 1.4 diff -u -p -r1.4 peflags.c --- peflags.c 21 Jun 2011 13:37:03 -0000 1.4 +++ peflags.c 24 Jul 2011 18:57:39 -0000 @@ -3,13 +3,20 @@ * Based on rebase.c by Jason Tishler * Significant contributions by Dave Korn * - * This program is free software; you can redistribute it and/or modify + * This program 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 2 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * See the COPYING file for full license information. */ #include <stdio.h> Index: peflagsall.in =================================================================== RCS file: /cvs/cygwin-apps/rebase/peflagsall.in,v retrieving revision 1.1 diff -u -p -r1.1 peflagsall.in --- peflagsall.in 20 Jun 2011 23:27:00 -0000 1.1 +++ peflagsall.in 24 Jul 2011 18:57:39 -0000 @@ -1,17 +1,23 @@ #!/bin/@ASH@ # -# Copyright (c) 2009 Charles Wilson +# Copyright (c) 2009,2011 Charles Wilson # Based on rebaseall by Jason Tishler # -# This program is free software; you can redistribute it and/or modify +# This program 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 2 of the License, or +# the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # -# A copy of the GNU General Public License can be found at -# http://www.gnu.org/ +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +# +# See the COPYING file for full license information. # Define constants tp1=${0%/*} @@ -131,9 +137,49 @@ ArgDynBase= # First see if caller requested help check_args_for_help "$@" +# Determine platform +Platform=`uname -s` +case $Platform in + *MINGW* | *mingw* ) Platform=mingw ;; + *CYGWIN* | *cygwin* ) Platform=cygwin ;; + *MSYS* | *msys* ) Platform=msys ;; + * ) + echo "Unsupported platform: $Platform" 1>&2 + exit 1 + ;; +esac + # Verify only ash or dash processes are running -grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename -if [ $? -eq 0 -a -z "$RebaseDebug" ] +ProcessResult=0 +case $Platform in + mingw|msys ) + /bin/ps -s | /bin/gawk '\ + # Count number of running ash or dash. \ + /\/bin\/(d)?ash(\.exe)?$/{ ash_cnt++; } \ + # Count number of ps and gawk. \ + /\/bin\/ps(\.exe)?$/{ cnt++; } \ + /\/bin\/gawk(\.exe)?$/{ cnt++; } \ + END{ \ + # Uncomment for testing: \ + # printf "TOTAL: %d CNT: %d ASH_CNT: %d\n", NR, cnt, ash_cnt; \ + # Only one of ps and gawk each may run. \ + if (cnt > 2) \ + exit 0; \ + # The total number of allowed processes is one less than the \ + # number of input lines. The extra line is the ps header output. \ + if (NR - cnt - ash_cnt > 1) \ + exit 0; \ + # All is well. \ + exit 1; \ + }' + ProcessResult=$? + ;; + cygwin ) + grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename + ProcessResult=$? + ;; +esac +if [ $ProcessResult -eq 0 -a -z "$RebaseDebug" ] then echo "$ProgramName: only ash or dash processes are allowed during this process." echo " Exit all Cygwin processes and stop all Cygwin services." @@ -209,10 +255,26 @@ ExeFile="$TmpDir/peflags_exe.lst" DllFile="$TmpDir/peflags_dll.lst" # Create file list -find /etc/setup -name '*.lst.gz' | xargs gzip -d -c | - grep -E "\.($Suffixes)\$" | - sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \ - -e 's/^/\//' -e '/d?ash\.exe$/d' -e '/peflags\.exe$/d' >"$TmpFile" +case $Platform in + cygwin) + find /etc/setup -name '*.lst.gz' | xargs gzip -d -c | + grep -E "\.($Suffixes)\$" | + sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \ + -e '/sys-root\/mingw/d' -e 's/^/\//' \ + -e '/d?ash\.exe$/d' -e '/peflags\.exe$/d' >"${TmpFile}" + ;; + msys) + for f in /bin /lib + do + find $f -type f | + grep -E "\.($Suffixes)\$" | + sed -e '/msys-1\.0.*\.dll$/d' -e '/cygwin1\.dll$/d' \ + -e '/cyglsa.*\.dll$/d' -e '/d?ash\.exe$/d' \ + -e '/peflags\.exe$/d' >>"$TmpFile" + done + ;; + mingw) ;; # no automatic files; only command line +esac # Append user supplied file list, if any if [ -n "$FileList" ] Index: rebase.c =================================================================== RCS file: /cvs/cygwin-apps/rebase/rebase.c,v retrieving revision 1.6 diff -u -p -r1.6 rebase.c --- rebase.c 21 Jul 2011 19:10:04 -0000 1.6 +++ rebase.c 24 Jul 2011 18:57:39 -0000 @@ -1,13 +1,20 @@ /* * Copyright (c) 2001, 2002, 2003, 2004, 2008, 2011 Jason Tishler * - * This program is free software; you can redistribute it and/or modify + * This program 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 2 of the License, or + * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * - * A copy of the GNU General Public License can be found at - * http://www.gnu.org/ + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * See the COPYING file for full license information. * * Written by Jason Tishler <jason@tishler.net> * @@ -17,6 +24,7 @@ #include <stdio.h> #include <time.h> #include <stdlib.h> +#include <limits.h> #include <sys/types.h> #include <sys/stat.h> #if defined(__CYGWIN__) || defined(__MSYS__) @@ -28,12 +36,15 @@ #include <locale.h> #include <getopt.h> #include <string.h> -#include <inttypes.h> +#if defined(__MSYS__) +/* MSYS has no inttypes.h */ +# define PRIx64 "llx" +#else +# include <inttypes.h> +#endif #include <errno.h> #include "imagehelper.h" - -#define roundup(x,y) ((((x) + ((y) - 1)) / (y)) * (y)) -#define roundup2(x,y) (((x) + (y) - 1) & ~((y) - 1)) +#include "rebase-db.h" BOOL save_image_info (); BOOL load_image_info (); @@ -51,6 +62,11 @@ char *file_list_fgets (char *buf, int si int file_list_fclose (FILE *file); void version (); +#if defined(__MSYS__) +/* MSYS has no strtoull */ +unsigned long long strtoull(const char *, char **, int); +#endif + #ifdef __x86_64__ WORD machine = IMAGE_FILE_MACHINE_AMD64; #else @@ -70,42 +86,8 @@ const char *stdin_file_list = "-"; const char *progname; -const char IMG_INFO_MAGIC[4] = "rBiI"; -const ULONG IMG_INFO_VERSION = 1; - ULONG ALLOCATION_SLOT; /* Allocation granularity. */ -#pragma pack (push, 4) - -typedef struct _img_info_hdr -{ - CHAR magic[4]; /* Always IMG_INFO_MAGIC. */ - WORD machine; /* IMAGE_FILE_MACHINE_I386/IMAGE_FILE_MACHINE_AMD64 */ - WORD version; /* Database version, always set to IMG_INFO_VERSION. */ - ULONG64 base; /* Base address (-b) used to generate database. */ - ULONG offset; /* Offset (-o) used to generate database. */ - BOOL down_flag; /* Always TRUE right now. */ - ULONG count; /* Number of img_info_t entries following header. */ -} img_info_hdr_t; - -typedef struct _img_info -{ - union { - PCHAR name; /* Absolute path to DLL. The strings are stored */ - ULONG64 _filler; /* right after the img_info_t table, in the same */ - }; /* order as the img_info_t entries. */ - ULONG name_size; /* Length of name string including trailing NUL. */ - ULONG64 base; /* Base address the DLL has been rebased to. */ - ULONG size; /* Size of the DLL at rebased time. */ - ULONG slot_size; /* Size of the DLL rounded to allocation granularity.*/ - struct { /* Flags */ - unsigned needs_rebasing : 1; /* Set to 0 in the database. Used only */ - /* while rebasing. */ - } flag; -} img_info_t; - -#pragma pack (pop) - img_info_t *img_info_list = NULL; unsigned int img_info_size = 0; unsigned int img_info_rebase_start = 0; @@ -122,13 +104,22 @@ unsigned int img_info_max_size = 0; #else #define IMG_INFO_FILE IMG_INFO_FILE_I386 #endif -char *db_file = IMG_INFO_FILE; -char tmp_file[] = SYSCONFDIR "/rebase.db.XXXXXX"; +char *DB_FILE = IMG_INFO_FILE; +char TMP_FILE[] = SYSCONFDIR "/rebase.db.XXXXXX"; +char *db_file = NULL; +char *tmp_file = NULL; -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) ULONG64 cygwin_dll_image_base = 0; ULONG cygwin_dll_image_size = 0; #endif +#if defined(__MSYS__) +# define CYGWIN_DLL "/usr/bin/msys-1.0.dll" +#elif defined (__CYGWIN__) +# define CYGWIN_DLL "/usr/bin/cygwin1.dll" +#endif + +#define LONG_PATH_MAX 32768 void gen_progname (const char *arg0) @@ -160,11 +151,17 @@ main (int argc, char *argv[]) if (image_storage_flag) { if (load_image_info () < 0) - return 2; + return 2; img_info_rebase_start = img_info_size; } -#ifdef __CYGWIN__ +#if defined(__MSYS__) + if (machine == IMAGE_FILE_MACHINE_I386) + { + GetImageInfos64 ("/bin/msys-1.0.dll", NULL, + &cygwin_dll_image_base, &cygwin_dll_image_size); + } +#elif defined(__CYGWIN__) if (machine == IMAGE_FILE_MACHINE_I386) { /* Fetch the Cygwin DLLs data to make sure that DLLs aren't rebased @@ -252,30 +249,13 @@ main (int argc, char *argv[]) return 0; } -int -img_info_cmp (const void *a, const void *b) -{ - ULONG64 abase = ((img_info_t *) a)->base; - ULONG64 bbase = ((img_info_t *) b)->base; - - if (abase < bbase) - return -1; - if (abase > bbase) - return 1; - return strcmp (((img_info_t *) a)->name, ((img_info_t *) b)->name); -} - -int -img_info_name_cmp (const void *a, const void *b) -{ - return strcmp (((img_info_t *) a)->name, ((img_info_t *) b)->name); -} - -#ifndef __CYGWIN__ +#if !defined(__CYGWIN__) && !defined(__MSYS__) int mkstemp (char *name) { - return open (mktemp (name), O_CREAT | O_TRUNC | O_EXCL, 0600); + return _open (mktemp (name), + O_RDWR | O_BINARY | O_CREAT | O_EXCL | O_TRUNC | _O_SHORT_LIVED, + _S_IREAD|_S_IWRITE); } #endif @@ -308,7 +288,7 @@ save_image_info () hdr.offset = offset; hdr.down_flag = down_flag; hdr.count = img_info_size; - if (write (fd, &hdr, sizeof hdr) < 0) + if (write (fd, &hdr, sizeof (hdr)) < 0) { fprintf (stderr, "%s: failed to write rebase database: %s\n", progname, strerror (errno)); @@ -336,7 +316,8 @@ save_image_info () break; } } -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) && !defined(__MSYS__) + /* fchmod is broken on msys */ fchmod (fd, 0660); #else chmod (tmp_file, 0660); @@ -384,19 +365,19 @@ load_image_info () int i; img_info_hdr_t hdr; - fd = open (db_file, O_RDONLY); + fd = open (db_file, O_RDONLY | O_BINARY); if (fd < 0) { /* It's no error if the file doesn't exist. However, in this case the -b option is mandatory. */ if (errno == ENOENT && image_base) - return 0; + return 0; fprintf (stderr, "%s: failed to open rebase database \"%s\":\n%s\n", progname, db_file, strerror (errno)); return -1; } /* First read the header. */ - if (read (fd, &hdr, sizeof hdr) < 0) + if (read (fd, &hdr, sizeof hdr) < sizeof hdr) { fprintf (stderr, "%s: failed to read rebase database \"%s\":\n%s\n", progname, db_file, strerror (errno)); @@ -464,7 +445,8 @@ load_image_info () } /* Now read the list. */ if (ret == 0 - && read (fd, img_info_list, img_info_size * sizeof (img_info_t)) < 0) + && read (fd, img_info_list, img_info_size * sizeof (img_info_t)) < + img_info_size * sizeof (img_info_t)) { fprintf (stderr, "%s: failed to read rebase database \"%s\":\n%s\n", progname, db_file, strerror (errno)); @@ -488,7 +470,8 @@ load_image_info () break; } if (read (fd, img_info_list[i].name, - img_info_list[i].name_size) < 0) + img_info_list[i].name_size) < + img_info_list[i].name_size) { fprintf (stderr, "%s: failed to read rebase database \"%s\": " "%s\n", progname, db_file, strerror (errno)); @@ -526,13 +509,13 @@ merge_image_info () for (i = img_info_rebase_start; i + 1 < img_info_size; ++i) if ((img_info_list[i].name_size == img_info_list[i + 1].name_size && !strcmp (img_info_list[i].name, img_info_list[i + 1].name)) -#ifdef __CYGWIN__ - || !strcmp (img_info_list[i].name, "/usr/bin/cygwin1.dll") +#if defined(__CYGWIN__) || defined(__MSYS__) + || !strcmp (img_info_list[i].name, CYGWIN_DLL) #endif ) { free (img_info_list[i].name); - memmove (img_info_list + i, img_info_list + i + 1, + memmove (img_info_list + i, img_info_list + i + 1, (img_info_size - i - 1) * sizeof (img_info_t)); --img_info_size; --i; @@ -606,7 +589,7 @@ merge_image_info () if (access (img_info_list[i].name, F_OK) == -1 || !GetImageInfos64 (img_info_list[i].name, NULL, &cur_base, &cur_size)) - { + { free (img_info_list[i].name); memmove (img_info_list + i, img_info_list + i + 1, (img_info_size - i - 1) * sizeof (img_info_t)); @@ -671,8 +654,8 @@ merge_image_info () new_base = floating_image_base - img_info_list[i].slot_size - offset; if (new_base >= img_info_list[end].base + img_info_list[end].slot_size -#ifdef __CYGWIN__ - /* Don't overlap the Cygwin DLL. */ +#if defined(__CYGWIN__) || defined(__MSYS__) + /* Don't overlap the Cygwin/MSYS DLL. */ && (new_base >= cygwin_dll_image_base + cygwin_dll_image_size || new_base + img_info_list[i].slot_size <= cygwin_dll_image_base) @@ -692,7 +675,7 @@ merge_image_info () } /* Nothing matches. Set floating_image_base to the start of the uppermost DLL at this point and try again. */ -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) if (floating_image_base >= cygwin_dll_image_base + cygwin_dll_image_size && img_info_list[end].base < cygwin_dll_image_base) floating_image_base = cygwin_dll_image_base; @@ -836,14 +819,14 @@ print_image_info () if (img_info_list[i].flag.needs_rebasing == 0) { free (img_info_list[i].name); - memmove (img_info_list + i, img_info_list + i + 1, + memmove (img_info_list + i, img_info_list + i + 1, (img_info_size - i - 1) * sizeof (img_info_t)); } else { free (img_info_list[i + 1].name); if (i + 2 < img_info_size) - memmove (img_info_list + i + 1, img_info_list + i + 2, + memmove (img_info_list + i + 1, img_info_list + i + 2, (img_info_size - i - 2) * sizeof (img_info_t)); } --img_info_size; @@ -913,7 +896,7 @@ rebase (const char *pathname, ULONG64 *n if (down_flag) *new_image_base -= offset; -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) retry: #endif @@ -972,7 +955,7 @@ retry: return FALSE; } -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) /* Avoid the case that a DLL is rebased into the address space taken by the Cygwin DLL. Only test in down_flag == TRUE case, otherwise the return value in new_image_base is not meaningful */ @@ -1033,11 +1016,11 @@ parse_args (int argc, char *argv[]) { case '4': machine = IMAGE_FILE_MACHINE_I386; - db_file = IMG_INFO_FILE_I386; + DB_FILE = IMG_INFO_FILE_I386; break; case '8': machine = IMAGE_FILE_MACHINE_AMD64; - db_file = IMG_INFO_FILE_AMD64; + DB_FILE = IMG_INFO_FILE_AMD64; break; case 'b': image_base = string_to_ulonglong (optarg); @@ -1090,6 +1073,69 @@ parse_args (int argc, char *argv[]) } args_index = optind; + + /* Initialize db_file and tmp_file from pattern */ +#if defined(__CYGWIN__) || defined(__MSYS__) + /* We don't explicitly free these, but (a) this function is only + * called once, and (b) we wouldn't free until exit() anyway, and + * that will happen automatically upon process cleanup. + */ + db_file = strdup(DB_FILE); + tmp_file = strdup(TMP_FILE); +#else + { + char exepath[LONG_PATH_MAX]; + char* p = NULL; + char* p2 = NULL; + size_t sz = 0; + + if (!GetModuleFileNameA (NULL, exepath, LONG_PATH_MAX)) + fprintf (stderr, "%s: can't determine rebase installation path\n", + progname); + + /* strip off exename and trailing slash */ + sz = strlen (exepath); + p = exepath + sz - 1; + while (p && (p > exepath) && (*p == '/' || *p == '\\')) + { + *p = '\0'; + p--; + } + p = strrchr(exepath, '/'); + p2 = strrchr(exepath, '\\'); + if (p || p2) + { + if (p2 > p) + p = p2; + if (p > exepath) + *p = '\0'; + else + { + p++; + *p = '\0'; + } + } + sz = strlen (exepath); + + /* We don't explicitly free these, but (a) this function is only + * called once, and (b) we wouldn't free until exit() anyway, and + * that will happen automatically upon process cleanup. + */ + db_file = (char *) calloc(sz + strlen(DB_FILE) + 1, sizeof(char)); + tmp_file = (char *) calloc(sz + strlen(TMP_FILE) + 1, sizeof(char)); + strcpy(db_file, exepath); + strcpy(&db_file[sz], DB_FILE); + strcpy(tmp_file, exepath); + strcpy(&tmp_file[sz], TMP_FILE); + + for (p = db_file; *p != '\0'; p++) + if (*p == '/') + *p = '\\'; + for (p = tmp_file; *p != '\0'; p++) + if (*p == '/') + *p = '\\'; + } +#endif } unsigned long long @@ -1252,3 +1298,4 @@ version () fprintf (stderr, "Copyright (c) 2001, 2002, 2003, 2004, 2008, 2011 " "Ralf Habacker, Jason Tishler, et al.\n"); } + Index: rebaseall.in =================================================================== RCS file: /cvs/cygwin-apps/rebase/rebaseall.in,v retrieving revision 1.4 diff -u -p -r1.4 rebaseall.in --- rebaseall.in 21 Jul 2011 19:10:04 -0000 1.4 +++ rebaseall.in 24 Jul 2011 18:57:39 -0000 @@ -3,13 +3,20 @@ # # Copyright (c) 2003, 2005, 2006, 2008, 2011 Jason Tishler # -# This program is free software; you can redistribute it and/or modify +# This program 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 2 of the License, or +# the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # -# A copy of the GNU General Public License can be found at -# http://www.gnu.org/ +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +# +# See the COPYING file for full license information. # # Written by Jason Tishler <jason@tishler.net> # @@ -64,9 +71,49 @@ case `uname -m` in ;; esac +# Determine platform +Platform=`uname -s` +case $Platform in + *MINGW* | *mingw* ) Platform=mingw ;; + *CYGWIN* | *cygwin* ) Platform=cygwin ;; + *MSYS* | *msys* ) Platform=msys ;; + * ) + echo "Unsupported platform: $Platform" 1>&2 + exit 1 + ;; +esac + # Verify only ash or dash processes are running -grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename -if [ $? -eq 0 -a -z "${RebaseDebug}" ] +ProcessResult=0 +case $Platform in + mingw|msys ) + /bin/ps -s | /bin/gawk '\ + # Count number of running ash or dash. \ + /\/bin\/(d)?ash(\.exe)?$/{ ash_cnt++; } \ + # Count number of ps and gawk. \ + /\/bin\/ps(\.exe)?$/{ cnt++; } \ + /\/bin\/gawk(\.exe)?$/{ cnt++; } \ + END{ \ + # Uncomment for testing: \ + # printf "TOTAL: %d CNT: %d ASH_CNT: %d\n", NR, cnt, ash_cnt; \ + # Only one of ps and gawk each may run. \ + if (cnt > 2) \ + exit 0; \ + # The total number of allowed processes is one less than the \ + # number of input lines. The extra line is the ps header output. \ + if (NR - cnt - ash_cnt > 1) \ + exit 0; \ + # All is well. \ + exit 1; \ + }' + ProcessResult=$? + ;; + cygwin ) + grep -E -q -i -v '/d?ash(.exe)?$' /proc/[0-9]*/exename + ProcessResult=$? + ;; +esac +if [ $ProcessResult -eq 0 -a -z "${RebaseDebug}" ] then echo "${ProgramName}: only ash or dash processes are allowed during rebasing" echo " Exit all Cygwin processes and stop all Cygwin services." @@ -139,11 +186,25 @@ fi TmpFile="$TmpDir/rebase.lst" # Create rebase list -find /etc/setup -name '*.lst.gz' | xargs gzip -d -c | - grep -E "\.($Suffixes)\$" | - sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \ - -e '/sys-root\/mingw/d' \ - -e 's/^/\//' -e '/d?ash\.exe$/d' -e '/rebase\.exe$/d' >"${TmpFile}" +case $Platform in + cygwin) + find /etc/setup -name '*.lst.gz' | xargs gzip -d -c | + grep -E "\.($Suffixes)\$" | + sed -e '/cygwin1\.dll$/d' -e '/cyglsa.*\.dll$/d' \ + -e '/sys-root\/mingw/d' -e 's/^/\//' \ + -e '/d?ash\.exe$/d' -e '/rebase\.exe$/d' >"${TmpFile}" + ;; + mingw|msys) + for f in /bin /lib + do + find $f -type f | + grep -E "\.($Suffixes)\$" | + sed -e '/msys-1\.0.*\.dll$/d' -e '/cygwin1\.dll$/d' \ + -e '/cyglsa.*\.dll$/d' -e '/d?ash\.exe$/d' \ + -e '/rebase\.exe$/d' >>"$TmpFile" + done + ;; +esac # Append user supplied file list, if any if [ -n "${FileList}" ] Index: build-aux/config.guess =================================================================== RCS file: /cvs/cygwin-apps/rebase/build-aux/config.guess,v retrieving revision 1.1 diff -u -p -r1.1 config.guess --- build-aux/config.guess 20 Jun 2011 23:27:01 -0000 1.1 +++ build-aux/config.guess 24 Jul 2011 18:57:39 -0000 @@ -803,6 +803,9 @@ EOF *:MINGW*:*) echo ${UNAME_MACHINE}-pc-mingw32 exit ;; + i*:MSYS*:*) + echo ${UNAME_MACHINE}-pc-msys + exit ;; i*:windows32*:*) # uname -m includes "-pc" on this system. echo ${UNAME_MACHINE}-mingw32 Index: build-aux/config.sub =================================================================== RCS file: /cvs/cygwin-apps/rebase/build-aux/config.sub,v retrieving revision 1.1 diff -u -p -r1.1 config.sub --- build-aux/config.sub 20 Jun 2011 23:27:01 -0000 1.1 +++ build-aux/config.sub 24 Jul 2011 18:57:39 -0000 @@ -771,6 +771,10 @@ case $basic_machine in ms1-*) basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'` ;; + msys) + basic_machine=i386-pc + os=-msys + ;; mvs) basic_machine=i370-ibm os=-mvs @@ -1293,7 +1297,7 @@ case $os in | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* \ - | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ + | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ | -mingw32* | -linux-gnu* | -linux-newlib* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ Index: imagehelper/Makefile.in =================================================================== RCS file: /cvs/cygwin-apps/rebase/imagehelper/Makefile.in,v retrieving revision 1.4 diff -u -p -r1.4 Makefile.in --- imagehelper/Makefile.in 21 Jun 2011 15:33:15 -0000 1.4 +++ imagehelper/Makefile.in 24 Jul 2011 18:57:39 -0000 @@ -54,8 +54,10 @@ FGREP = @FGREP@ DEFAULT_INCLUDES = -I. -I$(srcdir) DEFS = @DEFS@ -override CFLAGS+=-Wall -Werror -override CXXFLAGS+=-Wall -Werror +override CFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@ +override CXXFLAGS+=-Wall -Werror @EXTRA_CFLAG_OVERRIDES@ +override LDFLAGS+=-static @EXTRA_LDFLAG_OVERRIDES@ +override CXX_LDFLAGS+=@EXTRA_CXX_LDFLAG_OVERRIDES@ .SUFFIXES: .SUFFIXES: .c .cc .$(O) Index: imagehelper/rebase_main.cc =================================================================== RCS file: /cvs/cygwin-apps/rebase/imagehelper/rebase_main.cc,v retrieving revision 1.3 diff -u -p -r1.3 rebase_main.cc --- imagehelper/rebase_main.cc 8 Jul 2011 07:18:55 -0000 1.3 +++ imagehelper/rebase_main.cc 24 Jul 2011 18:57:39 -0000 @@ -25,7 +25,7 @@ #include <time.h> #include <stdlib.h> #include <getopt.h> -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) #include <sys/cygwin.h> #endif #include <windows.h> @@ -34,7 +34,7 @@ using namespace std; -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) || defined(__MSYS__) string PosixToWin32(const string& aPosixPath); #else #define PosixToWin32(aPosixPath) aPosixPath @@ -67,7 +67,7 @@ main(int argc, char* argv[]) { ULONG64 ImageBase; ULONG ImageSize; - GetImageInfos64(const_cast<LPSTR>(aFile.c_str()),&ImageBase,&ImageSize); + GetImageInfos64(const_cast<LPSTR>(aFile.c_str()),NULL,&ImageBase,&ImageSize); cout << aFile << ": " << "ImageBase: 0x" << hex << ImageBase << " ImageSize: 0x" << hex << ImageSize << endl; } else if (theCheckFlag) Index: imagehelper/sections.h =================================================================== RCS file: /cvs/cygwin-apps/rebase/imagehelper/sections.h,v retrieving revision 1.4 diff -u -p -r1.4 sections.h --- imagehelper/sections.h 8 Jul 2011 07:18:55 -0000 1.4 +++ imagehelper/sections.h 24 Jul 2011 18:57:39 -0000 @@ -23,6 +23,21 @@ #include <windows.h> +#if !defined(__CYGWIN__) || defined(__MSYS__) +/* MinGW|MSYS: mingw only defines uintptr_t for */ +/* MSVC 2005 or better, and MSYS doesn't have stdint.h */ +# ifndef _UINTPTR_T_DEFINED +# define _UINTPTR_T_DEFINED +# ifdef _WIN64 + typedef unsigned __int64 uintptr_t; +# else + typedef unsigned int uintptr_t; +# endif +# endif +#else +# include <stdint.h> +#endif + typedef unsigned int uint; typedef unsigned short ushort;
Attachment:
rebase-db.h
Description: Text document
Attachment:
rebase-db.c
Description: Text document
Attachment:
strtoll.c
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |