Mercurial > hg > xemacs-beta
comparison src/dumper.c @ 406:b8cc9ab3f761 r21-2-33
Import from CVS: tag r21-2-33
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:17:09 +0200 |
parents | 2f8bb876ab1d |
children | de805c49cfc1 |
comparison
equal
deleted
inserted
replaced
405:0e08f63c74d2 | 406:b8cc9ab3f761 |
---|---|
28 #include "elhash.h" | 28 #include "elhash.h" |
29 #include "sysfile.h" | 29 #include "sysfile.h" |
30 #include "console-stream.h" | 30 #include "console-stream.h" |
31 #include "dumper.h" | 31 #include "dumper.h" |
32 | 32 |
33 #ifdef WINDOWSNT | |
34 #define WINDOWS_LEAN_AND_MEAN | |
35 #include <windows.h> | |
36 #define PATH_MAX MAXPATHLEN | |
37 #else | |
33 #ifdef HAVE_MMAP | 38 #ifdef HAVE_MMAP |
34 #include <sys/mman.h> | 39 #include <sys/mman.h> |
40 #endif | |
35 #endif | 41 #endif |
36 | 42 |
37 #ifndef SEPCHAR | 43 #ifndef SEPCHAR |
38 #define SEPCHAR ':' | 44 #define SEPCHAR ':' |
39 #endif | 45 #endif |
98 int nb_opaquedmp; | 104 int nb_opaquedmp; |
99 } dump_header; | 105 } dump_header; |
100 | 106 |
101 char *pdump_start, *pdump_end; | 107 char *pdump_start, *pdump_end; |
102 static size_t pdump_length; | 108 static size_t pdump_length; |
109 | |
110 #ifdef WINDOWSNT | |
111 // Handle for the dump file | |
112 HANDLE pdump_hFile = INVALID_HANDLE_VALUE; | |
113 // Handle for the file mapping object for the dump file | |
114 HANDLE pdump_hMap = INVALID_HANDLE_VALUE; | |
115 #endif | |
116 | |
103 void (*pdump_free) (void); | 117 void (*pdump_free) (void); |
104 | 118 |
105 static const unsigned char align_table[256] = | 119 static const unsigned char align_table[256] = |
106 { | 120 { |
107 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, | 121 8, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, |
1095 | 1109 |
1096 return 1; | 1110 return 1; |
1097 } | 1111 } |
1098 | 1112 |
1099 #ifdef WINDOWSNT | 1113 #ifdef WINDOWSNT |
1114 /* Free the mapped file if we decide we don't want it after all */ | |
1100 static void pdump_file_unmap(void) | 1115 static void pdump_file_unmap(void) |
1101 { | 1116 { |
1117 UnmapViewOfFile (pdump_start); | |
1118 CloseHandle (pdump_hFile); | |
1119 CloseHandle (pdump_hMap); | |
1102 } | 1120 } |
1103 | 1121 |
1104 static int pdump_file_get(const char *path) | 1122 static int pdump_file_get(const char *path) |
1105 { | 1123 { |
1106 HANDLE hFile; | 1124 |
1107 HANDLE hMap; | 1125 pdump_hFile = CreateFile (path, |
1108 | 1126 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */ |
1109 hFile = CreateFile (path, | 1127 0, /* Not shared */ |
1110 GENERIC_READ + GENERIC_WRITE, /* Required for copy on write */ | 1128 NULL, /* Not inheritable */ |
1111 0, /* Not shared */ | 1129 OPEN_EXISTING, |
1112 NULL, /* Not inheritable */ | 1130 FILE_ATTRIBUTE_NORMAL, |
1113 OPEN_EXISTING, | 1131 NULL); /* No template file */ |
1114 FILE_ATTRIBUTE_NORMAL, | 1132 if (pdump_hFile == INVALID_HANDLE_VALUE) |
1115 NULL); /* No template file */ | |
1116 if (hFile == INVALID_HANDLE_VALUE) | |
1117 return 0; | 1133 return 0; |
1118 | 1134 |
1119 pdump_length = GetFileSize (hFile, NULL); | 1135 pdump_length = GetFileSize (pdump_hFile, NULL); |
1120 hMap = CreateFileMapping (hFile, | 1136 pdump_hMap = CreateFileMapping (pdump_hFile, |
1121 NULL, /* No security attributes */ | 1137 NULL, /* No security attributes */ |
1122 PAGE_WRITECOPY, /* Copy on write */ | 1138 PAGE_WRITECOPY, /* Copy on write */ |
1123 0, /* Max size, high half */ | 1139 0, /* Max size, high half */ |
1124 0, /* Max size, low half */ | 1140 0, /* Max size, low half */ |
1125 NULL); /* Unnamed */ | 1141 NULL); /* Unnamed */ |
1126 if (hMap == INVALID_HANDLE_VALUE) | 1142 if (pdump_hMap == INVALID_HANDLE_VALUE) |
1127 return 0; | 1143 return 0; |
1128 | 1144 |
1129 pdump_start = MapViewOfFile (hMap, | 1145 pdump_start = MapViewOfFile (pdump_hMap, |
1130 FILE_MAP_COPY, /* Copy on write */ | 1146 FILE_MAP_COPY, /* Copy on write */ |
1131 0, /* Start at zero */ | 1147 0, /* Start at zero */ |
1132 0, | 1148 0, |
1133 0); /* Map all of it */ | 1149 0); /* Map all of it */ |
1134 pdump_free = pdump_file_unmap; | 1150 pdump_free = pdump_file_unmap; |
1135 return 1; | 1151 return 1; |
1136 } | 1152 } |
1137 | 1153 |
1154 /* pdump_resource_free is called (via the pdump_free pointer) to release | |
1155 any resources allocated by pdump_resource_get. Since the Windows API | |
1156 specs specifically state that you don't need to (and shouldn't) free the | |
1157 resources allocated by FindResource, LoadResource, and LockResource this | |
1158 routine does nothing. */ | |
1138 static void pdump_resource_free (void) | 1159 static void pdump_resource_free (void) |
1160 { | |
1161 } | |
1162 | |
1139 static int pdump_resource_get (void) | 1163 static int pdump_resource_get (void) |
1140 { | 1164 { |
1141 HRSRC hRes; /* Handle to dump resource */ | 1165 HRSRC hRes; /* Handle to dump resource */ |
1142 HRSRC hResLoad; /* Handle to loaded dump resource */ | 1166 HRSRC hResLoad; /* Handle to loaded dump resource */ |
1143 | 1167 |
1266 } | 1290 } |
1267 | 1291 |
1268 int pdump_load(const char *argv0) | 1292 int pdump_load(const char *argv0) |
1269 { | 1293 { |
1270 char exe_path[PATH_MAX]; | 1294 char exe_path[PATH_MAX]; |
1295 #ifdef WINDOWSNT | |
1296 GetModuleFileName (NULL, exe_path, PATH_MAX); | |
1297 #else /* !WINDOWSNT */ | |
1271 char *w; | 1298 char *w; |
1272 #ifdef WINDOWSNT | |
1273 GetModuleFileName (NULL, exe_name, PATH_MAX); | |
1274 #else /* !WINDOWSNT */ | |
1275 const char *dir, *p; | 1299 const char *dir, *p; |
1276 | 1300 |
1277 dir = argv0; | 1301 dir = argv0; |
1278 if (dir[0] == '-') | 1302 if (dir[0] == '-') |
1279 { | 1303 { |