Lines Matching defs:thr
90 ThreadState *thr = cur_thread();
91 if (thr->proc())
108 ProcWire(gp->proc, thr);
113 ThreadState *thr = cur_thread();
114 if (thr->proc() != gp->proc)
116 ProcUnwire(gp->proc, thr);
177 static void SignalUnsafeCall(ThreadState *thr, uptr pc) {
178 if (atomic_load_relaxed(&thr->in_signal_handler) == 0 ||
179 !ShouldReport(thr, ReportTypeSignalUnsafe))
182 ObtainCurrentStack(thr, pc, &stack);
188 OutputReport(thr, rep);
192 void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz, uptr align,
200 GET_STACK_TRACE_FATAL(thr, pc);
206 GET_STACK_TRACE_FATAL(thr, pc);
209 void *p = allocator()->Allocate(&thr->proc()->alloc_cache, sz, align);
214 GET_STACK_TRACE_FATAL(thr, pc);
218 OnUserAlloc(thr, pc, (uptr)p, sz, true);
220 SignalUnsafeCall(thr, pc);
224 void user_free(ThreadState *thr, uptr pc, void *p, bool signal) {
227 OnUserFree(thr, pc, (uptr)p, true);
228 allocator()->Deallocate(&thr->proc()->alloc_cache, p);
230 SignalUnsafeCall(thr, pc);
233 void *user_alloc(ThreadState *thr, uptr pc, uptr sz) {
234 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, kDefaultAlignment));
237 void *user_calloc(ThreadState *thr, uptr pc, uptr size, uptr n) {
241 GET_STACK_TRACE_FATAL(thr, pc);
244 void *p = user_alloc_internal(thr, pc, n * size);
250 void *user_reallocarray(ThreadState *thr, uptr pc, void *p, uptr size, uptr n) {
254 GET_STACK_TRACE_FATAL(thr, pc);
257 return user_realloc(thr, pc, p, size * n);
260 void OnUserAlloc(ThreadState *thr, uptr pc, uptr p, uptr sz, bool write) {
261 DPrintf("#%d: alloc(%zu) = 0x%zx\n", thr->tid, sz, p);
266 ctx->metamap.AllocBlock(thr, pc, p, sz);
271 if (write && thr->ignore_reads_and_writes == 0 &&
272 atomic_load_relaxed(&thr->trace_pos))
273 MemoryRangeImitateWrite(thr, pc, (uptr)p, sz);
275 MemoryResetRange(thr, pc, (uptr)p, sz);
278 void OnUserFree(ThreadState *thr, uptr pc, uptr p, bool write) {
280 if (!thr->slot) {
282 UNUSED uptr sz = ctx->metamap.FreeBlock(thr->proc(), p, false);
283 DPrintf("#%d: free(0x%zx, %zu) (no slot)\n", thr->tid, p, sz);
286 SlotLocker locker(thr);
287 uptr sz = ctx->metamap.FreeBlock(thr->proc(), p, true);
288 DPrintf("#%d: free(0x%zx, %zu)\n", thr->tid, p, sz);
289 if (write && thr->ignore_reads_and_writes == 0)
290 MemoryRangeFreed(thr, pc, (uptr)p, sz);
293 void *user_realloc(ThreadState *thr, uptr pc, void *p, uptr sz) {
297 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz));
299 user_free(thr, pc, p);
302 void *new_p = user_alloc_internal(thr, pc, sz);
306 user_free(thr, pc, p);
311 void *user_memalign(ThreadState *thr, uptr pc, uptr align, uptr sz) {
316 GET_STACK_TRACE_FATAL(thr, pc);
319 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, align));
322 int user_posix_memalign(ThreadState *thr, uptr pc, void **memptr, uptr align,
327 GET_STACK_TRACE_FATAL(thr, pc);
330 void *ptr = user_alloc_internal(thr, pc, sz, align);
339 void *user_aligned_alloc(ThreadState *thr, uptr pc, uptr align, uptr sz) {
344 GET_STACK_TRACE_FATAL(thr, pc);
347 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, align));
350 void *user_valloc(ThreadState *thr, uptr pc, uptr sz) {
351 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, GetPageSizeCached()));
354 void *user_pvalloc(ThreadState *thr, uptr pc, uptr sz) {
360 GET_STACK_TRACE_FATAL(thr, pc);
365 return SetErrnoOnNull(user_alloc_internal(thr, pc, sz, PageSize));
405 ThreadState *thr = cur_thread();
406 if (ctx == 0 || !ctx->initialized || thr->ignore_interceptors)
412 ThreadState *thr = cur_thread();
413 if (ctx == 0 || !ctx->initialized || thr->ignore_interceptors)
419 ThreadState *thr = cur_thread();
420 if (thr->nomalloc) {
421 thr->nomalloc = 0; // CHECK calls internal_malloc().
425 return InternalAlloc(sz, &thr->proc()->internal_alloc_cache);
429 ThreadState *thr = cur_thread();
430 if (thr->nomalloc) {
431 thr->nomalloc = 0; // CHECK calls internal_malloc().
435 InternalFree(p, &thr->proc()->internal_alloc_cache);
491 ThreadState *thr = cur_thread();
492 allocator()->SwallowCache(&thr->proc()->alloc_cache);
493 internal_allocator()->SwallowCache(&thr->proc()->internal_alloc_cache);
494 ctx->metamap.OnProcIdle(thr->proc());