Skip to content

Commit ba50b97

Browse files
lucifer1004claudeHarry-Chen
authored
[Bugfix] Match the mapped filename in find_loaded_library (#47586)
Signed-off-by: Zihua Wu <13583761+lucifer1004@users.noreply.github.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Shengqi Chen <harry-chen@outlook.com>
1 parent b4cfbc2 commit ba50b97

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

vllm/utils/system_utils.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,26 @@ def set_ulimit(target_soft_limit: int = 65535):
308308

309309
def find_loaded_library(lib_name: str) -> str | None:
310310
"""
311-
According to according to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
311+
According to https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html,
312312
the file `/proc/self/maps` contains the memory maps of the process, which includes the
313313
shared libraries loaded by the process. We can use this file to find the path of the
314314
loaded library.
315315
""" # noqa
316-
found_line = None
316+
# Match the mapped file's name, not the whole line: an unrelated library
317+
# whose name merely contains lib_name (e.g. TileLang's libcudart_stub.so
318+
# when looking for libcudart) or a directory component containing it must
319+
# not win. Legitimate filenames are {lib_name}.so[.*] or a name-mangled
320+
# {lib_name}-<hash>.so[.*], and /proc/self/maps is ordered by mapping
321+
# address rather than load order, so a substring hit is a
322+
# nondeterministic hijack.
317323
with open("/proc/self/maps") as f:
318324
for line in f:
319-
if lib_name in line:
320-
found_line = line
321-
break
322-
if found_line is None:
323-
# the library is not loaded in the current process
324-
return None
325-
# if lib_name is libcudart, we need to match a line with:
326-
# address /path/to/libcudart-hash.so.11.0
327-
start = found_line.index("/")
328-
path = found_line[start:].strip()
329-
filename = path.split("/")[-1]
330-
assert filename.rpartition(".so")[0].startswith(lib_name), (
331-
f"Unexpected filename: {filename} for library {lib_name}"
332-
)
333-
return path
325+
start = line.find("/")
326+
if start == -1:
327+
continue
328+
path = line[start:].strip()
329+
filename = path.rsplit("/", maxsplit=1)[-1]
330+
if filename.startswith((f"{lib_name}.", f"{lib_name}-")):
331+
return path
332+
# the library is not loaded in the current process
333+
return None

0 commit comments

Comments
 (0)