Esempio n. 1
0
File: thread.c Progetto: Tilka/vlc
/*** Clock ***/
mtime_t mdate (void)
{
    /* We don't need the real date, just the value of a high precision timer */
    QWORD counter;
    ULONG freq;
    if (DosTmrQueryTime(&counter) || DosTmrQueryFreq(&freq))
        abort();

    /* Convert to from (1/freq) to microsecond resolution */
    /* We need to split the division to avoid 63-bits overflow */
    lldiv_t d = lldiv (Q2LL(counter), freq);

    return (d.quot * 1000000) + ((d.rem * 1000000) / freq);
}
Esempio n. 2
0
static BOOL clockTickTime(unsigned long *phigh, unsigned long *plow)
{
    APIRET rc = NO_ERROR;
    QWORD qword = {0,0};

    rc = DosTmrQueryTime(&qword);
    if (rc != NO_ERROR)
       return FALSE;

    *phigh = qword.ulHi;
    *plow  = qword.ulLo;

    return TRUE;
}
Esempio n. 3
0
int RAND_poll (void)
{
    char failed_module[20];

    QWORD qwTime;

    ULONG SysVars[QSV_FOREGROUND_PROCESS];

    if (hDoscalls == 0)
    {
        ULONG rc = DosLoadModule (failed_module, sizeof (failed_module), "DOSCALLS", &hDoscalls);

#ifndef __KLIBC__
        if (rc == 0)
        {
            rc = DosQueryProcAddr (hDoscalls, 976, NULL, (PFN *) & DosPerfSysCall);

            if (rc)
                DosPerfSysCall = NULL;

            rc = DosQueryProcAddr (hDoscalls, 368, NULL, (PFN *) & DosQuerySysState);

            if (rc)
                DosQuerySysState = NULL;
        }
#endif
    }

    /* Sample the hi-res timer, runs at around 1.1 MHz */
    DosTmrQueryTime (&qwTime);
    RAND_add (&qwTime, sizeof (qwTime), 2);

    /* Sample a bunch of system variables, includes various process & memory statistics */
    DosQuerySysInfo (1, QSV_FOREGROUND_PROCESS, SysVars, sizeof (SysVars));
    RAND_add (SysVars, sizeof (SysVars), 4);

    /* If available, sample CPU registers that count at CPU MHz
     * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
     */
    if (DosPerfSysCall)
    {
        CPUUTIL util;

        if (DosPerfSysCall (CMD_KI_RDCNT, (ULONG) & util, 0, 0) == 0)
        {
            RAND_add (&util, sizeof (util), 10);
        }
        else
        {
#ifndef __KLIBC__
            DosPerfSysCall = NULL;
#endif
        }
    }

    /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
    if (DosQuerySysState)
    {
        char *buffer = OPENSSL_malloc (256 * 1024);

        if (DosQuerySysState (0x1F, 0, 0, 0, buffer, 256 * 1024) == 0)
        {
            /* First 4 bytes in buffer is a pointer to the thread count
             * there should be at least 1 byte of entropy per thread
             */
            RAND_add (buffer, 256 * 1024, **(ULONG **) buffer);
        }

        OPENSSL_free (buffer);
        return 1;
    }

    return 0;
}
Esempio n. 4
0
BOOL wsReduceMain(INT vargc, CHAR **vargv)
{

	ULONG	i;
	UINT	uiArgvWsp = 1;		// Index into vargv[] of 1st WSP name

	/* Initialize global variable containing name of program. */
	strcpy(szProgName, vargv[0]);
	_strupr(szProgName);

#ifdef TMR
	DosTmrQueryTime((PQWORD)pqwTime0);
	printf("Top of Main, 0x%lx:0x%lx\n", pqwTime0[1], pqwTime0[0]);
#endif /* TMR */

	/*
	 * Parse command line.
	 */

	if (vargc < 2)
		wsRedUsage();
	else
	if (vargc > 1)
	{

	    /* If the first argument looks like it might be a switch... */

	    if (vargv[uiArgvWsp][0] == '/' || vargv[uiArgvWsp][0] == '-')
	    {

		/* Validate switch. */
		switch (vargv[uiArgvWsp][1])
		{

#ifdef DEBUG
		  case 'V':			/* Verbose (undocumented) */
		  case 'v':
		    fVerbose = TRUE;
		    uiArgvWsp++;
		    break;
#endif /* DEBUG */

		  case '?':			/* Help */
		  case 'H':
		  case 'h':
		    wsRedUsage();
		    break;

		  default:			/* Invalid switch specified */
		    printf("%s %s: Invalid switch: '%s'\n", szProgName,
				pszVersion, vargv[uiArgvWsp]);
		    wsRedUsage();
		    break;
		}
	    }
	}

	/* Assume rest of the args are WSP file names (1 per module).
	 * Allocate and initialize WsrMod[cModsTot].
	 */

	cModsTot = vargc - uiArgvWsp;
	WsrMod = (wsrmod_t *) AllocAndLockMem((cModsTot*sizeof(wsrmod_t)), &hMem[0]);
	if (WsrMod == NULL)
		wsRedExit(ERROR, PRINT_MSG, MSG_NO_MEM,cModsTot * sizeof(wsrmod_t),
				 vargv[uiArgvWsp]);

#ifdef DEBUG
	printf("%s %s: Module WSP files:\n", szProgName, pszVersion);
#endif /* DEBUG */

	for (i = 0; uiArgvWsp < (UINT)vargc; i++, uiArgvWsp++)
	{
		WsrMod[i].wsrmod_un.wsrmod_pchModFile = vargv[uiArgvWsp];
#ifdef DEBUG
		printf("\t%s\n", WsrMod[i].wsrmod_un.wsrmod_pchModFile);
#endif /* DEBUG */
	}

	// Get environment variable WSDIR for default path.
	rc = WsGetWSDIR(szWSDIRPath);

	// Initialize module and function information structures.
	wsRedInitialization();

	// Set up weighted decision matrix.
	wsRedSetup();


	// Perform the function reference data analysis.
	wsRedReorder();


	// Output the analysis results.
	wsRedOutput();

	// Output "un-touched" functions to PRF file.
	// Commented out because we do not want "un-touched" functions in prf file.
	// wsRedWriteWlk();

	// Cleanup memory allocations.
	wsRedCleanup();

	return(NO_ERROR);
}