// Aborts if cookie doesn't match, returns the signal flag otherwise.
extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_cookie_check(long cookie) {
  if (__libc_globals->setjmp_cookie != (cookie & ~1)) {
    async_safe_fatal("setjmp cookie mismatch");
  }

  return cookie & 1;
}
extern "C" void __libc_init_main_thread_final() {
  bionic_tcb* temp_tcb = __get_bionic_tcb();
  bionic_tls* temp_tls = &__get_bionic_tls();

  // Allocate the main thread's static TLS. (This mapping doesn't include a
  // stack.)
  ThreadMapping mapping = __allocate_thread_mapping(0, PTHREAD_GUARD_SIZE);
  if (mapping.mmap_base == nullptr) {
    async_safe_fatal("failed to mmap main thread static TLS: %s", strerror(errno));
  }

  const StaticTlsLayout& layout = __libc_shared_globals()->static_tls_layout;
  auto new_tcb = reinterpret_cast<bionic_tcb*>(mapping.static_tls + layout.offset_bionic_tcb());
  auto new_tls = reinterpret_cast<bionic_tls*>(mapping.static_tls + layout.offset_bionic_tls());

  __init_static_tls(mapping.static_tls);
  new_tcb->copy_from_bootstrap(temp_tcb);
  new_tls->copy_from_bootstrap(temp_tls);
  __init_tcb(new_tcb, &main_thread);
  __init_bionic_tls_ptrs(new_tcb, new_tls);

  main_thread.mmap_base = mapping.mmap_base;
  main_thread.mmap_size = mapping.mmap_size;

  __set_tls(&new_tcb->tls_slot(0));

  __free_temp_bionic_tls(temp_tls);
}
extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_cookie_get(long sigflag) {
  if (sigflag & ~1) {
    async_safe_fatal("unexpected sigflag value: %ld", sigflag);
  }

  return __libc_globals->setjmp_cookie | sigflag;
}
Example #4
0
int __fsetlocking(FILE* fp, int type) {
  int old_state = _EXT(fp)->_caller_handles_locking ? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL;
  if (type == FSETLOCKING_QUERY) {
    return old_state;
  }

  if (type != FSETLOCKING_INTERNAL && type != FSETLOCKING_BYCALLER) {
    // The API doesn't let us report an error, so blow up.
    async_safe_fatal("Bad type (%d) passed to __fsetlocking", type);
  }

  _EXT(fp)->_caller_handles_locking = (type == FSETLOCKING_BYCALLER);
  return old_state;
}
extern "C" __LIBC_HIDDEN__ long __bionic_setjmp_checksum_mismatch() {
  async_safe_fatal("setjmp checksum mismatch");
}