Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.4 KiB

  1. //
  2. // ORD.C - Keep track of ordinals in the current .sbr file
  3. //
  4. //
  5. #include "mbrmake.h"
  6. static WORD near cOrdFree; // number of free ords in this block
  7. static VA near vaOrdNext; // the next free ord
  8. static VA near vaOrdBase; // the first ord in this block
  9. static VA near vaOrdRoot; // the first ord block
  10. // ordinals may be sparse so they are hashed
  11. //
  12. // number of hash buckets
  13. #define PORD_MAX 512
  14. #define HASH_ORD(ord) ((ord)&511)
  15. static VA near rgvaOrd[PORD_MAX]; // array of linked-lists
  16. // allocation blocking (ORD_BLOCK objects per alloc)
  17. #define ORD_BLOCK 128
  18. VOID
  19. FreeOrdList()
  20. // free the ordinal alias list
  21. //
  22. {
  23. int i;
  24. // clean the hash table
  25. for (i=0; i<PORD_MAX; i++)
  26. rgvaOrd[i] = vaNil;
  27. vaOrdBase = vaOrdRoot;
  28. vaOrdNext = (PBYTE)vaOrdRoot + sizeof(ORD);
  29. cOrdFree = ORD_BLOCK - 1;
  30. }
  31. VA
  32. VaOrdFind (WORD ord)
  33. // search for the specified ord, return the corresponding PROP entry
  34. // return vaNil if not found
  35. //
  36. {
  37. VA vaOrd;
  38. SetVMClient(VM_SEARCH_ORD);
  39. vaOrd = rgvaOrd[HASH_ORD(ord)];
  40. while (vaOrd) {
  41. if (ord == gORD(vaOrd).aliasord) {
  42. SetVMClient(VM_MISC);
  43. return(cORD.vaOrdProp);
  44. }
  45. else
  46. vaOrd = cORD.vaNextOrd;
  47. }
  48. SetVMClient(VM_MISC);
  49. return(vaNil);
  50. }
  51. VA
  52. VaOrdAdd()
  53. // Add the symbol ordinal to the alias list.
  54. //
  55. {
  56. VA vaOrdNew;
  57. SetVMClient(VM_ADD_ORD);
  58. if (cOrdFree--) {
  59. vaOrdNew = vaOrdNext;
  60. vaOrdNext = (PBYTE)vaOrdNext + sizeof(ORD);
  61. }
  62. else if (vaOrdBase && gORD(vaOrdBase).vaNextOrd) {
  63. // if there is an old allocated block that we can re-use, then do so
  64. vaOrdBase = cORD.vaNextOrd;
  65. vaOrdNew = (PBYTE)vaOrdBase + sizeof(ORD);
  66. vaOrdNext = (PBYTE)vaOrdNew + sizeof(ORD);
  67. cOrdFree = ORD_BLOCK - 2;
  68. }
  69. else {
  70. // allocate a new block -- keep a backwards pointer in this block
  71. vaOrdNew = VaAllocGrpCb(grpOrd, sizeof(ORD) * ORD_BLOCK);
  72. if (!vaOrdRoot)
  73. vaOrdRoot = vaOrdNew;
  74. if (vaOrdBase) {
  75. gORD(vaOrdBase);
  76. cORD.vaNextOrd = vaOrdNew;
  77. pORD(vaOrdBase);
  78. }
  79. vaOrdBase = vaOrdNew;
  80. (PBYTE)vaOrdNew += sizeof(ORD);
  81. vaOrdNext = (PBYTE)vaOrdNew + sizeof(ORD);
  82. cOrdFree = ORD_BLOCK - 2;
  83. }
  84. gORD(vaOrdNew).aliasord = r_ordinal;
  85. cORD.vaNextOrd = rgvaOrd[HASH_ORD(r_ordinal)];
  86. rgvaOrd[HASH_ORD(r_ordinal)] = vaOrdNew;
  87. pORD(vaOrdNew);
  88. SetVMClient(VM_MISC);
  89. return(vaOrdNew);
  90. }