// Free stack frames until we hit the last one // or until we find the one that contains the sp. static void unwindstack(G *gp, byte *sp) { Stktop *top; byte *stk; // Must be called from a different goroutine, usually m->g0. if(g == gp) runtime·throw("unwindstack on self"); while((top = (Stktop*)gp->stackbase) != nil && top->stackbase != nil) { stk = gp->stackguard - StackGuard; if(stk <= sp && sp < gp->stackbase) break; gp->stackbase = top->stackbase; gp->stackguard = top->stackguard; if(top->free != 0) runtime·stackfree(stk, top->free); } if(sp != nil && (sp < gp->stackguard - StackGuard || gp->stackbase < sp)) { runtime·printf("recover: %p not in [%p, %p]\n", sp, gp->stackguard - StackGuard, gp->stackbase); runtime·throw("bad unwindstack"); } }
//----------------------------------------------------------------------------- // Purpose: // Input : *tempVal - //----------------------------------------------------------------------------- void ConVar::ChangeStringValue( const char *tempVal, float flOldValue ) { Assert( !( m_nFlags & FCVAR_NEVER_AS_STRING ) ); char* pszOldValue = (char*)stackalloc( m_StringLength ); memcpy( pszOldValue, m_pszString, m_StringLength ); int len = Q_strlen(tempVal) + 1; if ( len > m_StringLength) { if (m_pszString) { delete[] m_pszString; } m_pszString = new char[len]; m_StringLength = len; } memcpy( m_pszString, tempVal, len ); // Invoke any necessary callback function if ( m_fnChangeCallback ) { m_fnChangeCallback( this, pszOldValue, flOldValue ); } g_pCVar->CallGlobalChangeCallbacks( this, pszOldValue, flOldValue ); stackfree( pszOldValue ); }
// Called from runtime·lessstack when returning from a function which // allocated a new stack segment. The function's return value is in // m->cret. void runtime·oldstack(void) { Stktop *top, old; uint32 argsize; uintptr cret; byte *sp; G *g1; int32 goid; //printf("oldstack m->cret=%p\n", m->cret); g1 = m->curg; top = (Stktop*)g1->stackbase; sp = (byte*)top; old = *top; argsize = old.argsize; if(argsize > 0) { sp -= argsize; runtime·memmove(top->argp, sp, argsize); } goid = old.gobuf.g->goid; // fault if g is bad, before gogo USED(goid); if(old.free != 0) runtime·stackfree(g1->stackguard - StackGuard, old.free); g1->stackbase = old.stackbase; g1->stackguard = old.stackguard; cret = m->cret; m->cret = 0; // drop reference runtime·gogo(&old.gobuf, cret); }
void runtime·oldstack(void) { Stktop *top, old; uint32 argsize; byte *sp; G *g1; static int32 goid; //printf("oldstack m->cret=%p\n", m->cret); g1 = m->curg; top = (Stktop*)g1->stackbase; sp = (byte*)top; old = *top; argsize = old.argsize; if(argsize > 0) { sp -= argsize; runtime·mcpy(top->argp, sp, argsize); } goid = old.gobuf.g->goid; // fault if g is bad, before gogo if(old.free != 0) runtime·stackfree(g1->stackguard - StackGuard, old.free); g1->stackbase = old.stackbase; g1->stackguard = old.stackguard; runtime·gogo(&old.gobuf, m->cret); }
void CEntityTouchManager::FrameUpdatePostEntityThink() { VPROF( "CEntityTouchManager::FrameUpdatePostEntityThink" ); // Loop through all entities again, checking their untouch if flagged to do so int count = m_updateList.Count(); if ( count ) { // copy off the list CBaseEntity **ents = (CBaseEntity **)stackalloc( sizeof(CBaseEntity *) * count ); memcpy( ents, m_updateList.Base(), sizeof(CBaseEntity *) * count ); // clear it m_updateList.RemoveAll(); // now update those ents for ( int i = 0; i < count; i++ ) { //Assert( ents[i]->GetCheckUntouch() ); if ( ents[i]->GetCheckUntouch() ) { ents[i]->PhysicsCheckForEntityUntouch(); } } stackfree( ents ); } }
//----------------------------------------------------------------------------- // Parse a single metaclass //----------------------------------------------------------------------------- bool CPanelMetaClassMgrImp::ParseSingleMetaClass( const char* pFileName, const char* pMetaClassName, KeyValues* pMetaClassValues, int keyValueIndex ) { // Complain about duplicately defined metaclass names... if ( m_MetaClassDict.Find( pMetaClassName ) != m_MetaClassDict.InvalidIndex() ) { Warning( "Meta class %s duplicately defined (file %s)\n", pMetaClassName, pFileName ); return false; } // find the type... const char* pPanelType = pMetaClassValues->GetString( "type" ); if (!pPanelType || !pPanelType[0]) { Warning( "Unable to find type of meta class %s in file %s\n", pMetaClassName, pFileName ); return false; } unsigned short i = m_PanelTypeDict.Find( pPanelType ); if (i == m_PanelTypeDict.InvalidIndex()) { Warning( "Type %s of meta class %s undefined!\n", pPanelType, pMetaClassName ); stackfree(pLwrMetaClass); return false; } // Add it to the metaclass dictionary MetaClassDict_t element; element.m_TypeIndex = i; element.m_KeyValueIndex = keyValueIndex; element.m_pKeyValues = pMetaClassValues; m_MetaClassDict.Insert( pMetaClassName, element ); return true; }
// Called from runtime·lessstack when returning from a function which // allocated a new stack segment. The function's return value is in // m->cret. void runtime·oldstack(void) { Stktop *top; uint32 argsize; byte *sp, *old; uintptr *src, *dst, *dstend; G *gp; int64 goid; int32 oldstatus; gp = m->curg; top = (Stktop*)gp->stackbase; old = (byte*)gp->stackguard - StackGuard; sp = (byte*)top; argsize = top->argsize; if(StackDebug >= 1) { runtime·printf("runtime: oldstack gobuf={pc:%p sp:%p lr:%p} cret=%p argsize=%p\n", top->gobuf.pc, top->gobuf.sp, top->gobuf.lr, (uintptr)m->cret, (uintptr)argsize); } // gp->status is usually Grunning, but it could be Gsyscall if a stack overflow // happens during a function call inside entersyscall. oldstatus = gp->status; gp->sched = top->gobuf; gp->sched.ret = m->cret; m->cret = 0; // drop reference gp->status = Gwaiting; gp->waitreason = "stack unsplit"; if(argsize > 0) { sp -= argsize; dst = (uintptr*)top->argp; dstend = dst + argsize/sizeof(*dst); src = (uintptr*)sp; while(dst < dstend) *dst++ = *src++; } goid = top->gobuf.g->goid; // fault if g is bad, before gogo USED(goid); gp->stackbase = top->stackbase; gp->stackguard = top->stackguard; gp->stackguard0 = gp->stackguard; gp->panicwrap = top->panicwrap; runtime·stackfree(gp, old, top); gp->status = oldstatus; runtime·gogo(&gp->sched); }
//----------------------------------------------------------------------------- // Call this to install a new panel type //----------------------------------------------------------------------------- void CPanelMetaClassMgrImp::InstallPanelType( const char* pPanelName, IPanelFactory* pFactory ) { Assert( pPanelName && pFactory ); // convert to lowercase int len = Q_strlen(pPanelName) + 1; char* pTemp = (char*)stackalloc( len ); Q_strncpy( pTemp, pPanelName, len ); Q_strnlwr( pTemp, len ); m_PanelTypeDict.Insert( pTemp, pFactory ); stackfree( pTemp ); }
// Called from runtime·lessstack when returning from a function which // allocated a new stack segment. The function's return value is in // m->cret. void runtime·oldstack(void) { Stktop *top; Gobuf label; uint32 argsize; uintptr cret; byte *sp, *old; uintptr *src, *dst, *dstend; G *gp; int64 goid; //printf("oldstack m->cret=%p\n", m->cret); gp = m->curg; top = (Stktop*)gp->stackbase; old = (byte*)gp->stackguard - StackGuard; sp = (byte*)top; argsize = top->argsize; if(argsize > 0) { sp -= argsize; dst = (uintptr*)top->argp; dstend = dst + argsize/sizeof(*dst); src = (uintptr*)sp; while(dst < dstend) *dst++ = *src++; } goid = top->gobuf.g->goid; // fault if g is bad, before gogo USED(goid); label = top->gobuf; gp->stackbase = (uintptr)top->stackbase; gp->stackguard = (uintptr)top->stackguard; if(top->free != 0) runtime·stackfree(old, top->free); cret = m->cret; m->cret = 0; // drop reference runtime·gogo(&label, cret); }
VALUE Primitive (POSITION position) { char* board; char searchchar, horizchar; BOOLEAN* visited; BOOLEAN search_horiz; int i, current, r, c; lnode* stack = NULL; board = (char*)SafeMalloc((possize)*sizeof(char)); visited = (BOOLEAN*)SafeMalloc((boardsize)*sizeof(BOOLEAN)); for(i = 0; i < boardsize; i++) visited[i] = FALSE; generic_hash_unhash(position, board); if(swapmode == SWAP_DIRECTION || swapmode == SWAP_BOTH) horizchar = board[possize-1]; else horizchar = DEFAULT_HORIZPLAYER == WHITEPLAYER ? WHITECHAR : BLACKCHAR; if(generic_hash_turn(position) == WHITEPLAYER) searchchar = BLACKCHAR; else searchchar = WHITECHAR; if(horizchar == searchchar) { search_horiz = TRUE; for(i = 0; i < boardrows; i++) { if(board[boardcols*i] == searchchar) { push(&stack, boardcols*i); visited[boardcols*i] = TRUE; } } } else { search_horiz = FALSE; for(i = 0; i < boardcols; i++) { if(board[i] == searchchar) { push(&stack, i); visited[i] = TRUE; } } } while(stack != NULL) { current = pop(&stack); if((search_horiz && current % boardcols == boardcols - 1 && board[current] == searchchar) || (!search_horiz && current / boardcols == boardrows - 1 && board[current] == searchchar)) { stackfree(stack); SafeFree(visited); SafeFree(board); return gStandardGame ? lose : win; } else { r = (int)(current / boardcols); c = (int)(current % boardcols); if(inbounds(r-1, c) && !(visited[c+(r-1)*boardcols]) && board[c+(r-1)*boardcols] == searchchar) { push(&stack, c+(r-1)*boardcols); visited[c+(r-1)*boardcols] = TRUE; } if(inbounds(r-1, c+1) && !(visited[(c+1)+(r-1)*boardcols]) && board[(c+1)+(r-1)*boardcols] == searchchar) { push(&stack, (c+1) + (r-1)*boardcols); visited[(c+1)+(r-1)*boardcols] = TRUE; } if(inbounds(r, c-1) && !(visited[(c-1) + r*boardcols]) && board[(c-1) + r*boardcols] == searchchar) { push(&stack, (c-1) + r*boardcols); visited[(c-1) + r*boardcols] = TRUE; } if(inbounds(r, c+1) && !(visited[(c+1) + r*boardcols]) && board[(c+1) + r*boardcols] == searchchar) { push(&stack, (c+1) + r*boardcols); visited[(c+1) + r*boardcols] = TRUE; } if(inbounds(r+1, c-1) && !(visited[(c-1) + (r+1)*boardcols]) && board[(c-1) + (r+1)*boardcols] == searchchar) { push(&stack, (c-1) + (r+1)*boardcols); visited[(c-1) + (r+1)*boardcols] = TRUE; } if(inbounds(r+1, c) && !(visited[c+(r+1)*boardcols]) && board[c+(r+1)*boardcols] == searchchar) { push(&stack, c + (r+1)*boardcols); visited[(c + (r+1)*boardcols)] = TRUE; } } } stackfree(stack); SafeFree(visited); SafeFree(board); return undecided; }
void EmitDispLMAlphaAndNeighbors() { int i; Msg( "Finding displacement neighbors...\n" ); // Build the CCoreDispInfos. CUtlVector<dface_t*> faces; // Create the core dispinfos and init them for use as CDispUtilsHelpers. for ( int iDisp = 0; iDisp < nummapdispinfo; ++iDisp ) { CCoreDispInfo *pDisp = new CCoreDispInfo; if ( !pDisp ) { g_CoreDispInfos.Purge(); return; } int nIndex = g_CoreDispInfos.AddToTail(); pDisp->SetListIndex( nIndex ); g_CoreDispInfos[nIndex] = pDisp; } for ( i=0; i < nummapdispinfo; i++ ) { g_CoreDispInfos[i]->SetDispUtilsHelperInfo( g_CoreDispInfos.Base(), nummapdispinfo ); } faces.SetSize( nummapdispinfo ); int nMemSize = texinfo.Count() * sizeof(int); int *pSwappedTexInfos = (int*)stackalloc( nMemSize ); memset( pSwappedTexInfos, 0xFF, nMemSize ); for( i = 0; i < numfaces; i++ ) { dface_t *pFace = &dfaces[i]; if( pFace->dispinfo == -1 ) continue; mapdispinfo_t *pMapDisp = &mapdispinfo[pFace->dispinfo]; // Set the displacement's face index. ddispinfo_t *pDisp = &g_dispinfo[pFace->dispinfo]; pDisp->m_iMapFace = i; // Get a CCoreDispInfo. All we need is the triangles and lightmap texture coordinates. CCoreDispInfo *pCoreDispInfo = g_CoreDispInfos[pFace->dispinfo]; DispMapToCoreDispInfo( pMapDisp, pCoreDispInfo, pFace, pSwappedTexInfos ); faces[pFace->dispinfo] = pFace; } stackfree( pSwappedTexInfos ); // Generate and export neighbor data. ExportNeighborData( g_CoreDispInfos.Base(), g_dispinfo.Base(), nummapdispinfo ); // Generate and export the active vert lists. ExportAllowedVertLists( g_CoreDispInfos.Base(), g_dispinfo.Base(), nummapdispinfo ); // Now that we know which vertices are actually going to be around, snap the ones that won't // be around onto the slightly-reduced mesh. This is so the engine's ray test code and // overlay code works right. SnapRemainingVertsToSurface( g_CoreDispInfos.Base(), g_dispinfo.Base(), nummapdispinfo ); Msg( "Finding lightmap sample positions...\n" ); for ( i=0; i < nummapdispinfo; i++ ) { dface_t *pFace = faces[i]; ddispinfo_t *pDisp = &g_dispinfo[pFace->dispinfo]; CCoreDispInfo *pCoreDispInfo = g_CoreDispInfos[i]; pDisp->m_iLightmapSamplePositionStart = g_DispLightmapSamplePositions.Count(); CalculateLightmapSamplePositions( pCoreDispInfo, pFace, g_DispLightmapSamplePositions ); } StartPacifier( "Displacement Alpha : "); // Build lightmap alphas. int dispCount = 0; // How many we've processed. for( i = 0; i < nummapdispinfo; i++ ) { dface_t *pFace = faces[i]; Assert( pFace->dispinfo == i ); ddispinfo_t *pDisp = &g_dispinfo[pFace->dispinfo]; // Allocate space for the alpha values. pDisp->m_iLightmapAlphaStart = 0; // not used anymore ++dispCount; } EndPacifier(); }
static void stackinit (int size) { stackfree (); stack = (int *) cs_malloc (size + 1, sizeof (int)); stk_p = 0; }