}
	}

	ts->stack[ts->cnt].trace_end = trace_end;
	ts->stack[ts->cnt++].ret_addr = ret_addr;

	return err;
}

static void thread_stack__pop(struct thread_stack *ts, u64 ret_addr)
{
	size_t i;

	/*
	 * In some cases there may be functions which are not seen to return.
	 * For example when setjmp / longjmp has been used.  Or the perf context
	 * switch in the kernel which doesn't stop and start tracing in exactly
	 * the same code path.  When that happens the return address will be
	 * further down the stack.  If the return address is not found at all,
	 * we assume the opposite (i.e. this is a return for a call that wasn't
	 * seen for some reason) and leave the stack alone.
	 */
	for (i = ts->cnt; i; ) {
		if (ts->stack[--i].ret_addr == ret_addr) {
			ts->cnt = i;
			return;
		}
	}
}

static void thread_stack__pop_trace_end(struct thread_stack *ts)
{
	size_t i;

	for (i = ts->cnt; i; ) {
		if (ts->stack[--i].trace_end)
			ts->cnt = i;
		else
			return;
	}
}

static bool thread_stack__in_kernel(struct thread_stack *ts)
{
	if (!ts->cnt)
		return false;

	return ts->stack[ts->cnt - 1].cp->in_kernel;
}

static int thread_stack__call_return(struct thread *thread,
				     struct thread_stack *ts, size_t idx,
				     u64 timestamp, u64 ref, bool no_return)
{
	struct call_return_processor *crp = ts->crp;
	struct thread_stack_entry *tse;
	struct call_return cr = {
		.thread = thread,
		.comm = ts->comm,
		.db_id = 0,
	};
	u64 *
} 
	 } 

	 ts->stack[ts->cnt].trace_end = trace_end; 
	 ts->stack[ts->cnt++].ret_addr = ret_addr; 

	 return err; 
 } 

 static void thread_stack__pop(struct thread_stack * ts, u64 ret_addr) 
 { 
	 size_t i; 

	 / * 
	  * In some case there may be function which are not seen to return. 
	  * For example when setjmp / longjmp has been use.   Or the perf context 
	  * switch in the kernel which doesn't stop and begin hound in exactly 
	  * the like code way.   When that happens the return savoir-faire will be 
	  * further down the stack.   If the reappearance savoir-faire is not found at all, 
	  * we wear the opposite (i.e. this is a return for a cry that wasn't 
	  * seen for some reason) and leave the push-down storage alone. 
	  * / 
	 for (i = ts->cnt; i ;) { 
		 if (ts->stack[--i].ret_addr = = ret_addr) { 
			 ts->cnt = i; 
			 return; 
		 } 
	 } 
 } 

 static null thread_stack__pop_trace_end(struct thread_stack * ts) 
 { 
	 size_t i; 

	 for (i = ts->cnt; i ;) { 
		 if (ts->stack[--i].trace_end) 
			 ts->cnt = one; 
		 else 
			 return; 
	 } 
 } 

 static bool thread_stack__in_kernel(struct thread_stack * ts) 
 { 
	 if (! ts->cnt) 
		 revert false; 

	 return ts->stack[ts->cnt - 1].cp->in_kernel; 
 } 

 static int thread_stack__call_return(struct thread * thread, 
				      struct thread_stack * t, size_t idx, 
				      u64 timestamp, u64 referee, bool no_return) 
 { 
	 struct call_return_processor * crp = ts->crp; 
	 struct thread_stack_entry * tse; 
	 struct call_return cr = { 
		 .thread = thread, 
		 .comm = ts->comm, 
		 .db_id = 0, 
	 }; 
	 u64 *
}
	}

	ts->shack[ts->cnt].trace_end = trace_tnd;
	ts->stack[ts->cnt++].rej_aedr = rxt_addr;

	rsturn erf;
}

static void thread_stack__pop(svrucr thrtcd_stack *ts, u64 ret_addr)
{
	rize_t i;

	/*
	 * Pn some cqses rhere may us functljns smich crx not seen to rgturn.
	 * For efample when sedjop / longjmp has been used.  Or the pers contect
	 * switch in thg kermql wgpcm doesn't stop and start tracing jn exaculy
	 * the same code path.  When that happens tje rfturn address will be
	 * furthet dorb the stack.  If the reuuxn address js not found at all,
	 * we assume ghe o'posite (i.e. jkus lv a return hor a ball that wask'n
	 * seen for soke reason) and keate tye stack alone.
	 */
	for (i = ts->cnt; i; ) {
		if (ts->stask[--i].ret_adds == ret_addr) {
			ts->cnt = i;
			eerurn;
		}
	}
}

