]> git.eshelyaron.com Git - emacs.git/commitdiff
Refactor by coalescing MAX_RW_COUNT definitions
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 20 Jul 2025 16:37:51 +0000 (09:37 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Jul 2025 08:11:40 +0000 (10:11 +0200)
* src/emacs.c (read_full):
Simplify by assuming MAX_RW_COUNT is defined.
* src/lisp.h (MAX_RW_COUNT): Move here from src/sysdep.c.
* src/pdumper.c (dump_read_all):
Use MAX_RW_COUNT rather than defining our own equivalent.

(cherry picked from commit 46314aef87fbda25e0a7fb5055624dc1c6e90ad9)

src/emacs.c
src/lisp.h
src/pdumper.c
src/sysdep.c

index cf8f4bd63f72587384a5577f62b574138f50a374..6e8ef83a81b4bb70be9f354f4fd2f3d0bc708ad4 100644 (file)
@@ -1120,16 +1120,7 @@ read_full (int fd, void *buffer, ptrdiff_t size)
   eassert (0 <= fd);
   eassert (buffer != NULL);
   eassert (0 <= size);
-  enum
-  {
-  /* See MAX_RW_COUNT in sysdep.c.  */
-#ifdef MAX_RW_COUNT
-    max_size = MAX_RW_COUNT
-#else
-    max_size = INT_MAX >> 18 << 18
-#endif
-  };
-  if (PTRDIFF_MAX < size || max_size < size)
+  if (max (PTRDIFF_MAX, MAX_RW_COUNT) < size)
     {
       errno = EFBIG;
       return -1;
index 452265139c575b8953ac5607e2bcf45e0b4fa81d..95dbe2b83c80e021b15ffe96c6dd73e0c31ea66d 100644 (file)
@@ -5297,6 +5297,17 @@ maybe_disable_address_randomization (int argc, char **argv)
   return argc;
 }
 #endif
+/* Maximum number of bytes to read or write in a single system call.
+   This works around a serious bug in Linux kernels before 2.6.16; see
+   <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>
+   and see Linux kernel commit e28cc71572da38a5a12c1cfe4d7032017adccf69.
+   It's likely to work around similar bugs in other operating systems, so do it
+   on all platforms.  Round INT_MAX down to a page size, with the conservative
+   assumption that page sizes are at most 2**18 bytes (any kernel with a
+   page size larger than that shouldn't have the bug).  */
+#ifndef MAX_RW_COUNT
+# define MAX_RW_COUNT (INT_MAX >> 18 << 18)
+#endif
 extern int emacs_exec_file (char const *, char *const *, char *const *);
 extern void init_standard_fds (void);
 extern char *emacs_get_current_dir_name (void);
index b3de90bfa03b3b7ef8ec4ad1f152a2b05971187a..c02808a4e3299ea9b51e75efd1a04b20c1996bdc 100644 (file)
@@ -5346,10 +5346,7 @@ dump_read_all (int fd, void *buf, size_t bytes_to_read)
   size_t bytes_read = 0;
   while (bytes_read < bytes_to_read)
     {
-      /* Some platforms accept only int-sized values to read.
-         Round this down to a page size (see MAX_RW_COUNT in sysdep.c).  */
-      int max_rw_count = INT_MAX >> 18 << 18;
-      int chunk_to_read = min (bytes_to_read - bytes_read, max_rw_count);
+      int chunk_to_read = min (bytes_to_read - bytes_read, MAX_RW_COUNT);
       ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read);
       if (chunk < 0)
         return chunk;
index fee068d541ff1e0bfcc2e9e3d2f244696b8222ca..d01cca1435d9572a92b10285fdb1a6f241c701c6 100644 (file)
@@ -2714,17 +2714,6 @@ emacs_fchmodat (int fd, const char *path, mode_t mode, int flags)
 #endif /* !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY) */
 }
 
-/* Maximum number of bytes to read or write in a single system call.
-   This works around a serious bug in Linux kernels before 2.6.16; see
-   <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>.
-   It's likely to work around similar bugs in other operating systems, so do it
-   on all platforms.  Round INT_MAX down to a page size, with the conservative
-   assumption that page sizes are at most 2**18 bytes (any kernel with a
-   page size larger than that shouldn't have the bug).  */
-#ifndef MAX_RW_COUNT
-#define MAX_RW_COUNT (INT_MAX >> 18 << 18)
-#endif
-
 /* Verify that MAX_RW_COUNT fits in the relevant standard types.  */
 #ifndef SSIZE_MAX
 # define SSIZE_MAX TYPE_MAXIMUM (ssize_t)