MCPcopy Index your code
hub / github.com/BorrowSanitizer/bsan

github.com/BorrowSanitizer/bsan @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
2,519 symbols 5,058 edges 504 files 521 documented · 21%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

CI Benchmarks docs project chat Open in Dev Containers

BorrowSanitizer

BorrowSanitizer

BorrowSanitizer is work-in-progress LLVM instrumentation pass for detecting aliasing violations in multi-language Rust applications. Our project is still in early stages, and it is not functional yet. Our goal is to support detecting the following types of errors:

  • Violations of Rust's Tree Borrows aliasing model.
  • Accesses out-of-bounds
  • Use-after free errors.

This project contains a fork of Miri's borrow tracker (bsan-shared, bsan-rt), as well as several other components from both Miri and the Rust compiler.

Check out our website for more information.

Usage

The easiest way to try BorrowSanitizer is inside a Docker container. Our image supports the following platforms:

Platform Target Description
linux/amd64 aarch64-unknown-linux-gnu ARM64 Linux
linux/arm64 x86_64-unknown-linux-gnu X86 Linux

First, pull our latest image from GitHub's container registry.

docker pull ghcr.io/borrowsanitizer/bsan:latest

Then, launch a container and attach a shell.

docker run -it bsan:latest

Once inside the container, you can use our Cargo plugin to build and test crates using BorrowSanitizer.

cargo bsan test

Our plugin supports most of the same subcommands as Miri. When it's used for the first time, it will perform a one-time setup step of building an instrumented sysroot. You can trigger this step manually using the setup subcommand.

Building from Source

Every single command needed to build, test, and install BorrrowSanitizer can be accessed through xb, our build script. For first-time setup, run:

xb setup

This will install a custom Rust toolchain under the name bsan. Then, to install BorrowSanitizer, run:

xb install

This will place our tool's binaries into Cargo's home directory ($HOME/.cargo). You will need to have bsan set as the active toolchain (e.g. rustup default bsan) for our tool to work.

You can build and test components of the project using the build and test subcommands. For example, running xb build will build everything, but you can also pass the name of a subdirectory to build just that component, like so:

xb build bsan-rt

Nearly every subcommand can be used this way.

After making a change, you should run all of our CI steps locally using:

xb ci

BorrowSanitizer is dual-licensed under Apache and MIT, following the Rust project.

Zulip Zulip sponsors free hosting for BorrowSanitizer. Zulip is an organized team chat app designed for efficient communication.

Extension points exported contracts — how you extend this code

Exhaustive (Interface)
(no doc) [22 implementers]
bsan-rt/src/tree_borrows/exhaustive.rs
Id (Interface)
@run:0 [2 implementers]
tests/miri-tests/pass/validation_lifetime_resolution.rs
Buildable (Interface)
(no doc) [3 implementers]
bsan-script/src/commands.rs
BlitSort (Interface)
(no doc) [1 implementers]
tests/fail-dep/mirilli/blitsort-sys.rs
WordAligned (Interface)
# Safety Values must be aligned to the word size of the current platform. [3 implementers]
bsan-rt/src/memory/mod.rs
Foo (Interface)
track_caller on the impl but not the trait. [1 implementers]
tests/miri-tests/should-pass/performance/track-caller-attribute.rs
AllocState (Interface)
The public interface shared by all tree implementations. Consumers outside this module interact with the tree exclusivel [2 …
bsan-rt/src/tree_borrows/tree.rs
DeclaredTrait (Interface)
@run:0 [1 implementers]
tests/miri-tests/pass/deriving-associated-types.rs

Core symbols most depended-on inside this repo

push
called by 75
bsan-rt/src/tree_borrows/diagnostics.rs
get
called by 73
bsan-rt/src/tree_borrows/refcount.rs
iter
called by 68
bsan-rt/src/tree_borrows/data_structures/unimap.rs
write
called by 60
bsan-rt/src/tree_borrows/diagnostics.rs
transmute
called by 60
tests/miri-tests/pass/intptrcast.rs
from
called by 44
tests/miri-tests/pass/arrays.rs
f
called by 42
tests/miri-tests/pass/unsized.rs
clone
called by 40
bsan-rt/src/tree_borrows/refcount.rs

Shape

Function 1,431
Method 662
Class 307
Enum 65
Interface 54

Languages

Rust86%
C++13%
Python1%

Modules by API surface

bsan-pass/BorrowSanitizer.cpp122 symbols
tests/miri-tests/pass/dyn-upcast.rs56 symbols
bsan-rt/src/lib.rs45 symbols
bsan-rt/src/tree_borrows/perms.rs44 symbols
bsan-rt/src/tree_borrows/diagnostics.rs44 symbols
bsan-rt/llvm-wrapper/bsan.cpp43 symbols
bsan-rt/src/tree_borrows/tree.rs42 symbols
bsan-rt/llvm-wrapper/bsan_allocator.cpp36 symbols
bsan-script/src/env.rs34 symbols
bsan-script/src/commands.rs34 symbols
bsan-rt/src/tree_borrows/tree/tests.rs33 symbols
cargo-bsan/src/util.rs32 symbols

For agents

$ claude mcp add bsan \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact