Security.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. void
  7. Security::EncodeLargeConstants()
  8. {
  9. #pragma prefast(suppress:6236 6285, "logical-or of constants is by design")
  10. if (PHASE_OFF(Js::EncodeConstantsPhase, this->func) || CONFIG_ISENABLED(Js::DebugFlag) || !MD_ENCODE_LG_CONSTS)
  11. {
  12. return;
  13. }
  14. uint prevInstrConstSize = 0;
  15. FOREACH_INSTR_IN_FUNC_EDITING(instr, instrNext, this->func)
  16. {
  17. if (!instr->IsRealInstr())
  18. {
  19. if (instr->IsLabelInstr())
  20. {
  21. IR::LabelInstr * label = instr->AsLabelInstr();
  22. if (label->labelRefs.Count() > 1 || (label->labelRefs.Count() == 1 && label->labelRefs.Head() != label->m_prev))
  23. {
  24. if (this->cookieOpnd != nullptr)
  25. {
  26. this->cookieOpnd->Free(this->func);
  27. }
  28. this->baseOpnd = nullptr;
  29. this->cookieOpnd = nullptr;
  30. this->basePlusCookieOpnd = nullptr;
  31. }
  32. }
  33. continue;
  34. }
  35. IR::Opnd *src1 = instr->GetSrc1();
  36. IR::Opnd *src2 = instr->GetSrc2();
  37. IR::Opnd *dst = instr->GetDst();
  38. if (dst && this->baseOpnd && dst->IsEqual(this->baseOpnd))
  39. {
  40. if (this->cookieOpnd != nullptr)
  41. {
  42. this->cookieOpnd->Free(this->func);
  43. }
  44. this->baseOpnd = nullptr;
  45. this->cookieOpnd = nullptr;
  46. this->basePlusCookieOpnd = nullptr;
  47. }
  48. uint currInstrConstSize = 0;
  49. uint dstSize = dst ? CalculateConstSize(dst) : 0;
  50. uint src1Size = 0;
  51. uint src2Size = 0;
  52. if (src1)
  53. {
  54. src1Size = CalculateConstSize(src1);
  55. if (src2)
  56. {
  57. src2Size = CalculateConstSize(src2);
  58. }
  59. }
  60. prevInstrConstSize = currInstrConstSize;
  61. currInstrConstSize = dstSize + src1Size + src2Size;
  62. // we don't need to blind constants if user controlled byte size < 3
  63. if (currInstrConstSize + prevInstrConstSize <= 2 && !PHASE_FORCE1(Js::EncodeConstantsPhase))
  64. {
  65. continue;
  66. }
  67. bool isSrc1EqualDst = false;
  68. if (dstSize >= 2)
  69. {
  70. // don't count instrs where dst == src1 against size
  71. if (src1 && dstSize == src1Size && src1->IsEqual(dst))
  72. {
  73. currInstrConstSize -= dstSize;
  74. isSrc1EqualDst = true;
  75. if (currInstrConstSize + prevInstrConstSize <= 2 && !PHASE_FORCE1(Js::EncodeConstantsPhase))
  76. {
  77. continue;
  78. }
  79. }
  80. this->EncodeOpnd(instr, dst);
  81. if (isSrc1EqualDst)
  82. {
  83. instr->ReplaceSrc1(dst);
  84. }
  85. currInstrConstSize -= dstSize;
  86. if (currInstrConstSize + prevInstrConstSize <= 2 && !PHASE_FORCE1(Js::EncodeConstantsPhase))
  87. {
  88. continue;
  89. }
  90. }
  91. if (src1Size >= 2 && !isSrc1EqualDst)
  92. {
  93. this->EncodeOpnd(instr, src1);
  94. currInstrConstSize -= src1Size;
  95. if (currInstrConstSize + prevInstrConstSize <= 2 && !PHASE_FORCE1(Js::EncodeConstantsPhase))
  96. {
  97. continue;
  98. }
  99. }
  100. if (src2Size >= 2)
  101. {
  102. this->EncodeOpnd(instr, src2);
  103. currInstrConstSize -= src2Size;
  104. }
  105. } NEXT_INSTR_IN_FUNC_EDITING;
  106. }
  107. int
  108. Security::GetNextNOPInsertPoint()
  109. {
  110. uint frequency = (1 << CONFIG_FLAG(NopFrequency)) - 1;
  111. return (Math::Rand() & frequency) + 1;
  112. }
  113. void
  114. Security::InsertRandomFunctionPad(IR::Instr * instrBeforeInstr)
  115. {
  116. if (PHASE_OFF(Js::InsertNOPsPhase, instrBeforeInstr->m_func->GetTopFunc())
  117. || CONFIG_ISENABLED(Js::DebugFlag) || CONFIG_ISENABLED(Js::BenchmarkFlag))
  118. {
  119. return;
  120. }
  121. DWORD randomPad = Math::Rand() & ((0 - INSTR_ALIGNMENT) & 0xF);
  122. #ifndef _M_ARM
  123. if (randomPad == 1)
  124. {
  125. InsertSmallNOP(instrBeforeInstr, 1);
  126. return;
  127. }
  128. if (randomPad & 1)
  129. {
  130. InsertSmallNOP(instrBeforeInstr, 3);
  131. randomPad -= 3;
  132. }
  133. #endif
  134. Assert((randomPad & 1) == 0);
  135. while (randomPad >= 4)
  136. {
  137. InsertSmallNOP(instrBeforeInstr, 4);
  138. randomPad -= 4;
  139. }
  140. Assert(randomPad == 2 || randomPad == 0);
  141. if (randomPad == 2)
  142. {
  143. InsertSmallNOP(instrBeforeInstr, 2);
  144. }
  145. }
  146. void
  147. Security::InsertNOPs()
  148. {
  149. if (PHASE_OFF(Js::InsertNOPsPhase, this->func) || CONFIG_ISENABLED(Js::DebugFlag) || CONFIG_ISENABLED(Js::BenchmarkFlag))
  150. {
  151. return;
  152. }
  153. int count = 0;
  154. IR::Instr *instr = this->func->m_headInstr;
  155. while (true)
  156. {
  157. count = this->GetNextNOPInsertPoint();
  158. while (instr && count--)
  159. {
  160. instr = instr->GetNextRealInstr();
  161. }
  162. if (instr == nullptr)
  163. {
  164. break;
  165. }
  166. this->InsertNOPBefore(instr);
  167. };
  168. }
  169. void
  170. Security::InsertNOPBefore(IR::Instr *instr)
  171. {
  172. InsertSmallNOP(instr, (Math::Rand() & 0x3) + 1);
  173. }
  174. void
  175. Security::InsertSmallNOP(IR::Instr * instr, DWORD nopSize)
  176. {
  177. #if defined(_M_IX86) || defined(_M_X64)
  178. #ifdef _M_IX86
  179. if (AutoSystemInfo::Data.SSE2Available())
  180. { // on x86 system that has SSE2, encode fast NOPs as x64 does
  181. #endif
  182. Assert(nopSize >= 1 || nopSize <= 4);
  183. IR::Instr *nop = IR::Instr::New(Js::OpCode::NOP, instr->m_func);
  184. // Let the encoder know what the size of the NOP needs to be.
  185. if (nopSize > 1)
  186. {
  187. // 2, 3 or 4 byte NOP.
  188. IR::IntConstOpnd *nopSizeOpnd = IR::IntConstOpnd::New(nopSize, TyInt8, instr->m_func);
  189. nop->SetSrc1(nopSizeOpnd);
  190. }
  191. instr->InsertBefore(nop);
  192. #ifdef _M_IX86
  193. }
  194. else
  195. {
  196. IR::Instr *nopInstr = nullptr;
  197. IR::RegOpnd *regOpnd;
  198. IR::IndirOpnd *indirOpnd;
  199. switch (nopSize)
  200. {
  201. case 1:
  202. // nop
  203. nopInstr = IR::Instr::New(Js::OpCode::NOP, instr->m_func);
  204. break;
  205. case 2:
  206. // mov edi, edi ; 2 bytes
  207. regOpnd = IR::RegOpnd::New(nullptr, RegEDI, TyInt32, instr->m_func);
  208. nopInstr = IR::Instr::New(Js::OpCode::MOV, regOpnd, regOpnd, instr->m_func);
  209. break;
  210. case 3:
  211. // lea ecx, [ecx+00] ; 3 bytes
  212. regOpnd = IR::RegOpnd::New(nullptr, RegECX, TyInt32, instr->m_func);
  213. indirOpnd = IR::IndirOpnd::New(regOpnd, (int32)0, TyInt32, instr->m_func);
  214. nopInstr = IR::Instr::New(Js::OpCode::LEA, regOpnd, indirOpnd, instr->m_func);
  215. break;
  216. case 4:
  217. // lea esp, [esp+00] ; 4 bytes
  218. regOpnd = IR::RegOpnd::New(nullptr, RegESP, TyInt32, instr->m_func);
  219. indirOpnd = IR::IndirOpnd::New(regOpnd, (int32)0, TyInt32, instr->m_func);
  220. nopInstr = IR::Instr::New(Js::OpCode::LEA, regOpnd, indirOpnd, instr->m_func);
  221. break;
  222. default:
  223. Assert(false);
  224. break;
  225. }
  226. instr->InsertBefore(nopInstr);
  227. }
  228. #endif
  229. #elif defined(_M_ARM)
  230. // Can't insert 3 bytes, must choose between 2 and 4.
  231. IR::Instr *nopInstr = nullptr;
  232. switch (nopSize)
  233. {
  234. case 1:
  235. case 2:
  236. nopInstr = IR::Instr::New(Js::OpCode::NOP, instr->m_func);
  237. break;
  238. case 3:
  239. case 4:
  240. nopInstr = IR::Instr::New(Js::OpCode::NOP_W, instr->m_func);
  241. break;
  242. default:
  243. Assert(false);
  244. break;
  245. }
  246. instr->InsertBefore(nopInstr);
  247. #elif defined(_M_ARM64)
  248. // All ARM64 instructions are 4 bytes.
  249. IR::Instr *nopInstr = IR::Instr::New(Js::OpCode::NOP, instr->m_func);
  250. instr->InsertBefore(nopInstr);
  251. #endif
  252. }
  253. bool
  254. Security::DontEncode(IR::Opnd *opnd)
  255. {
  256. switch (opnd->GetKind())
  257. {
  258. case IR::OpndKindIntConst:
  259. {
  260. IR::IntConstOpnd *intConstOpnd = opnd->AsIntConstOpnd();
  261. return intConstOpnd->m_dontEncode;
  262. }
  263. case IR::OpndKindAddr:
  264. {
  265. IR::AddrOpnd *addrOpnd = opnd->AsAddrOpnd();
  266. return (addrOpnd->m_dontEncode ||
  267. !addrOpnd->IsVar() ||
  268. addrOpnd->m_address == nullptr ||
  269. !Js::TaggedNumber::Is(addrOpnd->m_address));
  270. }
  271. case IR::OpndKindIndir:
  272. {
  273. IR::IndirOpnd *indirOpnd = opnd->AsIndirOpnd();
  274. return indirOpnd->m_dontEncode || indirOpnd->GetOffset() == 0;
  275. }
  276. case IR::OpndKindInt64Const:
  277. return false;
  278. case IR::OpndKindList:
  279. {
  280. // We should only have RegOpnd in the ListOpnd therefore, we don't need to encode anything
  281. Assert(opnd->AsListOpnd()->All([](IR::ListOpndType* opnd) { return DontEncode(opnd); }));
  282. return true;
  283. }
  284. default:
  285. return true;
  286. }
  287. }
  288. uint
  289. Security::CalculateConstSize(IR::Opnd *opnd)
  290. {
  291. if (DontEncode(opnd))
  292. {
  293. return 0;
  294. }
  295. switch (opnd->GetKind())
  296. {
  297. #if TARGET_64
  298. case IR::OpndKindInt64Const:
  299. {
  300. IR::Int64ConstOpnd *intConstOpnd = opnd->AsInt64ConstOpnd();
  301. return GetByteCount(intConstOpnd->GetValue());
  302. }
  303. #endif
  304. case IR::OpndKindIntConst:
  305. {
  306. IR::IntConstOpnd *intConstOpnd = opnd->AsIntConstOpnd();
  307. return GetByteCount(intConstOpnd->GetValue());
  308. }
  309. case IR::OpndKindAddr:
  310. {
  311. IR::AddrOpnd *addrOpnd = opnd->AsAddrOpnd();
  312. return Js::TaggedInt::Is(addrOpnd->m_address) ? GetByteCount(Js::TaggedInt::ToInt32(addrOpnd->m_address)) : GetByteCount((intptr_t)addrOpnd->m_address);
  313. }
  314. case IR::OpndKindIndir:
  315. {
  316. IR::IndirOpnd * indirOpnd = opnd->AsIndirOpnd();
  317. return GetByteCount(indirOpnd->GetOffset());
  318. }
  319. default:
  320. Assume(UNREACHED);
  321. }
  322. return 0;
  323. }
  324. bool
  325. Security::EncodeOpnd(IR::Instr * instr, IR::Opnd *opnd)
  326. {
  327. IR::RegOpnd *newOpnd;
  328. bool isSrc2 = false;
  329. const auto unlinkSrc = [&]() {
  330. if (opnd != instr->GetSrc1())
  331. {
  332. Assert(opnd == instr->GetSrc2());
  333. isSrc2 = true;
  334. instr->UnlinkSrc2();
  335. }
  336. else
  337. {
  338. instr->UnlinkSrc1();
  339. }
  340. };
  341. switch (opnd->GetKind())
  342. {
  343. case IR::OpndKindIntConst:
  344. {
  345. IR::IntConstOpnd *intConstOpnd = opnd->AsIntConstOpnd();
  346. unlinkSrc();
  347. intConstOpnd->SetEncodedValue(EncodeValue(instr, intConstOpnd, intConstOpnd->GetValue(), &newOpnd));
  348. }
  349. break;
  350. case IR::OpndKindAddr:
  351. {
  352. IR::AddrOpnd *addrOpnd = opnd->AsAddrOpnd();
  353. unlinkSrc();
  354. addrOpnd->SetEncodedValue((Js::Var)this->EncodeValue(instr, addrOpnd, (IntConstType)addrOpnd->m_address, &newOpnd), addrOpnd->GetAddrOpndKind());
  355. }
  356. break;
  357. case IR::OpndKindIndir:
  358. {
  359. IR::IndirOpnd *indirOpnd = opnd->AsIndirOpnd();
  360. // Using 32 bit cookie causes major perf loss on the subsequent indirs, so only support this path for 16 bit offset
  361. // It's relatively rare for base to be null or to have index + offset, so fall back to the more generic xor method for these
  362. if (indirOpnd->GetBaseOpnd() && indirOpnd->GetIndexOpnd() == nullptr && Math::FitsInWord(indirOpnd->GetOffset()))
  363. {
  364. if (!this->baseOpnd || !this->baseOpnd->IsEqual(indirOpnd->GetBaseOpnd()))
  365. {
  366. if (this->cookieOpnd != nullptr)
  367. {
  368. this->cookieOpnd->Free(this->func);
  369. }
  370. this->cookieOpnd = BuildCookieOpnd(TyInt16, instr->m_func);
  371. this->basePlusCookieOpnd = IR::RegOpnd::New(TyMachReg, instr->m_func);
  372. this->baseOpnd = indirOpnd->GetBaseOpnd();
  373. IR::IndirOpnd * indir = IR::IndirOpnd::New(this->baseOpnd, this->cookieOpnd->AsInt32(), TyMachReg, instr->m_func);
  374. Lowerer::InsertLea(this->basePlusCookieOpnd, indir, instr);
  375. }
  376. int32 diff = indirOpnd->GetOffset() - this->cookieOpnd->AsInt32();
  377. indirOpnd->SetOffset((int32)diff);
  378. indirOpnd->SetBaseOpnd(this->basePlusCookieOpnd);
  379. return true;
  380. }
  381. IR::IntConstOpnd *indexOpnd = IR::IntConstOpnd::New(indirOpnd->GetOffset(), TyMachReg, instr->m_func);
  382. indexOpnd->SetValue(EncodeValue(instr, indexOpnd, indexOpnd->GetValue(), &newOpnd));
  383. indirOpnd->SetOffset(0);
  384. if (indirOpnd->GetIndexOpnd() != nullptr)
  385. {
  386. // update the base rather than the index, because index might have scale
  387. if (indirOpnd->GetBaseOpnd() != nullptr)
  388. {
  389. IR::RegOpnd * newBaseOpnd = IR::RegOpnd::New(TyMachReg, instr->m_func);
  390. Lowerer::InsertAdd(false, newBaseOpnd, newOpnd, indirOpnd->GetBaseOpnd(), instr);
  391. indirOpnd->ReplaceBaseOpnd(newBaseOpnd);
  392. }
  393. else
  394. {
  395. indirOpnd->SetBaseOpnd(newOpnd);
  396. }
  397. }
  398. else
  399. {
  400. indirOpnd->SetIndexOpnd(newOpnd);
  401. }
  402. }
  403. return true;
  404. default:
  405. return false;
  406. }
  407. IR::Opnd *dst = instr->GetDst();
  408. if (dst)
  409. {
  410. #if TARGET_64
  411. // Ensure the left and right operand has the same type (that might not be true for constants on x64)
  412. newOpnd = (IR::RegOpnd *)newOpnd->UseWithNewType(dst->GetType(), instr->m_func);
  413. #endif
  414. if (dst->IsRegOpnd())
  415. {
  416. IR::RegOpnd *dstRegOpnd = dst->AsRegOpnd();
  417. StackSym *dstSym = dstRegOpnd->m_sym;
  418. if (dstSym)
  419. {
  420. dstSym->m_isConst = false;
  421. dstSym->m_isIntConst = false;
  422. dstSym->m_isInt64Const = false;
  423. dstSym->m_isTaggableIntConst = false;
  424. dstSym->m_isFltConst = false;
  425. }
  426. }
  427. }
  428. LowererMD::ImmedSrcToReg(instr, newOpnd, isSrc2 ? 2 : 1);
  429. return true;
  430. }
  431. IR::IntConstOpnd *
  432. Security::BuildCookieOpnd(IRType type, Func * func)
  433. {
  434. IntConstType cookie = 0;
  435. switch (type)
  436. {
  437. case TyInt8:
  438. cookie = (int8)Math::Rand();
  439. break;
  440. case TyUint8:
  441. cookie = (uint8)Math::Rand();
  442. break;
  443. case TyInt16:
  444. cookie = (int16)Math::Rand();
  445. break;
  446. case TyUint16:
  447. cookie = (uint16)Math::Rand();
  448. break;
  449. #if TARGET_32
  450. case TyVar:
  451. #endif
  452. case TyInt32:
  453. cookie = (int32)Math::Rand();
  454. break;
  455. case TyUint32:
  456. cookie = (uint32)Math::Rand();
  457. break;
  458. #if TARGET_64
  459. case TyVar:
  460. case TyInt64:
  461. case TyUint64:
  462. cookie = Math::Rand();
  463. break;
  464. #endif
  465. default:
  466. Assume(UNREACHED);
  467. }
  468. IR::IntConstOpnd * cookieOpnd = IR::IntConstOpnd::New(cookie, type, func);
  469. #if DBG_DUMP
  470. cookieOpnd->SetName(_u("cookie"));
  471. #endif
  472. return cookieOpnd;
  473. }
  474. IntConstType
  475. Security::EncodeValue(IR::Instr * instr, IR::Opnd *opnd, IntConstType constValue, _Out_ IR::RegOpnd **pNewOpnd)
  476. {
  477. if (opnd->GetType() == TyInt32 || opnd->GetType() == TyInt16 || opnd->GetType() == TyInt8
  478. #if TARGET_32
  479. || opnd->GetType() == TyVar
  480. #endif
  481. )
  482. {
  483. IR::RegOpnd *regOpnd = IR::RegOpnd::New(StackSym::New(opnd->GetType(), instr->m_func), opnd->GetType(), instr->m_func);
  484. IR::Instr * instrNew = Lowerer::InsertMove(regOpnd, opnd, instr);
  485. IR::IntConstOpnd * cookieOpnd = BuildCookieOpnd(opnd->GetType(), instr->m_func);
  486. instrNew = IR::Instr::New(LowererMD::MDXorOpcode, regOpnd, regOpnd, cookieOpnd, instr->m_func);
  487. instr->InsertBefore(instrNew);
  488. LowererMD::Legalize(instrNew);
  489. StackSym * stackSym = regOpnd->m_sym;
  490. Assert(!stackSym->m_isSingleDef);
  491. Assert(stackSym->m_instrDef == nullptr);
  492. stackSym->m_isEncodedConstant = true;
  493. stackSym->constantValue = (int32)constValue;
  494. *pNewOpnd = regOpnd;
  495. int32 value = (int32)constValue;
  496. value = value ^ cookieOpnd->AsInt32();
  497. return value;
  498. }
  499. else if (opnd->GetType() == TyUint32 || opnd->GetType() == TyUint16 || opnd->GetType() == TyUint8)
  500. {
  501. IR::RegOpnd *regOpnd = IR::RegOpnd::New(StackSym::New(opnd->GetType(), instr->m_func), opnd->GetType(), instr->m_func);
  502. IR::Instr * instrNew = Lowerer::InsertMove(regOpnd, opnd, instr);
  503. IR::IntConstOpnd * cookieOpnd = BuildCookieOpnd(opnd->GetType(), instr->m_func);
  504. instrNew = IR::Instr::New(LowererMD::MDXorOpcode, regOpnd, regOpnd, cookieOpnd, instr->m_func);
  505. instr->InsertBefore(instrNew);
  506. LowererMD::Legalize(instrNew);
  507. StackSym * stackSym = regOpnd->m_sym;
  508. Assert(!stackSym->m_isSingleDef);
  509. Assert(stackSym->m_instrDef == nullptr);
  510. stackSym->m_isEncodedConstant = true;
  511. stackSym->constantValue = (uint32)constValue;
  512. *pNewOpnd = regOpnd;
  513. uint32 value = (uint32)constValue;
  514. value = value ^ cookieOpnd->AsUint32();
  515. return (IntConstType)value;
  516. }
  517. else
  518. {
  519. #if TARGET_64
  520. return this->EncodeAddress(instr, opnd, constValue, pNewOpnd);
  521. #else
  522. Assert(false);
  523. // (Prefast warning on failure to assign *pNewOpnd.)
  524. *pNewOpnd = nullptr;
  525. return 0;
  526. #endif
  527. }
  528. }
  529. #if TARGET_64
  530. size_t
  531. Security::EncodeAddress(IR::Instr * instr, IR::Opnd *opnd, size_t value, _Out_ IR::RegOpnd **pNewOpnd)
  532. {
  533. IR::Instr *instrNew = nullptr;
  534. IR::RegOpnd *regOpnd = IR::RegOpnd::New(TyMachReg, instr->m_func);
  535. instrNew = Lowerer::InsertMove(regOpnd, opnd, instr);
  536. IR::IntConstOpnd *cookieOpnd = BuildCookieOpnd(TyMachReg, instr->m_func);
  537. instrNew = IR::Instr::New(LowererMD::MDXorOpcode, regOpnd, regOpnd, cookieOpnd, instr->m_func);
  538. instr->InsertBefore(instrNew);
  539. LowererMD::Legalize(instrNew);
  540. StackSym * stackSym = regOpnd->m_sym;
  541. Assert(!stackSym->m_isSingleDef);
  542. Assert(stackSym->m_instrDef == nullptr);
  543. stackSym->m_isEncodedConstant = true;
  544. stackSym->constantValue = value;
  545. *pNewOpnd = regOpnd;
  546. return value ^ cookieOpnd->GetValue();
  547. }
  548. #endif