{"id":27147324,"url":"https://github.com/darkautism/wamr-rust-pthreadcall","last_synced_at":"2026-03-06T17:35:36.059Z","repository":{"id":286767243,"uuid":"962440631","full_name":"darkautism/wamr-rust-pthreadcall","owner":"darkautism","description":"Integrate WAMR into ESP32, without dealing with underlying pthread issues.","archived":false,"fork":false,"pushed_at":"2025-05-15T09:13:20.000Z","size":43,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-08T00:18:14.659Z","etag":null,"topics":["embedded-rust","embedded-systems","esp32","rust","wamr","wasm"],"latest_commit_sha":null,"homepage":"https://github.com/darkautism/wamr-rust-pthreadcall","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darkautism.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-08T06:55:48.000Z","updated_at":"2025-05-15T09:13:24.000Z","dependencies_parsed_at":"2025-04-11T03:49:29.893Z","dependency_job_id":"d6878ade-33ca-4c42-9370-813efef10395","html_url":"https://github.com/darkautism/wamr-rust-pthreadcall","commit_stats":null,"previous_names":["darkautism/wamr-rust-pthreadcall"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/darkautism/wamr-rust-pthreadcall","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkautism%2Fwamr-rust-pthreadcall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkautism%2Fwamr-rust-pthreadcall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkautism%2Fwamr-rust-pthreadcall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkautism%2Fwamr-rust-pthreadcall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darkautism","download_url":"https://codeload.github.com/darkautism/wamr-rust-pthreadcall/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darkautism%2Fwamr-rust-pthreadcall/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30188293,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T17:33:53.563Z","status":"ssl_error","status_checked_at":"2026-03-06T17:33:51.678Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["embedded-rust","embedded-systems","esp32","rust","wamr","wasm"],"created_at":"2025-04-08T11:25:47.907Z","updated_at":"2026-03-06T17:35:36.014Z","avatar_url":"https://github.com/darkautism.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wamr-rust-pthreadcall [![dependency status](https://deps.rs/repo/github/darkautism/wamr-rust-pthreadcall/status.svg)](https://deps.rs/repo/github/darkautism/wamr-rust-pthreadcall)\nThis project makes it easier to integrate WAMR into ESP32, allowing you to focus on application logic without dealing with underlying pthread issues.\n\n## Background and Problem\nWhen running WAMR on ESP32, you might encounter crashes, especially errors related to POSIX threads (pthread). Research indicates that this happens because WAMR expects to run within a pthread context. However, the main program (```app_main```) of ESP32 is actually a FreeRTOS task, not a pthread. As a result, WAMR's internal pthread functions (e.g., ```pthread_self```) fail because they cannot retrieve the current thread ID in a non-pthread context.\nAccording to the official documentation [POSIX Threads Support - ESP32](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/pthread.html):\n\n```\npthread_self()\n\n        An assert will fail if this function is called from a FreeRTOS task which is not a pthread.\n```\nThis explains why the original WAMR crashes.\n\n## How to Avoid the Issue\nThe ```wamr-rust-pthreadcall``` library provides the ```call_pthread``` function, which resolves this issue by executing WAMR functions within the correct pthread context. This prevents crashes and ensures WAMR runs stably on ESP32.\n\n## Usage\nUsing this library is straightforward. First, add the dependency in your ```Cargo.toml``` file:\n```toml\n\n[dependencies]\nwamr-rust-pthreadcall = { git=\"https://github.com/darkautism/wamr-rust-pthreadcall.git\" }\n```\n\nThen, in your Rust code, use ```call_pthread``` to replace the original ```call``` method. Here's an example:\n```rust\n\nuse wamr_rust_pthreadcall::PThreadExtension;\nuse wamr_rust_sdk::function::Function;\nuse wamr_rust_sdk::instance::Instance;\nuse wamr_rust_sdk::value::WasmValue;\n\nlet params: Vec\u003cWasmValue\u003e = vec![];\nlet result = function\n    .call_pthread(\u0026instance, \u0026params)\n    .expect(\"Failed to call WAMR function\");\nlog::info!(\"Program exited with code: {:?}\", result);\n```\n\nIf your need more object running into pthread, you can use another function:\n\n```rust\n    let a: Result\u003cVec\u003cWasmValue\u003e, RuntimeError\u003e =\n    wamr_rust_pthreadcall::call_pthread(4096, move || {\n        let runtime = match Runtime::builder()\n            .use_system_allocator()\n            .register_host_function(\n                \"vTaskDelay\",\n                esp_idf_svc::sys::vTaskDelay as *mut std::ffi::c_void,\n            )\n            .build()\n        {\n            Ok(runtime) =\u003e runtime,\n            Err(e) =\u003e {\n                log::error!(\"Failed to load WAMR runtime: {}\", e);\n                return Err(e);\n            }\n        };\n        let module = match Module::from_file(\u0026runtime, d.as_path()) {\n            Ok(module) =\u003e module,\n            Err(e) =\u003e {\n                log::error!(\"Failed to load WAMR module: {}\", e);\n                return Err(e);\n            }\n        };\n\n        let instance = match Instance::new(\u0026runtime, \u0026module, config::GAMEMEMORY) {\n            Ok(instance) =\u003e instance,\n            Err(e) =\u003e {\n                log::error!(\"Failed to create WAMR instance: {}\", e);\n                return Err(e);\n            }\n        };\n\n        let function = match Function::find_export_func(\u0026instance, config::ENTRYPOINT) {\n            Ok(function) =\u003e function,\n            Err(e) =\u003e {\n                log::error!(\"Failed to find WAMR function: {}\", e);\n                return Err(e);\n            }\n        };\n        let params: Vec\u003cWasmValue\u003e = vec![];\n        function.call(\u0026instance, \u0026params)\n    })\n    .expect(\"Pthread create failed\");\n```\n\nThis way, the library automatically handles the creation and management of pthreads, ensuring WebAssembly functions are executed in the correct context.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkautism%2Fwamr-rust-pthreadcall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkautism%2Fwamr-rust-pthreadcall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkautism%2Fwamr-rust-pthreadcall/lists"}