Skip to content

Commit 768e4d6

Browse files
authored
Merge pull request #45 from VRIG-RITSEC/v8_patches
V8 patches
2 parents 35e2e69 + cdd7c9e commit 768e4d6

File tree

8 files changed

+583
-86
lines changed

8 files changed

+583
-86
lines changed

.dockerignore

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,23 @@
1-
# Git
21
.git
32
.gitignore
4-
5-
# Build artifacts
6-
.build/
7-
*.xcodeproj
8-
*.xcworkspace
9-
10-
# Swift Package Manager
11-
.swiftpm/
12-
Package.resolved
13-
14-
# Documentation
15-
Docs/
16-
*.md
17-
!README.md
18-
19-
# Tests
20-
Tests/
21-
22-
# Docker files (except the one we're using)
23-
Cloud/Docker/
24-
Cloud/GCE/
25-
Cloud/Triage/
26-
27-
# V8 source (will be built in container)
28-
v8/
29-
30-
# Temporary files
31-
*.tmp
323
*.log
33-
.DS_Store
34-
Thumbs.db
35-
36-
# IDE files
4+
*.err
5+
logs/
6+
corpus/
7+
.venv/
8+
__pycache__/
9+
*.pyc
10+
*.pyo
11+
*.pyd
12+
.Python
13+
build/
14+
dist/
15+
*.egg-info/
3716
.vscode/
3817
.idea/
3918
*.swp
4019
*.swo
41-
42-
# OS files
20+
*~
4321
.DS_Store
44-
.DS_Store?
45-
._*
46-
.Spotlight-V100
47-
.Trashes
48-
ehthumbs.db
49-
Thumbs.db
22+
.build/
23+
Package.resolved

Sources/Agentic_System/rises-the-fog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,16 @@ def __init__(self):
4646
# self.ebg = EBG(self.model, api_key=self.openai_api_key, anthropic_api_key=self.anthropic_api_key)
4747

4848

49-
def run():
49+
def run(force_logging: bool = False):
5050

5151
site.addsitedir(Path(__file__).parent.parent)
5252
#smolagent-fork
5353

54-
5554
parser = argparse.ArgumentParser(description="Rise the FoG agentic system")
5655
parser.add_argument("--debug", action="store_true", help="Enable debug logging to fog logs")
5756
args = parser.parse_args()
57+
#force logging
58+
args.debug = force_logging
5859

5960
if args.debug:
6061
log_dir = Path(__file__).parent / 'agents' / 'fog_logs'

Sources/setup.py

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
1-
# import Agentic_System.rises_the_fog as fog
21
import subprocess
32
import os
3+
import sys
4+
from pathlib import Path
5+
from concurrent.futures import ThreadPoolExecutor
6+
import importlib.util
7+
import rises_the_fog as fog
48

