Skip to contentSkip to conversation

Replaced instances of mmap64() with mmap()

PATCH New Jake Freeland 2 participants 2 messages Oct 5, 2022 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Replaced instances of mmap64() with mmap()

The mmap64() function exists to point 32-bit architectures to an mmap interface with the capability to address a 64-bit memory address space. As 32-bit machines are replaced by 64-bit, there is no longer a need to keep mmap64() around. This is especially apparent in operating systems like FreeBSD that exclude the mmap64() function altogether. This patch replaces all instances of mmap64() with mmap().

---
 lib/i915/gem_mman.c          |  4 ++--
 lib/igt_vgem.c               |  2 +-
 tests/i915/gem_mmap_gtt.c    | 22 +++++++++++-----------
 tests/i915/gem_mmap_offset.c | 12 ++++++------
 4 files changed, 20 insertions(+), 20 deletions(-)
lib/i915/gem_mman.c +2 -2
index aa9ac6f3..a9a3bc42 100644
@@ -118,7 +118,7 @@ void *__gem_mmap__gtt(int fd, uint32_t handle, uint64_t size, unsigned prot)
 	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg))
 		return NULL;
 
-	ptr = mmap64(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
+	ptr = drm_mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
 	if (ptr == MAP_FAILED)
 		ptr = NULL;
 	else
@@ -331,7 +331,7 @@ void *__gem_mmap_offset(int fd, uint32_t handle, uint64_t offset, uint64_t size,
 	if (igt_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_OFFSET, &arg))
 		return NULL;
 
-	ptr = mmap64(0, size, prot, MAP_SHARED, fd, arg.offset + offset);
+	ptr = drm_mmap(0, size, prot, MAP_SHARED, fd, arg.offset + offset);
 
 	if (ptr == MAP_FAILED)
 		ptr = NULL;
lib/igt_vgem.c +1 -1
index 7f933b23..4e30415b 100644
@@ -76,7 +76,7 @@ void *__vgem_mmap(int fd, struct vgem_bo *bo, unsigned prot)
 	if (drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &arg))
 		return NULL;
 
-	ptr = mmap64(0, bo->size, prot, MAP_SHARED, fd, arg.offset);
+	ptr = drm_mmap(0, bo->size, prot, MAP_SHARED, fd, arg.offset);
 	if (ptr == MAP_FAILED)
 		return NULL;
 
tests/i915/gem_mmap_gtt.c +11 -11
index e39b9047..64c4de60 100644
@@ -113,11 +113,11 @@ test_access(int fd)
 	mmap_arg.handle = handle;
 	do_ioctl(fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &mmap_arg);
 
-	igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
+	igt_assert(drm_mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
 			  MAP_SHARED, fd, mmap_arg.offset));
 
 	/* Check that the same offset on the other fd doesn't work. */
-	igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
+	igt_assert(drm_mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
 			  MAP_SHARED, fd2, mmap_arg.offset) == MAP_FAILED);
 	igt_assert(errno == EACCES);
 
@@ -128,7 +128,7 @@ test_access(int fd)
 
 	/* Recheck that it works after flink. */
 	/* Check that the same offset on the other fd doesn't work. */
