Esempio n. 1
0
        Addr
        Socket::getName() const
        {
            if( isOpen() )
            {
                Addr::AddrType name;
                socklen_t from_len = sizeof( name );
                int err = ::getsockname( getFD(),
                                         (struct sockaddr *)&name,
                                         &from_len );
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(CYGWIN)
                if( err == SOCKET_ERROR )
                {
                    err = WSAGetLastError();
                    return Addr();
                }
#else
                if( err < 0 )
                    return Addr();
#endif
                return Addr( name );
            }
            else
                return Addr();
        }
Esempio n. 2
0
// display player message
void BWMem::DisplayPlayerMessage(HANDLE hProcess, HWND hWndBW, const char *msgtext, int durationS)
{
	// read current message index
	unsigned char index;
	ReadBytes(hProcess, (char*)Addr(MSGINDEX), (char*)&index, sizeof(index));

	// real index
	int realindex = (int)index;
	DWORD adr = Addr(MSGTEXT0)+realindex*218;
	DWORD adrt = Addr(MSGTICK0)+realindex*4;

	// write message time
	DWORD time = GetTickCount() + durationS*1000;
	WriteBytes(hProcess, (char*)adrt, (char*)&time, sizeof(time));

	// write message text
	WriteBytes(hProcess, (char*)adr, msgtext, strlen(msgtext)+1);

	// increment message index
	index = (index+1)%11;
	WriteBytes(hProcess, (char*)Addr(MSGINDEX), (char*)&index, sizeof(index));

	// invalidate screen
	Sleep(100);
	_Invalidate(hWndBW);
}
Esempio n. 3
0
/*
** Set the Expr.span field of the given expression to span all
** text between the two given tokens.
*/
void sqliteExprSpan(Expr *pExpr, Token *pLeft, Token *pRight){
  assert( pRight!=0 );
  assert( pLeft!=0 );
  /* Note: pExpr might be NULL due to a prior malloc failure */
  if( pExpr && pRight->z && pLeft->z ){
    if( pLeft->dyn==0 && pRight->dyn==0 ){
      pExpr->span.z = pLeft->z;
      pExpr->span.n = pRight->n + Addr(pRight->z) - Addr(pLeft->z);
    }else{
      pExpr->span.z = 0;
    }
  }
}
Esempio n. 4
0
// get game time (in tick unit, divide by 24 to get seconds)
unsigned long BWMem::GetTick(HANDLE hProcess)
{
	// read current tick
	unsigned long tick;
	ReadBytes(hProcess, (char*)Addr(TICK), (char*)&tick, sizeof(tick));
	return tick;
}
Esempio n. 5
0
void* CModule::AddFunction(LPCTSTR pFunctionName)
{_STT();
	// Sanity check
	if ( pFunctionName == NULL ) return NULL;

	void *pf = Addr( pFunctionName );
	if ( pf != NULL ) return pf;

	pf = (void*)GetProcAddress( m_hModule, pFunctionName );
	if ( pf == NULL ) return FALSE;

	// Save index
	DWORD index = Size();

	// Allocate memory
	LPFUNCTIONINFO pfi = (LPFUNCTIONINFO)New( NULL, 0, pFunctionName );
	if ( pfi == NULL ) return FALSE;
	
	// Save function name and address
	pfi->addr = pf;

	// Need more space?
	if ( m_ptrs.size() <= index )
	{	if ( index < 8 ) m_ptrs.grow( 8 ); else m_ptrs.grow( index * 2 ); }
	m_ptrs[ index ] = pf;

	return pf;	
}
Esempio n. 6
0
	Addr max_addr()
	{
		Addr tmp;
		std::fill(tmp.begin(), tmp.end()
			, (std::numeric_limits<typename Addr::value_type>::max)());
		return Addr(tmp);
	}
Esempio n. 7
0
// get replay file (if any)
const char *BWMem::GetReplay(HANDLE hProcess, char *repfile)
{
	// read replay file name if any
	repfile[0]=0;
	ReadBytes(hProcess, (char*)Addr(REPLAYFILE), repfile, 255);
	if(strlen(repfile)<=4 || stricmp(&repfile[strlen(repfile)-4],".rep")!=0) repfile[0]=0;
	return repfile;
}
Esempio n. 8
0
BWrepPlayerInfo *BWMem::GetPlayerDesc(HANDLE hProcess)
{
	// read login
	char name[32];
	BWMem::ReadBytes(hProcess, (char*)Addr(LOGIN), name, sizeof(name));
	if(name[0]!=0)
		return _GetAnyPlayerDesc(hProcess, name);
	return 0;
}
Esempio n. 9
0
 InetAddressV4 InetAddressV4::CreateFromString(std::string const &addr, unsigned short port)
 {
   sockaddr_in SockAddr = { 0 };
   SockAddr.sin_family = AF_INET;
   SockAddr.sin_addr.s_addr = inet_addr(addr.c_str());
   SockAddr.sin_port = htons(port);
   InetAddressV4 Addr(reinterpret_cast<sockaddr const *>(&SockAddr), sizeof(SockAddr));
   return Addr;
 }
Esempio n. 10
0
// get player supply
void BWMem::GetSupply(HANDLE hProcess, int *used, int *available)
{
	char sup[16];
	ReadBytes(hProcess, (char*)Addr(SUPPLY_STR), (char*)&sup, sizeof(sup));
	*used = atoi(&sup[1]);
	char *p=&sup[1];
	while(*p!='/' && p<&sup[16]) p++;
	*available = atoi(&p[1]);
}
Esempio n. 11
0
        int
        Socket::recv( char* msg,
                      size_t len,
                      Addr& from,
                      int flags,
                      CheckingType check )
        {
            if( check == DONT_CHECK )
            {
                Addr::AddrType addr;
                socklen_t from_len = sizeof( addr );
                int rval = ::recvfrom( getFD(), msg,
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
                                                                           (int)len,
#else
                                                                           len,
#endif
                                                                           flags,
                                       (struct sockaddr *)&addr, &from_len );
                from = Addr( addr );
                return rval;
            }
            else
            {
                for(;;)
                {
                    Addr::AddrType addr;
                    socklen_t from_len = sizeof( addr );
                    int received = ::recvfrom( getFD(), msg,
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
                                                                                  (int)len,
#else
                                                                                   len,
#endif
                                                                                   flags,
                                               (struct sockaddr *)&addr,
                                               &from_len );
                    from = Addr( addr );
                    if( received != -1
                        || errno != EINTR )
                        return received;
                }
            }
        }
