Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!att!cbnewsk!ech From: ech@cbnewsk.ATT.COM (ned.horvath) Newsgroups: comp.sys.mac.programmer Subject: Re: HLock and Think C 4.0 Message-ID: <1553@cbnewsk.ATT.COM> Date: 24 Nov 89 02:05:13 GMT References: <3997@sbcs.sunysb.edu> Organization: AT&T Bell Laboratories Lines: 34 From article <3997@sbcs.sunysb.edu>, by vallon@sbcs.sunysb.edu (Justin Vallon): ! Yes, it is safe to do a BlockMove without locking the handle. One of IM's ! appendicies is a list of routines that move/purge memory. BlockMove isn't ! in it, so you can use it without locking. ! ! However, you seem to have discovered the problem. The first call to your ! ANSI library causes a LoadSeg (see Segment Loader for details), since the ! library (is presumably) in an unloaded segment. Notice that LoadSeg is in ! the list of routines that may move/purge memory. Memory is moved, and the ! address to your string is now pointing into never-never land. The second ! call succeeds because the segment has been loaded, and LoadSeg is not ! called. ! Solution: (1) Make sure that all "safe" routines (ie: ones that do not ! move/purge memory) are always loaded. This insures that a disasterous ! LoadSeg is not called when you are vulnerable. (2) Be paranoid, and ! Lock everything all the time. This sort of defeats the purpose, and it's ! sort of like stopping at a green light, just in case. ! (1) is probably a better solution. I usually leave the libraries in the ! main segment, so that stuff like this doesn't happen. This is difficult when linked with the full ANSI library in TC4 (around 24K I think). However, it is very sensible to preload the segment(s) containing MacTraps and ANSI. You can do this explicitly: touch the library, select the Get Info command, and note the segment number. In ResEdit, open the built application, open CODE, touch the segment, and do a Get Info. Set the Preload bit. An indirect method is to simply make a call on the library early, and never UnloadSeg any library segment. A dummy BlockMove call would appear to do it! =Ned Horvath=