// SPDX-License-Identifier: MIT #include "bozo/native/compiled_libraries.h" #include #include using namespace bozo::native::irx; namespace { void check(bool ok){if(!ok)throw std::runtime_error("native library memset assertion failed");} void fill(Env &e){ const auto caller=e.cpu.gpr[31]; for(unsigned size:{0u,1u,3u,16u,255u})for(unsigned offset:{0u,1u,7u}){ for(unsigned i=0;i<264;++i)e.w8(0x7100+i,0x35); e.cpu.gpr[4]=0x7100+offset;e.cpu.gpr[5]=0x1234ab;e.cpu.gpr[6]=size;e.cpu.gpr[31]=0x7004; check(e.call(0x7380,0x7004) && e.cpu.gpr[2]==0x7100+offset); for(unsigned i=0;i<264;++i)check(e.r8(0x7100+i)==(i>=offset && i(0x400),{{0x7380,"sysclib",14}},{},false}); host.addImage({"bad-memset",0x1415,0x7400,0x7400,0,std::vector(0x400),{{0x7780,"sysclib",14}},{},false}); } } int main(){try{ bozo::libs::Libraries a,b;CompiledLibraries first(a,0x10000),second(b,0x10000);images(first);images(second); check(first.startImage("memset")==1 && second.startImage("memset")==1); bool rejected=false;try{first.startImage("bad-memset");}catch(const std::runtime_error &){rejected=true;}check(rejected); first.reset();check(first.startImage("memset")==1); std::puts("native library memset byte truncation/ranges/canaries/bounds/reset/isolation passed");return 0; }catch(const std::exception &e){std::fprintf(stderr,"%s\n",e.what());return 1;}}