title: SIGBUS When Using Placement new?
body: <p>I have the following code (updated):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cassert&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;new&gt;
  
  struct S {
  uint32_t a;
  uint32_t b;
  };
  
  int main() {
      const auto fd = open("/tmp/abc.txt", O_RDWR | O_CREAT, S_IRWXU);
      assert(fd &gt; 0);
      void* ptr = mmap(nullptr, sizeof(S), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
      assert(MAP_FAILED != ptr);
      std::cout &lt;&lt; "address: " &lt;&lt; ptr &lt;&lt; std::endl;
      auto tptr = new (ptr) S();
      tptr-&gt;a = 99;
      const auto rc = msync(&amp;ptr, sizeof(S), MS_ASYNC);
      std::cout &lt;&lt; "msync returned " &lt;&lt; rc &lt;&lt; std::endl;
      if (rc != 0) {
          std::cout &lt;&lt; "error code = " &lt;&lt; errno &lt;&lt; ": " &lt;&lt; strerror(errno) &lt;&lt; std::endl;
      }
  }
  </code></pre>
  
  <p>And when I ran it in GDB, I got this:</p>
  
  <pre><code>address: 0x7ffff7ff8000
  
  Program received signal SIGBUS, Bus error.
  0x0000000000400adb in main () at msync.cpp:20
  20      auto tptr = new (ptr) S();
  </code></pre>
  
  <p>I see some people mentioned memory alignment issue, and I checked 0x7ffff7ff8000 is divisible by 2, 8, 16, 32, and 64.  Then, I am confused what kind of alignment it is expecting.  Or it is something else?</p>
  
  <p>Thanks in advance.</p>