Example #1
0
TInt TestGetThreadContext(DThread* aThread,TDes8* aContext)
	{
	TArmRegSet context1;
	TArmRegSet context2;

	memclr(&context1,sizeof(context1));
	memclr(&context2,sizeof(context2));
	NKern::Lock();
	TUint32 unused;
	NKern::ThreadGetUserContext(&aThread->iNThread,&context1,unused);
	TInt r=GetThreadUserContext(&aThread->iNThread,context2);
	NKern::Unlock();
	DumpContext(context1,-1);
	DumpContext(context2,r);

	TInt len,maxLen;
	Kern::KUDesInfo(*aContext,len,maxLen);
	if(maxLen>KMaxThreadContext)
		maxLen = KMaxThreadContext;
	TPtr8 ptr((TUint8*)&context1,maxLen,maxLen);
	Kern::KUDesPut(*aContext,ptr);

	for(TUint i=0; i<sizeof(context1); i++)
		if(((TUint8*)&context1)[i]!=((TUint8*)&context2)[i])
			return KErrGeneral;
	return r;
	}
Example #2
0
/* ________________________________________________
 . watch thread creation
 . ________________________________________________ */
NTSTATUS NewZwCreateThread(
	OUT PHANDLE phThread,
	IN ACCESS_MASK AccessMask,
	IN POBJECT_ATTRIBUTES ObjectAttributes,
	IN HANDLE hProcess,
	OUT PCLIENT_ID pClientId,
	IN PCONTEXT pContext,
	OUT PSTACKINFO pStackInfo,
	IN BOOLEAN bSuspended
)
{
	int rc;
	STACKINFO StackInfo;
	CHAR aProcessName[PROCNAMELEN];
		
	GetProcessName( aProcessName );		
	DbgPrint("rootkit: NewZwCreateThread() from %s\n", aProcessName);

	DumpObjectAttributes(ObjectAttributes);

	if(bSuspended) DbgPrint("create suspended\n");

	DumpContext(pContext);
	
	/* dump stack info */
	if(pStackInfo)
	{
		DbgPrint("StackInfo.TopOfStack=0x%X\n", pStackInfo->TopOfStack);
		DbgPrint("StackInfo.BottomOfStack=0x%X\n", pStackInfo->BottomOfStack);
		DbgPrint("StackInfo.OnePageBelowTopOfStack=0x%X\n", pStackInfo->OnePageBelowTopOfStack);
	}

	DbgPrint("parent process 0x%X\n", hProcess);



	rc = ((ZWCREATETHREAD)(OldZwCreateThread)) (
									phThread,
									AccessMask,
									ObjectAttributes,
									hProcess,
									pClientId,
									pContext,
									pStackInfo,
									bSuspended
									);
	if(phThread) DbgPrint("thread handle 0x%X\n", *phThread);
	DbgPrint("ZwCreateThread : rc = %x\n", rc);
    
	
	DumpContext(pContext);
	
	return rc;
}
static void
VerifyContextParent(nsIFrame* aFrame, nsStyleContext* aContext,
                    nsStyleContext* aParentContext)
{
  // get the contexts not provided
  if (!aContext) {
    aContext = aFrame->StyleContext();
  }

  if (!aParentContext) {
    nsIFrame* providerFrame;
    aParentContext = aFrame->GetParentStyleContext(&providerFrame);
    // aParentContext could still be null
  }

  NS_ASSERTION(aContext, "Failure to get required contexts");
  nsStyleContext* actualParentContext = aContext->GetParent();

  if (aParentContext) {
    if (aParentContext != actualParentContext) {
      DumpContext(aFrame, aContext);
      if (aContext == aParentContext) {
        NS_ERROR("Using parent's style context");
      } else {
        NS_ERROR("Wrong parent style context");
        fputs("Wrong parent style context: ", stdout);
        DumpContext(nullptr, actualParentContext);
        fputs("should be using: ", stdout);
        DumpContext(nullptr, aParentContext);
        VerifySameTree(actualParentContext, aParentContext);
        fputs("\n", stdout);
      }
    }

  } else {
    if (actualParentContext) {
      NS_ERROR("Have parent context and shouldn't");
      DumpContext(aFrame, aContext);
      fputs("Has parent context: ", stdout);
      DumpContext(nullptr, actualParentContext);
      fputs("Should be null\n\n", stdout);
    }
  }

  nsStyleContext* childStyleIfVisited = aContext->GetStyleIfVisited();
  // Either childStyleIfVisited has aContext->GetParent()->GetStyleIfVisited()
  // as the parent or it has a different rulenode from aContext _and_ has
  // aContext->GetParent() as the parent.
  if (childStyleIfVisited &&
      !((childStyleIfVisited->RuleNode() != aContext->RuleNode() &&
         childStyleIfVisited->GetParent() == aContext->GetParent()) ||
        childStyleIfVisited->GetParent() ==
          aContext->GetParent()->GetStyleIfVisited())) {
    NS_ERROR("Visited style has wrong parent");
    DumpContext(aFrame, aContext);
    fputs("\n", stdout);
  }
}