Skip to content
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

fix:148解析错误 #156

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion tools/kallsym.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,37 @@ static void *memmem(const void *haystack, size_t haystack_len, const void *const
}
#endif

//copy from https://github.com/gcc-mirror/gcc/blob/master/libiberty/memmem.c
static /* Return the first occurrence of NEEDLE in HAYSTACK. */
void *
gcc_libc_memmem (const void *haystack, size_t haystack_len, const void *needle,
size_t needle_len)
{
const char *begin;
const char *const last_possible
= (const char *) haystack + haystack_len - needle_len;

if (needle_len == 0)
/* The first occurrence of the empty string is deemed to occur at
the beginning of the string. */
return (void *) haystack;

/* Sanity check, otherwise the loop might search through the whole
memory. */
if (__builtin_expect (haystack_len < needle_len, 0))
return NULL;

for (begin = (const char *) haystack; begin <= last_possible; ++begin)
if (begin[0] == ((const char *) needle)[0] &&
!memcmp ((const void *) &begin[1],
(const void *) ((const char *) needle + 1),
needle_len - 1))
return (void *) begin;

return NULL;
}
void *(*memmem_ptr)(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len);

static int find_linux_banner(kallsym_t *info, char *img, int32_t imglen)
{
/*
Expand All @@ -58,13 +89,22 @@ static int find_linux_banner(kallsym_t *info, char *img, int32_t imglen)
char *imgend = img + imglen;
char *banner = (char *)img;
info->banner_num = 0;
while ((banner = (char *)memmem(banner + 1, imgend - banner, linux_banner_prefix, prefix_len)) != NULL) {

memmem_ptr = memmem;
#ifdef __ANDROID__
memmem_ptr = gcc_libc_memmem;
#endif
while ((banner = (char *)memmem_ptr(banner + 1, imgend - banner, linux_banner_prefix, prefix_len)) != NULL) {
if (isdigit(*(banner + prefix_len)) && *(banner + prefix_len + 1) == '.') {
info->linux_banner_offset[info->banner_num++] = (int32_t)(banner - img);
tools_logi("linux_banner %d: %s", info->banner_num, banner);
tools_logi("linux_banner offset: 0x%lx\n", banner - img);
}
}
if(info->banner_num<=0) {
tools_loge("find linux_banner error\n");
return -1;
}
banner = img + info->linux_banner_offset[info->banner_num - 1];

char *uts_release_start = banner + prefix_len;
Expand Down
Loading