#include "nt/providers.h" #include "desktop/foreign_surface.h" #include #include #include #include #include #include #include #include #include static void check(bool value,const char *message) { if (!value) throw std::runtime_error(message); } int main(int argc,char **argv) { uint64_t window=0; pid_t child=0; try { check(argc==3,"bootstrap and foreign-present fixture required"); std::ifstream file(argv[2],std::ios::binary | std::ios::ate); check(bool(file) && file.tellg()>0 && file.tellg()<1024*1024,"invalid foreign-present fixture"); std::vector bytes(size_t(file.tellg())); file.seekg(0); check(bool(file.read(reinterpret_cast(bytes.data()),std::streamsize(bytes.size()))),"short foreign-present fixture"); raven::ModuleSet modules; auto &entry=modules.add("foreign-present.exe",std::move(bytes)); window=raven::window_handle_base()+1; raven::publish_window(window,64,48); const auto target=modules.resolve({"foreign-present.exe","target_window",0,false,0})-entry.loaded.base(); std::memcpy(entry.loaded.data().data()+target,&window,sizeof window); const auto control=modules.resolve({"foreign-present.exe","control",0,false,0})-entry.loaded.base(); auto &command=*reinterpret_cast(entry.loaded.data().data()+control); child=::fork(); check(child>=0,"foreign-present fork failed"); if (!child) { try { const auto result=entry.image.is_64 ? raven::run_native_process(modules,entry,argv[1],std::chrono::seconds(8)) : raven::run_native_process_x86(modules,entry,argv[1],std::chrono::seconds(8)); std::cerr<<"Foreign presentation returned "<(command).store(frame+1,std::memory_order_release); } int status=0; while (::waitpid(child,&status,0)<0) check(errno==EINTR,"foreign-present wait failed"); child=0; check(WIFEXITED(status) && !WEXITSTATUS(status),"foreign Vulkan child failed"); raven::withdraw_window(window); std::cout<<"Real foreign Vulkan frame reached its owner\n"; } catch (const std::exception &error) { if (child>0) { ::kill(child,SIGKILL); while (::waitpid(child,nullptr,0)<0 && errno==EINTR) {} } if (window) raven::withdraw_window(window); std::cerr<