5-
# fog.run()
6-
7-
def revert_to_original():
8-
script_dir = os.path.dirname(os.path.abspath(__file__))
9-
a = os.path.join(script_dir, "Agentic_System/orginals/ProgramTemplateWeights.swift")
10-
b = os.path.join(script_dir, "Fuzzilli/CodeGen/ProgramTemplateWeights.swift")
11-
os.rename(a, b)
12-
a = os.path.join(script_dir, "Agentic_System/orginals/ProgramTemplates.swift")
13-
b = os.path.join(script_dir, "Fuzzilli/CodeGen/ProgramTemplates.swift")
14-
os.rename(a, b)
15-
16-
17-
def write_sql(reuslt: bool):
18-
if reuslt:
19-
with open("sql.sql", "r") as f:
20-
sql = f.read()
21-
else:
22-
with open("sql.sql", "r") as f:
23-
sql = f.read()
24-
25-
return sql
26-
27-
result = subprocess.run(["swift", "build"], capture_output=True, text=True)
28-
if result.returncode == 0:
29-
write_sql(True)
30-
print("Build templates succeeded")
31-
else:
32-
write_sql(False)
33-
revert_to_original()
34-
print("Build templates failed")
35-
print(result.stdout)
36-
print(result.stderr)
37-
r2 = subprocess.run(["swift", "build"], capture_output=True, text=True)
38-
if r2.returncode == 0:
39-
print("Build reverted succeeded")
40-
else:
41-
print("safety revert failed")
42-
print(r2.stdout)
43-
print(r2.stderr)
44-
exit(1)
9+
# script_dir = Path(__file__).parent
10+
# print(script_dir)
11+
# fog_module_path = script_dir / "rises-the-fog.py"
12+
# spec = importlib.util.spec_from_file_location("rises_the_fog", fog_module_path)
13+
# fog = importlib.util.module_from_spec(spec)
14+
# spec.loader.exec_module(fog)
15+
16+
#export V8_PATH=/usr/share/vrigatoni/v8_2/v8/out/
17+
#export D8_PATH=/usr/share/vrigatoni/v8_2/v8/out/fuzzbuild/d8
18+
#export FUZZILLI_TOOL_BIN=/mnt/vdb/fuzzillai/.build/x86_64-unknown-linux-gnu/debug/FuzzILTool
19+
#export FUZZILLI_PATH=/mnt/vdb/fuzzilla
20+
21+
with ThreadPoolExecutor(max_workers=16) as executor:
22+
futures = [executor.submit(fog.run, force_logging=True) for _ in range(16)]
23+
for i, future in enumerate(futures):
24+
print(f"started: {i}")
25+
future.result()
26+
27+
# def revert_to_original():
28+
# script_dir = os.path.dirname(os.path.abspath(__file__))
29+
# a = os.path.join(script_dir, "Agentic_System/orginals/ProgramTemplateWeights.swift")
30+
# b = os.path.join(script_dir, "Fuzzilli/CodeGen/ProgramTemplateWeights.swift")
31+
# os.rename(a, b)
32+
# a = os.path.join(script_dir, "Agentic_System/orginals/ProgramTemplates.swift")
33+
# b = os.path.join(script_dir, "Fuzzilli/CodeGen/ProgramTemplates.swift")
34+
# os.rename(a, b)
35+
36+
37+
# def write_sql(reuslt: bool):
38+
# if reuslt:
39+
# with open("sql.sql", "r") as f:
40+
# sql = f.read()
41+
# else:
42+
# with open("sql.sql", "r") as f:
43+
# sql = f.read()
44+
45+
# return sql
46+
47+
# result = subprocess.run(["swift", "build"], capture_output=True, text=True)
48+
# if result.returncode == 0:
49+
# write_sql(True)
50+
# print("Build templates succeeded")
51+
# else:
52+
# write_sql(False)
53+
# revert_to_original()
54+
# print("Build templates failed")
55+
# print(result.stdout)
56+
# print(result.stderr)
57+
# r2 = subprocess.run(["swift", "build"], capture_output=True, text=True)
58+
# if r2.returncode == 0:
59+
# print("Build reverted succeeded")
60+
# else:
61+
# print("safety revert failed")
62+
# print(r2.stdout)
63+
# print(r2.stderr)
64+
# exit(1)
4565

docker-compose.master.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ services:
2121
retries: 5
2222
restart: unless-stopped
2323
networks:
24-
- fuzzing-network
24+
- fuzzilli-network
2525

2626
volumes:
2727
postgres_master_data:
2828

2929
networks:
30-
fuzzing-network:
30+
fuzzilli-network:
3131
driver: bridge
3232

