Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Merge pull request #14 from intel/fix/fuzzer/partition
Browse files Browse the repository at this point in the history
fuzzer/partition: use x86_range parameter
  • Loading branch information
Wenzel authored Sep 11, 2024
2 parents e068923 + 83f21ac commit baf3e1f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions vmsifter/fuzzer/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ class X86Range:


def partition(nb_parts: int, x86_range: X86Range = DEFAULT_X86_RANGE) -> List[X86Range]:
max = int.from_bytes(settings.x86.max_end_first_byte, byteorder="big")
if nb_parts > max:
end = int.from_bytes(x86_range.end[0:1], byteorder="big")
start = int.from_bytes(x86_range.start[0:1], byteorder="big")
if nb_parts > end:
raise ValueError(f"Partitioning over {max} ranges is unsupported")

def int_to_bytes(value: int):
return value.to_bytes(1, byteorder="big")

step = max // nb_parts
rem = max % nb_parts
step = (end - start) // nb_parts
rem = (end - start) % nb_parts
# ex: nb_parts = 2
# start=0, end=0 + 127 - 1
# start=127, end=255-1 (remainder) converted to 255 below since it's the last range
ranges = [X86Range(start=int_to_bytes(v), end=int_to_bytes(v + step - 1)) for v in range(0, max - rem, step)]
ranges = [X86Range(start=int_to_bytes(v), end=int_to_bytes(v + step - 1)) for v in range(start, end - rem, step)]
# set first range
ranges[0].start = x86_range.start
# set last range
ranges[-1].end = settings.x86.max_end_first_byte
ranges[-1].end = x86_range.end
return ranges

0 comments on commit baf3e1f

Please sign in to comment.