Esempio n. 1
0
void getinfo()
{ char buf[1024];
  char *pbuf,*pbuf1,*pbuf2;
  ULONG rc,ulEnv,ulPTDA,ulSeg,ulErrorClass,ulErrorAction,ulErrorLoc;
  PID pid;
  USHORT cb,usEnvHob,usEnvHar;
  FILE *f;
  char buf1[1000];
  
  for (rc=0,pid=0;rc==0 && pid!=0x3a;) {
    rc=DosPerfSysCall(0xC5,(ULONG)buf,sizeof(buf),0); //get thread info
    pid=(PID)(*((USHORT*)&buf[18]));
  }  
  ulPTDA=*(ULONG*)&buf[12];
  printf("%i PID %X PTDA %X\n",rc,pid,ulPTDA);

  rc=DosPerfSysCall(0xC1,(ULONG)buf,sizeof(buf),ulPTDA); //get PTDA
  usEnvHob=*((USHORT*)&buf[272]);
  printf("%i ENVHOB %04X\n",rc,usEnvHob);
  
  rc=DosPerfSysCall(0xD0,(ULONG)buf,0x10,(ULONG)usEnvHob); //get env hob info  
  usEnvHar=*((USHORT*)&buf[0]);
  printf("%i ENVHAR %04X\n",rc,usEnvHar);
  
  rc=DosPerfSysCall(0xCD,(ULONG)buf,0x16,(ULONG)usEnvHar); //get env arena record
  ulEnv=(ULONG)(*((USHORT*)&buf[6]))<<16;
  printf("%i ENV ADDR %08X\n",rc,ulEnv);
  

  DosAllocMem((void**)&pbuf2,0x1000,0x13);
  rc=DosPerfSysCall(0xDB,(ULONG)pbuf2,ulPTDA,0);  
  printf("0xDB %i\n",rc);


  DosAllocMem((void**)&pbuf,0x1000,0x13);
//get linear memory info
  rc=DosPerfSysCall(0xDC,(ULONG)pbuf,ulEnv,ulPTDA);
  printf("0xDC %i\n",rc);
  f=fopen("DC.TXT","w");
  fwrite(pbuf,0x1000,1,f);
  fclose(f);


  DosAllocMem((void**)&pbuf1,0x114,0x13);
  memset(pbuf1,0,0x114);

  rc=DosPerfSysCall(0xD9,(ULONG)&pbuf1,0,0);
  printf("%i %p %p %s\n",rc,pbuf1,&pbuf1,pbuf1);

  f=fopen("D9.TXT","w");
  fwrite(pbuf1,0x114,1,f);
  fclose(f);

  DosFreeMem(pbuf);
  DosFreeMem(pbuf1);
  DosFreeMem(pbuf2);
}  
Esempio n. 2
0
 void main (int argc, char *argv[])
 {
     APIRET      rc;
     int         i, iter, sleep_sec;
     double      ts_val, ts_val_prev;
     double      idle_val, idle_val_prev;
     double      busy_val, busy_val_prev;
     double      intr_val, intr_val_prev;
     CPUUTIL     CPUUtil;
 
     if ((argc < 2) || (*argv[1] < '1') || (*argv[1] > '9')) {
         fprintf(stderr, "usage: %s [1-9]\n", argv[0]);
         exit(0);
     }
     sleep_sec = *argv[1] - '0';
 
     iter = 0;
     do {
         rc = DosPerfSysCall(CMD_KI_RDCNT,(ULONG) &CPUUtil,0,0);
         if (rc) {
             fprintf(stderr, "CMD_KI_RDCNT failed rc = %d\n",rc);
             exit(1);
         }
         ts_val = LL2F(CPUUtil.ulTimeHigh, CPUUtil.ulTimeLow);
         idle_val = LL2F(CPUUtil.ulIdleHigh, CPUUtil.ulIdleLow);
         busy_val = LL2F(CPUUtil.ulBusyHigh, CPUUtil.ulBusyLow);
         intr_val = LL2F(CPUUtil.ulIntrHigh, CPUUtil.ulIntrLow);
 
         if (iter > 0) {
             double  ts_delta = ts_val - ts_val_prev;
           printf("idle: %4.2f%%  busy: %4.2f%%  intr: %4.2f%%\n",
                    (idle_val - idle_val_prev)/ts_delta*100.0,
                    (busy_val - busy_val_prev)/ts_delta*100.0,
                    (intr_val - intr_val_prev)/ts_delta*100.0);
         }
 
         ts_val_prev = ts_val;
         idle_val_prev = idle_val;
         busy_val_prev = busy_val;
         intr_val_prev = intr_val;
 
         iter++;
         DosSleep(1000*sleep_sec);
 
     } while (1);
 }
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;
}
  /* This is a 1 processor example */
  int main (int argc, char *argv[])
  {
     APIRET      rc;
     int         i, iter, sleep_sec, cputhrtl50;
     double      ts_val, ts_val_prev;
     double      idle_val, idle_val_prev;
     double      busy_val, busy_val_prev;
     double      intr_val, intr_val_prev;
     CPUUTIL     CPUUtil;

     if ((argc < 2) || (*argv[1] < '1') || (*argv[1] > '9')) {
     sleep_sec =5;
     } else
     sleep_sec = *argv[1] - '0';

     DosSetPriority(PRTYS_THREAD, PRTYC_FOREGROUNDSERVER, 15L, 0L);

     cputhrtl50 = 100;
     iter = 0;
     do {
         rc = DosPerfSysCall(CMD_KI_RDCNT,(ULONG) &CPUUtil,0,0);
         if (rc) {
             fprintf(stderr, "CMD_KI_RDCNT failed rc = %d\n",rc);
             exit(1);
         }
         ts_val = LL2F(CPUUtil.ulTimeHigh, CPUUtil.ulTimeLow);
         idle_val = LL2F(CPUUtil.ulIdleHigh, CPUUtil.ulIdleLow);
         busy_val = LL2F(CPUUtil.ulBusyHigh, CPUUtil.ulBusyLow);
         intr_val = LL2F(CPUUtil.ulIntrHigh, CPUUtil.ulIntrLow);

         if (iter > 0) {
             double  ts_delta = ts_val - ts_val_prev;
#ifdef DEBUG
             printf("idle: %4.2f%%  busy: %4.2f%%  intr: %4.2f%%\n",
                    (idle_val - idle_val_prev)/ts_delta*100.0,
                    (busy_val - busy_val_prev)/ts_delta*100.0,
                    (intr_val - intr_val_prev)/ts_delta*100.0);
#endif

         if (((idle_val - idle_val_prev)/ts_delta*100.0) > 70){
         if (((idle_val - idle_val_prev)/ts_delta*100.0) > 80){
         if (((idle_val - idle_val_prev)/ts_delta*100.0) > 90){
             if (cputhrtl50 != 15){
             system( "setgetthrtl 0 15");
             system( "setgetthrtl 1 15");
             system( "setgetstate 0 1");
             system( "setgetstate 1 1");
             cputhrtl50 = 15;}} else
             if (cputhrtl50 != 25){
             system( "setgetthrtl 0 25");
             system( "setgetthrtl 1 25");
             system( "setgetstate 0 1");
             system( "setgetstate 1 1");
             cputhrtl50 = 25;}} else
             if (cputhrtl50 != 50){
             system( "setgetthrtl 0 50");
             system( "setgetthrtl 1 50");
             system( "setgetstate 0 1");
             system( "setgetstate 1 1");
             cputhrtl50 = 50;}}


         if (((idle_val - idle_val_prev)/ts_delta*100.0) < 50){
         if (((idle_val - idle_val_prev)/ts_delta*100.0) < 40){
         if (((idle_val - idle_val_prev)/ts_delta*100.0) < 30){
             if (cputhrtl50 != 100){
             system( "setgetthrtl 0 100");
             system( "setgetthrtl 1 100");
             system( "setgetstate 0 0");
             system( "setgetstate 1 0");
             cputhrtl50 = 100;}} else
             if (cputhrtl50 != 75){
             system( "setgetthrtl 0 85");
             system( "setgetthrtl 1 85");
             system( "setgetstate 0 0");
             system( "setgetstate 1 0");
             cputhrtl50 = 75;}} else
             if (cputhrtl50 != 50){
             system( "setgetthrtl 0 75");
             system( "setgetthrtl 1 75");
             system( "setgetstate 0 0");
             system( "setgetstate 1 0");
             cputhrtl50 = 50;}}

         }

         ts_val_prev = ts_val;
         idle_val_prev = idle_val;
         busy_val_prev = busy_val;
         intr_val_prev = intr_val;

         iter = 1;
         DosSleep(1000*sleep_sec);

     } while (1);
return 0;
  }