Esempio n. 12
0
Addr Socket::getPeer() const
{
	Addr::AddrType name;
	socklen_t from_len = sizeof (name);
	int err = ::getpeername(m_socket, (struct sockaddr *) & name, &from_len);
	if(err < 0)
		throw GetNameErr(errno);

	return Addr(name);
}
Esempio n. 13
0
std::size_t do_parse_successor(const_buffer buf, ip::tcp::endpoint& ep)
{
	const successor_frame<Addr>* frame = buffer_cast<const successor_frame<Addr>*>(buf);

	typename Addr::bytes_type ip_bytes;
	std::memcpy(ip_bytes.data(), frame->sucessor_ip, ip_bytes.size());
	ep.address(Addr(ip_bytes));
	ep.port(u16(frame->sucessor_port));

	return sizeof(successor_frame<Addr>);
}
static inline
typename Generic_obj_space<SPACE>::Addr
Generic_obj_space<SPACE>::map_max_address()
{
  Mword r;

  r = (Mem_layout::Caps_end - Mem_layout::Caps_start) / sizeof(Entry);
  if (Map_max_address < r)
    r = Map_max_address;

  return Addr(r);
}
Esempio n. 15
0
/*
** This routine is called by the parser while in the middle of
** parsing a variable declaration in a procedure block.  The pFirst
** token is the first token in the sequence of tokens that describe
** the type of the variable currently under construction.   pLast is
** the last token in the sequence.  Use this information to
** construct a string that contains the typename of the variable
** and store that string in zType.
*/ 
void sqliteAddProcVarType(Parse *pParse, Token *pFirst, Token *pLast){
  Block *p;
  int i, j;
  int n;
  char *z, **pz;
  Variable *pVar;

  if( (p = pParse->pCurrentBlock)==0 ) return;
  i = p->nVar-1;
  if( i<0 ) return;
  pVar = &p->aVar[i];
  pz = &pVar->zType;
  n = pLast->n + Addr(pLast->z) - Addr(pFirst->z);
  sqliteSetNString(pz, pFirst->z, n, 0);
  z = *pz;
  if( z==0 ) return;
  for(i=j=0; z[i]; i++){
    int c = z[i];
    if( isspace(c) ) continue;
    z[j++] = c;
  }
  z[j] = 0;
}
Esempio n. 16
0
int Socket::recv(char* msg, size_t len, Addr& from, int flags, CheckingType check)
{
	if(check == DONT_CHECK)
	{
		Addr::AddrType addr;
		socklen_t from_len = sizeof (addr);
		int rval = ::recvfrom(m_socket, msg, len, flags, (struct sockaddr *) & addr, &from_len);
		from = Addr(addr);
		return rval;
	}
	else
	{
		for(;;)
		{
			Addr::AddrType addr;
			socklen_t from_len = sizeof (addr);
			int received = ::recvfrom(m_socket, msg, len, flags, (struct sockaddr *) & addr, &from_len);
			from = Addr(addr);
			if(received != -1 || errno != EINTR)
				return received;
		}
	}
}
Esempio n. 17
0
BOOL CR_ModuleEx::_PrepareForDisAsm32() {
    if (!IsModuleLoaded() || !Is32Bit())
        return FALSE;

    _CreateInfo32();

    if (Info32()->Entrances().size()) {
        return TRUE;
    }

    // register entrances
    auto RVA = RVAOfEntryPoint();
    CR_Addr32 va = VA32FromRVA(RVA);
    Info32()->Entrances().emplace(va);
    {
        auto codefunc = make_shared<CR_CodeFunc32>();
        codefunc->Addr() = va;
        codefunc->Name() = "EntryPoint";
        codefunc->StackArgSizeRange().Set(0);
        codefunc->FuncFlags() |= cr_FF_CDECL;
        Info32()->MapAddrToCodeFunc().emplace(va, codefunc);
        MapRVAToFuncName().emplace(RVA, codefunc->Name());
        MapFuncNameToRVA().emplace(codefunc->Name(), RVA);
    }

    // exporting functions are entrances
    for (auto& e_symbol : ExportSymbols()) {
        va = VA32FromRVA(e_symbol.dwRVA);
        if (!AddressInCode32(va)) {
            continue;
        }

        Info32()->Entrances().emplace(va);
        MapRVAToFuncName().emplace(e_symbol.dwRVA, e_symbol.pszName);
        MapFuncNameToRVA().emplace(e_symbol.pszName, e_symbol.dwRVA);
    }
    return TRUE;
} // CR_ModuleEx::_PrepareForDisAsm32
Esempio n. 18
0
BOOL CR_ModuleEx::_DisAsmAddr64(CR_Addr64 func, CR_Addr64 va) {
    if (!IsModuleLoaded() || !Is64Bit())
        return FALSE;

    // calculate
    int len;
    char outbuf[256];
    CR_Addr64 addr;

    // add or retrieve the code function
    auto cf = Info64()->CodeFuncFromAddr(func);
    if (cf == NULL) {
        Info64()->MapAddrToCodeFunc().emplace(func, make_shared<CR_CodeFunc64>());
        cf = Info64()->CodeFuncFromAddr(func);
    }
    assert(cf);
    if (func == va) {
        cf->Addr() = func;
    }

    auto pCode = CodeSectionHeader();
    assert(pCode);

    DWORD rva = RVAFromVA64(va);
    LPBYTE input = m_pLoadedImage + rva;
    LPBYTE iend = m_pLoadedImage + pCode->RVA + pCode->SizeOfRawData;
    while (input < iend) {
        // add or retrieve op.code
        auto oc = Info64()->OpCodeFromAddr(va);
        if (oc == NULL) {
            Info64()->MapAddrToOpCode().emplace(va, make_shared<CR_OpCode64>());
            oc = Info64()->OpCodeFromAddr(va);
            // set op.code address
            oc->Addr() = va;
        }
        assert(oc);
        if (oc->FuncAddrs().count(func) > 0)
            break;


        // add function address for this op.code
        oc->FuncAddrs().emplace(func);
        if (oc->FuncAddrs().size() > 1) {
            cf->FuncFlags() |= cr_FF_FUNCINFUNC;   // function in function
        }

        if (oc->Codes().empty()) {
            // disassemble
            len = disasm(input, outbuf, sizeof(outbuf), 64, va, false, 0);

            // parse insn
            if (!len || input + len > iend) {
                len = 1;
                oc->Name() = "???";
                oc->OpCodeType() = cr_OCT_UNKNOWN;
                // don't decompile if any unknown instruction.
                cf->FuncFlags() |= cr_FF_INVALID;
            } else {
                oc->Parse(outbuf);
            }

            // complement operand size
            oc->DeductOperandSizes();

            // add asm codes to op.code
            oc->Codes().insert(oc->Codes().end(), input, &input[len]);
        } else {
            len = int(oc->Codes().size());
        }

        BOOL bBreak = FALSE;
        switch (oc->OpCodeType()) {
        case cr_OCT_JCC:    // conditional jump
            switch (oc->Operand(0)->GetOperandType()) {
            case cr_DF_IMM:
                addr = oc->Operand(0)->Value64();
                cf->Jumpers().emplace(va);
                cf->Jumpees().emplace(addr);
                break;

            default:
                break;
            }
            break;

        case cr_OCT_JMP:    // jump
            switch (oc->Operand(0)->GetOperandType()) {
            case cr_DF_IMM:
                if (func == va) {
                    // func is jumper
                    cf->FuncFlags() |= cr_FF_JUMPERFUNC;

                    addr = oc->Operand(0)->Value64();
                    Info64()->Entrances().emplace(addr);
                    cf->Callers().emplace(addr);

                    auto newcf = Info64()->CodeFuncFromAddr(addr);
                    if (newcf == NULL) {
                        Info64()->MapAddrToCodeFunc().emplace(
                            addr, make_shared<CR_CodeFunc64>());
                        newcf = Info64()->CodeFuncFromAddr(addr);
                    }
                    newcf->Addr() = addr;
                    newcf->Callees().emplace(func);
                } else {
                    addr = oc->Operand(0)->Value64();
                    cf->Jumpers().emplace(va);
                    cf->Jumpees().emplace(addr);
                }
                break;

            case cr_DF_MEMIMM:
                if (func == va) {
                    // func is jumper
                    cf->FuncFlags() |= cr_FF_JUMPERFUNC;

                    bBreak = TRUE;
                }
                break;

            default:
                break;
            }
            bBreak = TRUE;
            break;

        case cr_OCT_CALL:   // call
            switch (oc->Operand(0)->GetOperandType()) {
            case cr_DF_IMM:
                // function call
                addr = oc->Operand(0)->Value64();
                Info64()->Entrances().emplace(addr);
                cf->Callees().emplace(addr);
                {
                    auto newcf = Info64()->CodeFuncFromAddr(addr);
                    if (newcf == NULL) {
                        Info64()->MapAddrToCodeFunc().emplace(
                            addr, make_shared<CR_CodeFunc64>());
                        newcf = Info64()->CodeFuncFromAddr(addr);
                    }
                    newcf->Addr() = addr;
                    newcf->Callers().emplace(func);
                }
                break;

            default:
                break;
            }
            break;

        case cr_OCT_RETURN: // return
            if (oc->Operands().size() && oc->Operand(0)->GetOperandType() == cr_DF_IMM) {
                cf->StackArgSizeRange().Set(oc->Operand(0)->Value64());
            } else {
                if (func == va) {
                    cf->FuncFlags() |= cr_FF_RETURNONLY;
                }
            }
            cf->Exits().insert(va);
            bBreak = TRUE;
            break;

        default:
            break;
        }

        if (bBreak)
            break;

        // move to next position
        input += len;
        va += len;
    }

    return TRUE;
} // CR_ModuleEx::_DisAsmAddr64
Esempio n. 19
0
// get player gas resources
unsigned long BWMem::GetGas(HANDLE hProcess)
{
	unsigned long gas;
	ReadBytes(hProcess, (char*)Addr(GAS), (char*)&gas, sizeof(gas));
	return gas;
}
Esempio n. 20
0
void random_setup(
    size_t                                    num_var    ,
    const pod_vector<opcode_t>&               op_vec     ,
    const pod_vector<addr_t>&                 arg_vec    ,
    pod_vector<Addr>*                         op2arg_vec ,
    pod_vector<Addr>*                         op2var_vec ,
    pod_vector<Addr>*                         var2op_vec )
{
    if( op2arg_vec->size() != 0 )
    {   CPPAD_ASSERT_UNKNOWN( op2arg_vec->size() == op_vec.size() );
        CPPAD_ASSERT_UNKNOWN( op2var_vec->size() == op_vec.size() );
        CPPAD_ASSERT_UNKNOWN( var2op_vec->size() == num_var        );
        return;
    }
    CPPAD_ASSERT_UNKNOWN( op2var_vec->size() == 0         );
    CPPAD_ASSERT_UNKNOWN( op2var_vec->size() == 0         );
    CPPAD_ASSERT_UNKNOWN( var2op_vec->size() == 0         );
    CPPAD_ASSERT_UNKNOWN( OpCode( op_vec[0] ) == BeginOp );
    CPPAD_ASSERT_NARG_NRES(BeginOp, 1, 1);
    //
    size_t num_op     = op_vec.size();
    size_t  var_index = 0;
    size_t  arg_index = 0;
    //
    op2arg_vec->resize( num_op );
    op2var_vec->resize( num_op );
    var2op_vec->resize( num_var  );
# ifndef NDEBUG
    // value of var2op for auxillary variables is num_op (invalid)
    for(size_t i_var = 0; i_var < num_var; ++i_var)
        (*var2op_vec)[i_var] = Addr( num_op );
    // value of op2var is num_var (invalid) when NumRes(op) = 0
    for(size_t i_op = 0; i_op < num_op; ++i_op)
        (*op2var_vec)[i_op] = Addr( num_var );
# endif
    for(size_t i_op = 0; i_op < num_op; ++i_op)
    {   OpCode  op          = OpCode( op_vec[i_op] );
        //
        // index of first argument for this operator
        (*op2arg_vec)[i_op]   = Addr( arg_index );
        arg_index            += NumArg(op);
        //
        // index of first result for next operator
        var_index  += NumRes(op);
        if( NumRes(op) > 0 )
        {   // index of last (primary) result for this operator
            (*op2var_vec)[i_op] = Addr( var_index - 1 );
            //
            // mapping from primary variable to its operator
            (*var2op_vec)[var_index - 1] = Addr( i_op );
        }
        // CSumOp
        if( op == CSumOp )
        {   CPPAD_ASSERT_UNKNOWN( NumArg(CSumOp) == 0 );
            //
            // pointer to first argument for this operator
            const addr_t* op_arg = arg_vec.data() + arg_index;
            //
            // The actual number of arugments for this operator is
            // op_arg[4] + 1
            // Correct index of first argument for next operator
            arg_index += size_t(op_arg[4] + 1);
        }
        //
        // CSkip
        if( op == CSkipOp )
        {   CPPAD_ASSERT_UNKNOWN( NumArg(CSumOp) == 0 );
            //
            // pointer to first argument for this operator
            const addr_t* op_arg = arg_vec.data() + arg_index;
            //
            // The actual number of arugments for this operator is
            // 7 + op_arg[4] + op_arg[5].
            // Correct index of first argument for next operator.
            arg_index += size_t(7 + op_arg[4] + op_arg[5]);
        }
    }
}
Esempio n. 21
0
Token DnInLexer::nextToken() {
  while(c != LEX_EOF) {
    switch(c) {
      case ' ': case '\t': case '\n': case '\r': skipSpaces(); continue;
      case '=':
        consume();
        if (c == '=') { // ==
          consume();
          return Token(EQUALEQUAL, "==");
        } else {
          return Token(EQUAL, "=");
        }
      case '+':
          consume();
          return Token(PLUS, "+");
      case '-':
          consume();
          return Token(MINUS, "-");
      case '/':
          consume();
          return Token(DIV, "/");
      case '*':
          consume();
          return Token(MUL, "*");
      case '%':
          consume();
          return Token(MOD, "%");
      case '&':
          consume();
          return Token(AND, "&");
      case '!':
          consume();
          return Token(NOT, "!");
      case '<':
        consume();
        if (c == '=') { // <=
          consume();
          return Token(LESSEQUAL, "<=");
        } else {
          return Token(LESS, "<");
        }
      case '>':
        consume();
        if (c == '=') { // >=
          consume();
          return Token(ABOVEEQUAL, ">=");
        } else {
          return Token(ABOVE, ">");
        }
      case '\"':
        /* "hoge" (string) */
        if(isString()) return String();
      default:
        if(isDecimal()) {
          /* {D} */
          if(isFloat()) return FloatConst();
          else return IntConst();
        }else {
          /* {L} It could be id or reserved word */
          return Addr();
        }
        break;
      }
  }
  return Token(EOF_TYPE, "<EOF>");
}
Esempio n. 22
0
/**
 * The main import function...
 */
