| 677 | static bool _in_parse_libraries = false; |
| 678 | |
| 679 | void Symbols::parseKernelSymbols(CodeCache* cc) { |
| 680 | int fd; |
| 681 | if (FdTransferClient::hasPeer()) { |
| 682 | fd = FdTransferClient::requestKallsymsFd(); |
| 683 | } else { |
| 684 | fd = open("/proc/kallsyms", O_RDONLY); |
| 685 | } |
| 686 | |
| 687 | if (fd == -1) { |
| 688 | Log::warn("open(\"/proc/kallsyms\"): %s", strerror(errno)); |
| 689 | return; |
| 690 | } |
| 691 | |
| 692 | FILE* f = fdopen(fd, "r"); |
| 693 | if (f == NULL) { |
| 694 | Log::warn("fdopen(): %s", strerror(errno)); |
| 695 | close(fd); |
| 696 | return; |
| 697 | } |
| 698 | |
| 699 | char str[256]; |
| 700 | while (fgets(str, sizeof(str) - 8, f) != NULL) { |
| 701 | size_t len = strlen(str) - 1; // trim the '\n' |
| 702 | strcpy(str + len, "_[k]"); |
| 703 | |
| 704 | SymbolDesc symbol(str); |
| 705 | char type = symbol.type(); |
| 706 | if (type == 'T' || type == 't' || type == 'W' || type == 'w') { |
| 707 | const char* addr = symbol.addr(); |
| 708 | if (addr != NULL) { |
| 709 | if (!_have_kernel_symbols) { |
| 710 | if (strncmp(symbol.name(), "__LOAD_PHYSICAL_ADDR", 20) == 0 || |
| 711 | strncmp(symbol.name(), "phys_startup", 12) == 0) { |
| 712 | continue; |
| 713 | } |
| 714 | _have_kernel_symbols = true; |
| 715 | } |
| 716 | cc->add(addr, 0, symbol.name()); |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | fclose(f); |
| 722 | } |
| 723 | |
| 724 | static void collectSharedLibraries(std::unordered_map<u64, SharedLibrary>& libs, int max_count) { |
| 725 | FILE* f = fopen("/proc/self/maps", "r"); |