-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
142 lines (98 loc) · 5.49 KB
/
config.py
File metadata and controls
142 lines (98 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import os
from pathlib import Path
import pandas as pd
import ast
import yaml
print("start")
# --- Portable path setup ---------------------------------------------------
# Repo root = two levels up from this file (scripts/post-process-traces/config.py)
REPO_ROOT = Path(__file__).resolve().parents[2]
# Pre-computed static-analysis databases live in the lima-static-analyzer submodule.
KERNEL_VERSION = "linux-6.1"
STATIC_ANALYZER_DIR = REPO_ROOT / "lima-static-analyzer"
STATIC_DATA_DIR = STATIC_ANALYZER_DIR / "data" / KERNEL_VERSION
# The static analyzer's config.yaml is the single source of truth for kernel paths.
with open(STATIC_ANALYZER_DIR / "config.yaml") as _f:
_KV_CFG = yaml.safe_load(_f)["kernel_versions"][KERNEL_VERSION]
print(REPO_ROOT)
# vmlinux image for address resolution
linux_image = str(REPO_ROOT / "kernel_image_ubuntu22" / "vmlinux")
# raw dynamic-tracer output
trace_dir = str(REPO_ROOT / "locks-access-traces") + "/"
print(trace_dir)
# Set static analysis dir (pre-computed DBs in the lima-static-analyzer submodule)
static_analysis_dir = str(STATIC_DATA_DIR)
lock_primitives = ["mutex", "rt_mutex", "write_sem", "read_sem", "read_rw",
"write_rw", "read_rw_bh", "write_rw_bh", "read_rw_irq", "write_rw_irq", "read_rw_irqsave",
"write_rw_irqsave", "spin", "irqsave_spin", "irq_spin", "bh_spin"]
# syscalls = ["link", "unlink", "fstat", "lseek", "close", "write", "pwrite", "munmap", "mprotect", "rename",
# "pread", "stat", "mmap", "read", "pipe", "open", "alarm", "clone", "connect", "nanosleep", "mkdir", "futex"]
# Kernel source tree for cscope; comes from the static analyzer config.yaml.
# Override with the LIMA_KERNEL_SRC env var if your source lives elsewhere.
kernel_path = os.environ.get("LIMA_KERNEL_SRC", _KV_CFG["source_dir"]).rstrip("/") + "/"
# Prefix stripped from the outgoing-calls DB to make paths kernel-relative
# (matches old_source_dir the DB was generated with).
_OLD_KERNEL_SRC_PREFIX = (_KV_CFG.get("old_source_dir") or "/root/linux-6.1-clangd").rstrip("/") + "/"
print(kernel_path)
# load lockdep keys (generated under the repo root by utils.py, read back here)
lockdep_keys_base_path = str(REPO_ROOT / "lockdep") + "/"
# load lock name to struct mapping file
lock_name_to_struct_db_path = str(STATIC_DATA_DIR / "lock_struct_map_db") + "/"
# load acquires and wrappers file
lock_acquire_funcs_file = str(REPO_ROOT / "locks" / "lock_acquire_functions.csv")
lock_wrappers_file = str(REPO_ROOT / "locks" / "wrappers.csv")
#load locks db
locks_db = pd.read_csv(STATIC_DATA_DIR / "locks_db" / "locks_db_v1.csv")
# outgoing calls dbq
outgoing_calls_db_path = str(STATIC_DATA_DIR / "outgoing_calls_db") + "/"
print(outgoing_calls_db_path)
load_outgoing_calls_db = True
#remove this when running search
count = 0
outgoing_calls_combined_df = pd.DataFrame()
if load_outgoing_calls_db:
# count += 1
#itearte over the files in the outgoing_calls_db and concate it into a single dataframe
for file in os.listdir(outgoing_calls_db_path):
# print(file)
outgoing_calls_df = pd.DataFrame()
if file.endswith(".csv"):
# print(file)
#concatenate the files
outgoing_calls_df = pd.read_csv(outgoing_calls_db_path + file)
outgoing_calls_combined_df = pd.concat([outgoing_calls_combined_df, outgoing_calls_df])
# handle .gz files
elif file.endswith(".gz"):
# print(file)
outgoing_calls_df = pd.read_csv(outgoing_calls_db_path + file, compression='gzip')
outgoing_calls_combined_df = pd.concat([outgoing_calls_combined_df, outgoing_calls_df])
else:
continue
outgoing_calls_combined_df["caller_path"] = outgoing_calls_combined_df["caller_path"].str.replace(_OLD_KERNEL_SRC_PREFIX, "", regex=False)
outgoing_calls_combined_df["callee_path"] = outgoing_calls_combined_df["callee_path"].str.replace(_OLD_KERNEL_SRC_PREFIX, "", regex=False)
outgoing_calls_combined_df.dropna(inplace=True)
outgoing_calls_combined_df['from_line'] = outgoing_calls_combined_df['from_line'].apply(ast.literal_eval)
# update the outgoing_calls_combined_df
# outgoing_calls_combined_df['from_line'] = outgoing_calls_combined_df['from_line'].apply(ast.literal_eval)
# outgoing_calls_combined_df["caller_path"] = outgoing_calls_combined_df["caller_path"].str.replace("/root/linux-6.1-clangd/", "", regex=False)
# outgoing_calls_combined_df["callee_path"] = outgoing_calls_combined_df["callee_path"].str.replace("/root/linux-6.1-clangd/", "", regex=False)
# outgoing_calls_combined_df.dropna(inplace=True)
# outgoing_calls_combined_df['from_line'] = outgoing_calls_combined_df['from_line'].apply(ast.literal_eval)
# print(outgoing_calls_combined_df.dtypes)
# print(outgoing_calls_combined_df.head())
# p = Path(__file__).parents[2]
# print(p)
# get dir two levels up
# linux_image = os.path.join(cur_dir, "../../vmlinux")
# load a outgoinf calls db
# test_outgoing_calls_db = pd.read_csv(outgoing_calls_db + "outgoing_calls_kernel.csv")
# test_outgoing_calls_db['from_line'] = test_outgoing_calls_db['from_line'].apply(ast.literal_eval)
# # # write back to the file with the correct type
# test_outgoing_calls_db.to_csv("test.csv", index=False)
# print the type of rows
# print(test_outgoing_calls_db.dtypes)
# print(test_outgoing_calls_db.head())
# # iterate over the rows
# for index, row in test_outgoing_calls_db.iterrows():
# # from_lines = ast.literal_eval(row["from_line"])
# print(type(row["from_line"]))