static INLINE void CopyCodeSafelyInitial(uint8_t *dest, uint8_t *src, uint32_t size, int bundle_size) { CopyBundleTails(dest, src, size, bundle_size); NaClWriteMemoryBarrier(); CopyBundleHeads(dest, src, size, bundle_size); }
static void ReplaceBundleHeadsWithHalts(uint8_t *dest, uint32_t size, int bundle_size) { uint32_t *dest_ptr = (uint32_t*) dest; uint32_t *end_ptr = (uint32_t*) (dest + size); while (dest_ptr < end_ptr) { /* dont assume 1-byte halt, write entire NACL_HALT_WORD */ *dest_ptr = NACL_HALT_WORD; dest_ptr += bundle_size / sizeof(uint32_t); } NaClWriteMemoryBarrier(); }
static void HandleSuspendSignal(struct NaClSignalContext *regs) { uint32_t tls_idx = NaClTlsGetIdx(); struct NaClAppThread *natp = nacl_thread[tls_idx]; struct NaClSignalContext *suspended_registers = &natp->suspended_registers->context; /* Sanity check. */ if (natp->suspend_state != (NACL_APP_THREAD_UNTRUSTED | NACL_APP_THREAD_SUSPENDING)) { NaClSignalErrorMessage("HandleSuspendSignal: " "Unexpected suspend_state\n"); NaClAbort(); } if (suspended_registers != NULL) { *suspended_registers = *regs; /* * Ensure that the change to natp->suspend_state does not become * visible before the change to natp->suspended_registers. */ NaClWriteMemoryBarrier(); } /* * Indicate that we have suspended by setting * NACL_APP_THREAD_SUSPENDED. We should not need an atomic * operation for this since the calling thread will not be trying to * change suspend_state. */ natp->suspend_state |= NACL_APP_THREAD_SUSPENDED; FutexWake(&natp->suspend_state, 1); /* Wait until we are asked to resume. */ while (1) { Atomic32 state = natp->suspend_state; if ((state & NACL_APP_THREAD_SUSPENDED) != 0) { FutexWait(&natp->suspend_state, state); continue; /* Retry */ } break; } /* * Apply register modifications. We need to use a snapshot of * natp->suspended_registers because, since we were asked to resume, * we could have been asked to suspend again, and * suspended_registers could have been allocated in the new * suspension request but not in the original suspension request. */ if (suspended_registers != NULL) { *regs = *suspended_registers; } }