mirror of
https://git.freebsd.org/ports.git
synced 2025-07-07 12:29:16 -04:00
This patch is a backport of ca44241 from upstream: runtime: Use MAP_FIXED flag to ensure buffer halves are contiguous It fixes SIGSEGV observed with GNU Radio buffers consumers such as comms/gqrx. Discussed here: https://github.com/gqrx-sdr/gqrx/issues/1275 https://github.com/gnuradio/gnuradio/pull/6854 PR: 272543 Reported by: trasz Obtained from: GNU Radio team (GH pull request: 6854) MFH: 2023Q3
44 lines
1.7 KiB
C++
44 lines
1.7 KiB
C++
Use MAP_FIXED flag to ensure buffer halves are contiguous
|
|
|
|
(backport of ca44241)
|
|
|
|
--- gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc.orig 2021-09-30 14:10:55 UTC
|
|
+++ gnuradio-runtime/lib/vmcircbuf_mmap_tmpfile.cc
|
|
@@ -107,19 +107,11 @@ vmcircbuf_mmap_tmpfile::vmcircbuf_mmap_tmpfile(int siz
|
|
throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
|
|
}
|
|
|
|
- // unmap the 2nd half
|
|
- if (munmap((char*)first_copy + size, size) == -1) {
|
|
- close(seg_fd); // cleanup
|
|
- perror("gr::vmcircbuf_mmap_tmpfile: munmap (1)");
|
|
- throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
|
|
- }
|
|
-
|
|
- // map the first half into the now available hole where the
|
|
- // second half used to be.
|
|
+ // map the first half into the second half of the address space.
|
|
void* second_copy = mmap((char*)first_copy + size,
|
|
size,
|
|
PROT_READ | PROT_WRITE,
|
|
- MAP_SHARED,
|
|
+ MAP_SHARED | MAP_FIXED,
|
|
seg_fd,
|
|
(off_t)0);
|
|
|
|
@@ -127,15 +119,6 @@ vmcircbuf_mmap_tmpfile::vmcircbuf_mmap_tmpfile(int siz
|
|
munmap(first_copy, size); // cleanup
|
|
close(seg_fd);
|
|
perror("gr::vmcircbuf_mmap_tmpfile: mmap(2)");
|
|
- throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
|
|
- }
|
|
-
|
|
- // check for contiguity
|
|
- if ((char*)second_copy != (char*)first_copy + size) {
|
|
- munmap(first_copy, size); // cleanup
|
|
- munmap(second_copy, size);
|
|
- close(seg_fd);
|
|
- perror("gr::vmcircbuf_mmap_tmpfile: non-contiguous second copy");
|
|
throw std::runtime_error("gr::vmcircbuf_mmap_tmpfile");
|
|
}
|
|
|