int CachegrindLoader::loadInternal(TraceData* data,
                                   QIODevice* device, const QString& filename)
{
    if (!data || !device) return 0;

    _data = data;
    _filename = filename;
    _lineNo = 0;

    loadStart(_filename);

    FixFile file(device, _filename);
    if (!file.exists()) {
        loadFinished(QStringLiteral("File does not exist"));
        return 0;
    }

    int statusProgress = 0;

#if USE_FIXCOST
    // FixCost Memory Pool
    FixPool* pool = _data->fixPool();
#endif

    _part = 0;
    partsAdded = 0;
    prepareNewPart();

    FixString line;
    char c;

    // current position
    nextLineType  = SelfCost;
    // default if there is no "positions:" line
    hasLineInfo = true;
    hasAddrInfo = false;

    while (file.nextLine(line)) {

        _lineNo++;

#if TRACE_LOADER
        qDebug() << "[CachegrindLoader] " << _filename << ":" << _lineNo
                 << " - '" << QString(line) << "'";
#endif

        // if we cannot strip a character, this was an empty line
        if (!line.first(c)) continue;

        if (c <= '9') {

            if (c == '#') continue;

            // parse position(s)
            if (!parsePosition(line, currentPos)) {
                error(QStringLiteral("Invalid position specification '%1'").arg(line));
                continue;
            }

            // go through after big switch
        }
        else { // if (c > '9')

            line.stripFirst(c);

            /* in order of probability */
            switch(c) {

            case 'f':

                // fl=
                if (line.stripPrefix("l=")) {

                    setFile(line);
                    // this is the default for new functions
                    currentFunctionFile = currentFile;
                    continue;
                }

                // fi=, fe=
                if (line.stripPrefix("i=") ||
                    line.stripPrefix("e=")) {

                    setFile(line);
                    continue;
                }

                // fn=
                if (line.stripPrefix("n=")) {

                    if (currentFile != currentFunctionFile)
                        currentFile = currentFunctionFile;
                    setFunction(line);

                    // on a new function, update status
                    int progress = (int)(100.0 * file.current() / file.len() +.5);
                    if (progress != statusProgress) {
                        statusProgress = progress;

                        /* When this signal is connected, it most probably
         * should lead to GUI update. Thus, when multiple
         * "long operations" (like file loading) are in progress,
         * this can temporarly switch to another operation.
         */
                        loadProgress(statusProgress);
                    }

                    continue;
                }

                break;

            case 'c':
                // cob=
                if (line.stripPrefix("ob=")) {
                    setCalledObject(line);
                    continue;
                }

                // cfi= / cfl=
                if (line.stripPrefix("fl=") ||
                    line.stripPrefix("fi=")) {
                    setCalledFile(line);
                    continue;
                }

                // cfn=
                if (line.stripPrefix("fn=")) {

                    setCalledFunction(line);
                    continue;
                }

                // calls=
                if (line.stripPrefix("alls=")) {
                    // ignore long lines...
                    line.stripUInt64(currentCallCount);
                    nextLineType = CallCost;
                    continue;
                }

                // cmd:
                if (line.stripPrefix("md:")) {
                    QString command = QString(line).trimmed();
                    if (!_data->command().isEmpty() &&
                        _data->command() != command) {

                        error(QStringLiteral("Redefined command, was '%1'").arg(_data->command()));
                    }
                    _data->setCommand(command);
                    continue;
                }

                // creator:
                if (line.stripPrefix("reator:")) {
                    // ignore ...
                    continue;
                }

                break;

            case 'j':

                // jcnd=
                if (line.stripPrefix("cnd=")) {
                    bool valid;

                    valid = line.stripUInt64(jumpsFollowed) &&
                            line.stripPrefix("/") &&
                            line.stripUInt64(jumpsExecuted) &&
                            parsePosition(line, targetPos);

                    if (!valid) {
                        error(QStringLiteral("Invalid line after 'jcnd'"));
                    }
                    else
                        nextLineType = CondJump;
                    continue;
                }

                if (line.stripPrefix("ump=")) {
                    bool valid;

                    valid = line.stripUInt64(jumpsExecuted) &&
                            parsePosition(line, targetPos);

                    if (!valid) {
                        error(QStringLiteral("Invalid line after 'jump'"));
                    }
                    else
                        nextLineType = BoringJump;
                    continue;
                }

                // jfi=
                if (line.stripPrefix("fi=")) {
                    currentJumpToFile = compressedFile(line);
                    continue;
                }

                // jfn=
                if (line.stripPrefix("fn=")) {

                    if (!currentJumpToFile) {
                        // !=0 as functions needs file
                        currentJumpToFile = currentFile;
                    }

                    currentJumpToFunction =
                            compressedFunction(line,
                                               currentJumpToFile,
                                               currentObject);
                    continue;
                }

                break;

            case 'o':

                // ob=
                if (line.stripPrefix("b=")) {
                    setObject(line);
                    continue;
                }

                break;

            case '#':
                continue;

            case 'a':
                // "arch: arm"
                if (line.stripPrefix("rch: arm")) {
                    TraceData::Arch a = _data->architecture();
                    if ((a != TraceData::ArchUnknown) &&
                        (a != TraceData::ArchARM)) {
                        error(QStringLiteral("Redefined architecture!"));
                    }
                    _data->setArchitecture(TraceData::ArchARM);
                    continue;
                }
                break;

            case 't':

                // totals:
                if (line.stripPrefix("otals:")) continue;

                // thread:
                if (line.stripPrefix("hread:")) {
                    prepareNewPart();
                    _part->setThreadID(QString(line).toInt());
                    continue;
                }

                // timeframe (BB):
                if (line.stripPrefix("imeframe (BB):")) {
                    _part->setTimeframe(line);
                    continue;
                }

                break;

            case 'd':

                // desc:
                if (line.stripPrefix("esc:")) {

                    line.stripSurroundingSpaces();

                    // desc: Trigger:
                    if (line.stripPrefix("Trigger:")) {
                        _part->setTrigger(line);
                    }

                    continue;
                }
                break;

            case 'e':

                // events:
                if (line.stripPrefix("vents:")) {
                    prepareNewPart();
                    mapping = _data->eventTypes()->createMapping(line);
                    _part->setEventMapping(mapping);
                    continue;
                }

                // event:<name>[=<formula>][:<long name>]
                if (line.stripPrefix("vent:")) {
                    line.stripSurroundingSpaces();

                    FixString e, f, l;
                    if (!line.stripName(e)) {
                        error(QStringLiteral("Invalid event"));
                        continue;
                    }
                    line.stripSpaces();
                    if (!line.stripFirst(c)) continue;

                    if (c=='=') f = line.stripUntil(':');
                    line.stripSpaces();

                    // add to known cost types
                    if (line.isEmpty()) line = e;
                    EventType::add(new EventType(e,line,f));
                    continue;
                }
                break;

            case 'p':

                // part:
                if (line.stripPrefix("art:")) {
                    prepareNewPart();
                    _part->setPartNumber(QString(line).toInt());
                    continue;
                }

                // pid:
                if (line.stripPrefix("id:")) {
                    prepareNewPart();
                    _part->setProcessID(QString(line).toInt());
                    continue;
                }

                // positions:
                if (line.stripPrefix("ositions:")) {
                    prepareNewPart();
                    QString positions(line);
                    hasLineInfo = positions.contains(QStringLiteral("line"));
                    hasAddrInfo = positions.contains(QStringLiteral("instr"));
                    continue;
                }
                break;

            case 'v':

                // version:
                if (line.stripPrefix("ersion:")) {
                    // ignore for now
                    continue;
                }
                break;

            case 's':

                // summary:
                if (line.stripPrefix("ummary:")) {
                    if (!mapping) {
                        error(QStringLiteral("No event line found. Skipping file"));
                        delete _part;
                        return false;
                    }

                    _part->totals()->set(mapping, line);
                    continue;
                }

            case 'r':

                // rcalls= (deprecated)
                if (line.stripPrefix("calls=")) {
                    // handle like normal calls: we need the sum of call count
                    // recursive cost is discarded in cycle detection
                    line.stripUInt64(currentCallCount);
                    nextLineType = CallCost;

                    warning(QStringLiteral("Old file format using deprecated 'rcalls'"));
                    continue;
                }
                break;

            default:
                break;
            }

            error(QStringLiteral("Invalid line '%1%2'").arg(c).arg(line));
            continue;
        }

        if (!mapping) {
            error(QStringLiteral("No event line found. Skipping file"));
            delete _part;
            return false;
        }

        // for a cost line, we always need a current function
        ensureFunction();



        if (!currentFunctionSource ||
            (currentFunctionSource->file() != currentFile)) {
            currentFunctionSource = currentFunction->sourceFile(currentFile,
                                                                true);
        }

#if !USE_FIXCOST
        if (hasAddrInfo) {
            if (!currentInstr ||
                (currentInstr->addr() != currentPos.fromAddr)) {
                currentInstr = currentFunction->instr(currentPos.fromAddr,
                                                      true);

                if (!currentInstr) {
                    error(QString("Invalid address '%1'").arg(currentPos.fromAddr.toString()));

                    continue;
                }

                currentPartInstr = currentInstr->partInstr(_part,
                                                           currentPartFunction);
            }
        }

        if (hasLineInfo) {
            if (!currentLine ||
                (currentLine->lineno() != currentPos.fromLine)) {

                currentLine = currentFunctionSource->line(currentPos.fromLine,
                                                          true);
                currentPartLine = currentLine->partLine(_part,
                                                        currentPartFunction);
            }
            if (hasAddrInfo && currentInstr)
                currentInstr->setLine(currentLine);
        }
#endif

#if TRACE_LOADER
        qDebug() << _filename << ":" << _lineNo;
        qDebug() << "  currentInstr "
                 << (currentInstr ? qPrintable(currentInstr->toString()) : ".");
        qDebug() << "  currentLine "
                 << (currentLine ? qPrintable(currentLine->toString()) : ".")
                 << "( file " << currentFile->name() << ")";
        qDebug() << "  currentFunction "
                 << qPrintable(currentFunction->prettyName());
        qDebug() << "  currentCalled "
                 << (currentCalledFunction ? qPrintable(currentCalledFunction->prettyName()) : ".");
#endif

        // create cost item

        if (nextLineType == SelfCost) {

#if USE_FIXCOST
            new (pool) FixCost(_part, pool,
                               currentFunctionSource,
                               currentPos,
                               currentPartFunction,
                               line);
#else
            if (hasAddrInfo) {
                TracePartInstr* partInstr;
                partInstr = currentInstr->partInstr(_part, currentPartFunction);

                if (hasLineInfo) {
                    // we need to set <line> back after reading for the line
                    int l = line.len();
                    const char* s = line.ascii();

                    partInstr->addCost(mapping, line);
                    line.set(s,l);
                }
                else
                    partInstr->addCost(mapping, line);
            }

            if (hasLineInfo) {
                TracePartLine* partLine;
                partLine = currentLine->partLine(_part, currentPartFunction);
                partLine->addCost(mapping, line);
            }
#endif

            if (!line.isEmpty()) {
                error(QStringLiteral("Garbage at end of cost line ('%1')").arg(line));
            }
        }
        else if (nextLineType == CallCost) {
            nextLineType = SelfCost;

            TraceCall* calling = currentFunction->calling(currentCalledFunction);
            TracePartCall* partCalling =
                    calling->partCall(_part, currentPartFunction,
                                      currentCalledPartFunction);

#if USE_FIXCOST
            FixCallCost* fcc;
            fcc = new (pool) FixCallCost(_part, pool,
                                         currentFunctionSource,
                                         hasLineInfo ? currentPos.fromLine : 0,
                                         hasAddrInfo ? currentPos.fromAddr : Addr(0),
                                         partCalling,
                                         currentCallCount, line);
            fcc->setMax(_data->callMax());
            _data->updateMaxCallCount(fcc->callCount());
#else
            if (hasAddrInfo) {
                TraceInstrCall* instrCall;
                TracePartInstrCall* partInstrCall;

                instrCall = calling->instrCall(currentInstr);
                partInstrCall = instrCall->partInstrCall(_part, partCalling);
                partInstrCall->addCallCount(currentCallCount);

                if (hasLineInfo) {
                    // we need to set <line> back after reading for the line
                    int l = line.len();
                    const char* s = line.ascii();

                    partInstrCall->addCost(mapping, line);
                    line.set(s,l);
                }
                else
                    partInstrCall->addCost(mapping, line);

                // update maximum of call cost
                _data->callMax()->maxCost(partInstrCall);
                _data->updateMaxCallCount(partInstrCall->callCount());
            }

            if (hasLineInfo) {
                TraceLineCall* lineCall;
                TracePartLineCall* partLineCall;

                lineCall = calling->lineCall(currentLine);
                partLineCall = lineCall->partLineCall(_part, partCalling);

                partLineCall->addCallCount(currentCallCount);
                partLineCall->addCost(mapping, line);

                // update maximum of call cost
                _data->callMax()->maxCost(partLineCall);
                _data->updateMaxCallCount(partLineCall->callCount());
            }
#endif
            currentCalledFile = 0;
            currentCalledPartFile = 0;
            currentCalledObject = 0;
            currentCalledPartObject = 0;
            currentCallCount = 0;

            if (!line.isEmpty()) {
                error(QStringLiteral("Garbage at end of call cost line ('%1')").arg(line));
            }
        }
        else { // (nextLineType == BoringJump || nextLineType == CondJump)

            TraceFunctionSource* targetSource;

            if (!currentJumpToFunction)
                currentJumpToFunction = currentFunction;

            targetSource = (currentJumpToFile) ?
                               currentJumpToFunction->sourceFile(currentJumpToFile, true) :
                               currentFunctionSource;

#if USE_FIXCOST
            new (pool) FixJump(_part, pool,
                               /* source */
                               hasLineInfo ? currentPos.fromLine : 0,
                               hasAddrInfo ? currentPos.fromAddr : 0,
                               currentPartFunction,
                               currentFunctionSource,
                               /* target */
                               hasLineInfo ? targetPos.fromLine : 0,
                               hasAddrInfo ? targetPos.fromAddr : Addr(0),
                               currentJumpToFunction,
                               targetSource,
                               (nextLineType == CondJump),
                               jumpsExecuted, jumpsFollowed);
#else
            if (hasAddrInfo) {
                TraceInstr* jumpToInstr;
                TraceInstrJump* instrJump;
                TracePartInstrJump* partInstrJump;

                jumpToInstr = currentJumpToFunction->instr(targetPos.fromAddr,
                                                           true);
                instrJump = currentInstr->instrJump(jumpToInstr,
                                                    (nextLineType == CondJump));
                partInstrJump = instrJump->partInstrJump(_part);
                partInstrJump->addExecutedCount(jumpsExecuted);
                if (nextLineType == CondJump)
                    partInstrJump->addFollowedCount(jumpsFollowed);
            }

            if (hasLineInfo) {
                TraceLine* jumpToLine;
                TraceLineJump* lineJump;
                TracePartLineJump* partLineJump;

                jumpToLine = targetSource->line(targetPos.fromLine, true);
                lineJump = currentLine->lineJump(jumpToLine,
                                                 (nextLineType == CondJump));
                partLineJump = lineJump->partLineJump(_part);

                partLineJump->addExecutedCount(jumpsExecuted);
                if (nextLineType == CondJump)
                    partLineJump->addFollowedCount(jumpsFollowed);
            }
#endif

            if (0) {
                qDebug() << _filename << ":" << _lineNo
                         << " - jump from 0x" << currentPos.fromAddr.toString()
                         << " (line " << currentPos.fromLine
                         << ") to 0x" << targetPos.fromAddr.toString()
                         << " (line " << targetPos.fromLine << ")";

                if (nextLineType == BoringJump)
                    qDebug() << " Boring Jump, count " << jumpsExecuted.pretty();
                else
                    qDebug() << " Cond. Jump, followed " << jumpsFollowed.pretty()
                             << ", executed " << jumpsExecuted.pretty();
            }

            nextLineType = SelfCost;
            currentJumpToFunction = 0;
            currentJumpToFile = 0;

            if (!line.isEmpty()) {
                error(QStringLiteral("Garbage at end of jump cost line ('%1')").arg(line));
            }

        }
    }

    loadFinished();

    if (mapping) {
        _part->invalidate();
        _part->totals()->clear();
        _part->totals()->addCost(_part);
        data->addPart(_part);
        partsAdded++;
    }
    else {
        delete _part;
    }

    device->close();

    return partsAdded;
}
static inline
typename Generic_obj_space<SPACE>::Addr
Generic_obj_space<SPACE>::map_max_address()
{
  return Addr(Slots_per_dir * Caps_per_page);
}
Esempio n. 24
0
/*
 * PPC page cache
 */
