aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-04-09 15:42:10 -0700
committerPaul Eggert2019-04-09 15:43:35 -0700
commite44ff2de819ead77b00c7fb4ede75ada685ff099 (patch)
treeb6601cd73ce266584f862cbad98e2a11fe143492
parent44a39e3e761c0774cd1bb9360db7f49e1d66ec06 (diff)
downloademacs-e44ff2de819ead77b00c7fb4ede75ada685ff099.tar.gz
emacs-e44ff2de819ead77b00c7fb4ede75ada685ff099.zip
Remove assumption of uint64_t etc. in portable code
C11 doesn’t guarantee the existence of types like uint64_t, so avoid these types in portable code, as it’s easy to do so. There’s no need to avoid the types in w32-specific code, since w32 is guaranteed to have them. * lib-src/make-fingerprint.c (main): * src/fingerprint-dummy.c: * src/fingerprint.h: * src/pdumper.c (dump_fingerprint, struct dump_header): Prefer unsigned char to uint8_t in portable code, as either will do. Put an "#include <config.h>" in fingerprint.c files, so that the corresponding .o file is rebuilt after ./configure is run. * lib-src/make-fingerprint.c (main): Simplify loop. * src/Makefile.in (fingerprint.c): Update atomically. * src/pdumper.c: Omit unnecessary check that off_t is the same size as int32_t or int64_t, as the code does not rely on this assumption. (dump_off): Use int_least32_t, not int32_t. (struct dump_reloc): Use unsigned int, not uint32_t. (dump_anonymous_allocate_w32, dump_anonymous_allocate_posix) (dump_anonymous_allocate, dump_map_file_w32, dump_map_file_posix) (dump_map_file: Do the sanity checks at compile time, not at run-time, to avoid usage of uint64_t etc. on non-w32 platforms.
-rw-r--r--lib-src/make-fingerprint.c12
-rw-r--r--src/Makefile.in4
-rw-r--r--src/fingerprint-dummy.c4
-rw-r--r--src/fingerprint.h4
-rw-r--r--src/pdumper.c93
5 files changed, 47 insertions, 70 deletions
diff --git a/lib-src/make-fingerprint.c b/lib-src/make-fingerprint.c
index d310366442d..4bfeaa0742c 100644
--- a/lib-src/make-fingerprint.c
+++ b/lib-src/make-fingerprint.c
@@ -89,7 +89,7 @@ main (int argc, char **argv)
89 fclose (f); 89 fclose (f);
90 } 90 }
91 91
92 uint8_t digest[32]; 92 unsigned char digest[32];
93 sha256_finish_ctx (&ctx, digest); 93 sha256_finish_ctx (&ctx, digest);
94 94
95 if (raw) 95 if (raw)
@@ -99,12 +99,12 @@ main (int argc, char **argv)
99 } 99 }
100 else 100 else
101 { 101 {
102 printf ("#include \"fingerprint.h\"\n"); 102 puts ("#include <config.h>\n"
103 printf ("\n"); 103 "#include \"fingerprint.h\"\n"
104 printf ("const uint8_t fingerprint[32] = { "); 104 "unsigned char const fingerprint[] = {");
105 for (int i = 0; i < 32; ++i) 105 for (int i = 0; i < 32; ++i)
106 printf ("%s0x%02X", i ? ", " : "", digest[i]); 106 printf ("\t0x%02X,\n", digest[i]);
107 printf (" };\n"); 107 puts ("};");
108 } 108 }
109 109
110 return EXIT_SUCCESS; 110 return EXIT_SUCCESS;
diff --git a/src/Makefile.in b/src/Makefile.in
index 10b2da319b2..0613a0dbed4 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -629,7 +629,9 @@ $(libsrc)/make-fingerprint$(EXEEXT): $(libsrc)/make-fingerprint.c $(lib)/libgnu.
629 $(MAKE) -C $(libsrc) make-fingerprint$(EXEEXT) 629 $(MAKE) -C $(libsrc) make-fingerprint$(EXEEXT)
630 630
631fingerprint.c: temacs.in$(EXEEXT) $(libsrc)/make-fingerprint$(EXEEXT) 631fingerprint.c: temacs.in$(EXEEXT) $(libsrc)/make-fingerprint$(EXEEXT)
632 $(libsrc)/make-fingerprint$(EXEEXT) temacs.in$(EXEEXT) > fingerprint.c 632 $(AM_V_GEN)$(libsrc)/make-fingerprint$(EXEEXT) temacs.in$(EXEEXT) \
633 >$@.tmp
634 $(AM_V_at)mv $@.tmp $@
633 635
634## We have to create $(etc) here because init_cmdargs tests its 636## We have to create $(etc) here because init_cmdargs tests its
635## existence when setting Vinstallation_directory (FIXME?). 637## existence when setting Vinstallation_directory (FIXME?).
diff --git a/src/fingerprint-dummy.c b/src/fingerprint-dummy.c
index 1603519783e..04938bd1d08 100644
--- a/src/fingerprint-dummy.c
+++ b/src/fingerprint-dummy.c
@@ -17,7 +17,9 @@ GNU General Public License for more details.
17You should have received a copy of the GNU General Public License 17You should have received a copy of the GNU General Public License
18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 18along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20#include <config.h>
21
20#include "fingerprint.h" 22#include "fingerprint.h"
21 23
22/* Dummy fingerprint to use as hash input. */ 24/* Dummy fingerprint to use as hash input. */
23const uint8_t fingerprint[32] = { 0 }; 25unsigned char const fingerprint[32] = { 0 };
diff --git a/src/fingerprint.h b/src/fingerprint.h
index 913b668b4e0..0b195fd0ca7 100644
--- a/src/fingerprint.h
+++ b/src/fingerprint.h
@@ -20,12 +20,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20#ifndef EMACS_FINGERPRINT_H 20#ifndef EMACS_FINGERPRINT_H
21#define EMACS_FINGERPRINT_H 21#define EMACS_FINGERPRINT_H
22 22
23#include <stdint.h>
24
25/* We generate fingerprint.c and fingerprint.o from all the sources in 23/* We generate fingerprint.c and fingerprint.o from all the sources in
26 Emacs. This way, we have a unique value that we can use to pair 24 Emacs. This way, we have a unique value that we can use to pair
27 data files (like a portable dump image) with a specific build of 25 data files (like a portable dump image) with a specific build of
28 Emacs. */ 26 Emacs. */
29extern const uint8_t fingerprint[32]; 27extern unsigned char const fingerprint[32];
30 28
31#endif 29#endif
diff --git a/src/pdumper.c b/src/pdumper.c
index 68c412d47cd..3aa941221db 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -123,8 +123,6 @@ verify (sizeof (intptr_t) == sizeof (ptrdiff_t));
123verify (sizeof (void (*)(void)) == sizeof (void *)); 123verify (sizeof (void (*)(void)) == sizeof (void *));
124verify (sizeof (ptrdiff_t) <= sizeof (Lisp_Object)); 124verify (sizeof (ptrdiff_t) <= sizeof (Lisp_Object));
125verify (sizeof (ptrdiff_t) <= sizeof (EMACS_INT)); 125verify (sizeof (ptrdiff_t) <= sizeof (EMACS_INT));
126verify (sizeof (off_t) == sizeof (int32_t)
127 || sizeof (off_t) == sizeof (int64_t));
128verify (CHAR_BIT == 8); 126verify (CHAR_BIT == 8);
129 127
130#define DIVIDE_ROUND_UP(x, y) (((x) + (y) - 1) / (y)) 128#define DIVIDE_ROUND_UP(x, y) (((x) + (y) - 1) / (y))
@@ -145,9 +143,9 @@ static struct
145} remembered_data[32]; 143} remembered_data[32];
146static int nr_remembered_data = 0; 144static int nr_remembered_data = 0;
147 145
148typedef int32_t dump_off; 146typedef int_least32_t dump_off;
149#define DUMP_OFF_MIN INT32_MIN 147#define DUMP_OFF_MIN INT_LEAST32_MIN
150#define DUMP_OFF_MAX INT32_MAX 148#define DUMP_OFF_MAX INT_LEAST32_MAX
151 149
152__attribute__((format (printf,1,2))) 150__attribute__((format (printf,1,2)))
153static void 151static void
@@ -290,10 +288,10 @@ verify (DUMP_ALIGNMENT >= GCALIGNMENT);
290 288
291struct dump_reloc 289struct dump_reloc
292{ 290{
293 uint32_t raw_offset : DUMP_RELOC_OFFSET_BITS; 291 unsigned int raw_offset : DUMP_RELOC_OFFSET_BITS;
294 ENUM_BF (dump_reloc_type) type : DUMP_RELOC_TYPE_BITS; 292 ENUM_BF (dump_reloc_type) type : DUMP_RELOC_TYPE_BITS;
295}; 293};
296verify (sizeof (struct dump_reloc) == sizeof (int32_t)); 294verify (sizeof (struct dump_reloc) == sizeof (dump_off));
297 295
298/* Set the type of a dump relocation. 296/* Set the type of a dump relocation.
299 297
@@ -323,7 +321,7 @@ dump_reloc_set_offset (struct dump_reloc *reloc, dump_off offset)
323} 321}
324 322
325static void 323static void
326dump_fingerprint (const char *label, const uint8_t *xfingerprint) 324dump_fingerprint (const char *label, unsigned char const *xfingerprint)
327{ 325{
328 fprintf (stderr, "%s: ", label); 326 fprintf (stderr, "%s: ", label);
329 for (int i = 0; i < 32; ++i) 327 for (int i = 0; i < 32; ++i)
@@ -354,7 +352,7 @@ struct dump_header
354 char magic[sizeof (dump_magic)]; 352 char magic[sizeof (dump_magic)];
355 353
356 /* Associated Emacs binary. */ 354 /* Associated Emacs binary. */
357 uint8_t fingerprint[32]; 355 unsigned char fingerprint[32];
358 356
359 /* Relocation table for the dump file; each entry is a 357 /* Relocation table for the dump file; each entry is a
360 struct dump_reloc. */ 358 struct dump_reloc. */
@@ -4230,17 +4228,12 @@ enum dump_memory_protection
4230 DUMP_MEMORY_ACCESS_READWRITE = 3, 4228 DUMP_MEMORY_ACCESS_READWRITE = 3,
4231}; 4229};
4232 4230
4231#if VM_SUPPORTED == VM_MS_WINDOWS
4233static void * 4232static void *
4234dump_anonymous_allocate_w32 (void *base, 4233dump_anonymous_allocate_w32 (void *base,
4235 size_t size, 4234 size_t size,
4236 enum dump_memory_protection protection) 4235 enum dump_memory_protection protection)
4237{ 4236{
4238#if VM_SUPPORTED != VM_MS_WINDOWS
4239 (void) base;
4240 (void) size;
4241 (void) protection;
4242 emacs_abort ();
4243#else
4244 void *ret; 4237 void *ret;
4245 DWORD mem_type; 4238 DWORD mem_type;
4246 DWORD mem_prot; 4239 DWORD mem_prot;
@@ -4269,26 +4262,22 @@ dump_anonymous_allocate_w32 (void *base,
4269 ? EBUSY 4262 ? EBUSY
4270 : EPERM; 4263 : EPERM;
4271 return ret; 4264 return ret;
4272#endif
4273} 4265}
4266#endif
4267
4268#if VM_SUPPORTED == VM_POSIX
4274 4269
4275/* Old versions of macOS only define MAP_ANON, not MAP_ANONYMOUS. 4270/* Old versions of macOS only define MAP_ANON, not MAP_ANONYMOUS.
4276 FIXME: This probably belongs elsewhere (gnulib/autoconf?) */ 4271 FIXME: This probably belongs elsewhere (gnulib/autoconf?) */
4277#ifndef MAP_ANONYMOUS 4272# ifndef MAP_ANONYMOUS
4278#define MAP_ANONYMOUS MAP_ANON 4273# define MAP_ANONYMOUS MAP_ANON
4279#endif 4274# endif
4280 4275
4281static void * 4276static void *
4282dump_anonymous_allocate_posix (void *base, 4277dump_anonymous_allocate_posix (void *base,
4283 size_t size, 4278 size_t size,
4284 enum dump_memory_protection protection) 4279 enum dump_memory_protection protection)
4285{ 4280{
4286#if VM_SUPPORTED != VM_POSIX
4287 (void) base;
4288 (void) size;
4289 (void) protection;
4290 emacs_abort ();
4291#else
4292 void *ret; 4281 void *ret;
4293 int mem_prot; 4282 int mem_prot;
4294 4283
@@ -4333,8 +4322,8 @@ dump_anonymous_allocate_posix (void *base,
4333 if (ret == MAP_FAILED) 4322 if (ret == MAP_FAILED)
4334 ret = NULL; 4323 ret = NULL;
4335 return ret; 4324 return ret;
4336#endif
4337} 4325}
4326#endif
4338 4327
4339/* Perform anonymous memory allocation. */ 4328/* Perform anonymous memory allocation. */
4340static void * 4329static void *
@@ -4342,14 +4331,14 @@ dump_anonymous_allocate (void *base,
4342 const size_t size, 4331 const size_t size,
4343 enum dump_memory_protection protection) 4332 enum dump_memory_protection protection)
4344{ 4333{
4345 void *ret = NULL; 4334#if VM_SUPPORTED == VM_POSIX
4346 if (VM_SUPPORTED == VM_MS_WINDOWS) 4335 return dump_anonymous_allocate_posix (base, size, protection);
4347 ret = dump_anonymous_allocate_w32 (base, size, protection); 4336#elif VM_SUPPORTED == VM_MS_WINDOWS
4348 else if (VM_SUPPORTED == VM_POSIX) 4337 return dump_anonymous_allocate_w32 (base, size, protection);
4349 ret = dump_anonymous_allocate_posix (base, size, protection); 4338#else
4350 else 4339 errno = ENOSYS;
4351 errno = ENOSYS; 4340 return NULL;
4352 return ret; 4341#endif
4353} 4342}
4354 4343
4355/* Undo the effect of dump_reserve_address_space(). */ 4344/* Undo the effect of dump_reserve_address_space(). */
@@ -4371,18 +4360,11 @@ dump_anonymous_release (void *addr, size_t size)
4371#endif 4360#endif
4372} 4361}
4373 4362
4363#if VM_SUPPORTED == VM_MS_WINDOWS
4374static void * 4364static void *
4375dump_map_file_w32 (void *base, int fd, off_t offset, size_t size, 4365dump_map_file_w32 (void *base, int fd, off_t offset, size_t size,
4376 enum dump_memory_protection protection) 4366 enum dump_memory_protection protection)
4377{ 4367{
4378#if VM_SUPPORTED != VM_MS_WINDOWS
4379 (void) base;
4380 (void) fd;
4381 (void) offset;
4382 (void) size;
4383 (void) protection;
4384 emacs_abort ();
4385#else
4386 void *ret = NULL; 4368 void *ret = NULL;
4387 HANDLE section = NULL; 4369 HANDLE section = NULL;
4388 HANDLE file; 4370 HANDLE file;
@@ -4437,21 +4419,14 @@ dump_map_file_w32 (void *base, int fd, off_t offset, size_t size,
4437 if (section && !CloseHandle (section)) 4419 if (section && !CloseHandle (section))
4438 emacs_abort (); 4420 emacs_abort ();
4439 return ret; 4421 return ret;
4440#endif
4441} 4422}
4423#endif
4442 4424
4425#if VM_SUPPORTED == VM_POSIX
4443static void * 4426static void *
4444dump_map_file_posix (void *base, int fd, off_t offset, size_t size, 4427dump_map_file_posix (void *base, int fd, off_t offset, size_t size,
4445 enum dump_memory_protection protection) 4428 enum dump_memory_protection protection)
4446{ 4429{
4447#if VM_SUPPORTED != VM_POSIX
4448 (void) base;
4449 (void) fd;
4450 (void) offset;
4451 (void) size;
4452 (void) protection;
4453 emacs_abort ();
4454#else
4455 void *ret; 4430 void *ret;
4456 int mem_prot; 4431 int mem_prot;
4457 int mem_flags; 4432 int mem_flags;
@@ -4481,22 +4456,22 @@ dump_map_file_posix (void *base, int fd, off_t offset, size_t size,
4481 if (ret == MAP_FAILED) 4456 if (ret == MAP_FAILED)
4482 ret = NULL; 4457 ret = NULL;
4483 return ret; 4458 return ret;
4484#endif
4485} 4459}
4460#endif
4486 4461
4487/* Map a file into memory. */ 4462/* Map a file into memory. */
4488static void * 4463static void *
4489dump_map_file (void *base, int fd, off_t offset, size_t size, 4464dump_map_file (void *base, int fd, off_t offset, size_t size,
4490 enum dump_memory_protection protection) 4465 enum dump_memory_protection protection)
4491{ 4466{
4492 void *ret = NULL; 4467#if VM_SUPPORTED == VM_POSIX
4493 if (VM_SUPPORTED == VM_MS_WINDOWS) 4468 return dump_map_file_posix (base, fd, offset, size, protection);
4494 ret = dump_map_file_w32 (base, fd, offset, size, protection); 4469#elif VM_SUPPORTED == VM_MS_WINDOWS
4495 else if (VM_SUPPORTED == VM_POSIX) 4470 return dump_map_file_w32 (base, fd, offset, size, protection);
4496 ret = dump_map_file_posix (base, fd, offset, size, protection); 4471#else
4497 else 4472 errno = ENOSYS;
4498 errno = ENOSYS;
4499 return ret; 4473 return ret;
4474#endif
4500} 4475}
4501 4476
4502/* Remove a virtual memory mapping. 4477/* Remove a virtual memory mapping.