libgo/runtime/stack.c
static void doscanstack1(G *gp, void *gcw) {
#ifdef USING_SPLIT_STACK
	void* sp;
	size_t spsize;
	void* next_segment;
	void* next_sp;
	void* initial_sp;

	if (gp == runtime_g()) {
		// Scanning our own stack.
		sp = __splitstack_find(nil, nil, &spsize, &next_segment,
				       &next_sp, &initial_sp);
	} else {
		// Scanning another goroutine's stack.
		// The goroutine is usually asleep (the world is stopped).

		// The exception is that if the goroutine is about to enter or might
		// have just exited a system call, it may be executing code such
		// as schedlock and may have needed to start a new stack segment.
		// Use the stack segment and stack pointer at the time of
		// the system call instead, since that won't change underfoot.
		if(gp->gcstack != 0) {
			sp = (void*)(gp->gcstack);
			spsize = gp->gcstacksize;
			next_segment = (void*)(gp->gcnextsegment);
			next_sp = (void*)(gp->gcnextsp);
			initial_sp = (void*)(gp->gcinitialsp);
		} else {
			sp = __splitstack_find_context((void**)(&gp->stackcontext[0]),
						       &spsize, &next_segment,
						       &next_sp, &initial_sp);
		}
	}
	if(sp != nil) {
		scanstackblock(sp, (uintptr)(spsize), gcw);
		while((sp = __splitstack_find(next_segment, next_sp,
					      &spsize, &next_segment,
					      &next_sp, &initial_sp)) != nil)
			scanstackblock(sp, (uintptr)(spsize), gcw);
	}
#else
	byte* bottom;
	byte* top;

	if(gp == runtime_g()) {
		// Scanning our own stack.
		bottom = (byte*)&gp;
	} else {
		// Scanning another goroutine's stack.
		// The goroutine is usually asleep (the world is stopped).
		bottom = (void*)gp->gcnextsp;
		if(bottom == nil)
			return;
	}
	top = (byte*)(void*)(gp->gcinitialsp) + gp->gcstacksize;
	if(top > bottom)
		scanstackblock(bottom, (uintptr)(top - bottom), gcw);
	else
		scanstackblock(top, (uintptr)(bottom - top), gcw);
#endif
}
// Scan gp's stack after saving registers.
Scan gp's stack after saving registers.
Scan gp ' s stack after saving registers .
static void doscanstack1(G *gp, void *gcw) {
#ifdef USING_SPLIT_STACK
	void* sp;
	size_t spsize;
	void* next_segment;
	void* next_sp;
	void* initial_sp;
	if (gp == runtime_g()) {
		sp = __splitstack_find(nil, nil, &spsize, &next_segment,
				       &next_sp, &initial_sp);
	} else {
		if(gp->gcstack != 0) {
			sp = (void*)(gp->gcstack);
			spsize = gp->gcstacksize;
			next_segment = (void*)(gp->gcnextsegment);
			next_sp = (void*)(gp->gcnextsp);
			initial_sp = (void*)(gp->gcinitialsp);
		} else {
			sp = __splitstack_find_context((void**)(&gp->stackcontext[0]),
						       &spsize, &next_segment,
						       &next_sp, &initial_sp);
		}
	}
	if(sp != nil) {
		scanstackblock(sp, (uintptr)(spsize), gcw);
		while((sp = __splitstack_find(next_segment, next_sp,
					      &spsize, &next_segment,
					      &next_sp, &initial_sp)) != nil)
			scanstackblock(sp, (uintptr)(spsize), gcw);
	}
#else
	byte* bottom;
	byte* top;
	if(gp == runtime_g()) {
		bottom = (byte*)&gp;
	} else {
		bottom = (void*)gp->gcnextsp;
		if(bottom == nil)
			return;
	}
	top = (byte*)(void*)(gp->gcinitialsp) + gp->gcstacksize;
	if(top > bottom)
		scanstackblock(bottom, (uintptr)(top - bottom), gcw);
	else
		scanstackblock(top, (uintptr)(bottom - top), gcw);
#endif
}
static void doscanstack1 ( G * gp , void * gcw ) { #ifdef USING_SPLIT_STACK void * sp ; size_t spsize ; void * next_segment ; void * next_sp ; void * initial_sp ; if ( gp == runtime_g ( ) ) { sp = __splitstack_find ( nil , nil , & spsize , & next_segment , & next_sp , & initial_sp ) ; } else { if ( gp -> gcstack != 0 ) { sp = ( void * ) ( gp -> gcstack ) ; spsize = gp -> gcstacksize ; next_segment = ( void * ) ( gp -> gcnextsegment ) ; next_sp = ( void * ) ( gp -> gcnextsp ) ; initial_sp = ( void * ) ( gp -> gcinitialsp ) ; } else { sp = __splitstack_find_context ( ( void * * ) ( & gp -> stackcontext [ 0 ] ) , & spsize , & next_segment , & next_sp , & initial_sp ) ; } } if ( sp != nil ) { scanstackblock ( sp , ( uintptr ) ( spsize ) , gcw ) ; while ( ( sp = __splitstack_find ( next_segment , next_sp , & spsize , & next_segment , & next_sp , & initial_sp ) ) != nil ) scanstackblock ( sp , ( uintptr ) ( spsize ) , gcw ) ; } #else byte * bottom ; byte * top ; if ( gp == runtime_g ( ) ) { bottom = ( byte * ) & gp ; } else { bottom = ( void * ) gp -> gcnextsp ; if ( bottom == nil ) return ; } top = ( byte * ) ( void * ) ( gp -> gcinitialsp ) + gp -> gcstacksize ; if ( top > bottom ) scanstackblock ( bottom , ( uintptr ) ( top - bottom ) , gcw ) ; else scanstackblock ( top , ( uintptr ) ( bottom - top ) , gcw ) ; #endif }
Scan gp's stack after saving registers.
Scan gp ' s stack after saving registers .
// Scanning our own stack. // Scanning another goroutine's stack. // The goroutine is usually asleep (the world is stopped). // The exception is that if the goroutine is about to enter or might // have just exited a system call, it may be executing code such // as schedlock and may have needed to start a new stack segment. // Use the stack segment and stack pointer at the time of // the system call instead, since that won't change underfoot. // Scanning our own stack. // Scanning another goroutine's stack. // The goroutine is usually asleep (the world is stopped).