INTERFACE[ppc32]:


EXTENSION class Mem_space
{
private:
  Status v_insert_cache(Pte_ptr *e, Address virt, size_t size,
                        unsigned page_attribs,
                        Dir_type *dir = 0);
  unsigned long v_delete_cache(Pt_entry *e, unsigned page_attribs);
};


//------------------------------------------------------------------------------
IMPLEMENTATION[ppc32]:

IMPLEMENT
Mem_space::Status
Mem_space::v_insert_cache(Pte_ptr *e, Address virt, size_t size,
                          unsigned page_attribs, Dir_type *dir = 0)
{
#ifdef FIX_THIS
  if(!dir) dir = _dir;

  Pdir::Iter i =
    dir->walk(Addr(virt), Pdir::Depth, Kmem_alloc::q_allocator(_quota));

  if (EXPECT_FALSE(!i.e->valid() && i.shift() != Config::PAGE_SHIFT))
    return Insert_err_nomem;

  Address i_phys;

  //get physical addresses
  Pte_htab::pte_lookup(i.e, &i_phys);

  if(i.e->valid() && e->addr() == i_phys)
    {
      Status state = pte_attrib_upgrade(i.e, size, page_attribs);
      return state;
    }

  *i.e = e->raw() | page_attribs;

  //if super-page, set Pse_bit in Pdir
  if(size == Config::SUPERPAGE_SIZE)
    {
      i = dir->walk(Addr(virt), Pdir::Super_level);
      *i.e = i.e->raw() | Pte_ptr::Pse_bit;
    }

  return Insert_ok;
#else
  (void)e; (void)virt; (void)size; (void)page_attribs; (void)dir;
  return Insert_err_nomem;
#endif
}

