"""Inject corruption at every protected word into actual production checks.""" from pathlib import Path import tempfile,subprocess root=Path(__file__).resolve().parents[1] header='\n'.join(l for l in (root/'kernel/mbx_dma.h').read_text().splitlines() if not l.startswith('#include')) s=(root/'kernel/mbx_dma.c').read_text();s=s[s.index('/* Check every word,'):] prefix=r''' #include #include #include #include #include #include #include typedef uint32_t u32;typedef uint32_t __le32;typedef uint8_t u8;typedef uint64_t dma_addr_t; #define TABLE_BYTES 32768 #define PAGE_BYTES 4096 #define le32_to_cpu(x) (x) #define dma_rmb() ((void)0) ''' main=r''' int main(void){ struct mbx_dma_memory m={0};m.stage=MBX_DMA_QUIESCED; m.tables=malloc(TABLE_BYTES);m.guard=malloc(4096);m.target=malloc(4096);m.ta=malloc(36864); m.guard_dma=0x90000000;m.target_dma=0x90001000;m.parameters_dma=0x90002000;m.tiles_dma=0x90012000;m.ta_dma=0x90020000; memset(m.guard,0xa5,4096);memset(m.target,0x3c,4096);memset((u8 *)m.ta+32768,0x5a,4096); unsigned tests=0; for(unsigned pages=0;pages<=128;pages+=1){ m.frame_page_count=pages;for(unsigned i=0;i=16&&i<32?m.parameters_dma+4096*(i-16): i>=32&&i<36?m.tiles_dma+4096*(i-32):i>=256&&i<256+pages?m.frame_dma[i-256]: i>=128&&i<132?m.ta_dma+4096*(i-128):i==144?m.ta_dma+16384:i==146?m.ta_dma+20480: i==148?m.ta_dma+24576:i==152?m.ta_dma+28672:m.guard_dma; assert(!mbx_dma_verify_bounds(&m)); for(unsigned i=0;i<8192;++i){t[i]^=1;assert(mbx_dma_verify_bounds(&m)==-EOVERFLOW);t[i]^=1;++tests;} } void *buffers[]={m.guard,(u8 *)m.target+2048,(u8 *)m.ta+32768};unsigned words[]={1024,512,1024}; for(unsigned b=0;b<3;++b)for(unsigned i=0;i