|
@@ -115,7 +115,7 @@ SecureZeroMemory(PVOID ptr, SIZE_T cnt)
|
|
|
#ifdef HAVE_SIGNAL_H
|
|
|
#include <signal.h>
|
|
|
#endif
|
|
|
-#ifdef HAVE_SYS_MMAN_H
|
|
|
+#ifdef HAVE_MMAP
|
|
|
#include <sys/mman.h>
|
|
|
#endif
|
|
|
#ifdef HAVE_SYS_SYSLIMITS_H
|
|
@@ -203,25 +203,17 @@ tor_rename(const char *path_old, const char *path_new)
|
|
|
sandbox_intern_string(path_new));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- * Other configs rename the symbols using macros (including getpagesize).
|
|
|
- * So check for sys/mman.h and unistd.h, and a getpagesize declaration. */
|
|
|
-#if (defined(HAVE_SYS_MMAN_H) && defined(HAVE_UNISTD_H) && \
|
|
|
- defined(HAVE_DECL_GETPAGESIZE))
|
|
|
-#define COMPAT_HAS_MMAN_AND_PAGESIZE
|
|
|
-#endif
|
|
|
-
|
|
|
-#if defined(COMPAT_HAS_MMAN_AND_PAGESIZE) || \
|
|
|
- defined(RUNNING_DOXYGEN)
|
|
|
+#if defined(HAVE_MMAP) || defined(RUNNING_DOXYGEN)
|
|
|
|
|
|
- * failure, return NULL. Sets errno properly, using ERANGE to mean
|
|
|
- * "empty file". */
|
|
|
+ * failure, return NULL. Sets errno properly, using ERANGE to mean
|
|
|
+ * "empty file". Must only be called on trusted Tor-owned files, as changing
|
|
|
+ * the underlying file's size causes unspecified behavior. */
|
|
|
tor_mmap_t *
|
|
|
tor_mmap_file(const char *filename)
|
|
|
{
|
|
|
int fd;
|
|
|
char *string;
|
|
|
- int page_size, result;
|
|
|
+ int result;
|
|
|
tor_mmap_t *res;
|
|
|
size_t size, filesize;
|
|
|
struct stat st;
|
|
@@ -250,13 +242,6 @@ tor_mmap_file(const char *filename)
|
|
|
return NULL;
|
|
|
}
|
|
|
size = filesize = (size_t)(st.st_size);
|
|
|
-
|
|
|
- * Should we check for weird crap like mmapping a named pipe here,
|
|
|
- * or just wait for if (!size) below to fail?
|
|
|
- */
|
|
|
-
|
|
|
- page_size = getpagesize();
|
|
|
- size += (size%page_size) ? page_size-(size%page_size) : 0;
|
|
|
|
|
|
if (st.st_size > SSIZE_T_CEILING || (off_t)size < st.st_size) {
|
|
|
log_warn(LD_FS, "File \"%s\" is too large. Ignoring.",filename);
|