Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab644a0e authored by Florian Mayer's avatar Florian Mayer
Browse files

static_assert to catch struct mismatches earlier

Change-Id: Ia6294c6f8848d0d3d0d7d901e3b78ac3babdf7ac
parent dd75c27f
Loading
Loading
Loading
Loading
+21 −0
Original line number Original line Diff line number Diff line
@@ -371,12 +371,29 @@ static int debuggerd_dispatch_pseudothread(void* arg) {
      {.iov_base = thread_info->ucontext, .iov_len = sizeof(ucontext_t)},
      {.iov_base = thread_info->ucontext, .iov_len = sizeof(ucontext_t)},
  };
  };


  constexpr size_t kHeaderSize = sizeof(version) + sizeof(siginfo_t) + sizeof(ucontext_t);

  if (thread_info->process_info.fdsan_table) {
  if (thread_info->process_info.fdsan_table) {
    // Dynamic executables always use version 4. There is no need to increment the version number if
    // Dynamic executables always use version 4. There is no need to increment the version number if
    // the format changes, because the sender (linker) and receiver (crash_dump) are version locked.
    // the format changes, because the sender (linker) and receiver (crash_dump) are version locked.
    version = 4;
    version = 4;
    expected = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataDynamic);
    expected = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataDynamic);


    static_assert(sizeof(CrashInfoHeader) + sizeof(CrashInfoDataDynamic) ==
                      kHeaderSize + sizeof(thread_info->process_info),
                  "Wire protocol structs do not match the data sent.");
#define ASSERT_SAME_OFFSET(MEMBER1, MEMBER2) \
    static_assert(sizeof(CrashInfoHeader) + offsetof(CrashInfoDataDynamic, MEMBER1) == \
                      kHeaderSize + offsetof(debugger_process_info, MEMBER2), \
                  "Wire protocol offset does not match data sent: " #MEMBER1);
    ASSERT_SAME_OFFSET(fdsan_table_address, fdsan_table);
    ASSERT_SAME_OFFSET(gwp_asan_state, gwp_asan_state);
    ASSERT_SAME_OFFSET(gwp_asan_metadata, gwp_asan_metadata);
    ASSERT_SAME_OFFSET(scudo_stack_depot, scudo_stack_depot);
    ASSERT_SAME_OFFSET(scudo_region_info, scudo_region_info);
    ASSERT_SAME_OFFSET(scudo_ring_buffer, scudo_ring_buffer);
#undef ASSERT_SAME_OFFSET

    iovs[3] = {.iov_base = &thread_info->process_info,
    iovs[3] = {.iov_base = &thread_info->process_info,
               .iov_len = sizeof(thread_info->process_info)};
               .iov_len = sizeof(thread_info->process_info)};
  } else {
  } else {
@@ -384,6 +401,10 @@ static int debuggerd_dispatch_pseudothread(void* arg) {
    version = 1;
    version = 1;
    expected = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataStatic);
    expected = sizeof(CrashInfoHeader) + sizeof(CrashInfoDataStatic);


    static_assert(
        sizeof(CrashInfoHeader) + sizeof(CrashInfoDataStatic) == kHeaderSize + sizeof(uintptr_t),
        "Wire protocol structs do not match the data sent.");

    iovs[3] = {.iov_base = &thread_info->process_info.abort_msg, .iov_len = sizeof(uintptr_t)};
    iovs[3] = {.iov_base = &thread_info->process_info.abort_msg, .iov_len = sizeof(uintptr_t)};
  }
  }
  errno = 0;
  errno = 0;