home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / internal / 1594 next >
Encoding:
Text File  |  1992-11-15  |  6.9 KB  |  193 lines

  1. Path: sparky!uunet!stanford.edu!agate!dog.ee.lbl.gov!network.ucsd.edu!mvb.saic.com!macro32
  2. From: Hunter Goatley <goathunter@WKUVX1.BITNET>
  3. Newsgroups: vmsnet.internals
  4. Subject: Locking down C routines under Alpha
  5. Message-ID: <00963AA1.423C6B80.1463@WKUVX1.BITNET>
  6. Date: Sun, 15 Nov 1992 19:04:38 CST
  7. Organization: Macro32<==>Vmsnet.Internals Gateway
  8. X-Gateway-Source-Info: Mailing List
  9. Lines: 182
  10.  
  11. Patrick Mahan (mahan@TGV.COM) sent me the following message and asked
  12. me to forward it to MACRO32.
  13.  
  14. Hunter
  15. ------
  16. Hunter Goatley, VMS Systems Programmer, Western Kentucky University
  17. goathunter@WKUVX1.BITNET, 502-745-5251
  18.  
  19. ---------------------------------------------------------------------------
  20. Date: Sun, 15 Nov 92 16:44:44 PST
  21. From: <mahan@TGV.COM>
  22.  
  23. #
  24. #gleason@mwk.uucp writes:
  25. #>
  26. #>  OK, got my Alpha station, and I'm converting reams of MACRO-32 to
  27. #>C, learning C as I go (and this gives me plenty of practice reading
  28. #>Alpha crash dumps ;-) ).
  29. #>
  30. #Fun, isn't it? 8-)
  31. #
  32.  
  33. LDL, LDL, LDL, LDL, LDL, STO, LDL, LDL, LDL (yea, almost like a song ;-)).
  34.  
  35. #
  36. #>  In many of these programs, entire routines need to be locked in the
  37. #>working set.
  38. #>
  39. #>  In the original MACRO program, all I had to do was something like...
  40. #[...]
  41. #>  What's the best way to do the equivalent in C? Getting the start
  42. #>address is not so hard...(int*)&funcname seems to be adequate...but
  43. #>I don't know how to get the ending address...
  44. #>
  45. #The only way I've been able to do it is by putting another (possibly
  46. #void) routine after the one you want.
  47. #
  48.  
  49. Correct.  Under VAX C you can used stub procedures to bracket the code
  50. you want to lock down.
  51.  
  52. #
  53. #Note however that this still doesn't do what you want/need to do.
  54. #Under Alpha, the address of the function is actually the address of
  55. #the procedure descriptor for that function.  Specifying those
  56. #addresses just locks down the procedure descriptor, which needs to be
  57. #done, but you must also still lock down the code itself.
  58. #
  59. #With the Alpha porting toolkit, there is a MACRO-32 example in the
  60. #_Porting MACRO-32 Code_ (whatever it's really called).  It uses some
  61. #new macros to lock things down: $LOCKED_PAGE_START and
  62. #$LOCKED_PAGE_END.  There's also $LOCK_PAGE and $LOCK_PAGE_INIT, but
  63. #I'm not sure how they're used.  The macros are not available for
  64. #anything except MACRO-32, as far as I can tell.
  65. #
  66. #Another manual (_Recompiling and Relinking_) talked about this
  67. #problem, but the C example was "To be supplied" in all the field test
  68. #documentation.  I haven't had time to take the macros and figure
  69. #out how to do it for C.
  70. #
  71.  
  72. The way to perform this same feat under GEM C on the Alpha is in three
  73. steps.
  74.  
  75.         1) Place all of the code that needs to be locked down inside of
  76.            one or more code modules where they WILL NOT share with code
  77.            that doesn't need to be locked down.
  78.  
  79.            Now using the CLUSTER link option, create 3 clusters in your
  80.            image like so
  81.  
  82.                 CLUSTER=START_OF_LOCKED_CODE
  83.                 CLUSTER=LOCKED_CODE,,,LOCKED_CODE.OBJ
  84.                 CLUSTER=END_OF_LOCKED_CODE
  85.  
  86.            Using the COLLECT link option, place a symbol in the clusters
  87.            START_OF_LOCKED_CODE and END_OF_LOCKED_CODE so that you can
  88.            later reference them, for example:
  89.  
  90.                 COLLECT=START_OF_LOCKED_CODE,START_OF_CODE
  91.                 COLLECT=END_OF_LOCKED_CODE,END_OF_CODE
  92.  
  93.            You now have two references that bracket the code, including the
  94.            linkage sections, that you want to lock down.
  95.  
  96.         2) In the routine you wish to lock the code down in, declare both
  97.            "endpoints" of your lock code like so -
  98.  
  99.                 extern START_OF_CODE(), END_OF_CODE();
  100.  
  101.            However, you cannot just lock down everything in memory starting
  102.            at START_OF_CODE and ending at END_OF_CODE because of the way the
  103.            Alpha linker works.  On the Alpha, the linker does some page
  104.            aligning which will cause "holes" in your image,  this side
  105.            effect is documented in the RECOMPILING_RELINKING manual provided
  106.            with the cross tools.
  107.  
  108.            Instead, first retrieve the system PAGE SIZE via a call to
  109.            $GETSYI using the item code (SYI$_PAGE_SIZE).  Then starting with
  110.            the address pointed to by START_OF_CODE, first check to see if
  111.            the page is readable using the C builtin __PAL_PROBER instruction.
  112.            If it is readable, then lock that page down, and move on to
  113.            the next page in memory.  Repeat this until you have reached the
  114.            address pointed to by END_OF_CODE.  Below is a C routine I wrote
  115.            to lock down all of the known pages between two addresses.
  116.  
  117.  
  118. #include <syidef.h>
  119. #include <decc$library_include:builtins.h>
  120. /*
  121.  *      Lock pages in memory for Alpha.  We do this because the address
  122.  *      space we want to lock down is not contiguous.  Thus we probe
  123.  *      each page for Read then lock it down.
  124.  */
  125. int Lock_Alpha_Pages(Addr_Start, Addr_End)
  126. char *Addr_Start, *Addr_End;
  127. {
  128.         int i;
  129.         unsigned long int Page_Size;
  130.         unsigned long int InAddr[2];
  131.         char Error[200];
  132.         struct {
  133.                 unsigned short int Size;
  134.                 unsigned short int Code;
  135.                 char *Buffer;
  136.                 unsigned short int *Resultant_Length;
  137.         } ItemList[2];
  138.  
  139.         /*
  140.          *      Get the PAGE SIZE of the System
  141.          */
  142.         ItemList[0].Size = sizeof(Page_Size);
  143.         ItemList[0].Code = SYI$_PAGE_SIZE;
  144.         ItemList[0].Buffer = (char *)&Page_Size;
  145.         ItemList[0].Resultant_Length = 0;
  146.         ItemList[1].Size = 0;
  147.         ItemList[1].Code = 0;
  148.         if (!(i = SYS$GETSYI(0, 0, 0, ItemList, 0, 0, 0) & 1)) {
  149.                 return (i);
  150.         }
  151.         /*
  152.          *      From Start Address until End Address, probe and
  153.          *      lockdown the pages
  154.          */
  155.         for (InAddr[0] = (unsigned long int)Addr_Start;
  156.              InAddr[0] < (unsigned long int)Addr_End;
  157.              InAddr[0] = InAddr[0] + Page_Size) {
  158.  
  159.                 /*
  160.                  *      Set up the input address range
  161.                  */
  162.                 InAddr[1] = InAddr[0] + Page_Size - 4;
  163.                 /*
  164.                  *      Probe the page for 4 bytes
  165.                  */
  166.                 i = __PAL_PROBER((void *)InAddr[0], 4, 0);
  167.                 /*
  168.                  *      Check for probe success
  169.                  */
  170.                 if (!(i & 1)) continue;
  171.                 /*
  172.                  *      Lock the Page down
  173.                  */
  174.                 i = sys$lkwset(InAddr, 0, 0);
  175.                 if (!(i & 1)) {
  176.                         return(i);
  177.                 }
  178.         }
  179.         /*
  180.          *      Done, return success
  181.          */
  182.         return(1);
  183. }
  184.  
  185.            This should allow you to lock down any code you need.
  186.  
  187. Patrick L. Mahan
  188.  
  189. --- TGV Window Washer ------------------------------- Mahan@TGV.COM ---------
  190.  
  191. Waking a person unnecessarily should not be considered  - Lazarus Long
  192. a capital crime.  For a first offense, that is            From the Notebooks of
  193.