コード例 #1
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetNextThread -
 * NB - callers must continue to call this function until it returns FALSE
 */
BOOL GetNextThread( ThreadList *info, ThreadPlace *place,
                    DWORD pid, BOOL first )
{

    DWORD                       curpid;
    PERF_COUNTER_DEFINITION     *counter;
    BOOL                        error;

    error = FALSE;
    if( first ) {
        beginRead( FALSE );
        initObj( &regData, &threadObject, N_THREAD );
        if( threadObject == NULL ) error = TRUE;
        if( !error ) {
            place->index = 0;
            place->obj = threadObject;
            place->pid = pid;
            place->inst = getFirstInstance( threadObject );
        }
    } else {
        place->index ++;
        if( place->index < place->obj->NumInstances ) {
            place->inst = getNextInstance( place->inst );
        }
    }
    if( !error ) {
        counter = findCounter( place->obj, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        for( ; place->index < place->obj->NumInstances; place->index ++ ) {
            if( place->inst == NULL ) {
                error = TRUE;
                break;
            }
            curpid = getCounterDWORD( place->inst, counter );
            if( curpid == place->pid ) break;
            place->inst = getNextInstance( place->inst );
        }
    }
    if( !error && place->index >= place->obj->NumInstances ) error = TRUE;
    if( !error ) {
        counter = findCounter( place->obj, N_THREADID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->tid = getCounterDWORD( place->inst, counter );
        counter = findCounter( place->obj, N_BASE_PRIORITY );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->priority = getCounterDWORD( place->inst, counter );
    } else {
        endRead( FALSE );
    }
    return( !error );
}
コード例 #2
0
//-----------------------------------------------------------------------
void CompositorChain::setCompositorEnabled(size_t position, bool state)
{
	CompositorInstance* inst = getCompositor(position);
	if (!state && inst->getEnabled())
	{
		// If we're disabling a 'middle' compositor in a chain, we have to be
		// careful about textures which might have been shared by non-adjacent
		// instances which have now become adjacent. 
		CompositorInstance* nextInstance = getNextInstance(inst, true);
		if (nextInstance)
		{
			CompositionTechnique::TargetPassIterator tpit = nextInstance->getTechnique()->getTargetPassIterator();
			while(tpit.hasMoreElements())
			{
				CompositionTargetPass* tp = tpit.getNext();
				if (tp->getInputMode() == CompositionTargetPass::IM_PREVIOUS)
				{
					if (nextInstance->getTechnique()->getTextureDefinition(tp->getOutputName())->pooled)
					{
						// recreate
						nextInstance->freeResources(false, true);
						nextInstance->createResources(false);
					}
				}

			}
		}

	}
    inst->setEnabled(state);
}
コード例 #3
0
ファイル: Sound.cpp プロジェクト: zaclolz/Blood-Crystals
int CSoundManager::play(int index) {
    if(index < 0 || index >= m_nCount)return -1; //bail if bad index

    int instance = getNextInstance(index);
    if(instance < m_nInstanceCount[index]) //if unused copy found
        m_pInstance[index][instance]->Play(); //play it

    m_nLastPlayedSound = index;
    m_nLastPlayedInstance = instance;

    return instance;
} //play
コード例 #4
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetThreadInfo
 */
BOOL GetThreadInfo( DWORD pid, DWORD tid, ThreadStats *info ) {

    PERF_COUNTER_DEFINITION     *pid_counter;
    PERF_COUNTER_DEFINITION     *tid_counter;
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curid;
    DWORD                       i;
    BOOL                        error;

    error = FALSE;
    beginRead( FALSE );
    initObj( &regData, &threadObject, N_THREAD );
    if( threadObject == NULL ) {
        error = TRUE;
    }
    if( !error ) {
        pid_counter = findCounter( threadObject, N_PROCID );
        tid_counter = findCounter( threadObject, N_THREADID );
        if( pid_counter == NULL || tid_counter == NULL ) error = TRUE;
    }
    if( !error ) {
        inst = getFirstInstance( threadObject );
        for( i=0; i < threadObject->NumInstances; i++ ) {
            if( inst == NULL ) {
                error = TRUE;
                break;
            }
            curid = getCounterDWORD( inst, tid_counter );
            if( curid == tid ) {
                curid = getCounterDWORD( inst, pid_counter );
                if( curid == pid ) break;
            }
            inst = getNextInstance( inst );
        }
    }
    if( !error && i == threadObject->NumInstances ) {
         error = TRUE;
    } else {
        info->tid = tid;
        info->pid = pid;
        counter = findCounter( threadObject, N_BASE_PRIORITY );
        info->base_pri = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_CUR_PRIORITY );
        info->cur_pri = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_THREAD_STATE );
        info->state = getCounterDWORD( inst, counter );
        counter = findCounter( threadObject, N_WAIT_REASON );
        info->wait_reason = getCounterDWORD( inst, counter );
    }
    endRead( FALSE );
    return( !error );
}
コード例 #5
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetProcessInfo
 */