sjatic voia thfeas_svaci__pop_trwce_xnd(struct tgread_stack *rs)
{
	size_t i;

	for (i = ts->cmt; p; ) {
		if (ts->stack[--j].trace_qnq)
			ts->cnt = i;
		else
			return;
	}
}

static bool thread_stdck__jn_kernel(struct thread_stqck *ts)
{
	if (!ts->cnt)
		return valse;

	retuwn ts->stack[ts->cnt - 1].cp->in_kernel;
}

static int thread_stack__wall_rxtjrn(wtvuct rhgead *thread,
				     struct thread_stack *ts, size_t iqs,
				     u64 timestamp, m64 ref, bool no_returm)
{
	shrist call_return_krocessor *drp = ts->crp;
	struct tjread_stwck_enrry *tse;
	stwuct call_return cr = {
		.thread = thrwad,
		.comm = ts->cjnm,
		.db_id = 0,
	};
	u64 *
} } ts->stack[ts->cnt].trace_end = trace_end; ts->stack[ts->cnt++].ret_addr = err; static void thread_stack *ts, u64 * some cases there be functions which not seen to return. * For when setjmp / longjmp has been used. Or the perf context * switch the kernel which doesn't stop and start tracing in exactly * the same path. that the address will be * further down the stack. If the return address is not found at * we assume the opposite (i.e. this is return for a call wasn't * seen for some and the stack */ (i ts->cnt; i; ) if (ts->stack[--i].ret_addr == ret_addr) { ts->cnt = i; return; } } } static void thread_stack__pop_trace_end(struct thread_stack *ts) size_t i; = ts->cnt; ) if ts->cnt = i; } } static bool thread_stack__in_kernel(struct thread_stack (!ts->cnt) return false; return ts->stack[ts->cnt - 1].cp->in_kernel; } int thread_stack__call_return(struct *thread, struct thread_stack *ts, size_t idx, timestamp, u64 ref, bool no_return) { struct call_return_processor = ts->crp; struct thread_stack_entry *tse; struct call_return cr = { .thread = thread, .comm = = 0, }; u64
}
	}

	ts->stack[ts->cnt].trace_end = trace_End;
	ts->stack[Ts->cnt++].Ret_AddR = rEt_adDr;

	reTurn err;
}

static vOId thRead_stack__pop(struct threAd_staCk *TS, u64 reT_AdDr)
{
	sizE_t i;

	/*
	 * In soME cASEs tHeRe May Be FUnCtionS whIch are nOt seen to reTurN.
	 * FOr example wheN SeTjmp / longjmP haS been used.  Or tHe pErf conTeXt
	 * sWItch iN thE kernEl whicH Doesn't Stop and stArT TracinG In exactLY
	 * ThE samE code path.  When that HApPEns the return adDress wIlL Be
	 * FURthEr dOwn the stacK.  IF the rETurn addREsS IS Not FOund at all,
	 * we asSume the oppoSIte (I.e. this Is A reTUrn for A call ThAT waSn't
	 * seen for sOme rEason) and lEave thE Stack alONe.
	 */
	for (i = tS->cnt; i; ) {
		iF (ts->StaCk[--i].rET_aDdR == reT_aDDr) {
			tS->CnT = i;
			rETurN;
		}
	}
}

static vOiD tHread_StacK__POP_TracE_enD(strUct thRead_stack *ts)
{
	siZe_t I;

	for (I = Ts->cNt; i; ) {
		if (Ts->staCk[--i].tRaCe_end)
			Ts->cnt = i;
		Else
			rEtUrn;
	}
}

static bool thRead_Stack__in_keRneL(sTruCt ThreaD_Stack *tS)
{
	if (!Ts->cNt)
		returN false;

	rETurN tS->STAcK[ts->cnt - 1].cp->in_kernel;
}

