Skip to content

Commit 8294273

Browse files
committed
Bit more doc
1 parent 8447609 commit 8294273

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ As a bonus, we also get detection of memory use-after-free and corruption for fr
5353

5454
# Usage
5555

56-
1. Set `BAD_ACCESS_GUARDS_ENABLE=1` for your **in-house** builds (you probably want it off in production...)
56+
1. Define `BAD_ACCESS_GUARDS_ENABLE=1` for your **in-house** builds (you probably want it off in production...)
5757
2. Declare the shadow memory that will hold the state and pointer to stack with `BA_GUARD_DECL(varname)`
58-
3. For all (relevant) read operations of the container/object, use the scope guard `BA_GUARD_READ(varname)`
59-
4. For all (relevant) write operations of the container/object, use the scope guard `BA_GUARD_WRITE(varname)`. But only if it always writes!
60-
5. Add `BA_GUARD_DESTROY(varname)` at the beginning of the destructor
58+
3. For all (relevant) read operations of the container / object, use the scope guard `BA_GUARD_READ(varname)`.
59+
4. For all (relevant) write operations of the container / object, use the scope guard `BA_GUARD_WRITE(varname)`.
60+
Do this only if it always writes! For example, don't use it on `operator[]` even though it returns a reference, use `BA_GUARD_READ` instead.
61+
5. Add `BA_GUARD_DESTROY(varname)` at the beginning of the destructor.
6162
6. Enjoy!
6263

6364
# Examples

src/BadAccessGuards.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#pragma once
22

3-
// TODO: documentation
3+
// 1. Define `BAD_ACCESS_GUARDS_ENABLE=1` for your **in-house** builds (you probably want it off in production...)
4+
// 2. Declare the shadow memory that will hold the state and pointer to stack with `BA_GUARD_DECL(varname)`
5+
// 3. For all (relevant) read operations of the container / object, use the scope guard `BA_GUARD_READ(varname)`.
6+
// 4. For all (relevant) write operations of the container / object, use the scope guard `BA_GUARD_WRITE(varname)`.
7+
// Do this only if it always writes! For example, don't use it on `operator[]` even though it returns a reference, use `BA_GUARD_READ` instead.
8+
// 5. Add `BA_GUARD_DESTROY(varname)` at the beginning of the destructor.
9+
// 6. Enjoy!
10+
//
11+
// You may optionally configure it with `BadAccessGuardSetConfig`.
412

513
#if !defined(BAD_ACCESS_GUARDS_ENABLE)
614
# if defined(NDEBUG)
@@ -207,18 +215,19 @@ struct BadAccessGuardDestroy
207215

208216
struct BadAccessGuardConfig
209217
{
210-
// Should we allow to break at all, or simply call BadAccessGuardReport
211-
// Default: true
218+
// Should we allow to break at all, or simply call `reportBadAccess`
219+
// Default: true.
212220
bool allowBreak;
213221
// Set this to true if you want to break early.
214222
// Usually you would want to set this to true when the debugger is connected.
215223
// If no debugger is connected, you most likely want this set to false to get the error in your logs.
216224
// Of course, if you save minidumps, logging is probably unnecessary.
217-
// Default true on windows if a debugger is detected during startup
225+
// Default: true on Windows if a debugger is detected during startup, false otherwise.
218226
bool breakASAP;
219227

220228
// If non-null, used to report errors instead of the default function.
221-
// Breaking is still controlled by allowBreak and breakASAP.
229+
// Breaking is still controlled by `allowBreak` and `breakASAP`.
230+
// Returning false can prevent triggering the breakpoint (except if `breakASAP` is true)
222231
using ReportBadAccessFunction = bool(StateAndStackAddr previousOperation, BadAccessGuardState toState, bool assertionOrWarning, const char* message);
223232
ReportBadAccessFunction* reportBadAccess;
224233
};

0 commit comments

Comments
 (0)