-	igt_assert(mmap64(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
+	igt_assert(drm_mmap(0, OBJECT_SIZE, PROT_READ | PROT_WRITE,
 			  MAP_SHARED, fd2, mmap_arg.offset));
 }
 
@@ -159,11 +159,11 @@ test_short(int fd)
 	for (pages = 1; pages <= OBJECT_SIZE / PAGE_SIZE; pages <<= 1) {
 		uint8_t *r, *w;
 
-		w = mmap64(0, pages * PAGE_SIZE, PROT_READ | PROT_WRITE,
+		w = drm_mmap(0, pages * PAGE_SIZE, PROT_READ | PROT_WRITE,
 			   MAP_SHARED, fd, mmap_arg.offset);
 		igt_assert(w != MAP_FAILED);
 
-		r = mmap64(0, pages * PAGE_SIZE, PROT_READ,
+		r = drm_mmap(0, pages * PAGE_SIZE, PROT_READ,
 			   MAP_SHARED, fd, mmap_arg.offset);
 		igt_assert(r != MAP_FAILED);
 
@@ -384,13 +384,13 @@ test_isolation(int i915)
 
 	close(B);
 
-	ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+	ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr != MAP_FAILED);
 	munmap(ptr, 4096);
 
 	close(A);
 
-	ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+	ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 	igt_assert(ptr == MAP_FAILED);
 }
 
@@ -400,7 +400,7 @@ test_close_race(int i915)
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	_Atomic uint32_t *handles;
 
-	handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	handles = drm_mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
 	igt_fork(child, ncpus + 1) {
@@ -418,7 +418,7 @@ test_close_race(int i915)
 				  &mmap_arg) != -1) {
 				void *ptr;
 
-				ptr = mmap64(0, 4096,
+				ptr = drm_mmap(0, 4096,
 					     PROT_WRITE, MAP_SHARED, i915,
 					     mmap_arg.offset);
 				if (ptr != MAP_FAILED) {
@@ -444,7 +444,7 @@ test_flink_race(int i915)
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	_Atomic uint32_t *handles;
 
-	handles = mmap64(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	handles = drm_mmap(0, 4096, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
 	igt_fork(child, ncpus + 1) {
@@ -469,7 +469,7 @@ test_flink_race(int i915)
 				  &mmap_arg) != -1) {
 				void *ptr;
 
-				ptr = mmap64(0, 4096,
+				ptr = drm_mmap(0, 4096,
 					     PROT_WRITE, MAP_SHARED, fd,
 					     mmap_arg.offset);
 				if (ptr != MAP_FAILED) {
tests/i915/gem_mmap_offset.c +6 -6
index 2b416edd..126aaa24 100644
@@ -67,7 +67,7 @@ __mmap_offset(int i915, uint32_t handle, uint64_t offset, uint64_t size,
 	if (mmap_offset_ioctl(i915, &arg))
 		return NULL;
 
-	ptr = mmap64(0, size, prot, MAP_SHARED, i915, arg.offset + offset);
+	ptr = drm_mmap(0, size, prot, MAP_SHARED, i915, arg.offset + offset);
 	if (ptr == MAP_FAILED)
 		ptr = NULL;
 	else
@@ -321,12 +321,12 @@ static void isolation(int i915)
 				 t->name, B, b, offset_b);
 
 			errno = 0;
-			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);
+			ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, i915, offset_a);
 			igt_assert(ptr == MAP_FAILED);
 			igt_assert_eq(errno, EACCES);
 
 			errno = 0;
-			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);
+			ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, i915, offset_b);
 			igt_assert(ptr == MAP_FAILED);
 			igt_assert_eq(errno, EACCES);
 
@@ -344,13 +344,13 @@ static void isolation(int i915)
 
 			close(B);
 
-			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+			ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr != MAP_FAILED);
 			munmap(ptr, 4096);
 
 			close(A);
 
-			ptr = mmap64(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
+			ptr = drm_mmap(0, 4096, PROT_READ, MAP_SHARED, A, offset_a);
 			igt_assert(ptr == MAP_FAILED);
 		}
 	}
@@ -553,7 +553,7 @@ static void close_race(int i915, int timeout)
 	_Atomic uint32_t *handles;
 	size_t len = ALIGN((ncpus + 1) * sizeof(uint32_t), 4096);
 
-	handles = mmap64(0, len, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
+	handles = drm_mmap(0, len, PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
 	igt_assert(handles != MAP_FAILED);
 
 	igt_fork(child, ncpus + 1) {
Signature · 1 line
2.37.0 (Apple Git-136)
#1 lore raw

[igt-dev] ✗ Fi.CI.BUILD: failure for Replaced instances of mmap64() with mmap() (rev4)

== Series Details ==

== Series Details ==

Series: Replaced instances of mmap64() with mmap() (rev4)
URL : https://patchwork.freedesktop.org/series/108698/
State : failure

== Summary ==

IGT patchset build failed on latest successful build 17292ab1e63802d8456670f606f8ad78082d09ee igt_core: add a line break at the end of some internal_assert

ninja: Entering directory `/opt/igt/build'
[1/935] Generating version.h with a custom command.
[2/933] Compiling C object 'lib/76b5a35@@igt-i915_gem_mman_c@sta/i915_gem_mman.c.o'.
FAILED: lib/76b5a35@@igt-i915_gem_mman_c@sta/i915_gem_mman.c.o
cc -Ilib/76b5a35@@igt-i915_gem_mman_c@sta -Ilib -I../../../usr/src/igt-gpu-tools/lib -I../../../usr/src/igt-gpu-tools/include/drm-uapi -I../../../usr/src/igt-gpu-tools/include/linux-uapi -I../../../usr/src/igt-gpu-tools/lib/stubs/syscalls -I. -I../../../usr/src/igt-gpu-tools/ -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libdrm -I/usr/include/x86_64-linux-gnu -I/usr/include/valgrind -I/usr/include -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O2 -g -D_GNU_SOURCE -include config.h -D_FORTIFY_SOURCE=2 -Wbad-function-cast -Wdeclaration-after-statement -Wformat=2 -Wimplicit-fallthrough=0 -Wlogical-op -Wmissing-declarations -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-prototypes -Wuninitialized -Wunused -Wno-clobbered -Wno-maybe-uninitialized -Wno-missing-field-initializers -Wno-pointer-arith -Wno-address-of-packed-member -Wno-sign-compare -Wno-type-limits -Wno-unused-parameter -Wno-unused-result -Werror=address -Werror=array-bounds -Werror=implicit -Werror=init-self -Werror=int-to-pointer-cast -Werror=main -Werror=missing-braces -Werror=nonnull -Werror=pointer-to-int-cast -Werror=return-type -Werror=sequence-point -Werror=trigraphs -Werror=write-strings -fno-builtin-malloc -fno-builtin-calloc -fcommon -fPIC -pthread '-DIGT_DATADIR="/opt/igt/share/igt-gpu-tools"' '-DIGT_SRCDIR="/usr/src/igt-gpu-tools/tests"' '-DIGT_LOG_DOMAIN="i915/gem_mman"' -MD -MQ 'lib/76b5a35@@igt-i915_gem_mman_c@sta/i915_gem_mman.c.o' -MF 'lib/76b5a35@@igt-i915_gem_mman_c@sta/i915_gem_mman.c.o.d' -o 'lib/76b5a35@@igt-i915_gem_mman_c@sta/i915_gem_mman.c.o' -c ../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c ../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c: In function ‘__gem_mmap__gtt’:
../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c:121:8: error: implicit declaration of function ‘drm_mmap’; did you mean ‘gem_munmap’? [-Werror=implicit-function-declaration]

  121 |  ptr = drm_mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
      |        ^~~~~~~~
      |        gem_munmap

../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c:121:8: warning: nested extern declaration of ‘drm_mmap’ [-Wnested-externs] ../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c:121:6: warning: assignment to ‘void *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
121 | ptr = drm_mmap(0, size, prot, MAP_SHARED, fd, mmap_arg.offset);
| ^
../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c: In function ‘__gem_mmap_offset’:
../../../usr/src/igt-gpu-tools/lib/i915/gem_mman.c:334:6: warning: assignment to ‘void *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
334 | ptr = drm_mmap(0, size, prot, MAP_SHARED, fd, arg.offset + offset);
| ^
cc1: some warnings being treated as errors
ninja: build stopped: subcommand failed.