On 19 Sep 2010, at 14:48, Marcel Kilgus wrote:

> gdgqler wrote:
>> If you add a Thing to the list of Things by using the software
>> described in the manual for the Trap #1 routine sms.lthg you will
> 
> Just to be sure, none of the trap #1 thing entry routines are
> supported in SMSQ/E. Just the traditional HOT_REXT way of calling
> them.
> 
>> find that the linkage block you have provided is partially completed
>> (which is correct) but that, in addition, the long word 12 bytes
>> before the start of the linkage block is set with the linkage block's 
>> address.
>> 
>> Does anyone know the reason for this bizarre and potentially dangerous 
>> operation?
> 
> Tobias almost nailed it, but not 100% (if I understand him correctly).
> This is a bit of a hack, but not unheard of: a few utilities use this
> mechanism. As you know, when a job is killed in QDOS, its memory
> allocations are freed. If the allocated memory belongs to a driver,
> the driver's close routine is called (this is the normal way open
> channels are ensured to be closed when a job is killed!). Now, the
> thing system employs the same mechanism to be invoked when a job is
> killed, just like a driver would have been called. To do so a fake
> driver control block address is entered into the heap data structure.
> The address is calculated thus that the only valid field of this
> "virtual" DCB is at the iod_clos offset, which aligns with and thus
> contains the address of th_frzap. So this routine will be called when
> the owning job is killed.
> 
> IOW: the whole thing uses the assumption that no other field of the
> DCB is of interest to the OS, which is of course true.

Yes - that explains it.

However, I have set up two programs as executable Things with both the Thing 
itself and the linkage block being inside the program. When these programs are 
LRESPRd they are owned by the Master Basic. I assume this means that the 
"killing" mechanism would never be used. Anyone writing programs in the same 
way should therefore be aware of the planting of the linkage address in its 
assumed header.


>> The source code for this is:
>> 
>>        LEA          TH_FRZAP+IOD_IOLK-IOD_CLOS(A1),A0
> 
> It's basically pure chance that this resolves to 0. So in principle
> this line is indeed not needed, but it's just good practice to use the
> symbols so a programmer can at least begin to understand what's going
> on (and obviously even then it's difficult to understand!). And if
> somebody were to modify the thing header structure, the line would be
> needed again. Of course nobody would be so daft to do so. ;-)
> 

Marcel is of course quite right. I myself would not have used the one 
instruction for this for the very reasons Marcel has given!

But that is not a reason for having a little bit of fun.

George
_______________________________________________
QL-Users Mailing List
http://www.q-v-d.demon.co.uk/smsqe.htm

Reply via email to