Windows NT 4.0 source code leak
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.

432 lines
11 KiB

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