BOOL GetProcessInfo( DWORD pid, ProcStats *info ) {

    DWORD                       i;
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curpid;
    BOOL                        error;

    beginRead( FALSE );
    error = FALSE;
    initObj( &regData, &processObject, N_PROCESS );
    if( processObject == NULL ) error = TRUE;
    if( !error ) {
        counter = findCounter( processObject, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        inst = getFirstInstance( processObject );
        for( i=0; i < processObject->NumInstances; i++ ) {
            if( inst == NULL ) {
                error = TRUE;
                break;
            }
            curpid = getCounterDWORD( inst, counter );
            if( curpid == pid ) break;
            inst = getNextInstance( inst );
        }
    }
    if( !error && curpid == pid && info != NULL ) {
        info->pid = curpid;
        counter = findCounter( processObject, N_BASE_PRIORITY );
        if( counter == NULL ) {
            error = TRUE;
        } else {
            info->priority = getCounterDWORD( inst, counter );
            wsprintf( info->name, "%ls",
                      (char *)inst + inst->NameOffset );
        }
    }
    endRead( FALSE );
    return( !error && curpid == pid );
}
コード例 #6
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetNextProcess
 * NB - callers must continue to call this function until it returns FALSE
 */
BOOL GetNextProcess( ProcList *info, ProcPlace *place, BOOL first ) {

    PERF_COUNTER_DEFINITION     *counter;
    BOOL                        error;

    error = FALSE;
    if( first ) {
        beginRead( FALSE );
        initObj( &regData, &processObject, N_PROCESS );
        if( processObject == NULL ) error = TRUE;
        if( !error ) {
            place->index = 0;
            place->obj = processObject;
            place->inst = getFirstInstance( processObject );
        }
    } else {
        place->index ++;
        if( place->index >= processObject->NumInstances ) {
            endRead( FALSE );
            return( FALSE );
        }
        place->inst = getNextInstance( place->inst );
    }
    if( place->inst == NULL ) error = TRUE;
    if( !error ) {
        counter = findCounter( place->obj, N_PROCID );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->pid = getCounterDWORD( place->inst, counter );
        counter = findCounter( place->obj, N_BASE_PRIORITY );
        if( counter == NULL ) error = TRUE;
    }
    if( !error ) {
        info->priority = getCounterDWORD( place->inst, counter );
        wsprintf( info->name, "%ls",
                  (char *)( place->inst ) + place->inst->NameOffset );
    } else {
        endRead( FALSE );
    }
    return( !error );
}
コード例 #7
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * getProcessIndex
 */
static BOOL getProcessIndex( DWORD pid, DWORD *indexout ) {

    DWORD                       curpid;
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       index;

    counter = findCounter( processObject, N_PROCID );
    if( counter == NULL ) return( FALSE );
    inst = getFirstInstance( processObject );
    if( inst == NULL ) return( FALSE );
    for( index=0; index < processObject->NumInstances; index++ ) {
        if( inst == NULL ) break;
        curpid = getCounterDWORD( inst, counter );
        if( curpid == pid ) {
            *indexout = index;
            return( TRUE );
        }
        inst = getNextInstance( inst );
    }
    return( FALSE );
}
コード例 #8
0
ファイル: memorydump.cpp プロジェクト: wxdublin/insight-vmi
Instance MemoryDump::queryInstance(const QString& queryString,
                                   KnowledgeSources src) const
{
    QStringList components = queryString.split('.', QString::SkipEmptyParts);

    if (components.isEmpty())
        queryError("Empty query string given");

	Instance result, prev;
	
	while (!components.isEmpty()) {
		result = getNextInstance(components.first(), result, src);

        if (!result.isValid()) {
            QString s(prev.fullName());
            if (!s.isEmpty())
                s += ".";
            s += components.first();
            if (result.origin() == Instance::orCandidate)
                queryError(QString("The selected member candidate for \"%1\" is invalid")
                            .arg(s));
            else if (result.origin() == Instance::orRuleEngine)
                queryError(QString("The instance \"%1\" returned by the rule engine is invalid.")
                           .arg(s));
            else
                queryError(QString("The instance \"%1\" is invalid (origin: %2)")
                           .arg(s)
                           .arg(Instance::originToString(result.origin())));
        }

        prev = result;
        components.pop_front();
    }

	return result;
}
コード例 #9
0
ファイル: memorydump.cpp プロジェクト: wxdublin/insight-vmi
void MemoryDump::init()
{
#define memDumpInitError(e) \
    genericError("Failed to initialize this MemoryDump instance with " \
                 "required run-time values from the dump. Error was: " + \
                 e.message)


    // Open virtual memory for reading
    if (!_vmem->open(QIODevice::ReadOnly))
        throw IOException(
                QString("Error opening virtual memory (filename=\"%1\")").arg(_fileName),
                __FILE__,
                __LINE__);

    // The virtual address translation depends on the runtime
    // value of "high_memory". We need to query its value and add it to
    // _specs.vmallocStart before we can translate paged addresses.
    try {
        Instance highMem = queryInstance("high_memory");
        _specs.highMemory = (_specs.sizeofPointer == 4) ?
                    (quint64)highMem.toUInt32() : highMem.toUInt64();
    }
    catch (QueryException& e) {
        if (!_factory->findVarByName("high_memory")) {
            // This is a failure for 32-bit systems
            if (_specs.arch & MemSpecs::ar_i386)
                memDumpInitError(e);
            // Resort to the failsafe value for 64-bit systems
            else {
                debugmsg("Variable \"high_memory\" not found, resorting to "
                         "failsafe default value");
                _specs.highMemory = HIGH_MEMORY_FAILSAFE_X86_64;
            }
        }
        else
            memDumpInitError(e);
    }

    if (_specs.arch & MemSpecs::ar_i386) {
        // This symbol only exists depending on the kernel version
        QString ve_name("vmalloc_earlyreserve");
        if (_factory->findVarByName(ve_name)) {
            try {
                Instance ve = queryInstance(ve_name);
                _specs.vmallocEarlyreserve = ve.toUInt32();
            }
            catch (QueryException& e) {
                genericError("Failed to initialize this MemoryDump instance with "
                        "required run-time values from the dump. Error was: " + e.message);
            }
        }
        else
            _specs.vmallocEarlyreserve = 0;
    }

    // Compare the Linux kernel version to the parsed symbols
    QString uts_ns_name("init_uts_ns");
    if (!_specs.version.release.isEmpty() &&
        _factory->findVarByName(uts_ns_name))
    {
        try {
            struct MemSpecs::Version ver;
            Instance uts_ns = queryInstance(uts_ns_name);
            uts_ns = getNextInstance("name", uts_ns, ksNone);
            // Read in all version information
            if (!_specs.version.machine.isEmpty())
                ver.machine = trimQuotes(
                            uts_ns.member("machine",
                                          BaseType::trLexical).toString());
            if (!_specs.version.release.isEmpty())
                ver.release = trimQuotes(
                            uts_ns.member("release",
                                          BaseType::trLexical).toString());
            if (!_specs.version.sysname.isEmpty())
                ver.sysname = trimQuotes(
                            uts_ns.member("sysname",
                                          BaseType::trLexical).toString());
            if (!_specs.version.version.isEmpty())
                ver.version = trimQuotes(
                            uts_ns.member("version",
                                          BaseType::trLexical).toString());

            if (!_specs.version.equals(ver)) {
                Console::errMsg("WARNING",
                                QString("The memory in '%0' belongs to a "
                                        "different kernel version than the "
                                        "loaded symbols!\n"
                                        "  Kernel symbols: %1\n"
                                        "  Memory file:    %2")
                                .arg(ShellUtil::shortFileName(_fileName))
                                .arg(_specs.version.toString())
                                .arg(ver.toString()));
            }
        }
        catch (QueryException& e) {
            genericError("Failed to retrieve kernel version information of "
                         "this memory dump. Error was: " + e.message);
        }
    }

    // Initialization done
    _specs.initialized = true;
}
コード例 #10
0
ファイル: memorydump.cpp プロジェクト: wxdublin/insight-vmi
QString MemoryDump::dump(const QString& type, quint64 address, int length,
                         const ColorPalette& col) const
{
    if (type == "char") {
        char c;
        if (_vmem->readAtomic(address, &c, sizeof(char)) != sizeof(char))
            queryError(QString("Cannot read memory from address 0x%1")
                       .arg(address, (_specs.sizeofPointer << 1), 16, QChar('0')));
        return QString("%1 (0x%2)").arg(c).arg(c, (sizeof(c) << 1), 16, QChar('0'));
    }
    if (type == "int") {
        qint32 i;
        if (_vmem->readAtomic(address, (char*)&i, sizeof(qint32)) != sizeof(qint32))
            queryError(QString("Cannot read memory from address 0x%1")
                       .arg(address, (_specs.sizeofPointer << 1), 16, QChar('0')));
        return QString("%1 (0x%2)").arg(i).arg((quint32)i, (sizeof(i) << 1), 16, QChar('0'));
    }
    if (type == "long") {
        qint64 l;
        if (_vmem->readAtomic(address, (char*)&l, sizeof(qint64)) != sizeof(qint64))
            queryError(QString("Cannot read memory from address 0x%1")
                       .arg(address, (_specs.sizeofPointer << 1), 16, QChar('0')));
        return QString("%1 (0x%2)").arg(l).arg((quint64)l, (sizeof(l) << 1), 16, QChar('0'));
    }
    if (type == "raw" || type == "hex") {
        QString ret;
        const int buflen = 256, linelen = 16;
        char buf[buflen];
        char bufstr[linelen + 1] = {0};

        // Make sure we got a valid length
        if (length < 0)
            queryError(QString("No valid length given for dumping raw memory"));

        int totalBytesRead = 0, col = 0;
        while (length > 0) {
            int bytesRead = _vmem->readAtomic(address, buf, qMin(buflen, length));
            length -= bytesRead;

            int i = 0;
            while (i < bytesRead) {
                // New line every 16 bytes begins with address
                if (totalBytesRead % 16 == 0) {
                    if (totalBytesRead > 0) {
                        ret += QString("  |%0|\n").arg(bufstr, -linelen);
                        memset(bufstr, 0, linelen + 1);
                        col = 0;
                    }
                    ret += QString("%1 ").arg(address, _specs.sizeofPointer << 1, 16, QChar('0'));
                }

                // Wider column after 8 bytes
                if (totalBytesRead % 8 == 0)
                    ret += ' ';
                // Write the character as hex string
                if ((unsigned char)buf[i] < 16)
                    ret += '0';
                ret += QString::number((unsigned char)buf[i], 16) + ' ';
                // Add character to string buffer, if it's an ASCII char
                if ( ((unsigned char)buf[i] >= 32) && ((unsigned char)buf[i] < 127) )
                    bufstr[col] = buf[i];
                else
                    bufstr[col] = '.';

                ++col;
                ++totalBytesRead;
                ++address;
                ++i;
            }
        }

        // Finish it up
        if (col > 0) {
            while (col < linelen) {
                ret += "   ";
                if (col % 8 == 0)
                    ret += ' ';
                ++col;
            }
            ret += QString("  |%0|").arg(bufstr, -linelen);
        }

        return ret;
    }

	QStringList components = type.split('.', QString::SkipEmptyParts);
	Instance result;
	
    if (!components.isEmpty()) {
		// Get first instance
		result = getInstanceAt(components.first(), address, QStringList("user"));
		components.pop_front();
	
		while (!components.isEmpty()) {
			result = getNextInstance(components.first(), result, ksNone);
			components.pop_front();
		}
			
		return QString("%1%2%3 (ID%4 0x%5%6) @%7 0x%8%9\n")
				.arg(col.color(ctType))
				.arg(result.typeName())
				.arg(col.color(ctReset))
				.arg(col.color(ctTypeId))
				.arg((uint)result.type()->id(), 0, 16)
				.arg(col.color(ctReset))
				.arg(col.color(ctAddress))
				.arg(result.address(), 0, 16)
				.arg(col.color(ctReset)) + result.toString(&col);
	}

    queryError3("Unknown type: " + type,
    		QueryException::ecUnresolvedType, type);

    return QString();
}
コード例 #11
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetMemInfo
 */
BOOL GetMemInfo( DWORD procid, MemInfo *info ) {

    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;
    DWORD                       curpid;
    DWORD                       i;

    beginRead( TRUE );
    initObj( &costlyData, &procAddrObject, N_PROCESS_ADDR_SPACE );
    if( procAddrObject == NULL ) {
        info->modlist = NULL;
        info->modcnt = 0;
        goto GETMEMINFO_ERROR;
    }

    info->modlist = GetModuleList( procid, &info->modcnt );
    if( info->modlist == NULL ) goto GETMEMINFO_ERROR;

    counter = findCounter( procAddrObject, N_PROCID );
    if( counter == NULL ) goto GETMEMINFO_ERROR;

    inst = getFirstInstance( procAddrObject );
    for( i=0; ; i++ ) {
        if( i >= procAddrObject->NumInstances || inst == NULL ) {
            goto GETMEMINFO_ERROR;
        }
        curpid = getCounterDWORD( inst, counter );
        if( curpid == procid ) break;
        inst = getNextInstance( inst );
    }

    counter = findCounter( procAddrObject, N_MAP_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_MAP_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->mapped.execcopy = getCounterDWORD( inst, counter );

    info->mapped.tot = info->mapped.noaccess + info->mapped.read
                        + info->mapped.write + info->mapped.copy
                        + info->mapped.exec + info->mapped.execread
                        + info->mapped.execwrite + info->mapped.execcopy;


    counter = findCounter( procAddrObject, N_RES_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_RES_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->res.execcopy = getCounterDWORD( inst, counter );

    info->res.tot = info->res.noaccess + info->res.read
                    + info->res.write + info->res.copy
                    + info->res.exec + info->res.execread
                    + info->res.execwrite + info->res.execcopy;


    counter = findCounter( procAddrObject, N_IMAGE_SPACE_NO_ACC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.noaccess = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_READ );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.read = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_WRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.write = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_COPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.copy = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXEC );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.exec = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECREAD );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execread = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECWRITE );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execwrite = getCounterDWORD( inst, counter );

    counter = findCounter( procAddrObject, N_IMAGE_SPACE_EXECCOPY );
    if( counter == NULL ) goto GETMEMINFO_ERROR;
    info->image.execcopy = getCounterDWORD( inst, counter );

    info->image.tot = info->image.noaccess + info->image.read
                    + info->image.write + info->image.copy
                    + info->image.exec + info->image.execread
                    + info->image.execwrite + info->image.execcopy;

    endRead( TRUE );
    return( TRUE );

GETMEMINFO_ERROR:
    FreeModuleList( info->modlist, info->modcnt );
    endRead( TRUE );
    return( FALSE );
}
コード例 #12
0
ファイル: reg.c プロジェクト: Ukusbobra/open-watcom-v2
/*
 * GetImageMemInfo
 */
