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.

455 lines
12 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. resmgr.cxx
  5. Abstract:
  6. Stub and auxillary routine resource management helper routines.
  7. Notes:
  8. This file has a dependency on the type graph implementation.
  9. History:
  10. Sep-15-1993 VibhasC Created.
  11. ----------------------------------------------------------------------------*/
  12. /****************************************************************************
  13. * include files
  14. ***************************************************************************/
  15. #include "becls.hxx"
  16. #pragma hdrstop
  17. void GenNdrCorrRes( ANALYSIS_INFO* pAna );
  18. void
  19. CG_PROC::C_PreAllocateResources(
  20. ANALYSIS_INFO * pAna )
  21. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  22. Routine Description:
  23. Pre-allocate stub resources like local variables, parameter variables
  24. etc for the client side stub.
  25. Arguments:
  26. pAna - A pointer to the analysis block.
  27. Return Value:
  28. None.
  29. Notes:
  30. 1. All parameters are declared as resources for the client stub.
  31. 2. Standard client side resources like the stub message, rpc message
  32. status etc are local resources.
  33. ----------------------------------------------------------------------------*/
  34. {
  35. node_id * pRpcMessageType = new node_id( RPC_MESSAGE_VAR_NAME );
  36. node_id * pStubMessageType= new node_id( STUB_MESSAGE_VAR_NAME );
  37. node_id * pStatus = new node_id( RPC_STATUS_VAR_NAME );
  38. CG_ITERATOR ParamList;
  39. // Set up local copies of the stub message and the rpc message.
  40. pRpcMessageType->SetBasicType( (node_skl *)
  41. new node_def (RPC_MESSAGE_TYPE_NAME) );
  42. pRpcMessageType->SetEdgeType( EDGE_USE );
  43. pAna->AddLocalResource( RPC_MESSAGE_VAR_NAME,
  44. (node_skl *) pRpcMessageType
  45. );
  46. pStubMessageType->SetBasicType( (node_skl *)
  47. new node_def (STUB_MESSAGE_TYPE_NAME) );
  48. pStubMessageType->SetEdgeType( EDGE_USE );
  49. pAna->AddLocalResource( STUB_MESSAGE_VAR_NAME,
  50. (node_skl *) pStubMessageType
  51. );
  52. if( HasStatuses() )
  53. {
  54. pStatus = new node_id( RPC_STATUS_VAR_NAME );
  55. pStatus->SetBasicType( (node_skl *)
  56. new node_def (RPC_STATUS_TYPE_NAME) );
  57. pStatus->SetEdgeType( EDGE_USE );
  58. SetStatusResource( pAna->AddLocalResource( RPC_STATUS_VAR_NAME,
  59. (node_skl *) pStatus
  60. ));
  61. }
  62. // resource for cache
  63. // /deny causes a switch to /Oicf. This code will not be executed
  64. if ( fHasDeny )
  65. {
  66. GenNdrCorrRes( pAna );
  67. }
  68. // Add all params as param resources only if necessary (at least one param).
  69. if( GetMembers( ParamList ) )
  70. {
  71. CG_PARAM * pParam;
  72. node_skl * pType;
  73. ITERATOR_INIT( ParamList );
  74. while( ITERATOR_GETNEXT( ParamList, pParam ) )
  75. {
  76. pType = pParam->GetType();
  77. pAna->AddParamResource( (PNAME) pType->GetSymName(),
  78. pType->GetChild() //Yes not getbasictype()
  79. );
  80. }
  81. }
  82. //
  83. // Check for a structure or union return type. If one exists we must
  84. // allocate a local pointer with a munged name for the eventual
  85. // Ndr unmarshall call.
  86. //
  87. CG_RETURN * pReturn;
  88. if ( (pReturn = GetReturnType()) == 0 )
  89. return;
  90. //
  91. // If this is a by-value structure or union then we allocate a
  92. // local which is a pointer to the same type.
  93. //
  94. if ( ((CG_NDR *)pReturn->GetChild())->IsStruct() ||
  95. ((CG_NDR *)pReturn->GetChild())->IsUnion() ||
  96. ((CG_NDR *)pReturn->GetChild())->IsXmitRepOrUserMarshal() )
  97. {
  98. node_id * pLocalType;
  99. char * pName;
  100. pName = LOCAL_NAME_POINTER_MANGLE RETURN_VALUE_VAR_NAME;
  101. pLocalType = MakePtrIDNodeFromTypeName( pName, "void", 0 );
  102. pAna->AddLocalResource( pName,
  103. (node_skl *) pLocalType );
  104. }
  105. }
  106. void
  107. CG_PROC::S_PreAllocateResources(
  108. ANALYSIS_INFO * pAna )
  109. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  110. Routine Description:
  111. Pre-allocate variables that are needed on the server side.
  112. Arguments:
  113. pAna - A pointer to the analysis block.
  114. Return Value:
  115. None.
  116. Notes:
  117. 1. The rpc message is a parameter resource allocated on the server side.
  118. 2. All other local variables, are decided during/after the analysis phase.
  119. ----------------------------------------------------------------------------*/
  120. {
  121. node_id * pStubMessageType= new node_id( STUB_MESSAGE_VAR_NAME );
  122. node_param * pRpcMessageType = new node_param();
  123. node_param * pDWordType = new node_param();
  124. CG_ITERATOR ParamList;
  125. // The local copy of the rpc message pointer.
  126. pRpcMessageType->SetSymName( PRPC_MESSAGE_VAR_NAME );
  127. pRpcMessageType->SetBasicType( (node_skl *)
  128. new node_def (PRPC_MESSAGE_TYPE_NAME) );
  129. pRpcMessageType->SetEdgeType( EDGE_USE );
  130. pAna->AddParamResource( PRPC_MESSAGE_VAR_NAME,
  131. (node_skl *) pRpcMessageType
  132. );
  133. // For object procs , one more param after the rpc message.
  134. if( IsObject() )
  135. {
  136. // DWORD * pDwPhase parameter
  137. pDWordType->SetSymName( "_pdwStubPhase" );
  138. pDWordType->SetBasicType( (node_skl *)new node_def( "DWORD *" ) );
  139. pDWordType->SetEdgeType( EDGE_USE );
  140. pAna->AddParamResource( "_pdwStubPhase", pDWordType );
  141. }
  142. // Add the stub message local variable.
  143. pStubMessageType->SetBasicType( (node_skl *)
  144. new node_def (STUB_MESSAGE_TYPE_NAME) );
  145. pStubMessageType->SetEdgeType( EDGE_USE );
  146. pAna->AddLocalResource( STUB_MESSAGE_VAR_NAME,
  147. (node_skl *) pStubMessageType
  148. );
  149. if ( HasNotifyFlag() )
  150. {
  151. node_id * pNotifyFlag = new node_id( NOTIFY_FLAG_VAR_NAME );
  152. pNotifyFlag->SetBasicType( (node_skl *) new node_def( "boolean" ));
  153. pNotifyFlag->SetEdgeType( EDGE_USE );
  154. pAna->AddLocalResource( NOTIFY_FLAG_VAR_NAME,
  155. (node_skl *) pNotifyFlag );
  156. }
  157. // resource for cache
  158. // /deny causes a switch to /Oicf. This code will not be executed
  159. if ( fHasDeny )
  160. {
  161. GenNdrCorrRes( pAna );
  162. }
  163. //
  164. // Check for by-value [in] structures and unions. We must allocate
  165. // a local which is a pointer to the same type for these.
  166. //
  167. // Also check for arrays so I can put a hack in until we get their
  168. // allocation figured out.
  169. //
  170. if( GetMembers( ParamList ) )
  171. {
  172. CG_PARAM * pParam;
  173. node_skl * pType;
  174. while( ITERATOR_GETNEXT( ParamList, pParam ) )
  175. {
  176. pType = pParam->GetType();
  177. CG_NDR * pChild = (CG_NDR *)pParam->GetChild();
  178. ID_CG ChildID = pChild->GetCGID();
  179. if ( ChildID == ID_CG_GENERIC_HDL )
  180. {
  181. pChild = (CG_NDR *)pChild->GetChild();
  182. ChildID = pChild->GetCGID();
  183. }
  184. //
  185. // If this is a by-value structure or union then we allocate a
  186. // local which is a pointer to the same type.
  187. //
  188. if ( pChild->IsStruct() || pChild->IsUnion() ||
  189. pChild->IsXmitRepOrUserMarshal() )
  190. {
  191. char * pName;
  192. node_id * pLocalType;
  193. char * pPlainName = pType->GetSymName();
  194. pName = new char[strlen( pPlainName ) + 10];
  195. strcpy( pName, LOCAL_NAME_POINTER_MANGLE );
  196. strcat( pName, (PNAME) pPlainName );
  197. pLocalType = MakePtrIDNodeFromTypeName( pName,
  198. "void",
  199. 0 );
  200. pAna->AddLocalResource( pName,
  201. (node_skl *) pLocalType );
  202. }
  203. }
  204. }
  205. }
  206. /****************************************************************************
  207. utility fns
  208. ****************************************************************************/
  209. node_id *
  210. MakeIDNode(
  211. PNAME pName,
  212. node_skl * pType,
  213. expr_node * pExpr )
  214. {
  215. node_id * pID = new node_id( (char *)pName );
  216. pID->SetBasicType( pType );
  217. pID->SetEdgeType( EDGE_USE );
  218. pID->SetExpr( pExpr );
  219. return pID;
  220. }
  221. node_id *
  222. MakePtrIDNode(
  223. PNAME pName,
  224. node_skl * pType,
  225. expr_node * pExpr )
  226. {
  227. node_id * pID = new node_id( (char *)pName );
  228. node_pointer * pP = new node_pointer();
  229. pP->SetBasicType( pType );
  230. pP->SetEdgeType( EDGE_USE );
  231. pID->SetBasicType( pP );
  232. pID->SetEdgeType( EDGE_USE );
  233. pID->SetExpr( pExpr );
  234. return pID;
  235. }
  236. node_id *
  237. MakePtrIDNodeWithCastedExpr(
  238. PNAME pName,
  239. node_skl * pType,
  240. expr_node * pExpr )
  241. {
  242. node_id * pID = new node_id( (char *)pName );
  243. node_pointer * pP = new node_pointer();
  244. pP->SetBasicType( pType );
  245. pP->SetEdgeType( EDGE_USE );
  246. pID->SetBasicType( pP );
  247. pID->SetEdgeType( EDGE_USE );
  248. expr_cast * pCast = new expr_cast( pP, pExpr );
  249. pID->SetExpr( pCast );
  250. return pID;
  251. }
  252. node_id *
  253. MakeIDNodeFromTypeName(
  254. PNAME pName,
  255. PNAME pTypeName,
  256. expr_node * pExpr )
  257. {
  258. node_id * pID = new node_id( pName );
  259. node_def * pDef = new node_def(pTypeName);
  260. pID->SetBasicType( pDef );
  261. pID->SetEdgeType( EDGE_USE );
  262. pID->SetExpr( pExpr );
  263. return pID;
  264. }
  265. node_id *
  266. MakePtrIDNodeFromTypeName(
  267. PNAME pName,
  268. PNAME pTypeName,
  269. expr_node * pExpr )
  270. {
  271. node_id * pID = new node_id( pName );
  272. node_def * pDef = new node_def(pTypeName);
  273. node_pointer * pPtr = new node_pointer();
  274. pPtr->SetBasicType( pDef );
  275. pPtr->SetEdgeType( EDGE_USE );
  276. pID->SetBasicType( pPtr );
  277. pID->SetEdgeType( EDGE_USE );
  278. pID->SetExpr( pExpr );
  279. return pID;
  280. }
  281. node_id *
  282. MakePtrIDNodeFromTypeNameWithCastedExpr(
  283. PNAME pName,
  284. PNAME pTypeName,
  285. expr_node * pExpr )
  286. {
  287. node_id * pID = new node_id( pName );
  288. node_def * pDef = new node_def(pTypeName);
  289. node_pointer * pPtr = new node_pointer();
  290. pPtr->SetBasicType( pDef );
  291. pPtr->SetEdgeType( EDGE_USE );
  292. pID->SetBasicType( pPtr );
  293. pID->SetEdgeType( EDGE_USE );
  294. expr_cast * pCast = new expr_cast( pPtr, pExpr );
  295. pID->SetExpr( pCast );
  296. return pID;
  297. }
  298. node_param *
  299. MakeParamNode(
  300. PNAME pName,
  301. node_skl * pType )
  302. {
  303. node_param * pID = new node_param();
  304. pID->SetSymName( pName );
  305. pID->SetBasicType( pType );
  306. pID->SetEdgeType( EDGE_USE );
  307. return pID;
  308. }
  309. node_param *
  310. MakePtrParamNode(
  311. PNAME pName,
  312. node_skl * pType )
  313. {
  314. node_param * pID = new node_param( );
  315. node_pointer * pP = new node_pointer();
  316. pID->SetSymName( pName );
  317. pP->SetBasicType( pType );
  318. pP->SetEdgeType( EDGE_USE );
  319. pID->SetBasicType( pP );
  320. pID->SetEdgeType( EDGE_USE );
  321. return pID;
  322. }
  323. node_param *
  324. MakeParamNodeFromTypeName(
  325. PNAME pName,
  326. PNAME pTypeName )
  327. {
  328. node_param * pID = new node_param();
  329. node_def * pDef = new node_def(pTypeName);
  330. pID->SetSymName( pName );
  331. pID->SetBasicType( pDef );
  332. pID->SetEdgeType( EDGE_USE );
  333. return pID;
  334. }
  335. node_param *
  336. MakePtrParamNodeFromTypeName(
  337. PNAME pName,
  338. PNAME pTypeName )
  339. {
  340. node_param * pID = new node_param();
  341. node_def * pDef = new node_def(pTypeName);
  342. node_pointer * pPtr = new node_pointer();
  343. pID->SetSymName( pName );
  344. pPtr->SetBasicType( pDef );
  345. pPtr->SetEdgeType( EDGE_USE );
  346. pID->SetBasicType( pPtr );
  347. pID->SetEdgeType( EDGE_USE );
  348. return pID;
  349. }
  350. node_proc * MakeProcNodeWithNewName(
  351. PNAME pName,
  352. node_proc * pProc )
  353. {
  354. node_proc * pNewProc = new node_proc( pProc );
  355. pNewProc->SetSymName( pName );
  356. return pNewProc;
  357. }
  358. void
  359. GenNdrCorrRes (
  360. ANALYSIS_INFO* pAna
  361. )
  362. {
  363. node_id* pCacheType = new node_id( NDR_CORR_CACHE_VAR_NAME );
  364. expr_node* pExpr = new expr_constant( unsigned long( NDR_CORR_CACHE_SIZE ) );
  365. node_array* pArray = new node_array( 0, pExpr );
  366. node_base_type* pBaseType = new node_base_type( NODE_LONG, ATTR_UNSIGNED );
  367. pBaseType->SetSymName( "long" );
  368. pArray->SetBasicType( pBaseType );
  369. pArray->SetEdgeType( EDGE_USE );
  370. pCacheType->SetBasicType( pArray );
  371. pCacheType->SetEdgeType( EDGE_USE );
  372. pAna->AddLocalResource( NDR_CORR_CACHE_VAR_NAME, pCacheType );
  373. }