nsprpub/pr/src/misc/prthinfo.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "prlog.h"
michael@0 7 #include "prthread.h"
michael@0 8 #include "private/pprthred.h"
michael@0 9 #include "primpl.h"
michael@0 10
michael@0 11 PR_IMPLEMENT(PRWord *)
michael@0 12 PR_GetGCRegisters(PRThread *t, int isCurrent, int *np)
michael@0 13 {
michael@0 14 return _MD_HomeGCRegisters(t, isCurrent, np);
michael@0 15 }
michael@0 16
michael@0 17 PR_IMPLEMENT(PRStatus)
michael@0 18 PR_ThreadScanStackPointers(PRThread* t,
michael@0 19 PRScanStackFun scanFun, void* scanClosure)
michael@0 20 {
michael@0 21 PRThread* current = PR_GetCurrentThread();
michael@0 22 PRWord *sp, *esp, *p0;
michael@0 23 int n;
michael@0 24 void **ptd;
michael@0 25 PRStatus status;
michael@0 26 PRUint32 index;
michael@0 27 int stack_end;
michael@0 28
michael@0 29 /*
michael@0 30 ** Store the thread's registers in the thread structure so the GC
michael@0 31 ** can scan them. Then scan them.
michael@0 32 */
michael@0 33 p0 = _MD_HomeGCRegisters(t, t == current, &n);
michael@0 34 status = scanFun(t, (void**)p0, n, scanClosure);
michael@0 35 if (status != PR_SUCCESS)
michael@0 36 return status;
michael@0 37
michael@0 38 /* Scan the C stack for pointers into the GC heap */
michael@0 39 #if defined(XP_PC) && defined(WIN16)
michael@0 40 /*
michael@0 41 ** Under WIN16, the stack of the current thread is always mapped into
michael@0 42 ** the "task stack" (at SS:xxxx). So, if t is the current thread, scan
michael@0 43 ** the "task stack". Otherwise, scan the "cached stack" of the inactive
michael@0 44 ** thread...
michael@0 45 */
michael@0 46 if (t == current) {
michael@0 47 sp = (PRWord*) &stack_end;
michael@0 48 esp = (PRWord*) _pr_top_of_task_stack;
michael@0 49
michael@0 50 PR_ASSERT(sp <= esp);
michael@0 51 } else {
michael@0 52 sp = (PRWord*) PR_GetSP(t);
michael@0 53 esp = (PRWord*) t->stack->stackTop;
michael@0 54
michael@0 55 PR_ASSERT((t->stack->stackSize == 0) ||
michael@0 56 ((sp > (PRWord*)t->stack->stackBottom) &&
michael@0 57 (sp <= (PRWord*)t->stack->stackTop)));
michael@0 58 }
michael@0 59 #else /* ! WIN16 */
michael@0 60 #ifdef HAVE_STACK_GROWING_UP
michael@0 61 if (t == current) {
michael@0 62 esp = (PRWord*) &stack_end;
michael@0 63 } else {
michael@0 64 esp = (PRWord*) PR_GetSP(t);
michael@0 65 }
michael@0 66 sp = (PRWord*) t->stack->stackTop;
michael@0 67 if (t->stack->stackSize) {
michael@0 68 PR_ASSERT((esp > (PRWord*)t->stack->stackTop) &&
michael@0 69 (esp < (PRWord*)t->stack->stackBottom));
michael@0 70 }
michael@0 71 #else /* ! HAVE_STACK_GROWING_UP */
michael@0 72 if (t == current) {
michael@0 73 sp = (PRWord*) &stack_end;
michael@0 74 } else {
michael@0 75 sp = (PRWord*) PR_GetSP(t);
michael@0 76 }
michael@0 77 esp = (PRWord*) t->stack->stackTop;
michael@0 78 if (t->stack->stackSize) {
michael@0 79 PR_ASSERT((sp > (PRWord*)t->stack->stackBottom) &&
michael@0 80 (sp < (PRWord*)t->stack->stackTop));
michael@0 81 }
michael@0 82 #endif /* ! HAVE_STACK_GROWING_UP */
michael@0 83 #endif /* ! WIN16 */
michael@0 84
michael@0 85 #if defined(WIN16)
michael@0 86 {
michael@0 87 prword_t scan;
michael@0 88 prword_t limit;
michael@0 89
michael@0 90 scan = (prword_t) sp;
michael@0 91 limit = (prword_t) esp;
michael@0 92 while (scan < limit) {
michael@0 93 prword_t *test;
michael@0 94
michael@0 95 test = *((prword_t **)scan);
michael@0 96 status = scanFun(t, (void**)&test, 1, scanClosure);
michael@0 97 if (status != PR_SUCCESS)
michael@0 98 return status;
michael@0 99 scan += sizeof(char);
michael@0 100 }
michael@0 101 }
michael@0 102 #else
michael@0 103 if (sp < esp) {
michael@0 104 status = scanFun(t, (void**)sp, esp - sp, scanClosure);
michael@0 105 if (status != PR_SUCCESS)
michael@0 106 return status;
michael@0 107 }
michael@0 108 #endif
michael@0 109
michael@0 110 /*
michael@0 111 ** Mark all of the per-thread-data items attached to this thread
michael@0 112 **
michael@0 113 ** The execution environment better be accounted for otherwise it
michael@0 114 ** will be collected
michael@0 115 */
michael@0 116 status = scanFun(t, (void**)&t->environment, 1, scanClosure);
michael@0 117 if (status != PR_SUCCESS)
michael@0 118 return status;
michael@0 119
michael@0 120 /* if thread is not allocated on stack, this is redundant. */
michael@0 121 ptd = t->privateData;
michael@0 122 for (index = 0; index < t->tpdLength; index++, ptd++) {
michael@0 123 status = scanFun(t, (void**)ptd, 1, scanClosure);
michael@0 124 if (status != PR_SUCCESS)
michael@0 125 return status;
michael@0 126 }
michael@0 127
michael@0 128 return PR_SUCCESS;
michael@0 129 }
michael@0 130
michael@0 131 /* transducer for PR_EnumerateThreads */
michael@0 132 typedef struct PRScanStackData {
michael@0 133 PRScanStackFun scanFun;
michael@0 134 void* scanClosure;
michael@0 135 } PRScanStackData;
michael@0 136
michael@0 137 static PRStatus PR_CALLBACK
michael@0 138 pr_ScanStack(PRThread* t, int i, void* arg)
michael@0 139 {
michael@0 140 PRScanStackData* data = (PRScanStackData*)arg;
michael@0 141 return PR_ThreadScanStackPointers(t, data->scanFun, data->scanClosure);
michael@0 142 }
michael@0 143
michael@0 144 PR_IMPLEMENT(PRStatus)
michael@0 145 PR_ScanStackPointers(PRScanStackFun scanFun, void* scanClosure)
michael@0 146 {
michael@0 147 PRScanStackData data;
michael@0 148 data.scanFun = scanFun;
michael@0 149 data.scanClosure = scanClosure;
michael@0 150 return PR_EnumerateThreads(pr_ScanStack, &data);
michael@0 151 }
michael@0 152
michael@0 153 PR_IMPLEMENT(PRUword)
michael@0 154 PR_GetStackSpaceLeft(PRThread* t)
michael@0 155 {
michael@0 156 PRThread *current = PR_GetCurrentThread();
michael@0 157 PRWord *sp, *esp;
michael@0 158 int stack_end;
michael@0 159
michael@0 160 #if defined(WIN16)
michael@0 161 /*
michael@0 162 ** Under WIN16, the stack of the current thread is always mapped into
michael@0 163 ** the "task stack" (at SS:xxxx). So, if t is the current thread, scan
michael@0 164 ** the "task stack". Otherwise, scan the "cached stack" of the inactive
michael@0 165 ** thread...
michael@0 166 */
michael@0 167 if (t == current) {
michael@0 168 sp = (PRWord*) &stack_end;
michael@0 169 esp = (PRWord*) _pr_top_of_task_stack;
michael@0 170
michael@0 171 PR_ASSERT(sp <= esp);
michael@0 172 } else {
michael@0 173 sp = (PRWord*) PR_GetSP(t);
michael@0 174 esp = (PRWord*) t->stack->stackTop;
michael@0 175
michael@0 176 PR_ASSERT((t->stack->stackSize == 0) ||
michael@0 177 ((sp > (PRWord*)t->stack->stackBottom) &&
michael@0 178 (sp <= (PRWord*)t->stack->stackTop)));
michael@0 179 }
michael@0 180 #else /* ! WIN16 */
michael@0 181 #ifdef HAVE_STACK_GROWING_UP
michael@0 182 if (t == current) {
michael@0 183 esp = (PRWord*) &stack_end;
michael@0 184 } else {
michael@0 185 esp = (PRWord*) PR_GetSP(t);
michael@0 186 }
michael@0 187 sp = (PRWord*) t->stack->stackTop;
michael@0 188 if (t->stack->stackSize) {
michael@0 189 PR_ASSERT((esp > (PRWord*)t->stack->stackTop) &&
michael@0 190 (esp < (PRWord*)t->stack->stackBottom));
michael@0 191 }
michael@0 192 #else /* ! HAVE_STACK_GROWING_UP */
michael@0 193 if (t == current) {
michael@0 194 sp = (PRWord*) &stack_end;
michael@0 195 } else {
michael@0 196 sp = (PRWord*) PR_GetSP(t);
michael@0 197 }
michael@0 198 esp = (PRWord*) t->stack->stackTop;
michael@0 199 if (t->stack->stackSize) {
michael@0 200 PR_ASSERT((sp > (PRWord*)t->stack->stackBottom) &&
michael@0 201 (sp < (PRWord*)t->stack->stackTop));
michael@0 202 }
michael@0 203 #endif /* ! HAVE_STACK_GROWING_UP */
michael@0 204 #endif /* ! WIN16 */
michael@0 205 return (PRUword)t->stack->stackSize - ((PRWord)esp - (PRWord)sp);
michael@0 206 }

mercurial