IMPLEMENT
unsigned long
Mem_space::v_delete_cache(Pt_entry *e, unsigned page_attribs = Page_all_attribs)
{
#ifdef FIX_THIS
  unsigned ret;

  ret = e->raw() & page_attribs;

  if (!(page_attribs & Page_user_accessible))
    // downgrade PDE (superpage) rights
    e->del_attr(page_attribs);
  else
    // delete PDE (superpage)
    e = 0;

  return ret;
#else
  (void)e; (void)page_attribs;
  return 0;
#endif
}
Esempio n. 25
0
/**
 * Return false if this is no position specification
 */
bool CachegrindLoader::parsePosition(FixString& line,
                                     PositionSpec& newPos)
{
    char c;
    uint diff;

    if (hasAddrInfo) {

        if (!line.first(c)) return false;

        if (c == '*') {
            // nothing changed
            line.stripFirst(c);
            newPos.fromAddr = currentPos.fromAddr;
            newPos.toAddr = currentPos.toAddr;
        }
        else if (c == '+') {
            line.stripFirst(c);
            line.stripUInt(diff, false);
            newPos.fromAddr = currentPos.fromAddr + diff;
            newPos.toAddr = newPos.fromAddr;
        }
        else if (c == '-') {
            line.stripFirst(c);
            line.stripUInt(diff, false);
            newPos.fromAddr = currentPos.fromAddr - diff;
            newPos.toAddr = newPos.fromAddr;
        }
        else if (c >= '0') {
            uint64 v;
            line.stripUInt64(v, false);
            newPos.fromAddr = Addr(v);
            newPos.toAddr = newPos.fromAddr;
        }
        else return false;

        // Range specification
        if (line.first(c)) {
            if (c == '+') {
                line.stripFirst(c);
                line.stripUInt(diff);
                newPos.toAddr = newPos.fromAddr + diff;
            }
            else if ((c == '-') || (c == ':')) {
                line.stripFirst(c);
                uint64 v;
                line.stripUInt64(v);
                newPos.toAddr = Addr(v);
            }
        }
        line.stripSpaces();

#if TRACE_LOADER
        if (newPos.fromAddr == newPos.toAddr)
            qDebug() << " Got Addr " << newPos.fromAddr.toString();
        else
            qDebug() << " Got AddrRange " << newPos.fromAddr.toString()
                     << ":" << newPos.toAddr.toString();
#endif

    }

    if (hasLineInfo) {

        if (!line.first(c)) return false;

        if (c > '9') return false;
        else if (c == '*') {
            // nothing changed
            line.stripFirst(c);
            newPos.fromLine = currentPos.fromLine;
            newPos.toLine   = currentPos.toLine;
        }
        else if (c == '+') {
            line.stripFirst(c);
            line.stripUInt(diff, false);
            newPos.fromLine = currentPos.fromLine + diff;
            newPos.toLine = newPos.fromLine;
        }
        else if (c == '-') {
            line.stripFirst(c);
            line.stripUInt(diff, false);
            if (currentPos.fromLine < diff) {
                error(QStringLiteral("Negative line number %1")
                      .arg((int)currentPos.fromLine - (int)diff));
                diff = currentPos.fromLine;
            }
            newPos.fromLine = currentPos.fromLine - diff;
            newPos.toLine = newPos.fromLine;
        }
        else if (c >= '0') {
            line.stripUInt(newPos.fromLine, false);
            newPos.toLine = newPos.fromLine;
        }
        else return false;

        // Range specification
        if (line.first(c)) {
            if (c == '+') {
                line.stripFirst(c);
                line.stripUInt(diff);
                newPos.toLine = newPos.fromLine + diff;
            }
            else if ((c == '-') || (c == ':')) {
                line.stripFirst(c);
                line.stripUInt(newPos.toLine);
            }
        }
        line.stripSpaces();

#if TRACE_LOADER
        if (newPos.fromLine == newPos.toLine)
            qDebug() << " Got Line " << newPos.fromLine;
        else
            qDebug() << " Got LineRange " << newPos.fromLine
                     << ":" << newPos.toLine;
#endif

    }

    return true;
}
Esempio n. 26
0
 _SC_EXTERN Addr value(sc_uint8 idx) const
 {
     check_expr(idx < 3);
     check_expr(isValid());
     return Addr(sc_iterator3_value(mIterator, idx));
 }
