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.

486 lines
13 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1993-2000 Microsoft Corporation
  3. Module Name:
  4. bindndr.hxx
  5. Abstract:
  6. Contains routines for the generation of the new NDR format strings for
  7. the code generation bind classes.
  8. Notes:
  9. History:
  10. DKays Dec-1993 Created.
  11. ----------------------------------------------------------------------------*/
  12. #include "becls.hxx"
  13. #pragma hdrstop
  14. extern CMD_ARG * pCommand;
  15. void
  16. CG_HANDLE::GenNdrParamDescription( CCB * )
  17. {
  18. MIDL_ASSERT(0);
  19. }
  20. void
  21. CG_HANDLE::GenNdrParamDescriptionOld( CCB * )
  22. {
  23. MIDL_ASSERT(0);
  24. }
  25. unsigned char
  26. CG_HANDLE::MakeExplicitHandleFlag(
  27. CG_PARAM * pHandleParam )
  28. /*++
  29. Description:
  30. Produces a handle flag byte (actually, a nibble) that can keep the
  31. following simple flags:
  32. HANDLE_PARAM_IS_VIA_PTR - Bind param is a pointer to a handle type.
  33. Note:
  34. Flags are set on the upper nibble (lower nibble is used for generic
  35. handle size).
  36. --*/
  37. {
  38. unsigned char Flag = 0;
  39. if ( pHandleParam->GetChild()->IsPointer() )
  40. Flag |= HANDLE_PARAM_IS_VIA_PTR;
  41. return( Flag );
  42. }
  43. unsigned char
  44. CG_CONTEXT_HANDLE::MakeExplicitHandleFlag(
  45. CG_PARAM * pHandleParam )
  46. /*++
  47. Description:
  48. Produces a handle flag byte (actually, a nibble) that can keep the
  49. following simple flags:
  50. HANDLE_PARAM_IS_VIA_PTR - Bind param is a pointer to a handle type.
  51. HANDLE_PARAM_IS_IN - Bind param is [in] (context handles only).
  52. HANDLE_PARAM_IS_OUT - Bind param is [out] (context handles only).
  53. HANDLE_PARAM_IS_RETURN - Bind param is return (context handles only).
  54. Note:
  55. Flags are set on the upper nibble (lower nibble is used for generic
  56. handle size).
  57. --*/
  58. {
  59. unsigned char Flag = CG_HANDLE::MakeExplicitHandleFlag( pHandleParam );
  60. if ( pHandleParam->IsParamIn() )
  61. Flag |= HANDLE_PARAM_IS_IN;
  62. if ( pHandleParam->IsParamOut() )
  63. Flag |= HANDLE_PARAM_IS_OUT;
  64. if ( pHandleParam->GetCGID() == ID_CG_RETURN )
  65. Flag |= HANDLE_PARAM_IS_RETURN;
  66. return ( Flag );
  67. }
  68. void
  69. CG_PRIMITIVE_HANDLE::GetNdrHandleInfo( CCB * pCCB, NDR64_BINDINGS *pBinding )
  70. {
  71. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  72. pBinding->Primitive.HandleType = (NDR64_FORMAT_CHAR)(pCommand->IsNDR64Run() ? FC64_BIND_PRIMITIVE :
  73. FC_BIND_PRIMITIVE);
  74. pBinding->Primitive.Flags = MakeExplicitHandleFlag( pBindParam );
  75. pBinding->Primitive.Reserved = 0;
  76. pBinding->Primitive.StackOffset = 0xBAAD;
  77. // StackOffset should be reset by the callee
  78. }
  79. void
  80. CG_PRIMITIVE_HANDLE::GenNdrHandleFormat( CCB * pCCB )
  81. /*++
  82. The layout is:
  83. FC_BIND_PRIMITIVE
  84. handle flag <1>
  85. stack offset<2>
  86. --*/
  87. {
  88. FORMAT_STRING *pProcFormatString = pCCB->GetProcFormatString();
  89. CG_PARAM *pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  90. NDR64_BINDINGS binding;
  91. SetNdrBindDescriptionOffset( pProcFormatString->GetCurrentOffset() );
  92. GetNdrHandleInfo( pCCB, &binding );
  93. MIDL_ASSERT( FC_BIND_PRIMITIVE == binding.Primitive.HandleType );
  94. pProcFormatString->PushFormatChar(
  95. (FORMAT_CHARACTER ) binding.Primitive.HandleType );
  96. pProcFormatString->PushByte( binding.Primitive.Flags );
  97. pProcFormatString->PushUShortStackOffsetOrSize(
  98. pBindParam->GetStackOffset( pCCB, I386_STACK_SIZING ));
  99. }
  100. void
  101. CG_GENERIC_HANDLE::GetNdrHandleInfo( CCB * pCCB, NDR64_BINDINGS *pBinding )
  102. {
  103. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  104. NDR64_UINT8 Flags = MakeExplicitHandleFlag( pBindParam );
  105. NDR64_UINT8 RoutineIndex = (NDR64_UINT8)
  106. ( pCCB->LookupBindingRoutine(
  107. GetHandleTypeName() ) - 1 );
  108. pBinding->Generic.HandleType = (NDR64_FORMAT_CHAR)(pCommand->IsNDR64Run() ? FC64_BIND_GENERIC :
  109. FC_BIND_GENERIC);
  110. pBinding->Generic.Flags = Flags;
  111. pBinding->Generic.RoutineIndex = RoutineIndex;
  112. pBinding->Generic.Size = (NDR64_UINT8) GetMemorySize();
  113. pBinding->Generic.StackOffset = 0xBAAD;
  114. // StackOffset should be reset by the callee
  115. // Make a note if the table would be actually used by the interpreter.
  116. if ( pCCB->GetOptimOption() & OPTIMIZE_INTERPRETER )
  117. pCCB->SetInterpretedRoutinesUseGenHandle();
  118. //
  119. // Register the handle.
  120. //
  121. pCCB->RegisterGenericHandleType( GetHandleType() );
  122. }
  123. void
  124. CG_GENERIC_HANDLE::GenNdrHandleFormat( CCB * pCCB )
  125. /*++
  126. The layout is:
  127. FC_BIND_GENERIC
  128. handle flag, handle size <high nibble, low nibble>
  129. stack offset <2>
  130. routine index<1>
  131. FC_PAD
  132. --*/
  133. {
  134. FORMAT_STRING * pProcFormatString = pCCB->GetProcFormatString();
  135. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  136. NDR64_BINDINGS binding;
  137. SetNdrBindDescriptionOffset( pProcFormatString->GetCurrentOffset() );
  138. GetNdrHandleInfo( pCCB, &binding );
  139. MIDL_ASSERT( FC_BIND_GENERIC == binding.Primitive.HandleType );
  140. pProcFormatString->PushFormatChar(
  141. (FORMAT_CHARACTER) binding.Generic.HandleType );
  142. pProcFormatString->PushByte(
  143. binding.Generic.Flags | binding.Generic.Size );
  144. pProcFormatString->PushUShortStackOffsetOrSize(
  145. pBindParam->GetStackOffset( pCCB, I386_STACK_SIZING ) );
  146. pProcFormatString->PushByte( binding.Generic.RoutineIndex );
  147. pProcFormatString->PushFormatChar( FC_PAD );
  148. }
  149. void
  150. CG_CONTEXT_HANDLE::GetNdrHandleInfo( CCB * pCCB, NDR64_BINDINGS *pBinding )
  151. {
  152. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  153. unsigned char uFlags;
  154. MIDL_ASSERT( pCCB->GetCGNodeContext()->IsProc() );
  155. uFlags = MakeExplicitHandleFlag( pBindParam );
  156. if ( fStrictContext )
  157. {
  158. uFlags |= NDR_STRICT_CONTEXT_HANDLE;
  159. }
  160. if ( fNoSerialize )
  161. {
  162. uFlags |= NDR_CONTEXT_HANDLE_NOSERIALIZE;
  163. }
  164. else if ( fSerialize )
  165. {
  166. uFlags |= NDR_CONTEXT_HANDLE_SERIALIZE;
  167. }
  168. NDR64_UINT8 RoutineIndex = (NDR64_UINT8)
  169. ( pCCB->LookupRundownRoutine(
  170. GetRundownRtnName() ) - 1 );
  171. pBinding->Context.HandleType = (NDR64_FORMAT_CHAR)(pCommand->IsNDR64Run() ? FC64_BIND_CONTEXT :
  172. FC_BIND_CONTEXT);
  173. pBinding->Context.Flags = uFlags;
  174. pBinding->Context.RoutineIndex = RoutineIndex;
  175. pBinding->Context.Ordinal = 0; // BUGBUG
  176. pBinding->Context.StackOffset = 0xBAAD;
  177. // StackOffset should be reset by the callee
  178. if ( GetHandleType()->NodeKind() == NODE_DEF )
  179. {
  180. pCCB->RegisterContextHandleType( GetHandleType() );
  181. }
  182. }
  183. void
  184. CG_CONTEXT_HANDLE::GenNdrHandleFormat( CCB * pCCB )
  185. /*++
  186. The layout is:
  187. FC_BIND_CONTEXT
  188. handle flag <1> upper nibble ptr,in,out,ret, lower: strict,no,ser
  189. stack offset <2>
  190. routine index<1>
  191. FC_PAD
  192. --*/
  193. {
  194. FORMAT_STRING * pProcFormatString = pCCB->GetProcFormatString();
  195. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  196. NDR64_BINDINGS binding;
  197. SetNdrBindDescriptionOffset( pProcFormatString->GetCurrentOffset() );
  198. GetNdrHandleInfo( pCCB, &binding );
  199. MIDL_ASSERT( FC_BIND_CONTEXT == binding.Context.HandleType );
  200. pProcFormatString->PushFormatChar(
  201. (FORMAT_CHARACTER) binding.Context.HandleType );
  202. pProcFormatString->PushContextHandleFlagsByte( binding.Context.Flags );
  203. pProcFormatString->PushUShortStackOffsetOrSize(
  204. pBindParam->GetStackOffset( pCCB, I386_STACK_SIZING ) );
  205. pProcFormatString->PushByte( binding.Context.RoutineIndex );
  206. pProcFormatString->PushByte( binding.Context.Ordinal );
  207. }
  208. void
  209. CG_PRIMITIVE_HANDLE::GenNdrFormat( CCB * )
  210. /*++
  211. Routine Description :
  212. --*/
  213. {
  214. // Do nothing.
  215. }
  216. void
  217. CG_GENERIC_HANDLE::GenNdrFormat( CCB * pCCB )
  218. /*++
  219. Routine Description :
  220. This routine is only called in the case of a pointer to a generic handle
  221. in which case the context handle just acts as an intermediary between the
  222. pointer and underlying user type.
  223. --*/
  224. {
  225. CG_NDR * pChild;
  226. pChild = (CG_NDR *)GetChild();
  227. if ( GetFormatStringOffset() != -1 )
  228. return;
  229. pChild->GenNdrFormat( pCCB );
  230. SetFormatStringOffset( pChild->GetFormatStringOffset() );
  231. MIDL_ASSERT( pCCB->GetCGNodeContext()->IsProc() );
  232. //
  233. // Register the generic handle.
  234. //
  235. if ( ((CG_PROC *)pCCB->GetCGNodeContext())->GetHandleClassPtr() == this )
  236. pCCB->RegisterGenericHandleType( GetHandleType() );
  237. }
  238. void
  239. CG_CONTEXT_HANDLE::GenNdrFormat( CCB * pCCB )
  240. /*++
  241. Routine Description :
  242. --*/
  243. {
  244. FORMAT_STRING * pFormatString;
  245. CG_PARAM * pBindParam = (CG_PARAM *) pCCB->GetLastPlaceholderClass();
  246. CG_PROC * pProc;
  247. pProc = (CG_PROC *) pCCB->GetCGNodeContext();
  248. MIDL_ASSERT( pProc->IsProc() );
  249. if ( GetFormatStringOffset() != -1 )
  250. return;
  251. pFormatString = pCCB->GetFormatString();
  252. SetFormatStringOffset( pFormatString->GetCurrentOffset() );
  253. //
  254. // Output an abbreviated description in the type format string.
  255. //
  256. pFormatString->PushFormatChar( FC_BIND_CONTEXT );
  257. //
  258. // Register the rundown routine always, even if the context handle is
  259. // not used as the binding paramter.
  260. //
  261. if ( GetHandleType()->NodeKind() == NODE_DEF )
  262. {
  263. pCCB->RegisterContextHandleType( GetHandleType() );
  264. }
  265. // Flags.
  266. unsigned char uFlags = MakeExplicitHandleFlag( pBindParam );
  267. if ( fStrictContext )
  268. {
  269. uFlags |= NDR_STRICT_CONTEXT_HANDLE;
  270. }
  271. if ( fNoSerialize )
  272. {
  273. uFlags |= NDR_CONTEXT_HANDLE_NOSERIALIZE;
  274. }
  275. else if ( fSerialize )
  276. {
  277. uFlags |= NDR_CONTEXT_HANDLE_SERIALIZE;
  278. }
  279. if ( GetCannotBeNull() ||
  280. pBindParam->IsParamIn() && !pBindParam->IsParamOut() )
  281. {
  282. uFlags |= NDR_CONTEXT_HANDLE_CANNOT_BE_NULL;
  283. }
  284. pFormatString->PushContextHandleFlagsByte( uFlags );
  285. // Routine index.
  286. // IndexMgr keeps indexes 1..n, we use indexes 0..n-1
  287. pFormatString->PushByte(
  288. (char) (pCCB->LookupRundownRoutine(GetRundownRtnName()) - 1) );
  289. if ( pCCB->GetOptimOption() & OPTIMIZE_NON_NT351 )
  290. {
  291. // Context handle's parameter number.
  292. pFormatString->PushByte( pProc->GetContextHandleCount() );
  293. pProc->SetContextHandleCount( short(pProc->GetContextHandleCount() + 1) );
  294. }
  295. else
  296. {
  297. // Context handle's parameter number. MIDL 2.00.102 and older stubs.
  298. pFormatString->PushByte( pBindParam->GetParamNumber() );
  299. }
  300. SetFormatStringEndOffset( pFormatString->GetCurrentOffset() );
  301. pFormatString->OptimizeFragment( this );
  302. }
  303. void
  304. CG_PRIMITIVE_HANDLE::GenNdrParamOffline( CCB * )
  305. {
  306. // Do nothing.
  307. }
  308. void
  309. CG_GENERIC_HANDLE::GenNdrParamOffline( CCB * pCCB )
  310. {
  311. ((CG_NDR *)GetChild())->GenNdrParamOffline( pCCB );
  312. MIDL_ASSERT( pCCB->GetCGNodeContext()->IsProc() );
  313. //
  314. // Register the generic handle.
  315. //
  316. if ( ((CG_PROC *)pCCB->GetCGNodeContext())->GetHandleClassPtr() == this )
  317. pCCB->RegisterGenericHandleType( GetHandleType() );
  318. }
  319. void
  320. CG_CONTEXT_HANDLE::GenNdrParamOffline( CCB * pCCB )
  321. {
  322. GenNdrFormat( pCCB );
  323. }
  324. void
  325. CG_PRIMITIVE_HANDLE::GenNdrParamDescription( CCB * )
  326. {
  327. // No description is emitted, handle_t is not marshalled.
  328. }
  329. void
  330. CG_GENERIC_HANDLE::GetNdrParamAttributes(
  331. CCB * pCCB,
  332. PARAM_ATTRIBUTES *attributes )
  333. {
  334. ((CG_NDR *)GetChild())->GetNdrParamAttributes( pCCB, attributes );
  335. }
  336. void
  337. CG_GENERIC_HANDLE::GenNdrParamDescription( CCB * pCCB )
  338. {
  339. ((CG_NDR *)GetChild())->GenNdrParamDescription( pCCB );
  340. }
  341. void
  342. CG_CONTEXT_HANDLE::GetNdrParamAttributes(
  343. CCB * pCCB,
  344. PARAM_ATTRIBUTES *attributes )
  345. {
  346. CG_NDR::GetNdrParamAttributes( pCCB, attributes );
  347. }
  348. void
  349. CG_CONTEXT_HANDLE::GenNdrParamDescription( CCB * pCCB )
  350. {
  351. CG_NDR::GenNdrParamDescription( pCCB );
  352. }
  353. //
  354. // +++++++++++++++++++
  355. // Old style parameter description routines.
  356. // +++++++++++++++++++
  357. //
  358. void
  359. CG_PRIMITIVE_HANDLE::GenNdrParamDescriptionOld( CCB * pCCB )
  360. {
  361. FORMAT_STRING * pProcFormatString;
  362. pProcFormatString = pCCB->GetProcFormatString();
  363. pProcFormatString->PushFormatChar( FC_IGNORE );
  364. }
  365. void
  366. CG_GENERIC_HANDLE::GenNdrParamDescriptionOld( CCB * pCCB )
  367. {
  368. ((CG_NDR *)GetChild())->GenNdrParamDescriptionOld( pCCB );
  369. }
  370. void
  371. CG_CONTEXT_HANDLE::GenNdrParamDescriptionOld( CCB * pCCB )
  372. {
  373. CG_NDR::GenNdrParamDescriptionOld( pCCB );
  374. }