import assert from 'node:assert/strict'; // Applied only to an isolated host fixture or candidate source tree. The // original CPU0 constructor and the accepted source files remain unchanged. export function k2100ProcessGateSource(original) { const start=original.indexOf('pub struct Gate<'),end=original.indexOf('pub struct AuthorityCell<'); assert.ok(start>=0&&end>start); let gate=original.slice(start,end); const signature="pub unsafe fn new(hardware: &'a H, primary: StackBinding) -> Result {"; assert.equal(gate.split(signature).length,2); gate=gate.replace(signature,signature+` unsafe { Self::new_on_cpu(hardware, primary, 0) } } /// # Safety /// The caller retains the exact online CPU owner for expected_cpu and the /// exclusive primary stack throughout this gate's lifetime. The supplied /// hardware observes real registers. This grants no CPU migration right. pub unsafe fn new_on_cpu(hardware: &'a H, primary: StackBinding, expected_cpu: u64) -> Result {`); assert.equal(gate.split('r.cpu != 0').length,4); gate=gate.replace('r.cpu != 0','expected_cpu > 3 || r.cpu != expected_cpu'); gate=gate.replaceAll('r.cpu != 0','r.cpu != self.original.cpu'); assert.equal(gate.split('cpu: 0,').length,3); gate=gate.replaceAll('cpu: 0,','cpu: self.original.cpu as u16,'); let result=original.slice(0,start)+gate+original.slice(end); const threadCpu='cpu: if self.gate.main().is_ok() {\n 0'; assert.equal(result.split(threadCpu).length,2); result=result.replace(threadCpu,'cpu: if self.gate.main().is_ok() {\n self.gate.original.cpu as u32'); return result; }