BOOL GetImageMemInfo( DWORD procid, char *imagename, MemByType *imageinfo ) {

    DWORD                       index;
    DWORD                       i;
    BOOL                        ret;
    char                        buf[ _MAX_PATH ];
    PERF_COUNTER_DEFINITION     *counter;
    PERF_INSTANCE_DEFINITION    *inst;

    ret = FALSE;
    beginRead( FALSE );
    beginRead( TRUE );

    initObj( &costlyData, &imageObject, N_IMAGE );
    initObj( &regData, &processObject, N_PROCESS );
    if( imageObject == NULL || processObject == NULL ) goto GETIMAGEMEM_ERROR;

    inst = getFirstInstance( imageObject );
    if( !getProcessIndex( procid, &index ) ) goto GETIMAGEMEM_ERROR;

    for( i=0; i < imageObject->NumInstances; i += 1 ) {
        if( inst == NULL ) goto GETIMAGEMEM_ERROR;

        if( inst->ParentObjectInstance == index ) {
            wsprintf( buf, "%ls", (char *)inst + inst->NameOffset );
            if( !strcmp( buf, imagename ) ) {
                counter = findCounter( imageObject, N_NO_ACCESS );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->noaccess = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_READ_ONLY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->read = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_READ_WRITE );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->write = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_WRITE_COPY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->copy = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->exec = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_READ );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execread = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_WRITE );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execwrite = getCounterDWORD( inst, counter );

                counter = findCounter( imageObject, N_EXEC_COPY );
                if( counter == NULL ) goto GETIMAGEMEM_ERROR;
                imageinfo->execcopy = getCounterDWORD( inst, counter );

                imageinfo->tot = imageinfo->noaccess + imageinfo->read
                            + imageinfo->write + imageinfo->copy
                            + imageinfo->exec + imageinfo->execread
                            + imageinfo->execwrite + imageinfo->execcopy;
                ret = TRUE;
                break;
            }
        }
        inst = getNextInstance( inst );
    }
    endRead( TRUE );
    endRead( FALSE );
    return( ret);

GETIMAGEMEM_ERROR:
    endRead( TRUE );
    endRead( FALSE );
    return( FALSE );
}