Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!snorkelwacker!bloom-beacon!eru!hagbard!sunic!nuug!ifi!pers From: pers@ifi.uio.no (Per Siljubergs}sen) Newsgroups: comp.sys.mac.programmer Subject: Access global variables from trap patches? (Summary) Summary: Store reference to globals inside code Message-ID: <1990Oct4.062049.17455@ifi.uio.no> Date: 4 Oct 90 06:20:49 GMT References: <1990Sep24.231618.29949@ifi.uio.no> Organization: Dept. of Informatics, University of Oslo, Norway Lines: 64 Nntp-Posting-Host: gille.ifi.uio.no Originator: pers@gille.ifi.uio.no Thanks to all of you who helped me out with this. In article <1990Sep24.231618.29949@ifi.uio.no> pers@ifi.uio.no (Per Siljubergs}sen) writes: >The usual tips regarding stand-alone code don't seem to >help me. Say one of my patches need access to the globals: > > 1) The patch can't get it's hands on my A5 world or a > handle to the globals through the parameters, because > they (the parameters) must be the same as the trap. > > 2) I can't set up A5 before the patch gets called. I have > no way to predict when the system or the applications > will call the trap. Most of the answers I got, recommended to store a reference to the globals inside the stand-alone code segment. Here follows a little subset of comments (in received order): David Shayer writes: >The way I would probably do it is to store the A5 inside my code. >This is way DTS usually recommends. With a little assembly code, >you can set up space in your code, and have it set to zero. Also, >set up an assembly routine which returns the address of this space. >If its zero, you know its the first time through, and you have to >set up the A5 world. Otherwise just set A5 to the stored value. Mark Valence writes: > ... set aside a longword inside your patch. This >way, the INIT that installs the patch can store a pointer >to your global variables in the space you provided. This >gets around the problem of the instruction cache because >you are writing to that memory location before the code >is run (so it's not in the cache), and once you've >written to it, it never changes (so the instruction >cache will always be valid). Larry Rosenstein writes: >> 3) System 7.0 IPC? Is it possible? Even if it is, I would >> like this to work with System 6.x.x too. > >Actually in System 7 you can use the Gestalt manager to register your A5 >value under a 4-byt signature. Each piece of code can then look up the >value of A5 using that signature. [My comment: This works with System 6.0.4 and later.] Andrew D. Sonenblick writes: >I use A4--and Think C makes this very simple for me. All I have to do >is set it up to the the value A0 had the first time my init was called.. >and yes, I do save this to my own code. Apple said this isnt that bad >and shouldnt be a problem. I have done this and it works on all >processors and all systems... -Per ---------- Per Siljubergsaasen, Dept. of Informatics, University of Oslo, Norway pers@ifi.uio.no