void NaClAddrSpSquattingThreadIfLaunchCallback(
    struct NaClThreadInterface *vself) {
  struct NaClAddrSpSquattingThreadInterface *self =
      (struct NaClAddrSpSquattingThreadInterface *) vself;

  NaClVmHoleThreadStackIsSafe(self->nap);
}
Exemple #2
0
void WINAPI NaClAppThreadLauncher(void *state) {
  struct NaClAppThread *natp = (struct NaClAppThread *) state;
  uint32_t thread_idx;
  NaClLog(4, "NaClAppThreadLauncher: entered\n");

  NaClSignalStackRegister(natp->signal_stack);

  NaClLog(4, "      natp = 0x%016"NACL_PRIxPTR"\n", (uintptr_t) natp);
  NaClLog(4, " prog_ctr  = 0x%016"NACL_PRIxNACL_REG"\n", natp->user.prog_ctr);
  NaClLog(4, "stack_ptr  = 0x%016"NACL_PRIxPTR"\n",
          NaClGetThreadCtxSp(&natp->user));

  thread_idx = NaClGetThreadIdx(natp);
  CHECK(0 < thread_idx);
  CHECK(thread_idx < NACL_THREAD_MAX);
  NaClTlsSetCurrentThread(natp);
  nacl_user[thread_idx] = &natp->user;
#if NACL_WINDOWS
  nacl_thread_ids[thread_idx] = GetCurrentThreadId();
#elif NACL_OSX
  NaClSetCurrentMachThreadForThreadIndex(thread_idx);
#endif

  /*
   * We have to hold the threads_mu lock until after thread_num field
   * in this thread has been initialized.  All other threads can only
   * find and examine this natp through the threads table, so the fact
   * that natp is not consistent (no thread_num) will not be visible.
   */
  NaClXMutexLock(&natp->nap->threads_mu);
  natp->thread_num = NaClAddThreadMu(natp->nap, natp);
  NaClXMutexUnlock(&natp->nap->threads_mu);

  NaClVmHoleThreadStackIsSafe(natp->nap);

  NaClStackSafetyNowOnUntrustedStack();

  /*
   * Notify the debug stub, that a new thread is availible.
   */
  if (NULL != natp->nap->debug_stub_callbacks) {
    natp->nap->debug_stub_callbacks->thread_create_hook(natp);
  }

  /*
   * After this NaClAppThreadSetSuspendState() call, we should not
   * claim any mutexes, otherwise we risk deadlock.
   */
  NaClAppThreadSetSuspendState(natp, NACL_APP_THREAD_TRUSTED,
                               NACL_APP_THREAD_UNTRUSTED);

  NaClStartThreadInApp(natp, natp->user.prog_ctr);
}
int NaClAddrSpSquattingThreadIfStartThread(
    struct NaClThreadInterface *vself) {
  struct NaClAddrSpSquattingThreadInterface *self =
      (struct NaClAddrSpSquattingThreadInterface *) vself;
  NaClLog(2,
          "NaClAddrSpSquattingThreadIfStartThread: waiting to start thread\n");
  NaClVmHoleWaitToStartThread(self->nap);

  if (!NaClThreadInterfaceStartThread(vself)) {
    NaClLog(LOG_ERROR,
            "NaClAddrSpSquattingThreadIfStartThread: could not start thread\n");
    NaClVmHoleThreadStackIsSafe(self->nap);
    return 0;
  }
  NaClLog(2,
          "NaClAddrSpSquattingThreadIfStartThread: thread started\n");
  return 1;
}