-
Notifications
You must be signed in to change notification settings - Fork 34
Edge Sync File Id Strategy #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
365fe90
instrumentor: remove unused function
kyakdan 935e483
fuzzer: use 0 as the first edge ID
kyakdan b3a4888
fuzzer: move counter-related code into a dedicated file
kyakdan e74b57d
fuzzer: refactor addon types/functions into dedicated file
kyakdan f95e4f1
fuzzer: refactor tracing functions into dedicated file
kyakdan 82bea2e
instrumentor: add edge ID generation strategy interface
kyakdan b1989cf
instrumentor: add file sync edge ID strategy for multi-process modes
kyakdan 79321a2
core: use file sync strategy for libFuzzer's multi-process modes
kyakdan 4a6375b
fuzzer: refactor the fuzzer object and type
kyakdan 817d2f4
instrumentor: use os.EOL for adding a new line into the ID sync file
kyakdan 4c01791
instrumentor: move counter-generating functions into codeCoverage()
kyakdan 9ba1ca8
instrumentor: use returned release function to release lock on id file
kyakdan 430c6cf
instrumentor: extract EdgeIdStrategy into an interface
kyakdan 40e3c55
instrumentor: extract coverage tracking functions into CoverageTracker
kyakdan 718269c
instrumentor: fix naming in mock function
kyakdan 8a69526
instrumentor: extract compare tracing functions into dedicated object
kyakdan 116aa71
cli: mark the id_sync_file as hidden
kyakdan dafff5a
instrumentor: mark fatalExitCode of ID file sync strategy as readonly
kyakdan fa950e3
fuzzer: do not export the native addon through the fuzzer interface
kyakdan 185ac86
instrumentor: add an edge ID strategy returning zero IDs
kyakdan 1d59313
instrumentor: extract instrumentor into own class
kyakdan e36b000
instrumentor: add unit test for sync file ID strategy
kyakdan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Copyright 2023 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { default as bind } from "bindings"; | ||
|
|
||
| export type FuzzTargetAsyncOrValue = (data: Buffer) => void | Promise<void>; | ||
| export type FuzzTargetCallback = ( | ||
| data: Buffer, | ||
| done: (e?: Error) => void | ||
| ) => void; | ||
| export type FuzzTarget = FuzzTargetAsyncOrValue | FuzzTargetCallback; | ||
| export type FuzzOpts = string[]; | ||
|
|
||
| export type StartFuzzingSyncFn = ( | ||
| fuzzFn: FuzzTarget, | ||
| fuzzOpts: FuzzOpts | ||
| ) => void; | ||
| export type StartFuzzingAsyncFn = ( | ||
| fuzzFn: FuzzTarget, | ||
| fuzzOpts: FuzzOpts | ||
| ) => Promise<void>; | ||
|
|
||
| type NativeAddon = { | ||
| registerCoverageMap: (buffer: Buffer) => void; | ||
| registerNewCounters: (oldNumCounters: number, newNumCounters: number) => void; | ||
|
|
||
| traceUnequalStrings: ( | ||
| hookId: number, | ||
| current: string, | ||
| target: string | ||
| ) => void; | ||
|
|
||
| traceStringContainment: ( | ||
| hookId: number, | ||
| needle: string, | ||
| haystack: string | ||
| ) => void; | ||
| traceIntegerCompare: ( | ||
| hookId: number, | ||
| current: number, | ||
| target: number | ||
| ) => void; | ||
|
|
||
| tracePcIndir: (hookId: number, state: number) => void; | ||
|
|
||
| printVersion: () => void; | ||
| startFuzzing: StartFuzzingSyncFn; | ||
| startFuzzingAsync: StartFuzzingAsyncFn; | ||
| stopFuzzingAsync: (status?: number) => void; | ||
| }; | ||
|
|
||
| export const addon: NativeAddon = bind("jazzerjs"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2023 Code Intelligence GmbH | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { addon } from "./addon"; | ||
|
|
||
| export class CoverageTracker { | ||
| private static readonly MAX_NUM_COUNTERS: number = 1 << 20; | ||
| private static readonly INITIAL_NUM_COUNTERS: number = 1 << 9; | ||
| private readonly coverageMap: Buffer; | ||
| private currentNumCounters: number; | ||
|
|
||
| constructor() { | ||
| this.coverageMap = Buffer.alloc(CoverageTracker.MAX_NUM_COUNTERS, 0); | ||
| this.currentNumCounters = CoverageTracker.INITIAL_NUM_COUNTERS; | ||
| addon.registerCoverageMap(this.coverageMap); | ||
| addon.registerNewCounters(0, this.currentNumCounters); | ||
| } | ||
|
|
||
| enlargeCountersBufferIfNeeded(nextEdgeId: number) { | ||
| // Enlarge registered counters if needed | ||
| let newNumCounters = this.currentNumCounters; | ||
| while (nextEdgeId >= newNumCounters) { | ||
| newNumCounters = 2 * newNumCounters; | ||
| if (newNumCounters > CoverageTracker.MAX_NUM_COUNTERS) { | ||
| throw new Error( | ||
| `Maximum number (${CoverageTracker.MAX_NUM_COUNTERS}) of coverage counts exceeded.` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // Register new counters if enlarged | ||
| if (newNumCounters > this.currentNumCounters) { | ||
| addon.registerNewCounters(this.currentNumCounters, newNumCounters); | ||
| this.currentNumCounters = newNumCounters; | ||
| console.log( | ||
| `INFO: New number of coverage counters ${this.currentNumCounters}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Increments the coverage counter for a given ID. | ||
| * This function implements the NeverZero policy from AFL++. | ||
| * See https://aflplus.plus//papers/aflpp-woot2020.pdf | ||
| * @param edgeId the edge ID of the coverage counter to increment | ||
| */ | ||
| incrementCounter(edgeId: number) { | ||
| const counter = this.coverageMap.readUint8(edgeId); | ||
| this.coverageMap.writeUint8(counter == 255 ? 1 : counter + 1, edgeId); | ||
| } | ||
|
|
||
| readCounter(edgeId: number): number { | ||
| return this.coverageMap.readUint8(edgeId); | ||
| } | ||
| } | ||
|
|
||
| export const coverageTracker = new CoverageTracker(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.