v8_patch/cov-cc.diff

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
diff --git a/src/fuzzilli/cov.cc b/src/fuzzilli/cov.cc
2+
index bf8b6925993..c5e049a516f 100644
3+
--- a/src/fuzzilli/cov.cc
4+
+++ b/src/fuzzilli/cov.cc
5+
@@ -1,9 +1,16 @@
6+
// Copyright 2020 the V8 project authors. All rights reserved.
7+
-// Use of this source code is governed by a BSD-style license that can be
8+
-// found in the LICENSE file.
9+
+// Use of this source code is governed by a BSD-style license that can
10+
+// be found in the LICENSE file.
11+
12+
#include "src/fuzzilli/cov.h"
13+
14+
+// Include V8 headers first to avoid macro conflicts
15+
+#include "src/base/platform/memory.h"
16+
+#include "src/objects/feedback-vector.h"
17+
+#include "src/sandbox/hardware-support.h"
18+
+
19+
+// Include system headers after V8 headers
20+
+#include <cstddef>
21+
#include <fcntl.h>
22+
#include <inttypes.h>
23+
#include <stdio.h>
24+
@@ -14,14 +21,31 @@
25+
#include <sys/wait.h>
26+
#include <unistd.h>
27+
28+
-#include "src/base/platform/memory.h"
29+
-#include "src/sandbox/hardware-support.h"
30+
-
31+
-#define SHM_SIZE 0x100000
32+
+#define SHM_SIZE 0x202000
33+
#define MAX_EDGES ((SHM_SIZE - 4) * 8)
34+
+#define MAX_FEEDBACK_NEXUS 100000
35+
+
36+
+
37+
+struct FeedbackNexusData {
38+
+ uint32_t vector_address; // Address of FeedbackVector in V8 heap
39+
+ uint32_t ic_state; // InlineCacheState
40+
+};
41+
+
42+
+struct optimization_turbofan_data {
43+
+ uint32_t flags; // Flags used for optimization passes in PipelineImpl::OptimizeTurbofanGraph
44+
+ //uint32_t address_code;
45+
+ //uint32_t address_shared_info;
46+
+ //uint8_t bailout_reason;
47+
+ //bool is_osr;
48+
+};
49+
50+
struct shmem_data {
51+
uint32_t num_edges;
52+
+ uint32_t feedback_nexus_count;
53+
+ uint32_t max_feedback_nexus;
54+
+ uint32_t turbofan_flags;
55+
+ uint64_t turbofan_optimization_bits;
56+
+ FeedbackNexusData feedback_nexus_data[MAX_FEEDBACK_NEXUS];
57+
unsigned char edges[];
58+
};
59+
60+
@@ -83,6 +107,12 @@ extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t* start,
61+
62+
shmem->num_edges = static_cast<uint32_t>(stop - start);
63+
builtins_start = 1 + shmem->num_edges;
64+
+
65+
+ // Initialize feedback nexus fields
66+
+ shmem->feedback_nexus_count = 0;
67+
+ shmem->max_feedback_nexus = MAX_FEEDBACK_NEXUS;
68+
+ memset(shmem->feedback_nexus_data, 0, sizeof(FeedbackNexusData) * MAX_FEEDBACK_NEXUS);
69+
+
70+
fprintf(stderr,
71+
"[COV] edge counters initialized. Shared memory: %s with %u edges\n",
72+
shm_key, shmem->num_edges);
73+
@@ -115,12 +145,15 @@ void sanitizer_cov_prepare_for_hardware_sandbox() {
74+
#endif
75+
76+
uint32_t sanitizer_cov_count_discovered_edges() {
77+
+ // Calculate offset to edges array (after feedback nexus data)
78+
+ unsigned char* edges_ptr = (unsigned char*)shmem + offsetof(struct shmem_data, edges);
79+
+
80+
uint32_t on_edges_counter = 0;
81+
for (uint32_t i = 1; i < builtins_start; ++i) {
82+
const uint32_t byteIndex = i >> 3; // Divide by 8 using a shift operation
83+
const uint32_t bitIndex = i & 7; // Modulo 8 using a bitwise AND operation
84+
85+
- if (shmem->edges[byteIndex] & (1 << bitIndex)) {
86+
+ if (edges_ptr[byteIndex] & (1 << bitIndex)) {
87+
++on_edges_counter;
88+
}
89+
}
90+
@@ -128,14 +161,26 @@ uint32_t sanitizer_cov_count_discovered_edges() {
91+
}
92+
93+
extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t* guard) {
94+
- // There's a small race condition here: if this function executes in two
95+
- // threads for the same edge at the same time, the first thread might disable
96+
- // the edge (by setting the guard to zero) before the second thread fetches
97+
- // the guard value (and thus the index). However, our instrumentation ignores
98+
- // the first edge (see libcoverage.c) and so the race is unproblematic.
99+
+ /*
100+
+ // There's a small race condition here: if this function executes in two
101+
+ // threads for the same edge at the same time, the first thread might disable
102+
+ // the edge (by setting the guard to zero) before the second thread fetches
103+
+ // the guard value (and thus the index). However, our instrumentation ignores
104+
+ // the first edge (see libcoverage.c) and so the race is unproblematic.
105+
+ uint32_t index = *guard;
106+
+ shmem->edges[index / 8] |= 1 << (index % 8);
107+
+ *guard = 0;
108+
+ */
109+
+ if (!guard || *guard == 0) return; // guard already cleared — possible race
110+
uint32_t index = *guard;
111+
- shmem->edges[index / 8] |= 1 << (index % 8);
112+
*guard = 0;
113+
+
114+
+ // Check again in case another thread zeroed it just now (race hit)
115+
+ if (index == 0) return;
116+
+
117+
+ // Calculate offset to edges array (after feedback nexus data)
118+
+ unsigned char* edges_ptr = (unsigned char*)shmem + offsetof(struct shmem_data, edges);
119+
+ edges_ptr[index / 8] |= 1 << (index % 8);
120+
}
121+
122+
void cov_init_builtins_edges(uint32_t num_edges) {
123+
@@ -161,12 +206,53 @@ void cov_update_builtins_basic_block_coverage(
124+
fprintf(stderr, "[COV] Error: Size of builtins cov map changed.\n");
125+
exit(-1);
126+
}
127+
+
128+
+ // Calculate offset to edges array (after feedback nexus data)
129+
+ unsigned char* edges_ptr = (unsigned char*)shmem + offsetof(struct shmem_data, edges);
130+
+
131+
for (uint32_t i = 0; i < cov_map.size(); ++i) {
132+
if (cov_map[i]) {
133+
const uint32_t byteIndex = (i + builtins_start) >> 3;
134+
const uint32_t bitIndex = (i + builtins_start) & 7;
135+
136+
- shmem->edges[byteIndex] |= (1 << bitIndex);
137+
+ edges_ptr[byteIndex] |= (1 << bitIndex);
138+
}
139+
}
140+
}
141+
+
142+
+
143+
+void cov_serialize_feedback_nexus(v8::internal::FeedbackNexus* nexus, FeedbackNexusData* data) {
144+
+ if (!nexus || !data) return;
145+
+ data->vector_address = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(nexus->vector().ptr()));
146+
+ data->ic_state = static_cast<uint32_t>(nexus->ic_state());
147+
+}
148+
+
149+
+void cov_add_feedback_nexus(v8::internal::FeedbackNexus* nexus) {
150+
+ if (!shmem || !nexus) return;
151+
+
152+
+ // Check if we have space
153+
+ if (shmem->feedback_nexus_count >= MAX_FEEDBACK_NEXUS) {
154+
+ fprintf(stderr, "[COV] Warning: Feedback nexus buffer full, dropping entry\n");
155+
+ return;
156+
+ }
157+
+ cov_serialize_feedback_nexus(nexus,
158+
+ &shmem->feedback_nexus_data[shmem->feedback_nexus_count]);
159+
+ shmem->feedback_nexus_count++;
160+
+
161+
+ // printf("[COV] Added feedback nexus: %p\n", nexus);
162+
+ // printf("[COV] Feedback nexus count: %d\n", shmem->feedback_nexus_count);
163+
+ // printf("[COV] Feedback nexus data: %p\n", shmem->feedback_nexus_data);
164+
+ // printf("[COV] Feedback nexus data: %p\n", shmem->feedback_nexus_data[shmem->feedback_nexus_count]);
165+
+ // printf("[COV] Feedback nexus data: %p\n", shmem->feedback_nexus_data[shmem->feedback_nexus_count].vector_address);
166+
+ // printf("[COV] Feedback nexus data: %p\n", shmem->feedback_nexus_data[shmem->feedback_nexus_count].ic_state);
167+
+}
168+
+
169+
+void cov_set_turbofan_optimization_bits(uint64_t bit) {
170+
+ if (!shmem) return;
171+
+ shmem->turbofan_optimization_bits |= bit;
172+
+}
173+
+
174+
+void cov_set_maglev_optimization_bits(uint64_t /*bit*/) {
175+
+ // No-op: maglev bitmap is not exported in shmem layout.
176+
+}
177+
+// } // namespace v8

0 commit comments

Comments
 (0)