-
Notifications
You must be signed in to change notification settings - Fork 168
vma/util: ASAN problem fix. #1150
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
base: master
Are you sure you want to change the base?
vma/util: ASAN problem fix. #1150
Conversation
|
Can one of the admins verify this patch? |
Greptile OverviewGreptile SummaryThis PR fixes ASAN compatibility issues that occur when both ASAN and libvma override libc functions during initialization. Key Changes:
Both changes are necessary to enable ASAN-based debugging and memory analysis for VMA. Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Init as VMA Initialization
participant SysVars as sys_vars.cpp
participant Utils as utils.cpp
participant LibC as libc (open/read)
Note over Init,LibC: ASAN-safe initialization
Init->>Utils: read_file_to_int(path, default)
Utils->>LibC: open(path, O_RDONLY)
LibC-->>Utils: fd
alt fd >= 0
Utils->>LibC: read(fd, buffer, 20)
LibC-->>Utils: bytes read
alt sscanf succeeds
Utils->>LibC: close(fd)
Utils-->>Init: parsed value
else sscanf fails
Utils->>LibC: close(fd)
Utils-->>Init: default_value
end
else fd < 0
Utils-->>Init: default_value
end
Init->>SysVars: env_to_cpuset("-1", cpu_set)
alt input is "-1"
SysVars->>SysVars: CPU_ZERO(cpu_set)
SysVars-->>Init: success (0)
else input is hex (0x...)
SysVars->>SysVars: hex_to_cpuset()
SysVars-->>Init: result
else input is list
SysVars->>SysVars: list_to_cpuset()
SysVars-->>Init: result
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 1 comment
src/vma/util/sys_vars.cpp
Outdated
| { | ||
| int ret; | ||
| char* start = strdup(orig_start); // save the caller string from strtok destruction. | ||
| memset(&(cpu_set->__bits), 0, sizeof(cpu_set->__bits)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: directly accessing __bits field breaks encapsulation - use CPU_ZERO(cpu_set) instead
| memset(&(cpu_set->__bits), 0, sizeof(cpu_set->__bits)); | |
| CPU_ZERO(cpu_set); |
a5b54e4 to
9df92f3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, no comments
9df92f3 to
6a9a480
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
src/vma/util/utils.cpp
Outdated
| if (sz > 0) { | ||
| int value; | ||
| c[sz] = '\0'; | ||
| int n = sscanf(reinterpret_cast<const char *>(&c), "%d", &value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: unnecessary cast - c already decays to const char*
| int n = sscanf(reinterpret_cast<const char *>(&c), "%d", &value); | |
| int n = sscanf(c, "%d", &value); |
src/vma/util/sys_vars.cpp
Outdated
| { | ||
| int ret; | ||
| char* start = strdup(orig_start); // save the caller string from strtok destruction. | ||
| CPU_ZERO(cpu_set); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: CPU_ZERO will be called again in hex_to_cpuset or list_to_cpuset - move this call to after the "-1" check to avoid redundant operation
| CPU_ZERO(cpu_set); | |
| int len = strlen(orig_start); | |
| if (len == 2 && orig_start[0] == '-' && orig_start[1] == '1') { | |
| CPU_ZERO(cpu_set); | |
| return 0; | |
| } |
6a9a480 to
5a1dd09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, no comments
5a1dd09 to
8883af9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, no comments
Description
The changes is required to run the code compiled with ASAN. The problem is that both ASAN and libvma override libc standard functions and during initialization process some kind of "racing conditions" is possible. Function
read_file_to_intmost probably, has false-positive alert, but functionenv_to_cpusetis not. The default value-1is passed to fromenv_to_cpusettolist_to_cpusetfunction, which can't parse it correctly.What
Fix ASAN problems.
Why ?
ASAN can help to debug memory problems in some cases much more efficient, than e.g. valgrind.
Change type
What kind of change does this PR introduce?
Check list