home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-11 | 1.2 KB | 35 lines | [TEXT/MMCC] |
- // MyGestaltValue was written by François Pottier (pottier@dmi.ens.fr).
- // Please let me know if you find bugs in this code, or if you improve on it!
-
- // InstallGestaltValue looks for the 0xDEADBEEF constant in the selector's code and replaces it with the actual value.
- // Then it flushes the processor caches. Note that it looks for the constant only on 4-byte boundaries, so the constant had better
- // be there!
-
- #include "MyGestaltValue.h"
-
- static Boolean HWPrivAvailable (void)
- {
- return (GetOSTrapAddress(_HWPriv) != GetToolTrapAddress(_Unimplemented));
- }
-
- OSErr InstallGestaltValue (OSType signature, long value)
- {
- Handle selector;
- Ptr p;
-
- selector = Get1Resource('GSel', 0); // Load the resource containing the selector's code
- if (!selector) // Don't use ResError() because it sometimes returns noErr
- return memFullErr;
- DetachResource(selector);
-
- p = *selector; // Look for the magic cookie
- while (* (long*) p != 0xDEADBEEF) p++;
- * (long*) p = value; // Replace it with the actual value
-
- if (HWPrivAvailable()) { // Flush the processor caches, it's safer
- FlushDataCache();
- FlushInstructionCache();
- }
-
- return NewGestalt(signature, (SelectorFunctionUPP) *selector);
- }