Avoid atomic 64-bit load on Debian armel
authorStéphane Glondu <glondu@debian.org>
Fri, 28 Jun 2024 05:53:21 +0000 (07:53 +0200)
committerStéphane Glondu <glondu@debian.org>
Wed, 7 Aug 2024 12:12:25 +0000 (14:12 +0200)
Bug: https://github.com/ocaml/ocaml/issues/13234
Forwarded: https://github.com/ocaml/ocaml/pull/13267

Gbp-Pq: Name 0010-Avoid-atomic-64-bit-load-on-Debian-armel.patch

otherlibs/runtime_events/runtime_events_consumer.c

index 9df4eb5a901d58507a8d4ef6ee38931c56533b19..1771df70f508de1579507327cd316365dca0cdbc 100644 (file)
@@ -189,7 +189,16 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
 
   cursor->ring_file_size_bytes = GetFileSize(cursor->ring_file_handle, NULL);
 #else
-  ring_fd = open(runtime_events_loc, O_RDONLY, 0);
+#if defined(__ARM_ARCH) && __ARM_ARCH <= 5
+  /* Atomic 64-bit load requires RW memory on Debian armel.  See:
+     https://github.com/ocaml/ocaml/issues/13234 */
+  const int open_flags = O_RDWR;
+  const int mmap_prot = PROT_READ | PROT_WRITE;
+#else
+  const int open_flags = O_RDONLY;
+  const int mmap_prot = PROT_READ;
+#endif
+  ring_fd = open(runtime_events_loc, open_flags, 0);
 
   if( ring_fd == -1 ) {
     caml_stat_free(cursor);
@@ -210,7 +219,7 @@ caml_runtime_events_create_cursor(const char_os* runtime_events_path, int pid,
   /* This cast is necessary for compatibility with Illumos' non-POSIX
     mmap/munmap */
   cursor->metadata = (struct runtime_events_metadata_header *)
-                      mmap(NULL, cursor->ring_file_size_bytes, PROT_READ,
+                      mmap(NULL, cursor->ring_file_size_bytes, mmap_prot,
                           MAP_SHARED, ring_fd, 0);
 
   if( cursor->metadata == MAP_FAILED ) {