Exemplo n.º 1
0
char *InitSys( void )
{
    SEL         sel_global;
    SEL         sel_local;
    USHORT      rc;

    if( MaxBaud == 0 ) {
        MaxBaud = 3; /* 19200 -- see table */
    }
    rc = DosGetInfoSeg( &sel_global, &sel_local );
    if( rc != 0 ) return( TRP_OS2_no_info );
    GInfoSeg = MK_FP( sel_global, 0 );
    LInfoSeg = MK_FP( sel_local, 0 );
    rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL,
                     0, LInfoSeg->tidCurrent );
    if( rc != 0 ) return( TRP_OS2_cannot_set_thread_priority );
    ReadBuffAdd = 0;
    ReadBuffRemove = 0;
    ReadSemaphore = 0;
    rc = DosCreateThread( Reader, &ReaderId, ReaderStack+READER_STACKSIZE );
    if( rc != 0 ) return( TRP_OS2_cannot_create_helper_thread );
    rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, ReaderId );
    if( rc != 0 ) return( TRP_OS2_cannot_set_thread_priority );
    CurrentBaud = -1;
    return( NULL );
}
Exemplo n.º 2
0
void main()
{
    USHORT rc, Action;
    HFILE FileHandle;

    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_CTRLC);
    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_KILLPROCESS);
    DosSetSigHandler(BrkHandler, NULL, NULL, SIGA_ACCEPT, SIG_CTRLBREAK);

    DosSetPrty(PRTYS_PROCESS, PRTYC_IDLETIME, 0, 0);

    rc = DosOpen("Idlehlt$", &FileHandle, &Action, 0L,
                 FILE_NORMAL, FILE_OPEN, OPEN_SHARE_DENYNONE, 0L);

    if(!rc) {
        while(!ExitWhile)
            DosDevIOCtl(NULL, NULL, 0x01, 0x91, FileHandle);
        DosClose(FileHandle);
    } else {
        char buf[6], Message[36] = "HLT Driver not installed? rc=";
        char *src = buf, *dst = &Message[29];
        int len;

        utoa(rc, buf, 10);
        while(*dst++ = *src++);
        len = dst - Message;
        Message[len-1] = '\r';
        Message[len] = '\n';

        DosWrite(STDERR_FILENO, Message, len+1, &Action);
    }
}
Exemplo n.º 3
0
VOID InitDebugThread( VOID )
{
    TID                 tid;

    DosSemSet( &StopDoneSem );
    DosSemSet( &DebugReqSem );
    DosCreateThread( DoDebugRequests, &tid, stack + STACK_SIZE );
    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid );
}
Exemplo n.º 4
0
void InitScreen( void )
{
    TID                 tid;

    RestoreMainScreen( "WDPM" );
    DosSemSet( &PumpMessageSem );
    DosSemSet( &PumpMessageDoneSem );
    DosCreateThread( (PFNTHREAD)PumpMessageQueue, &tid, Stack+STACK_SIZE );
    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid );
}
Exemplo n.º 5
0
APIRET SetPriority( ULONG ulClass, LONG lLevel )
{
   APIRET    rc;                        /* creation return code       */

   rc = DosSetPrty( PRTYS_THREAD,
                    ulClass,
                    lLevel,
                    0 );               /* current process/thread     */

   if ( rc != NO_ERROR ) {
      fprintf( stdout, "DosSetPrty(%d,%d) failed with RC=%d.\r\n", ulClass, lLevel, rc );
   }

   return( rc );                       /* Return DosSetPriority rc   */

} /* end SetPriority() */
Exemplo n.º 6
0
static void far Respond( void )
{
    char        dummy;

    ServECB.fragCount = 2;
    ServECB.fragList[1].fragAddress = &dummy;
    ServECB.fragList[1].fragSize = sizeof( dummy );
    DosSetPrty( PRTYS_THREAD, PRTYC_NOCHANGE, +1, 0 );
    for( ;; ) {
        if( IpxReceive( IPXSocket, ~0UL, &ServECB ) == 0 ) {
            _IPX_ASSIGNADDR( RespHead.dest, ServHead.source );
            AssignArray( RespECB.immediateAddress, ServECB.immediateAddress );
            RespECB.fragList[1].fragAddress = &SPXSocket;
            IpxSend( IPXSocket, &RespECB );
        }
        if( ServerDie ) {
            ServerDie |= DIE_RESPOND;
            DosExit( EXIT_THREAD, 0 );
        }
    }
}
/* This function is called from two threads, one each to monitor the
 * keyboard and mouse messages.
 * All packets are passed on unchanged.  The thread just clears a
 * semaphore to alert the main background process that there has been some
 * activity, which means it won't blank or will restore the screen if
 * it is already blanked.
 *
 * Parameter is name of device to be monitored.
 */
void CALLBACK
MonitorThread(NPSZ npName)
{
   int             rc;
   MONIN           mnin;        /* monitor buffers */
   MONOUT          mnout;
   HMONITOR        hmon;
   char            bDataBuf[sizeof(MONIN)];  /* buffer used */
   USHORT          cbDataBufLen;
   PIDINFO         pidi;

   /* It has to be time-critical, so it doesn't impact response. */
   DosGetPID(&pidi);
   DosSetPrty(PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, pidi.tid);

   /* Initialize the lengths of the monitor buffer structures. */
   mnin.cb = sizeof(MONIN);
   mnout.cb = sizeof(MONOUT);

   /*
    * Register for the current session.
    */
   TRACE(tpMonOpen, TRUE, 0, npName);
   if (rc = DosMonOpen(npName, &hmon))
      ERRORCHK("DosMonOpen", rc);
   TRACE(tpMonReg, TRUE, 0, npName);
   rc = DosMonReg(hmon,
                  (PBYTE) & mnin,
                  (PBYTE) & mnout,
                  MONITOR_BEGIN, sgMonitor);
   TRACE(tpMonReg, FALSE, rc, npName);
   if (rc == 0)
      /*
       * Loop, passing on data and signalling main thread.
       */
      for (;;) {
         cbDataBufLen = sizeof(MONIN);
         if (DosMonRead((PBYTE) & mnin, DCWW_WAIT, bDataBuf, &cbDataBufLen))
            break;
         /* We shouldn't get a length 0 return, but best to check, before
          * testing the first byte... */
         if (cbDataBufLen > 0) {
            if (DosMonWrite((PBYTE) & mnout, bDataBuf, cbDataBufLen))
               break;
            /* Test for open/close/flush packets and ignore them;
             * they don't represent mouse/keyboard actions. */
            if (!(bDataBuf[0] & 0x07)) {
               TRACE(tpMonAction, FALSE, cbDataBufLen, npName);
               DosSemClear(&pSharedseg->semAction);
            }
         }
      }
   else {
      /* Failed to register */
      WtiLStrCpy(bDataBuf, "DosMonReg for ");
      WtiLStrCat(bDataBuf, npName);
      ERRORCHK(bDataBuf, rc);
   }

   /* If blanked, undo it, whatever the reason we're leaving... */
   if (pSharedseg->bBlanked)
      DosSemClear(&pSharedseg->semAction);

   /* Told to withdraw */
   DosExit(EXIT_THREAD, 0);
}
Exemplo n.º 8
0
void StartProg( const char *cmd, const char *prog, char *full_args, char *dos_args )
{

    const char  *src;
    char        *dst;
    USHORT      drive;
    ULONG       map;
    USHORT      len;
    USHORT      tid;
    USHORT      rc;
    char        buff[BSIZE];
    seg_offset  where;
    char        *cmd_tail;

    /* unused parameters */ (void)cmd;

    MaxThread = 0;
    GrowArrays( 1 );
    src = prog;
    dst = UtilBuff;
    DosQCurDisk( &drive, &map );
    if( src[0] == '\0' || src[1] == '\0' || src[1] != ':' ) {
        *dst++ = drive - 1 + 'A';
        *dst++ = ':';
    } else {
        *dst++ = *src++;
        *dst++ = *src++;
    }
    if( src[0] != '\\' ) {
        ++dst;
        len = BUFF_SIZE - ( dst - UtilBuff );
        DosQCurDir( drive, (PBYTE)dst, &len );
        dst[-1] = '\\';
        if( *dst == '\\' || *dst == '\0' ) {
            *dst = '\0';
        } else {
            while( *dst != '\0' ) {
                ++dst;
            }
            *dst++ = '\\';
        }
    }
    strcpy( dst, src );
    dst = UtilBuff + strlen( UtilBuff ) + 1;
    cmd_tail = dst;
    strcpy( dst, full_args );
    dst += strlen( dst );
    *++dst = '\0';      /* Need two nulls at end */
    LoadProg( UtilBuff, cmd_tail );
    Output( MsgArray[MSG_SAMPLE_1 - ERR_FIRST_MESSAGE] );
    Output( UtilBuff );
    Output( "\r\n" );
    Buff.pid = Pid;
    Buff.tid = 1;
    Buff.cmd = PT_CMD_STOP;
    LibLoadPTrace( &Buff );
    if( OSVer < 0x1400 ) {
        /* OS/2 2.x already dumped out MainMod as a Module load */
        CodeLoad( &Buff, MainMod, ExeName, SAMP_MAIN_LOAD );
    }
    InitialCS = Buff.u.r.CS;
    rc = DosCreateThread( Sleeper, (PUSHORT)&tid, Stack + STACK_SIZE );
    if( rc != 0 ) {
        InternalError( MsgArray[MSG_SAMPLE_4 - ERR_FIRST_MESSAGE] );
    }
    rc = DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 0, tid );
    if( rc != 0 ) {
        InternalError( MsgArray[MSG_SAMPLE_5 - ERR_FIRST_MESSAGE] );
    }
    Buff.pid = Pid;
    Buff.tid = 1;
    for( ;; ) {
        Buff.cmd = PT_CMD_GO;
        if( LibLoadPTrace( &Buff ) != 0 ) {
            InternalError( MsgArray[MSG_SAMPLE_7 - ERR_FIRST_MESSAGE] );
        }
        if( Buff.cmd == PT_RET_BREAK && Buff.u.r.DX != 0 ) {    /* a mark */
            len = 0;
            Buff.segv = Buff.u.r.DX;
            Buff.offv = Buff.u.r.AX;
            for( ;; ) {
                Buff.cmd = PT_CMD_READ_MEM_D;
                DosPTrace( &Buff );
                buff[len] = Buff.value;
                if( Buff.cmd != PT_RET_SUCCESS )
                    buff[len] = '\0';
                if( len == BSIZE )
                    buff[len] = '\0';
                if( buff[len] == '\0' )
                    break;
                ++len;
                Buff.offv++;
            }
            where.segment = Buff.u.r.CS;
            where.offset = Buff.u.r.IP;
            WriteMark( buff, where );
            Buff.cmd = PT_CMD_READ_REGS;
            DosPTrace( &Buff );
            Buff.u.r.IP++;
            Buff.cmd = PT_CMD_WRITE_REGS;
            DosPTrace( &Buff );
            continue;
        } else if( Buff.cmd == PT_RET_BREAK ) {         /* common info pass */
            CommonAddr.segment = Buff.u.r.CX;
            CommonAddr.offset = Buff.u.r.BX;
            Buff.cmd = PT_CMD_READ_REGS;
            DosPTrace( &Buff );
            Buff.u.r.IP++;
            Buff.cmd = PT_CMD_WRITE_REGS;
            DosPTrace( &Buff );
            continue;
        }
        if( Buff.cmd == PT_RET_FUNERAL )
            break;
        if( Buff.cmd != PT_RET_LIB_LOADED
          && Buff.cmd != PT_RET_STOPPED
          && Buff.cmd != PT_RET_TRD_TERMINATE ) {
            InternalError( MsgArray[MSG_SAMPLE_6 - ERR_FIRST_MESSAGE] );
            break;
        }
        RecordSample( Buff.u.r.IP, Buff.u.r.CS, Buff.tid );
    }
    report();
}
Exemplo n.º 9
0
unsigned int CallDosDebug( dos_debug __far *buff )
{
    QMSG        qmsg;
    int         num_paints;
    int         i;
    struct {
        RECTL   rcl;
        HWND    hwnd;
    }           paints[MAX_PAINTS];
    HPS         ps;
    char        class_name[80];
    TID         tid;

    if( !IsPMDebugger() ) {
        return( Call32BitDosDebug( buff ) );
    }

    switch( buff->Cmd ) {
    case DBG_C_ClearWatch:
    case DBG_C_Freeze:
    case DBG_C_LinToSel:
    case DBG_C_NumToAddr:
    case DBG_C_ReadCoRegs:
    case DBG_C_ReadMemBuf:
    case DBG_C_ReadMem_D:
    case DBG_C_ReadReg:
    case DBG_C_SelToLin:
    case DBG_C_SetWatch:
    case DBG_C_ThrdStat:
    case DBG_C_WriteCoRegs:
    case DBG_C_WriteMemBuf:
    case DBG_C_WriteMem_D:
    case DBG_C_WriteReg:
        return( Call32BitDosDebug( buff ) );
    }
    switch( buff->Cmd ) {
    case DBG_C_Go:
    case DBG_C_SStep:
    case DBG_C_Term:
        ReleaseQueue( buff->Pid, buff->Tid );
    }
    DebugReqBuff = buff;
    StopBuff = *buff;
    DosSemSet( &DebugDoneSem );
    DosSemClear( &DebugReqSem );
    num_paints = 0;
    if( IsPMDebugger() ) {
        while( WinGetMsg( HabDebugger, &qmsg, 0L, 0, 0 ) || InDosDebug ) {
            WinQueryClassName( qmsg.hwnd, MAX_CLASS_NAME, class_name );
            switch( qmsg.msg ) {
            case WM_CHAR:
                if( ( SHORT1FROMMP( qmsg.mp1 ) & KC_VIRTUALKEY ) &&
                    ( SHORT2FROMMP( qmsg.mp2 ) == VK_BREAK ) ) {
                    SetBrkPending();
                    DosCreateThread( StopApplication, &tid, stack2 + STACK_SIZE );
                    DosSetPrty( PRTYS_THREAD, PRTYC_TIMECRITICAL, 10, tid );
                    WakeThreads( StopBuff.Pid );
                    DosSemWait( &StopDoneSem, SEM_INDEFINITE_WAIT );
                    DosSemSet( &StopDoneSem );
                }
                break;
            case WM_COMMAND:
                CantDoIt();
                break;
            default:
                if( strcmp( class_name, "GUIClass" ) == 0 ||
                    strcmp( class_name, "WTool" ) == 0 ) {
                    switch( qmsg.msg ) {
                    case WM_PAINT:
                        if( num_paints >= MAX_PAINTS ) --num_paints;
                        paints[num_paints].hwnd = qmsg.hwnd;
                        ps = WinBeginPaint( qmsg.hwnd, 0, &paints[ num_paints ].rcl );
                        GpiErase( ps );
                        WinEndPaint( ps );
                        num_paints++;
                        break;
                    case WM_BUTTON1DOWN:
                    case WM_BUTTON2DOWN:
                    case WM_BUTTON3DOWN:
                        CantDoIt();
                        break;
                    case WM_MOUSEMOVE:
                    {
                        HPOINTER hourglass = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE );
                        if( WinQueryPointer( HWND_DESKTOP ) != hourglass ) {
                            WinSetPointer( HWND_DESKTOP, hourglass );
                        }
                        break;
                    }
                    default:
                        WinDefWindowProc( qmsg.hwnd, qmsg.msg, qmsg.mp1, qmsg.mp2 );
                    }
                } else {
                    WinDispatchMsg( HabDebugger, &qmsg );
                }
            }
        }
    } else {
        DosSemWait( &DebugDoneSem, SEM_INDEFINITE_WAIT );
    }
    switch( buff->Cmd ) {
    case DBG_N_Exception:
    case DBG_N_AsyncStop:
    case DBG_N_Watchpoint:
        AssumeQueue( buff->Pid, buff->Tid );
        break;
    }
    for( i = 0; i < num_paints; ++i ) {
        WinInvalidateRect( paints[i].hwnd, &paints[i].rcl, FALSE );
    }
    return( DebugReqResult );
}