Esempio n. 27
0
 bool
 Socket::isConnected() const
 {
     return getPeer() != Addr();
 }
Esempio n. 28
0
void BWMem::ReadPlayerDesc(HANDLE hProcess, BWrepPlayerInfo *player, int idx)
{
	ReadBytes(hProcess, (char*)(Addr(PlayerDesc)+idx*36), (char*)player, sizeof(BWrepPlayerInfo));
}
Esempio n. 29
0
// get player mineral resources
unsigned long BWMem::GetMineral(HANDLE hProcess)
{
	unsigned long mineral;
	ReadBytes(hProcess, (char*)Addr(REALMINERAL), (char*)&mineral, sizeof(mineral));
	return mineral;
}
Esempio n. 30
0
void SaveFile(void)
{
char	filename[11];
unsigned char	sectmap[195],usedmap[195],*found;
int filelength,maxdtrack,s,t,h,i,m,a,tt,ss;	
	
	
	if (validdsk != 0)
	{
		doOpenCommand(&file);
		fseek (file, 0, 2);
		filelength = ftell(file);
		fseek (file,0,0);
		
		if ( *(image+255) == 255)
		{
			maxdtrack = 4;
		}
		else
		{
			maxdtrack = 4 + *(image+255);
		};
		
		for (i=0; i<195; i++)
		{
			sectmap[i] = usedmap[i] = 0;
		}	
		
		for (t=0; t<maxdtrack; t++)
		{
			for (s=1; s<11; s++)
			{
				for (h=0; h<2; h++)
				{
					for (i=0; i<195; i++)
					{
						sectmap[i] |= *Addr(t,s,256*h+15+i);
					}			
				}
			}
		}
		
		if (maxdtrack>4)
		{
			sectmap[0] &= 254;
			sectmap[1] &= 3;
		
			if (maxdtrack>5)
			{
				a=1;
				m=4;
				
				for (i=0; i<10*(maxdtrack - 4); i++)
				{
					sectmap[a] &= m;
					
					m *=2;
					if (m==256)
					{
						a ++;
						m = 1;
					
					}
				
				}
			}
		}
		
	
	
		for (t=0; t<maxdtrack; t++)
		{
			for (s=1; s<11; s++)
			{
				for (h=0; h<2; h++)
				{
					
					if (*Addr(t,s,256*h) == 0)
					{
						found = Addr(t,s,256*h);
						h=2;
						s=10;
						t=maxdtrack;
					
					
					}
							
				}
			}
		}
	
		i=0;
		for (a=0;a<195;a++)
		{
			for(m=1;m<256;m *=2)
			{
				i += !(sectmap[a] && m);
			
			}
		}
		
		if (filelength > (510*i - 9))
		{
			printf("Sorry, Not enough space on dsk\n");
		}
		else
		{
	
			t=4;
			s=1;
			m=1;
			a=0;
			
			while ((sectmap[a] & m))
			{
				m *= 2;
				if (m==256)
				{
					m =1;
					a ++;		
				}
				
				s++;
				if (s==11)
				{
					s=1;
					t++;
					
					if (t==80)
						t=128;
				}
				
			}	
		
		
			printf ("Save Filename: ");
			
			i=0;		
			filename[i] = getchar();		
			while ((i<10) && (filename[i] != '\n'))
			{
				filename[++i] = getchar();
			}		
			while (filename[i] != '\n')
			{
				filename[i] = getchar();
			}	
			while (i<10)
			{
				filename[i++]=' ';
			}
			filename[10]=0;
			
		
		
			*(found) = 19;
			*Addr(t,s,0) = 19;
			for (i=0; i<10; i++)
			{
				*(found+1+i) = filename[i];
			}
		
			i = (filelength+9)/510;
			*(found+11) = i/256;
			*(found+12) = i%256;
			*(found+13) = t;
			*(found+14) = s;
			*(found+220) = 0;
			
			*(found+236) = 1;
			*Addr(t,s,8) = 1;
			*(found+237) = 0;
			*Addr(t,s,3) = 0;
			*(found+238) = 128;
			*Addr(t,s,4) = 128;
			
			*(found+239) = filelength/16384;
			*Addr(t,s,7) = filelength/16384;
			*(found+240) = filelength%256;
			*Addr(t,s,1) = filelength%256;
			*(found+241) = (filelength%16384)/256;
			*Addr(t,s,2) = (filelength%16384)/256;
		
			*(found+242) = 255;
			*(found+243) = 255;
			*(found+244) = 255;
			
			if (filelength < 502)
			{
				fread(Addr(t,s,9),1,filelength,file);
				*Addr(t,s,510) = 0;
				*Addr(t,s,511) = 0;
				
				usedmap[a] |= m;
				sectmap[a] |= m;
			}
			else
			{	
				
				fread(Addr(t,s,9),1,501,file);
				filelength -= 501;
				usedmap[a] |= m;
				sectmap[a] |= m;
			
				while (filelength > 0)
				{
					printf ("t %d s %d, ",t,s);
				
					tt = t;
					ss = s;
					
					while ((sectmap[a] & m))
					{
						m *= 2;
						if (m==256)
						{
							m =1;
							a ++;		
						}
						
						s++;
						if (s==11)
						{
							s=1;
							t++;
							
							if (t==80)
								t=128;
						}
						
					}	
					
					*Addr(tt,ss,510) = t;
					*Addr(tt,ss,511) = s;
				
					if (filelength > 510)
					{
						fread(Addr(t,s,0),1,510,file);
						filelength -= 510;
						usedmap[a] |= m;
						sectmap[a] |= m;
					}
					else
					{
						fread(Addr(t,s,0),1,filelength,file);
						filelength = 0;
						usedmap[a] |= m;
						sectmap[a] |= m;
						
						*Addr(t,s,510) = 0;
						*Addr(t,s,511) = 0;
					}
				
				}
			}
			for (i=0;i<195;i++)
			{
				*(found+15+i) = usedmap[i];
			
			}
			
			changes = 1;
			printf ("OK\n");
			
		}	
	}
}