Leaked source code of windows server 2003
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.

608 lines
14 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. anainfo.cxx
  5. Abstract:
  6. Implementation of the analysis classes.
  7. Notes:
  8. Author:
  9. History:
  10. VibhasC Jul-25-1993 Created.
  11. ----------------------------------------------------------------------------*/
  12. /****************************************************************************
  13. * include files
  14. ***************************************************************************/
  15. #include "allana.hxx"
  16. #pragma hdrstop
  17. /****************************************************************************
  18. * local definitions
  19. ***************************************************************************/
  20. /****************************************************************************
  21. * local data
  22. ***************************************************************************/
  23. short TempResourceCounter = 0;
  24. /****************************************************************************
  25. * externs
  26. ***************************************************************************/
  27. #ifdef MIDL_INTERNAL
  28. void
  29. ANALYSIS_INFO::Dump(
  30. ANAPHASE A )
  31. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32. Routine Description:
  33. Debug dump.
  34. Arguments:
  35. A - The analysis phase to be dumped.
  36. Return Value:
  37. None.
  38. Notes:
  39. ----------------------------------------------------------------------------*/
  40. {
  41. FILE * hFile = stdout;
  42. char * pTemp;
  43. OPTIM_OPTION Options = OPTIMIZE_NONE;
  44. static char Buffer[ 100 ];
  45. pTemp = ( A == ANA_PHASE_CLIENT_MARSHALL ) ? "Client Marshall" :
  46. ( A == ANA_PHASE_CLIENT_UNMARSHALL ) ? "Client UnMarshall":
  47. ( A == ANA_PHASE_SERVER_UNMARSHALL ) ? "Server UnMarshall":
  48. "Server Marshal";
  49. sprintf( Buffer, "\nDump of phase :%s\n", pTemp );
  50. fprintf( hFile, "%s", Buffer );
  51. //
  52. // dump optimisation options.
  53. //
  54. fprintf( hFile, "\nOptimize Options: ( " );
  55. if( Options )
  56. {
  57. if( Options & OPTIMIZE_SIZE )
  58. {
  59. fprintf( hFile, "Size " );
  60. Options &= ~OPTIMIZE_SIZE;
  61. }
  62. if( Options & OPTIMIZE_INTERPRETER )
  63. {
  64. fprintf( hFile, "Interpret " );
  65. Options &= ~OPTIMIZE_INTERPRETER;
  66. }
  67. if( Options & OPTIMIZE_NO_REF_CHECK )
  68. {
  69. fprintf( hFile, "NoRef " );
  70. Options &= ~OPTIMIZE_NO_REF_CHECK;
  71. }
  72. if( Options & OPTIMIZE_NO_CTXT_CHECK )
  73. {
  74. fprintf( hFile, "NoCtxt " );
  75. Options &= ~OPTIMIZE_NO_CTXT_CHECK;
  76. }
  77. if( Options & OPTIMIZE_NO_GEN_HDL_CHECK )
  78. {
  79. fprintf( hFile, "NoGenHdl " );
  80. Options &= ~OPTIMIZE_NO_GEN_HDL_CHECK;
  81. }
  82. }
  83. else
  84. fprintf( hFile, "default( speed )" );
  85. fprintf( hFile, " )" );
  86. //
  87. // all done.
  88. //
  89. fprintf( hFile, "\n" );
  90. }
  91. #endif // MIDL_INTERNAL
  92. void
  93. ANALYSIS_INFO::Reset()
  94. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  95. Routine Description:
  96. The Master clear or reset.
  97. Arguments:
  98. None.
  99. Return Value:
  100. NA.
  101. Notes:
  102. Create an alignment state machine instance.
  103. ----------------------------------------------------------------------------*/
  104. {
  105. //
  106. // Initialize the miscellaneous properties.
  107. //
  108. SetMiscProperties( DEFAULT_MISC_PROPERTIES );
  109. //
  110. // Set the default optimization options.
  111. //
  112. SetOptimOption( DEFAULT_OPTIM_OPTIONS );
  113. ResetArrayContext();
  114. SetRpcSSAllocateRecommended( 0 );
  115. }
  116. ANALYSIS_INFO::ANALYSIS_INFO()
  117. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  118. Routine Description:
  119. Constructor for analysis information manager block.
  120. Arguments:
  121. None.
  122. Return Value:
  123. NA.
  124. Notes:
  125. ----------------------------------------------------------------------------*/
  126. {
  127. //
  128. // Initialize and so on.
  129. //
  130. Reset();
  131. //
  132. // Set the analysis phase to be client side marshall by default.
  133. //
  134. SetCurrentPhase( ANA_PHASE_CLIENT_MARSHALL );
  135. //
  136. // Create a resource dictionary data base.
  137. //
  138. pResDictDatabase = new RESOURCE_DICT_DATABASE();
  139. OptimOptions = OPTIMIZE_NONE;
  140. SetLastPlaceholderClass(0);
  141. fRpcSSSwitchSet = 0;
  142. }
  143. RESOURCE *
  144. ANALYSIS_INFO::DoAddResource(
  145. RESOURCE_DICT * pResDict,
  146. PNAME pName,
  147. node_skl * pType )
  148. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  149. Routine Description:
  150. Add a resource to a dictionary.
  151. Arguments:
  152. pResDict - A pointer to the resource dictionary.
  153. pName - The resource name.
  154. pType - The type of the resource.
  155. Return Value:
  156. Notes:
  157. If the type of the resource does not indicate a param node, assume it
  158. is an ID node and create an id node for it.
  159. ----------------------------------------------------------------------------*/
  160. {
  161. RESOURCE * pRes;
  162. if( (pRes = pResDict->Search( pName )) == 0 )
  163. {
  164. pRes = pResDict->Insert( pName, pType );
  165. }
  166. return pRes;
  167. }
  168. RESOURCE *
  169. ANALYSIS_INFO::AddStandardResource(
  170. STANDARD_RES_ID ResID )
  171. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  172. Routine Description:
  173. Add a standard resource to the appropriate dictionary.
  174. Arguments:
  175. ResID - The standard resource ID.
  176. Return Value:
  177. Notes:
  178. Depending upon the resource in question, locate the correct dictionary
  179. to insert into, generate the type and insert in the dictionary.
  180. ----------------------------------------------------------------------------*/
  181. {
  182. RESOURCE_DICT * pResDict = 0;
  183. PNAME pName = 0;
  184. RESOURCE * pResource;
  185. node_id * pType;
  186. PNAME pTName = 0;
  187. static struct
  188. {
  189. char * pName;
  190. char * pTypeName;
  191. } LocalResIDToResName[] =
  192. {
  193. { RPC_MESSAGE_VAR_NAME, RPC_MESSAGE_TYPE_NAME }
  194. ,{ STUB_MESSAGE_VAR_NAME, STUB_MESSAGE_TYPE_NAME }
  195. ,{ STUB_DESC_STRUCT_VAR_NAME, STUB_DESC_STRUCT_TYPE_NAME }
  196. ,{ BUFFER_POINTER_VAR_NAME, BUFFER_POINTER_TYPE_NAME }
  197. ,{ RPC_STATUS_VAR_NAME, RPC_STATUS_TYPE_NAME }
  198. ,{ LENGTH_VAR_NAME, LENGTH_VAR_TYPE_NAME }
  199. ,{ BH_LOCAL_VAR_NAME, BH_LOCAL_VAR_TYPE_NAME }
  200. ,{ PXMIT_VAR_NAME, PXMIT_VAR_TYPE_NAME }
  201. };
  202. static struct
  203. {
  204. char * pName;
  205. char * pTypeName;
  206. }ParamResIDToResName[] =
  207. {
  208. { PRPC_MESSAGE_VAR_NAME, PRPC_MESSAGE_TYPE_NAME }
  209. };
  210. static struct
  211. {
  212. char * pName;
  213. char * pTypeName;
  214. } GlobalResIDToResName[] =
  215. {
  216. { AUTO_BH_VAR_NAME, AUTO_BH_TYPE_NAME }
  217. };
  218. if( IS_STANDARD_LOCAL_RESOURCE( ResID ) )
  219. {
  220. pResDict= pResDictDatabase->GetLocalResourceDict();
  221. pName = LocalResIDToResName[ ResID - ST_LOCAL_RESOURCE_START ].pName;
  222. pTName = LocalResIDToResName[ ResID - ST_LOCAL_RESOURCE_START ].pTypeName;
  223. }
  224. else if( IS_STANDARD_PARAM_RESOURCE( ResID ) )
  225. {
  226. pResDict= pResDictDatabase->GetParamResourceDict();
  227. pName = ParamResIDToResName[ ResID - ST_PARAM_RESOURCE_START ].pName;
  228. pTName = ParamResIDToResName[ ResID - ST_PARAM_RESOURCE_START ].pTypeName;
  229. }
  230. else if( IS_STANDARD_GLOBAL_RESOURCE( ResID ) )
  231. {
  232. pResDict= pResDictDatabase->GetGlobalResourceDict();
  233. pName = GlobalResIDToResName[ ResID - ST_GLOBAL_RESOURCE_START ].pName;
  234. pTName = GlobalResIDToResName[ ResID - ST_GLOBAL_RESOURCE_START ].pTypeName;
  235. }
  236. else
  237. {
  238. MIDL_ASSERT( FALSE );
  239. }
  240. if( (pResource = pResDict->Search( pName )) == 0 )
  241. {
  242. pType = new node_id( pName );
  243. pType->SetBasicType( new node_def( pTName ) );
  244. //gaj pType->SetEdgeType( EDGE_USE );
  245. pType->GetModifiers().SetModifier( ATTR_TAGREF );
  246. pResource = pResDict->Insert( pName, (node_skl *)pType );
  247. }
  248. return pResource;
  249. }
  250. PNAME
  251. ANALYSIS_INFO::GenTempResourceName(
  252. char * pPrefix )
  253. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  254. Routine Description:
  255. Generate the name for a temporary resource.
  256. Arguments:
  257. pPrefix - A null terminated prefix string. If this is null, nothing is
  258. added.
  259. Return Value:
  260. A freshly allocated resource name string.
  261. Notes:
  262. ----------------------------------------------------------------------------*/
  263. {
  264. char TempBuffer[ 30 ];
  265. sprintf( TempBuffer,
  266. "_%sM%d",
  267. pPrefix ? pPrefix : "",
  268. GetTempResourceCounter()
  269. );
  270. BumpTempResourceCounter();
  271. PNAME pName = (PNAME) new char [ strlen(TempBuffer) + 1 ];
  272. strcpy( pName, TempBuffer );
  273. return pName;
  274. }
  275. PNAME
  276. ANALYSIS_INFO::GenTRNameOffLastParam(
  277. char * pPrefix )
  278. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  279. Routine Description:
  280. Generate the name for a temporary resource.
  281. Arguments:
  282. pPrefix - A null terminated prefix string. If this is null, nothing is
  283. added.
  284. Return Value:
  285. A freshly allocated resource name string.
  286. Notes:
  287. ----------------------------------------------------------------------------*/
  288. {
  289. char TempBuffer[ 30 ];
  290. sprintf( TempBuffer,
  291. "_%sM",
  292. pPrefix ? pPrefix : ""
  293. );
  294. PNAME pName = (PNAME) new char [ strlen(TempBuffer) + 1 ];
  295. strcpy( pName, TempBuffer );
  296. return pName;
  297. }
  298. /****************************************************************************
  299. Utility functions.
  300. ****************************************************************************/
  301. //
  302. // This array defines the action taken when memory has been allocated for
  303. // a type.
  304. //
  305. static U_ACTION S_WhenMemoryAllocated[ 2 ] =
  306. {
  307. // Buffer re-use is not possible.
  308. { AN_NONE, // No Allocation needed.
  309. RA_NONE, // No reference action.
  310. UA_COPY_INTO_TYPE, // Copy from source to type ( resource )
  311. PR_TYPE // Presented expression is the type / resource
  312. }
  313. // When Buffer reuse is possible.
  314. ,{
  315. AN_NONE, // No allocation needed.
  316. RA_NONE, // No action for reference.
  317. UA_COPY_INTO_TYPE, // No Unmarshalling action.
  318. PR_TYPE // Presented expression is deref of src.
  319. }
  320. };
  321. //
  322. // This array defines the action taken when a reference has been allocated for
  323. // a type.
  324. //
  325. static U_ACTION S_WhenRefAllocated[ 2 ] =
  326. {
  327. // Buffer re-use is not possible.
  328. { AN_STACK, // Explicit allocation needed.
  329. RA_PATCH_TO_ADDR_OF_TYPE,// Patch ref to address of type.
  330. UA_COPY_INTO_TYPE, // Copy from source to type.
  331. PR_NONE // Presented expression tbd by caller.
  332. }
  333. // When Buffer reuse is possible.
  334. ,{
  335. AN_NONE, // No allocation needed.
  336. RA_PATCH_INTO_BUFFER, // Patch ref to position in buffer.
  337. UA_NONE, // No Unmarshalling action.
  338. PR_NONE // Presented expression is deref of src.
  339. }
  340. };
  341. static U_ACTION S_WhenMemoryAndRefAllocated[ 2 ] =
  342. {
  343. // Buffer re-use is not possible.
  344. { AN_ERROR, // Explicit allocation needed.
  345. RA_ERROR, // Patch ref to address of type.
  346. UA_ERROR, // Copy from source to type.
  347. PR_ERROR // Presented expression tbd by caller.
  348. }
  349. // When Buffer reuse is possible.
  350. ,{
  351. AN_ERROR, // No allocation needed.
  352. RA_ERROR, // Patch ref to position in buffer.
  353. UA_ERROR, // No Unmarshalling action.
  354. PR_ERROR // Presented expression is deref of src.
  355. }
  356. };
  357. static U_ACTION C_WhenMemoryAllocated[ 2 ] =
  358. {
  359. // Buffer re-use is not possible.
  360. { AN_EXISTS, // No Allocation needed.
  361. RA_NONE, // No reference action.
  362. UA_COPY_INTO_DEREF_OF_REF, // Copy from source to type ( resource )
  363. PR_NONE // Presented expression is the type / resource
  364. }
  365. #if 0
  366. { AN_NONE, // No Allocation needed.
  367. RA_NONE, // No reference action.
  368. UA_COPY_INTO_TYPE, // Copy from source to type ( resource )
  369. PR_NONE // Presented expression is the type / resource
  370. }
  371. #endif // 0
  372. // When Buffer reuse is possible.
  373. ,{
  374. AN_ERROR, // This situation must never happen on client
  375. RA_ERROR,
  376. UA_ERROR,
  377. PR_ERROR
  378. }
  379. };
  380. //
  381. // This array defines the action taken when a reference has been allocated for
  382. // a type.
  383. //
  384. static U_ACTION C_WhenRefAllocated[ 2 ] =
  385. {
  386. // Buffer re-use is not possible.
  387. { AN_NONE, // Explicit allocation needed.
  388. RA_NONE, // Patch ref to address of type.
  389. UA_COPY_INTO_DEREF_OF_REF,// Copy from source to type.
  390. PR_NONE // Presented expression tbd by caller.
  391. }
  392. // When Buffer reuse is possible.
  393. ,{
  394. AN_ERROR, // Must never happen on client
  395. RA_ERROR,
  396. UA_ERROR,
  397. PR_ERROR
  398. }
  399. };
  400. static U_ACTION C_WhenMemoryAndRefAllocated[ 2 ] =
  401. {
  402. // Buffer re-use is not possible.
  403. { AN_EXISTS, // No Allocation needed.
  404. RA_NONE, // No reference action.
  405. UA_COPY_INTO_DEREF_OF_REF,// Copy from source to type ( resource )
  406. PR_NONE // Presented expression is the type / resource
  407. }
  408. // When Buffer reuse is possible.
  409. ,{
  410. AN_ERROR, // Must never happen on client
  411. RA_ERROR,
  412. UA_ERROR,
  413. PR_ERROR
  414. }
  415. };
  416. U_ACTION
  417. CG_NDR::RecommendUAction(
  418. SIDE Side,
  419. BOOL fMemoryAllocated,
  420. BOOL fRefAllocated,
  421. BOOL fBufferReUsePossible,
  422. UAFLAGS )
  423. {
  424. BOOL fMemoryAndRefAllocated = (fMemoryAllocated && fRefAllocated);
  425. if( Side == C_SIDE )
  426. {
  427. if( fMemoryAndRefAllocated )
  428. return C_WhenMemoryAndRefAllocated[ fBufferReUsePossible ];
  429. else if( fMemoryAllocated )
  430. return C_WhenMemoryAllocated[ fBufferReUsePossible ];
  431. else
  432. return C_WhenRefAllocated[ fBufferReUsePossible ];
  433. }
  434. else
  435. {
  436. if( fMemoryAndRefAllocated )
  437. {
  438. MIDL_ASSERT( FALSE &&
  439. !"Server analysis should never have mem and ref allocated");
  440. return S_WhenRefAllocated[ fBufferReUsePossible ];
  441. }
  442. else if( fMemoryAllocated )
  443. return S_WhenMemoryAllocated[ fBufferReUsePossible ];
  444. else
  445. return S_WhenRefAllocated[ fBufferReUsePossible ];
  446. }
  447. }