aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2025-07-20 09:37:51 -0700
committerPaul Eggert2025-07-21 16:23:18 -0700
commit46314aef87fbda25e0a7fb5055624dc1c6e90ad9 (patch)
tree9cfc0629176b5b655d07b112f0f06041fe2167a7 /src
parentaaf9c5213f7102dca8da7b6aaf1d400419eda075 (diff)
downloademacs-46314aef87fbda25e0a7fb5055624dc1c6e90ad9.tar.gz
emacs-46314aef87fbda25e0a7fb5055624dc1c6e90ad9.zip
Refactor by coalescing MAX_RW_COUNT definitions
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c11
-rw-r--r--src/lisp.h11
-rw-r--r--src/pdumper.c5
-rw-r--r--src/sysdep.c11
4 files changed, 13 insertions, 25 deletions
diff --git a/src/emacs.c b/src/emacs.c
index cf8f4bd63f7..6e8ef83a81b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1120,16 +1120,7 @@ read_full (int fd, void *buffer, ptrdiff_t size)
1120 eassert (0 <= fd); 1120 eassert (0 <= fd);
1121 eassert (buffer != NULL); 1121 eassert (buffer != NULL);
1122 eassert (0 <= size); 1122 eassert (0 <= size);
1123 enum 1123 if (max (PTRDIFF_MAX, MAX_RW_COUNT) < size)
1124 {
1125 /* See MAX_RW_COUNT in sysdep.c. */
1126#ifdef MAX_RW_COUNT
1127 max_size = MAX_RW_COUNT
1128#else
1129 max_size = INT_MAX >> 18 << 18
1130#endif
1131 };
1132 if (PTRDIFF_MAX < size || max_size < size)
1133 { 1124 {
1134 errno = EFBIG; 1125 errno = EFBIG;
1135 return -1; 1126 return -1;
diff --git a/src/lisp.h b/src/lisp.h
index 605255dfaaa..b89a4647725 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -5297,6 +5297,17 @@ maybe_disable_address_randomization (int argc, char **argv)
5297 return argc; 5297 return argc;
5298} 5298}
5299#endif 5299#endif
5300/* Maximum number of bytes to read or write in a single system call.
5301 This works around a serious bug in Linux kernels before 2.6.16; see
5302 <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>
5303 and see Linux kernel commit e28cc71572da38a5a12c1cfe4d7032017adccf69.
5304 It's likely to work around similar bugs in other operating systems, so do it
5305 on all platforms. Round INT_MAX down to a page size, with the conservative
5306 assumption that page sizes are at most 2**18 bytes (any kernel with a
5307 page size larger than that shouldn't have the bug). */
5308#ifndef MAX_RW_COUNT
5309# define MAX_RW_COUNT (INT_MAX >> 18 << 18)
5310#endif
5300extern int emacs_exec_file (char const *, char *const *, char *const *); 5311extern int emacs_exec_file (char const *, char *const *, char *const *);
5301extern void init_standard_fds (void); 5312extern void init_standard_fds (void);
5302extern char *emacs_get_current_dir_name (void); 5313extern char *emacs_get_current_dir_name (void);
diff --git a/src/pdumper.c b/src/pdumper.c
index b3de90bfa03..c02808a4e32 100644
--- a/src/pdumper.c
+++ b/src/pdumper.c
@@ -5346,10 +5346,7 @@ dump_read_all (int fd, void *buf, size_t bytes_to_read)
5346 size_t bytes_read = 0; 5346 size_t bytes_read = 0;
5347 while (bytes_read < bytes_to_read) 5347 while (bytes_read < bytes_to_read)
5348 { 5348 {
5349 /* Some platforms accept only int-sized values to read. 5349 int chunk_to_read = min (bytes_to_read - bytes_read, MAX_RW_COUNT);
5350 Round this down to a page size (see MAX_RW_COUNT in sysdep.c). */
5351 int max_rw_count = INT_MAX >> 18 << 18;
5352 int chunk_to_read = min (bytes_to_read - bytes_read, max_rw_count);
5353 ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read); 5350 ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read);
5354 if (chunk < 0) 5351 if (chunk < 0)
5355 return chunk; 5352 return chunk;
diff --git a/src/sysdep.c b/src/sysdep.c
index fee068d541f..d01cca1435d 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2714,17 +2714,6 @@ emacs_fchmodat (int fd, const char *path, mode_t mode, int flags)
2714#endif /* !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY) */ 2714#endif /* !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY) */
2715} 2715}
2716 2716
2717/* Maximum number of bytes to read or write in a single system call.
2718 This works around a serious bug in Linux kernels before 2.6.16; see
2719 <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>.
2720 It's likely to work around similar bugs in other operating systems, so do it
2721 on all platforms. Round INT_MAX down to a page size, with the conservative
2722 assumption that page sizes are at most 2**18 bytes (any kernel with a
2723 page size larger than that shouldn't have the bug). */
2724#ifndef MAX_RW_COUNT
2725#define MAX_RW_COUNT (INT_MAX >> 18 << 18)
2726#endif
2727
2728/* Verify that MAX_RW_COUNT fits in the relevant standard types. */ 2717/* Verify that MAX_RW_COUNT fits in the relevant standard types. */
2729#ifndef SSIZE_MAX 2718#ifndef SSIZE_MAX
2730# define SSIZE_MAX TYPE_MAXIMUM (ssize_t) 2719# define SSIZE_MAX TYPE_MAXIMUM (ssize_t)