Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame^] | 1 | From 9ab360fd018d267fe174713d7e14454408b26043 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Sat, 17 Dec 2022 10:33:01 -0800 |
| 4 | Subject: [PATCH] Replace lfs64 functions and defines |
| 5 | |
| 6 | AC_SYS_LARGEFILE is already in use in configure.ac which detects |
| 7 | enabling lfs64 functions as needed, it will define _FILE_OFFSET_BITS=64 |
| 8 | which should make lseek same as lseek64 since off_t is 64bit on most of |
| 9 | current 32bit linux platforms |
| 10 | |
| 11 | Upstream-Status: Submitted [https://github.com/stressapptest/stressapptest/pull/100] |
| 12 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 13 | --- |
| 14 | src/os.cc | 18 ++++++------------ |
| 15 | src/worker.cc | 6 +++--- |
| 16 | 2 files changed, 9 insertions(+), 15 deletions(-) |
| 17 | |
| 18 | diff --git a/src/os.cc b/src/os.cc |
| 19 | index 1928e0a..faa6068 100644 |
| 20 | --- a/src/os.cc |
| 21 | +++ b/src/os.cc |
| 22 | @@ -142,7 +142,7 @@ int OsLayer::AddressMode() { |
| 23 | uint64 OsLayer::VirtualToPhysical(void *vaddr) { |
| 24 | uint64 frame, paddr, pfnmask, pagemask; |
| 25 | int pagesize = sysconf(_SC_PAGESIZE); |
| 26 | - off64_t off = ((uintptr_t)vaddr) / pagesize * 8; |
| 27 | + off_t off = ((uintptr_t)vaddr) / pagesize * 8; |
| 28 | int fd = open(kPagemapPath, O_RDONLY); |
| 29 | |
| 30 | /* |
| 31 | @@ -154,7 +154,7 @@ uint64 OsLayer::VirtualToPhysical(void *vaddr) { |
| 32 | if (fd < 0) |
| 33 | return 0; |
| 34 | |
| 35 | - if (lseek64(fd, off, SEEK_SET) != off || read(fd, &frame, 8) != 8) { |
| 36 | + if (lseek(fd, off, SEEK_SET) != off || read(fd, &frame, 8) != 8) { |
| 37 | int err = errno; |
| 38 | string errtxt = ErrorString(err); |
| 39 | logprintf(0, "Process Error: failed to access %s with errno %d (%s)\n", |
| 40 | @@ -607,9 +607,9 @@ bool OsLayer::AllocateTestMem(int64 length, uint64 paddr_base) { |
| 41 | dynamic_mapped_shmem_ = true; |
| 42 | } else { |
| 43 | // Do a full mapping here otherwise. |
| 44 | - shmaddr = mmap64(NULL, length, PROT_READ | PROT_WRITE, |
| 45 | - MAP_SHARED | MAP_NORESERVE | MAP_LOCKED | MAP_POPULATE, |
| 46 | - shm_object, 0); |
| 47 | + shmaddr = mmap(NULL, length, PROT_READ | PROT_WRITE, |
| 48 | + MAP_SHARED | MAP_NORESERVE | MAP_LOCKED | MAP_POPULATE, |
| 49 | + shm_object, 0); |
| 50 | if (shmaddr == reinterpret_cast<void*>(-1)) { |
| 51 | int err = errno; |
| 52 | string errtxt = ErrorString(err); |
| 53 | @@ -704,18 +704,12 @@ void *OsLayer::PrepareTestMem(uint64 offset, uint64 length) { |
| 54 | if (dynamic_mapped_shmem_) { |
| 55 | // TODO(nsanders): Check if we can support MAP_NONBLOCK, |
| 56 | // and evaluate performance hit from not using it. |
| 57 | -#ifdef HAVE_MMAP64 |
| 58 | - void * mapping = mmap64(NULL, length, PROT_READ | PROT_WRITE, |
| 59 | - MAP_SHARED | MAP_NORESERVE | MAP_LOCKED | MAP_POPULATE, |
| 60 | - shmid_, offset); |
| 61 | -#else |
| 62 | void * mapping = mmap(NULL, length, PROT_READ | PROT_WRITE, |
| 63 | MAP_SHARED | MAP_NORESERVE | MAP_LOCKED | MAP_POPULATE, |
| 64 | shmid_, offset); |
| 65 | -#endif |
| 66 | if (mapping == MAP_FAILED) { |
| 67 | string errtxt = ErrorString(errno); |
| 68 | - logprintf(0, "Process Error: PrepareTestMem mmap64(%llx, %llx) failed. " |
| 69 | + logprintf(0, "Process Error: PrepareTestMem mmap(%llx, %llx) failed. " |
| 70 | "error: %s.\n", |
| 71 | offset, length, errtxt.c_str()); |
| 72 | sat_assert(0); |
| 73 | diff --git a/src/worker.cc b/src/worker.cc |
| 74 | index 745a816..41e93a0 100644 |
| 75 | --- a/src/worker.cc |
| 76 | +++ b/src/worker.cc |
| 77 | @@ -1705,7 +1705,7 @@ bool FileThread::WritePages(int fd) { |
| 78 | int strict = sat_->strict(); |
| 79 | |
| 80 | // Start fresh at beginning of file for each batch of pages. |
| 81 | - lseek64(fd, 0, SEEK_SET); |
| 82 | + lseek(fd, 0, SEEK_SET); |
| 83 | for (int i = 0; i < sat_->disk_pages(); i++) { |
| 84 | struct page_entry src; |
| 85 | if (!GetValidPage(&src)) |
| 86 | @@ -1943,7 +1943,7 @@ bool FileThread::ReadPages(int fd) { |
| 87 | bool result = true; |
| 88 | |
| 89 | // Read our data back out of the file, into it's new location. |
| 90 | - lseek64(fd, 0, SEEK_SET); |
| 91 | + lseek(fd, 0, SEEK_SET); |
| 92 | for (int i = 0; i < sat_->disk_pages(); i++) { |
| 93 | struct page_entry dst; |
| 94 | if (!GetEmptyPage(&dst)) |
| 95 | @@ -3153,7 +3153,7 @@ bool DiskThread::ValidateBlockOnDisk(int fd, BlockData *block) { |
| 96 | |
| 97 | // Read block from disk and time the read. If it takes longer than the |
| 98 | // threshold, complain. |
| 99 | - if (lseek64(fd, address * kSectorSize, SEEK_SET) == -1) { |
| 100 | + if (lseek(fd, address * kSectorSize, SEEK_SET) == -1) { |
| 101 | logprintf(0, "Process Error: Unable to seek to sector %lld in " |
| 102 | "DiskThread::ValidateSectorsOnDisk on disk %s " |
| 103 | "(thread %d).\n", address, device_name_.c_str(), thread_num_); |