Rosetta fail on shared memory in Sonoma 14.3

I use UTM.app for virtualisation. I have full virtualise "Fedora 38-aarch64" in UTM.app with rosetta enabled. After upgrading Sonoma to 14.3 it stop properly virtualised shared memory. I have this test file:

#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>

int main ()
{
  int segment_id;
  char* shared_memory;
  struct shmid_ds shmbuffer;
  int segment_size;
  const int shared_segment_size = 0x6400;

  /* Allocate a shared memory segment.  */
  segment_id = shmget (IPC_PRIVATE, shared_segment_size,
                 IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
  /* Attach the shared memory segment.  */
  shared_memory = (char*) shmat (segment_id, 0, 0);
  printf ("shared memory attached at address %p\n", shared_memory);
  /* Determine the segment's size. */
  shmctl (segment_id, IPC_STAT, &shmbuffer);
  segment_size  =               shmbuffer.shm_segsz;
  printf ("segment size: %d\n", segment_size);
  /* Write a string to the shared memory segment.  */
  sprintf (shared_memory, "Hello, world.");
  /* Detach the shared memory segment.  */
  shmdt (shared_memory);

  /* Reattach the shared memory segment, at a different address.  */
  shared_memory = (char*) shmat (segment_id, (void*) 0x5000000, 0);
  printf ("shared memory reattached at address %p\n", shared_memory);
  /* Print out the string from shared memory.  */
  printf ("%s\n", shared_memory);
  /* Detach the shared memory segment.  */
  shmdt (shared_memory);

  /* Deallocate the shared memory segment.  */
  shmctl (segment_id, IPC_RMID, 0);

  return 0;
}

Command to compile it is

gcc -Wall a.c && ./a.out
  • When I compile it in virtualised Fedora work properly show this:
shared memory attached address
segment size:
shared memory reattached address
Hello, world.
  • When I compile directly on M1 mac id it die
shared memory attached  address
segment size:
shared memory reattached  address
Segmentation fault:
  • I'm try it also in docker x86 in virtualised fedora and also show error
  1. In "Fedora 38-aarch64 virtualised" run x86 docker "docker run -it --platform linux/amd64 oraclelinux:7.9 bash"
  2. Install gcc in docker shell "yum install -y gcc"
  3. After compile and run it die with
shared memory attached  address
segment size:
shared memory reattached  address
Hello, world.
assertion failed [rem_idx != ]: Unable  find existing allocation  shared memory segment to unmap
(VMAllocationTracker.cpp remove_shared_mem)
 Trace/breakpoint  (core dumped)

How can I fix it?

On previous version of Sonoma works properly.

Thank you

Answered by ibujna in 780423022

Main issue is in rosetta virtualization. So I use UTM.app for virtualize Fedora 38-aarch64 with rosetta enabled. Shared memory C-source test in fedora produce properly output. Main problem is when I try to run amd64 virtualized docker instance in fedora and test shared memory C-source test with rosetta that it produce this error:

assertion failed [rem_idx != ]: Unable  find existing allocation  shared memory segment to unmap
(VMAllocationTracker.cpp remove_shared_mem)
 Trace/breakpoint  (core dumped)

On previous version of Sonoma it work properly. Error occurred on Sonoma 14.3. I also try to upgrade to latest 14.3.1 but still has same.

Fast check of rosetta emulation is use Rancher desktop -> In preference -> Go to 'Virtual Machine' tab -> enable 'VZ' + enable 'Rosetta support' Next go to Images section -> Add image -> amd64/centos:7 -> Pull Run docker amd64 image -> docker run -it --platform=linux/amd64 amd64/centos:7 bash Check if process use rosetta -> ps ax -> should show

[root@7c9941f11436 /]# ps ax
  PID TTY      STAT   TIME COMMAND
    1 pts/0    Ss     0:00 /mnt/lima-rosetta/rosetta /usr/bin/bash
   15 pts/0    R+     0:00 /usr/bin/ps ax

Compile share C-source file and run it and it show error in emulation

shared memory attached at address 0x7fffff1ff000
segment size: 25600
shared memory reattached at address 0x5000000
Hello, world.
assertion failed [rem_idx != -1]: Unable to find existing allocation for shared memory segment to unmap
(VMAllocationTracker.cpp:745 remove_shared_mem)
 Trace/breakpoint trap (core dumped)

When I run same step on "arm64v8/centos" image it produce propelry output

[root@c8e5c3806b38 /]# ./a.out
shared memory attached at address 0xffff91e3e000
segment size: 25600
shared memory reattached at address 0x5000000
Hello, world.
[root@c8e5c3806b38 /]#

So I think there is some problem in rosetta 2 in Sonoma 14.3 and newer when try to run shmdt() function for detach shared memory segment which call in Rosetta

assertion failed [rem_idx != -1]: Unable to find existing allocation for shared memory segment to unmap
(VMAllocationTracker.cpp:745 remove_shared_mem)
 Trace/breakpoint trap (core dumped)

There’s a lot of stuff about virtualisation here, but AFAICT that’s a red herring. My reading of your question is that:

  • The code snippet you posted worked on macOS 14.2.

  • And now segfaults on macOS 14.3.

Is that accurate?

On previous version of Sonoma works properly.

What previous version? Because when I ran your code on my Mac, running 14.2.1 [1], I see the same segfault:

% ./Test746618
shared memory attached at address 0x1027ec000
segment size: 25600
shared memory reattached at address 0xffffffffffffffff
zsh: segmentation fault  ./Test746618

I tweaked the program to print errno and I got back ENOMEM, which is a documented error for this call. Looking at your code it seems to be trying to map the shared memory segment to the address 0x5000000, which is never going to work because, on our 64-bit systems, we prevent folks from using the bottom 4 GiB of memory in order to flush out pointer truncation bugs.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I’m on the road right now, and I generally avoid updating macOS while I’m out of the office.

Accepted Answer

Main issue is in rosetta virtualization. So I use UTM.app for virtualize Fedora 38-aarch64 with rosetta enabled. Shared memory C-source test in fedora produce properly output. Main problem is when I try to run amd64 virtualized docker instance in fedora and test shared memory C-source test with rosetta that it produce this error:

assertion failed [rem_idx != ]: Unable  find existing allocation  shared memory segment to unmap
(VMAllocationTracker.cpp remove_shared_mem)
 Trace/breakpoint  (core dumped)

On previous version of Sonoma it work properly. Error occurred on Sonoma 14.3. I also try to upgrade to latest 14.3.1 but still has same.

Fast check of rosetta emulation is use Rancher desktop -> In preference -> Go to 'Virtual Machine' tab -> enable 'VZ' + enable 'Rosetta support' Next go to Images section -> Add image -> amd64/centos:7 -> Pull Run docker amd64 image -> docker run -it --platform=linux/amd64 amd64/centos:7 bash Check if process use rosetta -> ps ax -> should show

[root@7c9941f11436 /]# ps ax
  PID TTY      STAT   TIME COMMAND
    1 pts/0    Ss     0:00 /mnt/lima-rosetta/rosetta /usr/bin/bash
   15 pts/0    R+     0:00 /usr/bin/ps ax

Compile share C-source file and run it and it show error in emulation

shared memory attached at address 0x7fffff1ff000
segment size: 25600
shared memory reattached at address 0x5000000
Hello, world.
assertion failed [rem_idx != -1]: Unable to find existing allocation for shared memory segment to unmap
(VMAllocationTracker.cpp:745 remove_shared_mem)
 Trace/breakpoint trap (core dumped)

When I run same step on "arm64v8/centos" image it produce propelry output

[root@c8e5c3806b38 /]# ./a.out
shared memory attached at address 0xffff91e3e000
segment size: 25600
shared memory reattached at address 0x5000000
Hello, world.
[root@c8e5c3806b38 /]#

So I think there is some problem in rosetta 2 in Sonoma 14.3 and newer when try to run shmdt() function for detach shared memory segment which call in Rosetta

assertion failed [rem_idx != -1]: Unable to find existing allocation for shared memory segment to unmap
(VMAllocationTracker.cpp:745 remove_shared_mem)
 Trace/breakpoint trap (core dumped)

5 months later, are there any updates on this? Just updated my mac from Ventura to Sonoma to find this *****. Apps that worked fine under rosetta emulation within a VM now raise exceptions like this all over the place. Docker users and so on affected.

Rosetta fail on shared memory in Sonoma 14.3
 
 
Q