/sdktools/vctools/cvpack.js/verify.c

https://github.com/Paolo-Maffei/OpenNT · C · 919 lines · 840 code · 79 blank · 0 comment · 301 complexity · 3911fa5c876438e38243b9d4bf4e35a8 MD5 · raw file

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. #define _REAL10
  5. #include "cvinfo.h"
  6. #include "cvtdef.h"
  7. #include "vmm.h"
  8. #include "vbuf.h"
  9. #include "cvexefmt.h"
  10. #include "compact.h"
  11. #include "defines.h"
  12. #include "engine.h"
  13. #ifdef WINDOWS
  14. #include "winstuff.h"
  15. #endif
  16. LOCAL void VerifyC7Ptr (uchar *);
  17. LOCAL void VerifyClass (uchar *);
  18. LOCAL void VerifyUnion (uchar *);
  19. LOCAL void VerifyEnum (uchar *);
  20. LOCAL void VerifyFieldList (uchar *);
  21. LOCAL void VerifyArgList (uchar *);
  22. LOCAL void VerifyMethodList (uchar *);
  23. LOCAL void VerifyProcedure (uchar *);
  24. LOCAL void VerifyMemberFunction (uchar *);
  25. LOCAL void VerifyArray (uchar *);
  26. LOCAL void VerifyBasicArray (uchar *);
  27. LOCAL void VerifyModifier (uchar *);
  28. LOCAL void VerifyCobolTypeRef (uchar *);
  29. LOCAL void VerifyVTShape (uchar *);
  30. LOCAL void VerifyBPRelative (uchar *);
  31. LOCAL void VerifyData (uchar *);
  32. LOCAL void VerifyRegister (uchar *);
  33. LOCAL void VerifyConstant (uchar *);
  34. LOCAL void VerifyTypedef (uchar *);
  35. LOCAL void VerifyProc (uchar *);
  36. LOCAL void VerifyThunk (uchar *);
  37. LOCAL void VerifyCodeLabel (uchar *);
  38. LOCAL void VerifyCompileFlag (uchar *);
  39. LOCAL void VerifyIndex (uchar *, ushort, char *);
  40. LOCAL uchar **GlobalIndexTable;
  41. LOCAL ushort NewIndex;
  42. LOCAL struct ModuleListType *ModuleList;
  43. ushort AddrSize;
  44. typedef struct {
  45. uchar type;
  46. void (*pfn) (uchar *);
  47. } FnTableEntry;
  48. FnTableEntry TypeFnTable[] = {
  49. { OLF_STRING, NULL }, // ok
  50. { OLF_LABEL, NULL }, // ok
  51. { OLF_BITFIELD, NULL }, // ok
  52. { OLF_FSTRING, NULL }, // ok
  53. { OLF_FARRIDX, NULL }, // ok
  54. { OLF_COBOL, NULL }, // ok
  55. { OLF_SCALAR, NULL }, // ok
  56. { OLF_NIL, NULL }, // ok
  57. { OLF_LIST, NULL }, // ok?
  58. { OLF_FIELDLIST, VerifyFieldList },
  59. { OLF_ARGLIST, VerifyArgList },
  60. { OLF_METHODLIST, VerifyMethodList },
  61. { OLF_VTSHAPE, VerifyVTShape },
  62. { OLF_COBOLTYPEREF, VerifyCobolTypeRef },
  63. { OLF_BARRAY, VerifyBasicArray },
  64. { OLF_MODIFIER, VerifyModifier },
  65. { OLF_NEWTYPE, NULL }, // ok?
  66. { OLF_C7PTR, VerifyC7Ptr },
  67. { OLF_C7STRUCTURE, VerifyClass },
  68. { OLF_CLASS, VerifyClass },
  69. { OLF_UNION, VerifyUnion },
  70. { OLF_ENUM, VerifyEnum },
  71. { OLF_MEMBERFUNC, VerifyMemberFunction },
  72. { OLF_ARRAY, VerifyArray },
  73. { OLF_PROCEDURE, VerifyProcedure }
  74. };
  75. #define TYPCNT (sizeof (TypeFnTable) / sizeof (FnTableEntry))
  76. FnTableEntry SymFnTable[] = {
  77. { OSYMEND, NULL }, // ok
  78. { OSYMBPREL, VerifyBPRelative },
  79. { OSYMREG, VerifyRegister },
  80. { OSYMCONST, VerifyConstant },
  81. { OSYMTYPEDEF, VerifyTypedef },
  82. { OSYMLOCAL, VerifyData },
  83. { OSYMGLOBAL, VerifyData },
  84. { OSYMGLOBALPROC, VerifyProc },
  85. { OSYMLOCALPROC, VerifyProc },
  86. { OSYMTHUNK, VerifyThunk },
  87. { OSYMSEARCH, NULL }, // ok
  88. { OSYMCV4LABEL, VerifyCodeLabel },
  89. { OSYMCV4BLOCK, NULL }, // ok
  90. { OSYMCV4WITH, NULL }, // ok
  91. { OSYMCOMPILE, VerifyCompileFlag }
  92. };
  93. #define SYMCNT (sizeof (SymFnTable) / sizeof (FnTableEntry))
  94. void FAR VerifyTypes ()
  95. {
  96. ushort i, j, n;
  97. for (i = 0, n = NewIndex - 512; i < n; i++) {
  98. for (j = 0; j < TYPCNT; j++) {
  99. if (GlobalIndexTable[i][3] == TypeFnTable[j].type) {
  100. if (TypeFnTable[j].pfn) {
  101. TypeFnTable[j].pfn (GlobalIndexTable[i]);
  102. }
  103. break;
  104. }
  105. }
  106. if (j >= TYPCNT) {
  107. Warning ("$$TYPES", "", "", "unknown type");
  108. }
  109. }
  110. }
  111. void FAR VerifySymbols ()
  112. {
  113. struct ModuleListType *mod;
  114. uchar *Symbols, *End;
  115. ushort i;
  116. AddrSize = (fLinearExe) ? 4 : 2;
  117. for (mod = ModuleList; mod; mod = mod->next) {
  118. if (mod->SymbolSize != 0) {
  119. if ( (Symbols = (uchar *)
  120. VmLoad (mod->SymbolsAddr, mod->SymbolSize, FALSE)) == NULL) {
  121. FarErrorExit (ERR_NOMEM);
  122. }
  123. for ( End = Symbols + mod->SymbolSize;
  124. Symbols < End;
  125. Symbols += *Symbols + 1) {
  126. for (i = 0; i < SYMCNT; i++) {
  127. if (Symbols[1] == SymFnTable[i].type) {
  128. if (SymFnTable[i].pfn) {
  129. SymFnTable[i].pfn (Symbols);
  130. }
  131. break;
  132. }
  133. }
  134. if (i >= SYMCNT) {
  135. Warning ("$$SYMBOLS", "", "", "unknown symbol");
  136. }
  137. }
  138. }
  139. }
  140. }
  141. LOCAL void VerifyC7Ptr (uchar *TypeString)
  142. {
  143. struct C7PtrAttrib attribute;
  144. ushort index;
  145. attribute = * (struct C7PtrAttrib *) (TypeString + 4);
  146. switch (attribute.ptrtype) {
  147. case 0: // near
  148. case 1: // far
  149. case 2: // huge
  150. case 3: // based on segment
  151. case 9: // based on self
  152. break;
  153. case 4: // based on value
  154. case 5: // based on segment value
  155. case 6: // based on addr of symbol
  156. case 7: // based on segment of symbol addr
  157. switch (TypeString[8] & 0x7f) {
  158. case OSYMREG :
  159. case OSYMBPREL :
  160. case OSYMLOCAL :
  161. case OSYMGLOBAL:
  162. break;
  163. default :
  164. Warning ("$$TYPES", "C7Ptr", "variant",
  165. "unexpected symbol in based pointer");
  166. break;
  167. }
  168. break;
  169. case 8 :
  170. if (* (ushort *) (TypeString + 8) == 0) {
  171. Warning ("$$TYPES", "C7Ptr", "variant",
  172. "type index 0 in based pointer");
  173. }
  174. break;
  175. default:
  176. Warning ("$$TYPES", "C7Ptr", "attribute", "unknown ptrtype attribute");
  177. }
  178. switch (attribute.ptrmode) {
  179. case 0: // pointer
  180. case 1: // reference
  181. break;
  182. case 2: // pointer to member
  183. case 3: // pointer to member function
  184. index = * (ushort *) (TypeString + 8);
  185. if (index == 0) {
  186. Warning ("$$TYPES", "C7Ptr", "variant", "type index 0");
  187. break;
  188. }
  189. if (index < 512) {
  190. Warning ("$$TYPES", "C7Ptr", "variant",
  191. "type index of containing class expected");
  192. break;
  193. }
  194. switch (GlobalIndexTable[index - 512][3]) {
  195. case OLF_C7STRUCTURE:
  196. case OLF_CLASS:
  197. break;
  198. default:
  199. Warning ("$$TYPES", "C7Ptr", "variant", "type index of containing class expected");
  200. }
  201. break;
  202. default:
  203. Warning ("$$TYPES", "C7Ptr", "attribute", "unknown ptrmode attribute");
  204. }
  205. if (attribute.unused != 0) {
  206. Warning ("$$TYPES", "C7Ptr", "attribute", "unused attribute bits not 0");
  207. }
  208. if (* (ushort *) (TypeString + 6) == 0) {
  209. Warning ("$$TYPES", "C7Ptr", "@type", "pointed to object type index 0");
  210. }
  211. }
  212. LOCAL void VerifyClass (uchar *TypeString)
  213. {
  214. struct C7StructProp prop;
  215. ushort index;
  216. index = * (ushort *) (TypeString + 6);
  217. if (index == 0) {
  218. Warning ("$$TYPES", "Class", "@fList", "type index 0");
  219. }
  220. else if (index < 512 || GlobalIndexTable[index - 512][3] != OLF_FIELDLIST) {
  221. Warning ("$$TYPES", "Class", "@fList", "type index of a field list expected");
  222. }
  223. prop = * (struct C7StructProp *) (TypeString + 8);
  224. if (prop.reserved != 0) {
  225. Warning ("$$TYPES", "Class", "prop", "reserved property bits not 0");
  226. }
  227. index = * (ushort *) (TypeString + 11);
  228. if ( index != 0
  229. &&
  230. (index < 512 || GlobalIndexTable[index - 512][3] != OLF_VTSHAPE)) {
  231. Warning ("$$TYPES", "Class", "@vshape", "type index of a VTShape expected");
  232. }
  233. }
  234. LOCAL void VerifyUnion (uchar *TypeString)
  235. {
  236. struct C7StructProp prop;
  237. ushort index;
  238. index = * (ushort *) (TypeString + 6);
  239. if (index == 0) {
  240. Warning ("$$TYPES", "Union", "@fList", "type index 0");
  241. }
  242. else if (index < 512 || GlobalIndexTable[index - 512][3] != OLF_FIELDLIST) {
  243. Warning ("$$TYPES", "Union", "@fList", "type index of a field list expected");
  244. }
  245. prop = * (struct C7StructProp *) (TypeString + 8);
  246. if (prop.reserved != 0) {
  247. Warning ("$$TYPES", "Union", "prop", "reserved property bits not 0");
  248. }
  249. }
  250. LOCAL void VerifyEnum (uchar *TypeString)
  251. {
  252. struct C7StructProp prop;
  253. ushort index;
  254. index = * (ushort *) (TypeString + 4);
  255. if (index == 0) {
  256. Warning ("$$TYPES", "Enum", "@type", "underlying type index 0");
  257. }
  258. index = * (ushort *) (TypeString + 8);
  259. if (index == 0) {
  260. Warning ("$$TYPES", "Union", "@fList", "type index 0");
  261. }
  262. else if (index < 512 || GlobalIndexTable[index - 512][3] != OLF_FIELDLIST) {
  263. Warning ("$$TYPES", "Enum", "@fList",
  264. "type index of a field list expected");
  265. }
  266. prop = * (struct C7StructProp *) (TypeString + 10);
  267. if (prop.reserved != 0) {
  268. Warning ("$$TYPES", "Enum", "prop", "reserved bits not 0");
  269. }
  270. }
  271. LOCAL void VerifyFieldList (uchar *TypeString)
  272. {
  273. uchar *Type = TypeString + 4;
  274. uchar *End = TypeString + LENGTH (TypeString) + 3;
  275. uchar *Temp;
  276. struct MemberAttrib attrib;
  277. ushort index;
  278. while (Type < End) {
  279. switch (*Type) {
  280. case OLF_MEMBER:
  281. Type++;
  282. attrib = * (struct MemberAttrib *) Type;
  283. if (attrib.access == 0) {
  284. Warning ("$$TYPES", "Member", "attr", "unknown access");
  285. }
  286. if (attrib.property > 4) {
  287. Warning ("$$TYPES", "Member", "attr", "unknown property");
  288. }
  289. if (attrib.unused != 0) {
  290. Warning ("$$TYPES", "Member", "attr", "unused bit not 0");
  291. }
  292. Type++;
  293. if (* (ushort *) Type == 0) {
  294. Warning ("$$TYPES", "Member", "@type", "type index 0");
  295. }
  296. Type += 2;
  297. Type += FarSkipNumericLeaf (Type);
  298. Type += *Type + 1;
  299. break;
  300. case OLF_STATICMEMBER:
  301. Type++;
  302. attrib = * (struct MemberAttrib *) Type;
  303. if (attrib.access == 0) {
  304. Warning ("$$TYPES", "StaticMember", "attr", "unknown access");
  305. }
  306. if (attrib.property > 4) {
  307. Warning ("$$TYPES", "StaticMember", "attr", "unknown property");
  308. }
  309. if (attrib.unused != 0) {
  310. Warning ("$$TYPES", "StaticMember", "attr", "unused bit not 0");
  311. }
  312. Type++;
  313. if (* (ushort *) Type == 0) {
  314. Warning ("$$TYPES", "StaticMember", "@type", "type index 0");
  315. }
  316. Type += 2;
  317. Type += *Type + 1;
  318. break;
  319. case OLF_BASECLASS:
  320. Type++;
  321. attrib = * (struct MemberAttrib *) Type;
  322. if (attrib.access == 0) {
  323. Warning ("$$TYPES", "BaseClass", "attr", "unknown access");
  324. }
  325. if (attrib.property > 4) {
  326. Warning ("$$TYPES", "BaseClass", "attr", "unknown property");
  327. }
  328. if (attrib.unused != 0) {
  329. Warning ("$$TYPES", "BaseClass", "attr", "unused bit not 0");
  330. }
  331. Type++;
  332. index = * (ushort *) Type;
  333. if (index == 0) {
  334. Warning ("$$TYPES", "BaseClass", "@type", "type index 0");
  335. }
  336. else if (index < 512) {
  337. Warning ("$$TYPES", "BaseClass", "@type",
  338. "type index of base class expected");
  339. }
  340. else {
  341. Temp = GlobalIndexTable[index - 512];
  342. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7STRUCTURE) {
  343. Warning ("$$TYPES", "BaseClass", "@type",
  344. "type index of base class expected");
  345. }
  346. }
  347. Type += 2;
  348. Type += FarSkipNumericLeaf (Type);
  349. break;
  350. case OLF_VBCLASS:
  351. Type++;
  352. attrib = * (struct MemberAttrib *) Type;
  353. if (attrib.access == 0) {
  354. Warning ("$$TYPES", "VirtualBaseClass", "attr", "unknown access");
  355. }
  356. if (attrib.property > 4) {
  357. Warning ("$$TYPES", "VirtualBaseClass", "attr", "unknown property");
  358. }
  359. if (attrib.unused != 0) {
  360. Warning ("$$TYPES", "VirtualBaseClass", "attr", "unused bit not 0");
  361. }
  362. Type++;
  363. index = * (ushort *) Type;
  364. if (index == 0) {
  365. Warning ("$$TYPES", "VirtualBaseClass", "@btype", "type index 0");
  366. }
  367. else if (index < 512) {
  368. Warning ("$$TYPES", "VirtualBaseClass", "@btype",
  369. "type index of virtual base class expected");
  370. }
  371. else {
  372. Temp = GlobalIndexTable[index - 512];
  373. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7STRUCTURE) {
  374. Warning ("$$TYPES", "VirtualBaseClass", "@btype",
  375. "type index of virtual base class expected");
  376. }
  377. }
  378. Type += 2;
  379. index = * (ushort *) Type;
  380. if (index == 0) {
  381. Warning ("$$TYPES", "VirtualBaseClass", "@vbptype", "type index 0");
  382. }
  383. else if (index < 512) {
  384. Warning ("$$TYPES", "VirtualBaseClass", "@vbptype",
  385. "type index of virtual base pointer expected");
  386. }
  387. else {
  388. Temp = GlobalIndexTable[index - 512];
  389. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7PTR) {
  390. Warning ("$$TYPES", "VirtualBaseClass", "@vbptype",
  391. "type index of virtual base pointer expected");
  392. }
  393. }
  394. Type += 2;
  395. Type += FarSkipNumericLeaf (Type);
  396. Type += FarSkipNumericLeaf (Type);
  397. break;
  398. case OLF_IVBCLASS:
  399. Type++;
  400. index = * (ushort *) Type;
  401. if (index == 0) {
  402. Warning ("$$TYPES", "Indirect VirtualBaseClass", "@btype", "type index 0");
  403. }
  404. else if (index < 512) {
  405. Warning ("$$TYPES", "Indirect VirtualBaseClass", "@btype",
  406. "type index of virtual base class expected");
  407. }
  408. else {
  409. Temp = GlobalIndexTable[index - 512];
  410. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7STRUCTURE) {
  411. Warning ("$$TYPES", "Indirect VirtualBaseClass", "@btype",
  412. "type index of virtual base class expected");
  413. }
  414. }
  415. Type += 2;
  416. break;
  417. case OLF_FRIENDCLASS:
  418. Type++;
  419. index = * (ushort *) Type;
  420. if (index == 0) {
  421. Warning ("$$TYPES", "FriendClass", "@type", "type index 0");
  422. }
  423. else if (index < 512) {
  424. Warning ("$$TYPES", "FriendClass", "@type",
  425. "type index of friend class expected");
  426. }
  427. else {
  428. Temp = GlobalIndexTable[index - 512];
  429. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7STRUCTURE) {
  430. Warning ("$$TYPES", "FriendClass", "@type",
  431. "type index of friend class expected");
  432. }
  433. }
  434. Type += 2;
  435. break;
  436. case OLF_VTABPTR:
  437. Type++;
  438. index = * (ushort *) Type;
  439. if (index == 0) {
  440. Warning ("$$TYPES", "VFuncTabPtr", "@type", "type index 0");
  441. }
  442. else if (index < 512) {
  443. Warning ("$$TYPES", "VFuncTabPtr", "@type",
  444. "type index of a C7Ptr expected");
  445. }
  446. else {
  447. Temp = GlobalIndexTable[index - 512];
  448. if (Temp[3] != OLF_C7PTR) {
  449. Warning ("$$TYPES", "VFuncTabPtr", "@type",
  450. "type index of a C7Ptr expected");
  451. }
  452. else {
  453. index = * (ushort *) (Temp + 6);
  454. if (index == 0) {
  455. Warning ("$$TYPES", "VFuncTabPtr", "@type",
  456. "type index 0");
  457. }
  458. else if (index < 512) {
  459. Warning ("$$TYPES", "VFuncTabPtr", "@type",
  460. "type index of a VTShape expected");
  461. }
  462. else {
  463. Temp = GlobalIndexTable[index - 512];
  464. if (Temp[3] != OLF_VTSHAPE) {
  465. Warning ("$$TYPES", "VFuncTabPtr", "@type",
  466. "type index of a VTShape expected");
  467. }
  468. }
  469. }
  470. }
  471. Type += 2;
  472. break;
  473. case OLF_VBASETABPTR:
  474. Type++;
  475. index = * (ushort *) Type;
  476. if (index == 0) {
  477. Warning ("$$TYPES", "VBaseTabPtr", "@type", "type index 0");
  478. }
  479. else if (index < 512) {
  480. Warning ("$$TYPES", "VBaseTabPtr", "@type",
  481. "type index of a C7Ptr expected");
  482. }
  483. else {
  484. Temp = GlobalIndexTable[index - 512];
  485. if (Temp[3] != OLF_C7PTR) {
  486. Warning ("$$TYPES", "VBaseTabPtr", "@type",
  487. "type index of a C7Ptr expected");
  488. }
  489. else {
  490. index = * (ushort *) (Temp + 6);
  491. if (index == 0) {
  492. Warning ("$$TYPES", "VBaseTabPtr", "@type",
  493. "type index 0");
  494. }
  495. else if (index < 512) {
  496. Warning ("$$TYPES", "VBaseTabPtr", "@type",
  497. "type index of a VTShape expected");
  498. }
  499. else {
  500. Temp = GlobalIndexTable[index - 512];
  501. if (Temp[3] != OLF_VTSHAPE) {
  502. Warning ("$$TYPES", "VBaseTabPtr", "@type",
  503. "type index of a VTShape expected");
  504. }
  505. }
  506. }
  507. }
  508. Type += 2;
  509. Type += FarSkipNumericLeaf (Type);
  510. break;
  511. case OLF_METHOD:
  512. Type += 3;
  513. index = * (ushort *) Type;
  514. if (index == 0) {
  515. Warning ("$$TYPES", "Method", "@type", "type index 0");
  516. }
  517. else if (index < 512 || GlobalIndexTable[index - 512][3] != OLF_METHODLIST) {
  518. Warning ("$$TYPES", "Method", "@type",
  519. "type index of a method list expected");
  520. }
  521. Type += 2;
  522. Type += *Type + 1;
  523. break;
  524. case OLF_ENUMERATE:
  525. Type++;
  526. attrib = * (struct MemberAttrib *) Type;
  527. if (attrib.access == 0) {
  528. Warning ("$$TYPES", "Enumerate", "attr", "unknown access");
  529. }
  530. if (attrib.property > 4) {
  531. Warning ("$$TYPES", "Enumerate", "attr", "unknown property");
  532. }
  533. if (attrib.unused != 0) {
  534. Warning ("$$TYPES", "Enumerate", "attr", "unused bit not 0");
  535. }
  536. Type ++;
  537. Type += FarSkipNumericLeaf (Type);
  538. Type += *Type + 1;
  539. break;
  540. case OLF_NESTEDTYPE:
  541. Type++;
  542. index = * (ushort *) Type;
  543. if (index == 0) {
  544. Warning ("$$TYPES", "NestedTypeDefinition", "index", "type index 0");
  545. }
  546. Type += 2;
  547. Type += *Type + 1;
  548. break;
  549. default:
  550. Warning ("$$TYPES", "FieldList", "", "unknown field entry");
  551. Type++; // why not?
  552. break;
  553. }
  554. }
  555. }
  556. LOCAL void VerifyArgList (uchar *TypeString)
  557. {
  558. uchar *Type = TypeString + 4;
  559. uchar *End = TypeString + LENGTH (TypeString) + 3;
  560. while (Type < End) {
  561. switch (*Type) {
  562. case OLF_INDEX:
  563. Type++;
  564. if (* (ushort *) Type == 0) {
  565. Warning ("$$TYPES", "ArgList - index leaf", "index", "type index 0");
  566. }
  567. Type += 2;
  568. break;
  569. case OLF_DEFARG:
  570. Type++;
  571. if (* (ushort *) Type == 0) {
  572. Warning ("$$TYPES", "ArgList - DEFARG", "index", "type index 0");
  573. }
  574. Type += 2;
  575. Type += *Type + 1;
  576. break;
  577. default:
  578. Warning ("$$TYPES", "ArgList", "", "unknown entry");
  579. break;
  580. }
  581. }
  582. }
  583. LOCAL void VerifyMethodList (uchar *TypeString)
  584. {
  585. uchar *Type = TypeString + 4;
  586. uchar *End = TypeString + LENGTH (TypeString) + 3;
  587. struct MListAttrib attrib;
  588. ushort index;
  589. while (Type < End) {
  590. attrib = * (struct MListAttrib *) Type;
  591. if (attrib.access == 0) {
  592. Warning ("$$TYPES", "mList", "attr", "unknown access");
  593. }
  594. if (attrib.property > 4) {
  595. Warning ("$$TYPES", "mList", "attr", "unknown property");
  596. }
  597. if (attrib.unused != 0) {
  598. Warning ("$$TYPES", "mList", "attr", "unused bit not 0");
  599. }
  600. Type++;
  601. index = * (ushort *) Type;
  602. if (index == 0) {
  603. Warning ("$$TYPES", "mList", "@type", "type index 0");
  604. }
  605. else if (index < 512 || GlobalIndexTable[index - 512][3] != OLF_MEMBERFUNC) {
  606. Warning ("$$TYPES", "mLists", "@type",
  607. "type index of procedure expected");
  608. }
  609. Type += 2;
  610. if (attrib.property == 4) {
  611. Type += FarSkipNumericLeaf (Type);
  612. }
  613. }
  614. }
  615. LOCAL void VerifyProcedure (uchar *TypeString)
  616. {
  617. ushort index;
  618. if (* (ushort *) (TypeString + 6) == 0) {
  619. Warning ("$$TYPES", "Procedure", "@rvtype", "type index 0");
  620. }
  621. if ( TypeString[8] != 0x63 && // C
  622. TypeString[8] != 0x64 && // C long
  623. TypeString[8] != 0x73 && // PLM long
  624. TypeString[8] != 0x74 && // PLM short
  625. TypeString[8] != 0x95 && // NEAR FASTCALL
  626. TypeString[8] != 0x96 && // FAR FASTCALL
  627. TypeString[8] != 0x97 // PCODE
  628. ) {
  629. Warning ("$$TYPES", "Procedure", "calling", "unknown calling convention");
  630. }
  631. index = * (ushort *)
  632. (TypeString + 9 + FarSkipNumericLeaf (TypeString + 9) + 1);
  633. if (index == 0) {
  634. Warning ("$$TYPES", "Procedure", "@list", "type index 0");
  635. }
  636. else if (index < 512) {
  637. if (index != 0x9c) { // not void
  638. Warning ("$$TYPES", "Procedure", "@list",
  639. "type index of an argument list expected");
  640. }
  641. }
  642. else if (GlobalIndexTable[index - 512][3] != OLF_ARGLIST) {
  643. Warning ("$$TYPES", "Procedure", "@list",
  644. "type index of an argument list expected");
  645. }
  646. }
  647. LOCAL void VerifyMemberFunction (uchar *TypeString)
  648. {
  649. ushort index;
  650. uchar *Temp;
  651. TypeString += 4;
  652. if (* (ushort *) TypeString == 0) {
  653. Warning ("$$TYPES", "MemberFunction", "@rvtype", "type index 0");
  654. }
  655. TypeString += 2;
  656. index = * (ushort *) TypeString;
  657. if (index == 0) {
  658. Warning ("$$TYPES", "MemberFunction", "@class", "type index 0");
  659. }
  660. else if (index < 512) {
  661. Warning ("$$TYPES", "MemberFunction", "@class",
  662. "type index of containing class expected");
  663. }
  664. else {
  665. Temp = GlobalIndexTable[index - 512];
  666. if (Temp[3] != OLF_CLASS && Temp[3] != OLF_C7STRUCTURE) {
  667. Warning ("$$TYPES", "MemberFunction", "@class",
  668. "type index of containing class expected");
  669. }
  670. }
  671. TypeString += 2;
  672. if (* (ushort *) TypeString == 0) {
  673. Warning ("$$TYPES", "MemberFunction", "@this", "type index 0");
  674. }
  675. TypeString += 2;
  676. if ( *TypeString != 0x63 && // C
  677. *TypeString != 0x64 && // C long
  678. *TypeString != 0x73 && // PLM long
  679. *TypeString != 0x74 && // PLM short
  680. *TypeString != 0x95 && // NEAR FASTCALL
  681. *TypeString != 0x96 && // FAR FASTCALL
  682. *TypeString != 0x97 // PCODE
  683. ) {
  684. Warning ("$$TYPES", "MemberFunction", "calling", "unknown calling convention");
  685. }
  686. TypeString++;
  687. TypeString += FarSkipNumericLeaf (TypeString);
  688. TypeString += FarSkipNumericLeaf (TypeString);
  689. index = * (ushort *) TypeString;
  690. if (index == 0) {
  691. Warning ("$$TYPES", "Procedure", "@list", "type index 0");
  692. }
  693. else if (index < 512) {
  694. if (index != 0x9c) { // not void
  695. Warning ("$$TYPES", "MemberFunction", "@list",
  696. "type index of an argument list expected");
  697. }
  698. }
  699. else if (GlobalIndexTable[index - 512][3] != OLF_ARGLIST) {
  700. Warning ("$$TYPES", "MemberFunction", "@list",
  701. "type index of an argument list expected");
  702. }
  703. }
  704. LOCAL void VerifyArray (uchar *TypeString)
  705. {
  706. uchar *Type = TypeString;
  707. Type += 4;
  708. Type += FarSkipNumericLeaf (Type);
  709. Type++;
  710. if (* (ushort *) Type == 0) {
  711. Warning ("$$TYPES", "Array", "@elem_type", "type index 0");
  712. }
  713. Type += 2;
  714. if ( Type < TypeString + LENGTH (TypeString) + 3
  715. &&
  716. *Type == OLF_INDEX
  717. &&
  718. * (ushort *) (Type + 1) == 0) {
  719. Warning ("$$TYPES", "Array", "@idx_type", "type index 0");
  720. }
  721. }
  722. LOCAL void VerifyBasicArray (uchar *TypeString)
  723. {
  724. if (* (ushort *) (TypeString + 5) == 0) {
  725. Warning ("$$TYPES", "BasicArray", "@elem_type", "type index 0");
  726. }
  727. }
  728. LOCAL void VerifyModifier (uchar *TypeString)
  729. {
  730. if (TypeString[4] != 1 && TypeString[4] != 2) {
  731. Warning ("$$TYPES", "Modifier", "attribute", "unknown attribute");
  732. }
  733. if (* (ushort *) (TypeString + 5) == 0) {
  734. Warning ("$$TYPES", "Modifier", "@type", "type index 0");
  735. }
  736. }
  737. LOCAL void VerifyCobolTypeRef (uchar *TypeString)
  738. {
  739. if (* (ushort *) (TypeString + 4) == 0) {
  740. Warning ("$$TYPES", "CobolTypeRef", "@type", "type index 0");
  741. }
  742. }
  743. LOCAL void VerifyVTShape (uchar *TypeString)
  744. {
  745. ushort count = * (ushort *) (TypeString + 4);
  746. uchar *Type = TypeString + 6;
  747. ushort i;
  748. for (i = 0; i < count; i++) {
  749. if (i % 2 == 0) {
  750. if (*Type & 0xf0 > 4) {
  751. Warning ("$$TYPES", "VTShape", "descriptor", "unknown descriptor");
  752. }
  753. }
  754. else {
  755. if (*Type++ & 0x0f > 4) {
  756. Warning ("$$TYPES", "VTShape", "descriptor", "unknown descriptor");
  757. }
  758. }
  759. }
  760. }
  761. LOCAL void VerifyBPRelative (uchar *Symbols)
  762. {
  763. VerifyIndex (Symbols, (ushort)(2 + AddrSize), "BP relative");
  764. }
  765. LOCAL void VerifyData (uchar *Symbols)
  766. {
  767. VerifyIndex (Symbols, (ushort)(4 + AddrSize), "Data");
  768. }
  769. LOCAL void VerifyRegister (uchar *Symbols)
  770. {
  771. uchar reg;
  772. VerifyIndex (Symbols, 2, "Register");
  773. reg = Symbols[4];
  774. if (reg > 29 && reg < 32 || reg > 35 && reg < 40 ||
  775. reg > 47 && reg < 128 || reg > 135) {
  776. Warning ("$$SYMBOLS", "Register", "register", "unknown register");
  777. }
  778. }
  779. LOCAL void VerifyConstant (uchar *Symbols)
  780. {
  781. VerifyIndex (Symbols, 2, "Constant");
  782. }
  783. LOCAL void VerifyTypedef (uchar *Symbols)
  784. {
  785. VerifyIndex (Symbols, 2, "Typedef");
  786. }
  787. LOCAL void VerifyProc (uchar *Symbols)
  788. {
  789. uchar rtntyp;
  790. VerifyIndex (Symbols, (ushort)(16 + AddrSize), "Proc");
  791. rtntyp = Symbols[18 + 4 * AddrSize];
  792. if (rtntyp != 0 && rtntyp != 4) {
  793. Warning ("$$SYMBOLS", "Proc", "return type", "unknown return type");
  794. }
  795. }
  796. LOCAL void VerifyThunk (uchar *Symbols)
  797. {
  798. if (Symbols[14] > 2) {
  799. Warning ("$$SYMBOLS", "Thunk", "ord", "unknown ordinal");
  800. }
  801. }
  802. LOCAL void VerifyCodeLabel (uchar *Symbols)
  803. {
  804. uchar labtyp;
  805. labtyp = Symbols[4 + AddrSize];
  806. if (labtyp != 0 && labtyp != 4) {
  807. Warning ("$$SYMBOLS", "Code label", "label type", "unknown label type");
  808. }
  809. }
  810. LOCAL void VerifyCompileFlag (uchar *Symbols)
  811. {
  812. ushort flags;
  813. flags = * (ushort *) (Symbols + 2);
  814. if ( (flags & 0xf000) >> 12 > 6) {
  815. Warning ("$$SYMBOLS", "Compile flag", "language", "unknown language");
  816. }
  817. if ( (flags & 0x0f00) >> 8 > 4) {
  818. Warning ("$$SYMBOLS", "Compile flag", "target processor", "unknown target processor");
  819. }
  820. if ( (flags & 0x0060) >> 5 > 2) {
  821. Warning ("$$SYMBOLS", "Compile flag", "float package", "float package");
  822. }
  823. if ( (flags & 0x0018) >> 3 > 2) {
  824. Warning ("$$SYMBOLS", "Compile flag", "ambient data", "unknown ambient data");
  825. }
  826. if ( (flags & 0x0006) >> 1 > 2) {
  827. Warning ("$$SYMBOLS", "Compile flag", "ambient code", "unknown ambient code");
  828. }
  829. }
  830. LOCAL void VerifyIndex (uchar *Symbols, ushort offset, char *type)
  831. {
  832. ushort index;
  833. index = * (ushort *) (Symbols + offset);
  834. if (index == 0) {
  835. Warning ("$$SYMBOLS", type, "type index", "type index 0");
  836. }
  837. else if (index >= NewIndex) {
  838. Warning ("$$SYMBOLS", type, "type index", "invalid type index");
  839. }
  840. }