MCPcopy Create free account
hub / github.com/XpuOS/xsched / FindFileNameFromAddress

Function FindFileNameFromAddress

platforms/hip/hal/src/kernel_param.cpp:28–64  ·  view source on GitHub ↗

Copy from rocclr/hipamd/src/hip_fatbin.cpp

Source from the content-addressed store, hash-verified

26
27// Copy from rocclr/hipamd/src/hip_fatbin.cpp
28static bool FindFileNameFromAddress(const void *image, std::string *fname_ptr, size_t *foffset_ptr)
29{
30 // Get the list of mapped file list
31 bool ret_value = false;
32 std::ifstream proc_maps;
33 proc_maps.open("/proc/self/maps", std::ifstream::in);
34 if (!proc_maps.is_open() || !proc_maps.good()) return ret_value;
35
36 // For every line on the list map find out low, high address
37 std::string line;
38 while (std::getline(proc_maps, line)) {
39 char dash;
40 std::stringstream tokens(line);
41 uintptr_t low_address, high_address;
42 tokens >> std::hex >> low_address >> std::dec >> dash >> std::hex >> high_address >> std::dec;
43 if (dash != '-') continue;
44
45 // If address is > low_address and < high_address, then this
46 // is the mapped file. Get the URI path and offset.
47 uintptr_t address = reinterpret_cast<uintptr_t>(image);
48 if ((address >= low_address) && (address < high_address)) {
49 std::string permissions, device, uri_file_path;
50 size_t offset;
51 uint64_t inode;
52 tokens >> permissions >> std::hex >> offset >> std::dec >> device >> inode >> uri_file_path;
53
54 if (inode == 0 || uri_file_path.empty()) return ret_value;
55
56 *fname_ptr = uri_file_path;
57 *foffset_ptr = offset + address - low_address;
58 ret_value = true;
59 break;
60 }
61 }
62
63 return ret_value;
64}
65
66// Copy from rocclr/hipamd/src/hip_fatbin.cpp
67static bool GetFileHandle(const char *fname, int *fd_ptr, size_t *sz_ptr)

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected