home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / e / setf.lha / setf.DoIO.e next >
Encoding:
Text File  |  1995-02-02  |  2.4 KB  |  103 lines

  1. /* setf.DoIO.e -- a program to monitor calls to DoIO() */
  2.  
  3. OPT OSVERSION=37
  4.  
  5. MODULE 'dos/dos', 'exec/ports', 'exec/tasks', 'exec/nodes',
  6.        'exec/memory', 'exec/io'
  7.  
  8. CONST OFFSET=$fe38  /* execbase offset of DoIO() */
  9.  
  10. OBJECT mymsg
  11.   msg:mn
  12.   s, t
  13. ENDOBJECT
  14.  
  15. DEF port:PTR TO mp
  16.  
  17. PROC main()
  18.   DEF ps, us, loop, sig, oldf
  19.   IF port:=CreateMsgPort()
  20.     Forbid()     /* Don't let anyone mess things up... */
  21.     IF oldf:=SetFunction(execbase, OFFSET, {newf})
  22.       PutLong({patch}, oldf)
  23.       Permit()    /* Now we can let everyone else back in */
  24.       LEA store(PC), A0
  25.       MOVE.L A4, (A0)    /* Store the A4 register... */
  26.       ps:=Shl(1,port.sigbit)   /* Set up port and user signal bits */
  27.       us:=SIGBREAKF_CTRL_C
  28.       loop:=TRUE
  29.       WHILE loop
  30.         sig:=Wait(ps OR us)
  31.         IF sig AND ps
  32.           printmsgs()
  33.         ENDIF
  34.         IF sig AND us
  35.           loop:=FALSE
  36.         ENDIF
  37.       ENDWHILE
  38.       Forbid()   /* Paranoid... */
  39.       SetFunction(execbase, OFFSET, oldf)
  40.     ENDIF
  41.     Permit()
  42.     printmsgs()   /* Make sure the port is empty */
  43.     DeleteMsgPort(port)
  44.   ENDIF
  45. ENDPROC
  46.  
  47. /* Nicely (?) print the messages out... */
  48. PROC printmsgs()
  49.   DEF msg:PTR TO mymsg, s:PTR TO io
  50.   WHILE msg:=GetMsg(port)
  51.     IF s:=msg.s
  52.       WriteF('Task \s sent: dev $\h, unit $\h, com $\h, flg $\h\n',
  53.              IF msg.t THEN msg.t ELSE '*unnamed*',
  54.              s.device, s.unit, s.command, s.flags)
  55.     ELSE
  56.       WriteF('Task \s sent NIL msg\n',
  57.              IF msg.t THEN msg.t ELSE '*unnamed*')
  58.     ENDIF
  59.     ReplyMsg(msg)
  60.     Dispose(msg.s)
  61.     DisposeLink(msg.t)
  62.     Dispose(msg)
  63.   ENDWHILE
  64. ENDPROC
  65.  
  66. /* Send a message to the patching process */
  67. PROC sendmsg()
  68.   DEF m:PTR TO mymsg, s:PTR TO io, tsk:tc, l:ln, i, p, q
  69.   MOVE.L A1, s
  70.   /* Allocate a new message */
  71.   m:=New(SIZEOF mymsg)
  72.   IF q:=s
  73.     p:=New(SIZEOF io)
  74.     FOR i:=1 TO SIZEOF io DO p[]++:=q[]++
  75.     m.s:=p
  76.   ENDIF
  77.   tsk:=FindTask(NIL)   /* Find out who we are */
  78.   m.t:=NIL
  79.   IF tsk
  80.     l:=tsk.ln
  81.     IF l AND l.name
  82.       m.t:=String(StrLen(l.name))
  83.       StrCopy(m.t, l.name, ALL)
  84.     ENDIF
  85.   ENDIF
  86.   PutMsg(port, m)
  87. ENDPROC
  88.  
  89. /* Place to store A4 register */
  90. store:  LONG 0
  91. /* Place to store real call */
  92. patch:  LONG 0
  93.  
  94. /* The new routine which will replace the original library function */
  95. newf:
  96.   MOVEM.L D0-D7/A0-A6, -(A7)
  97.   LEA store(PC), A0
  98.   MOVE.L (A0), A4 /* Reinstate the A4 register so we can use E code */
  99.   sendmsg()
  100.   MOVEM.L (A7)+, D0-D7/A0-A6
  101.   MOVE.L patch(PC), -(A7)
  102.   RTS
  103.