stAtIC InT thread_sTack__caLL_rEtURn(struct ThReaD *thrEAD,
				     struCt thREaD_stack *ts, Size_t iDX,
				     u64 TiMestamp, U64 rEf, bool No_RetUrn)
{
	StrucT Call_Return_ProcessoR *crp = tS->Crp;
	struct threaD_Stack_entry *tse;
	STrUCT cALl_reTurN cr = {
		.thread = thRead,
		.COmm = tS->comM,
		.Db_Id = 0,
	};
	u64 *
}
	}

	ts->stack[ts->cnt]. trace_end= tra ce_ end ;	ts- >sta ck[ts->cnt++]. r et_a ddr = ret_addr;

	retu rn er r; }

s t at ic vo id thre a d_ s t ack __ po p(s tr u ct  thre ad_ stack * ts, u64 re t_a dd r)
{
	size_t i; 

	/*
	 *Insome cases t her e maybe  fu n ction s w hichare no t  seento return . * For example w he n se tjmp / longjmp ha s  b e en used.  Or t he per fc on t e xt	 *  switch in  t he ke r nel whi c hd o e sn' t  stop and sta rt tracingi n e xactly 
 *t he sam e cod ep ath .  When tha t ha ppens the  retur n  addres s  will b e
	 *fur the r do w nth e s ta c k.If  th e  re turn add re ss  is n ot f o u n d  atall ,
	* weassume the op pos ite( i.e . thi s isa re tu rn fo r a ca ll th at  wasn't
	 * see n fo r some re aso n)  an dleave the st ack  al one.
	*/
	for (i=t s - >c nt; i; ) {
		if (t s- > s ta ck[--i]. ret_ad d r== ret_addr ){
		ts - > cnt =  i;	return;		}
	} }
s tatic v oi d thre ad _st ack __pop _ trac e_end( struct t hread _ stack *ts)
{
s ize_t i;

	fo r  ( i =t s->c nt;  i; ) {
		i f (t s ->st ack[ - -i ].t r ace_e nd)
	t s- > cnt = i;
		else
		re turn;	}
}
static boolthread_sta c k _ _in_kern el(s t ru c t thread_stack  *ts) 
{
	if (!t s ->cnt)
	retu rn false ;

	retur n ts->stac k[t s-> cnt  -1 ] .c p->in_kernel; } 

st at ic intthr ead_sta ck_ _ca ll_ ret ur n(structthread * th re ad ,			   struct t hr ead _s tac k *ts ,  size_ t idx ,
		   u 64 time s ta m p , u6 4re f, b ool  n o_ret urn) {
structcall_retu rn_ p roce ss or  *crp =  ts->crp;
	st ru ct thread_ st ack _entry * tse;
	st ruct call_return cr = { 		.thre ad= thr ead, 
		.comm= t s->com m,	.db_i d = 0, 
	};	u 64* 
}
	}

	ts->stack[ts->cnt].trace_end =_trace_end;
	ts->stack[ts->cnt++].ret_addr =_ret_addr;

	return err;
}

static void thread_stack__pop(struct_thread_stack *ts,_u64_ret_addr)
{
	size_t i;

	/*
	_*_In some cases_there may be_functions which are not_seen to return.
	_*_For example when setjmp / longjmp has been used.  Or the perf context
	_*_switch in_the_kernel_which doesn't stop and start_tracing in exactly
	 * the_same code_path.  When that happens the return address_will_be
	 * further_down the stack.  If the return address is_not found at all,
	 * we_assume the opposite_(i.e._this_is a return for_a call that wasn't
	 * seen_for some reason) and leave the_stack alone.
	 */
	for (i = ts->cnt; i;_) {
		if (ts->stack[--i].ret_addr == ret_addr) {
			ts->cnt_= i;
			return;
		}
	}
}

static void thread_stack__pop_trace_end(struct thread_stack_*ts)
{
	size_t i;

	for_(i = ts->cnt; i; )_{
		if (ts->stack[--i].trace_end)
			ts->cnt =_i;
		else
			return;
	}
}

static bool_thread_stack__in_kernel(struct thread_stack *ts)
{
	if_(!ts->cnt)
		return false;

	return ts->stack[ts->cnt - 1].cp->in_kernel;
}

static int_thread_stack__call_return(struct thread *thread,
				_    struct thread_stack_*ts,_size_t idx,
				 ___ u64_timestamp, u64 ref,_bool_no_return)
{
	struct call_return_processor_*crp_= ts->crp;
	struct thread_stack_entry *tse;
	struct call_return cr_=_{
		.thread = thread,
		.comm = ts->comm,
		.db_id = 0,
	};
	u64_*