{"id":15199465,"url":"https://github.com/sonodima/microseh","last_synced_at":"2026-03-14T22:06:33.433Z","repository":{"id":62108374,"uuid":"549490000","full_name":"sonodima/microseh","owner":"sonodima","description":"Structured Exception Handling (SEH) for Rust","archived":false,"fork":false,"pushed_at":"2024-02-22T09:41:04.000Z","size":74,"stargazers_count":20,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-02-23T09:48:04.843Z","etag":null,"topics":["exceptions","rust","seh","structured","windows"],"latest_commit_sha":null,"homepage":"https://docs.rs/microseh","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonodima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2022-10-11T09:05:24.000Z","updated_at":"2024-06-12T16:21:56.820Z","dependencies_parsed_at":"2024-06-12T16:21:52.415Z","dependency_job_id":null,"html_url":"https://github.com/sonodima/microseh","commit_stats":{"total_commits":33,"total_committers":4,"mean_commits":8.25,"dds":0.5151515151515151,"last_synced_commit":"00e0b1157fe435642490287ca13f280b2b84477f"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonodima%2Fmicroseh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonodima%2Fmicroseh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonodima%2Fmicroseh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonodima%2Fmicroseh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonodima","download_url":"https://codeload.github.com/sonodima/microseh/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249156107,"owners_count":21221712,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["exceptions","rust","seh","structured","windows"],"created_at":"2024-09-28T02:01:11.437Z","updated_at":"2026-03-14T22:06:28.376Z","avatar_url":"https://github.com/sonodima.png","language":"Rust","readme":"\u003ch1 align=\"center\"\u003eMicroSEH 🔴\u003c/h1\u003e\r\n\r\n\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://crates.io/crates/microseh\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/microseh.svg?color=edae00\u0026style=for-the-badge\"/\u003e\u003c/a\u003e\r\n  \u003ca href=\"https://github.com/sonodima/microseh/actions/workflows/ci.yml\"\u003e \r\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/sonodima/microseh/ci.yml?style=for-the-badge\u0026label=CI%20Status\"/\u003e\r\n  \u003c/a\u003e\r\n  \u003ca href=\"https://crates.io/crates/microseh\"\u003e\u003cimg src=\"https://img.shields.io/crates/d/microseh?color=pink\u0026style=for-the-badge\"/\u003e\u003c/a\u003e\r\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg?style=for-the-badge\"/\u003e\r\n\u003c/div\u003e\r\n\r\n\u003cbr\u003e\r\n\r\n\u003e MicroSEH is a tiny library that implements Structured Exception Handling (SEH) in Rust and can catch\r\n\u003e and handle hardware exceptions.\r\n\r\n## Why?\r\n\r\nHardware exceptions are a very powerful tool for specific use cases. One such use case is to\r\ndetect and handle illegal instructions at runtime.\r\n\r\n## Implementation\r\n\r\nIt turns out that implementing SEH in pure Rust has its own issues (as seen in\r\n[this article from NAMAZSO](https://engineering.zeroitlab.com/2022/03/13/rust-seh))\r\n\r\nThis library uses a different, simpler approach, which is to use a `C` stub that calls back into Rust, wrapping\r\nthe call in a `__try __except` block.\r\n\r\n## Usage\r\n\r\nAdd this to your `Cargo.toml`:\r\n\r\n```toml\r\n[dependencies]\r\nmicroseh = \"1.1\"\r\n```\r\n\r\n**Minimal Example:** Dereference an invalid pointer without crashing the program, and return the handled exception.\r\n\r\n```rust\r\nfn guarded() -\u003e Result\u003c(), microseh::Exception\u003e {\r\n    microseh::try_seh(|| unsafe {\r\n        // Read from an unallocated memory region. (we create an aligned not-null\r\n        // pointer to skip the checks in read_volatile that would raise a panic)\r\n        core::ptr::read_volatile(core::mem::align_of::\u003ci32\u003e() as *const i32);\r\n    })\r\n}\r\n```\r\n\r\n**Accessing Exception Data:** You can obtain the address and register dump of an exception.\r\n\r\n```rust\r\nif let Err(ex) = microseh::try_seh(|| unsafe {\r\n    // *questionable life choices go here*\r\n}) {\r\n    println!(\"address: {:x}\", ex.address());\r\n    println!(\"rax: {:x}\", ex.registers().rax());\r\n}\r\n```\r\n\r\n_For additional examples and practical use cases, please visit the [examples](./examples) directory!_\r\n\r\n## Portability\r\n\r\nSEH is an extension to the C language developed by Microsoft, and it is exclusively available\r\non Windows when using Microsoft Visual C++ (MSVC).\r\n\r\nMicroSEH is compatible with and has been tested on Windows platforms with the following\r\narchitectures: **x86**, **x86_64** and **aarch64**.\r\n\r\nWhen building for other unsupported platforms, the library will disable exception\r\nhandling and panic when `try_seh` is called.\r\n\r\n## Usage on Kernel Drivers\r\n\r\nThis library can compile to `no_std` and supports running in Windows Kernel Drivers using\r\nMicrosoft's [windows-drivers-rs](https://github.com/microsoft/windows-drivers-rs) project.\r\n\r\n## Cross-Compiling\r\n\r\nCross-compiling for Windows is possible with full support for SEH using the\r\n[cargo-xwin](https://github.com/rust-cross/cargo-xwin) project.\r\n\r\n## License\r\n\r\nThis work is released under the MIT license. A copy of the license is provided in the\r\n[LICENSE](./LICENSE) file.\r\n","funding_links":[],"categories":["Rust"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonodima%2Fmicroseh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonodima%2Fmicroseh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonodima%2Fmicroseh/lists"}