mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
be2a314e45
--HG-- rename : tools/profiler/sps/TableTicker.cpp => tools/profiler/TableTicker.cpp rename : tools/profiler/public/nsIProfiler.idl => tools/profiler/nsIProfiler.idl rename : tools/profiler/sps/platform-linux.cc => tools/profiler/platform-linux.cc rename : tools/profiler/sps/platform-win32.cc => tools/profiler/platform-win32.cc rename : tools/profiler/sps/platform.h => tools/profiler/platform.h rename : tools/profiler/sps/shared-libraries-linux.cc => tools/profiler/shared-libraries-linux.cc rename : tools/profiler/sps/shared-libraries-macos.cc => tools/profiler/shared-libraries-macos.cc rename : tools/profiler/sps/shared-libraries-win32.cc => tools/profiler/shared-libraries-win32.cc rename : tools/profiler/sps/shared-libraries.h => tools/profiler/shared-libraries.h rename : tools/profiler/sps/sps_sampler.h => tools/profiler/sps_sampler.h rename : tools/profiler/sps/thread_helper.h => tools/profiler/thread_helper.h rename : tools/profiler/sps/v8-support.h => tools/profiler/v8-support.h
66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#define PATH_MAX_TOSTRING(x) #x
|
|
#define PATH_MAX_STRING(x) PATH_MAX_TOSTRING(x)
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <limits.h>
|
|
#include <unistd.h>
|
|
#include "platform.h"
|
|
#include "shared-libraries.h"
|
|
|
|
#ifndef __GLIBC__
|
|
/* a crapy version of getline, because it's not included in bionic */
|
|
static ssize_t getline(char **lineptr, size_t *n, FILE *stream)
|
|
{
|
|
char *ret;
|
|
if (!*lineptr) {
|
|
*lineptr = (char*)malloc(4096);
|
|
}
|
|
ret = fgets(*lineptr, 4096, stream);
|
|
if (!ret)
|
|
return 0;
|
|
return strlen(*lineptr);
|
|
}
|
|
#endif
|
|
|
|
SharedLibraryInfo SharedLibraryInfo::GetInfoForSelf()
|
|
{
|
|
pid_t pid = getpid();
|
|
SharedLibraryInfo info;
|
|
char path[PATH_MAX];
|
|
snprintf(path, PATH_MAX, "/proc/%d/maps", pid);
|
|
FILE *maps = fopen(path, "r");
|
|
char *line = NULL;
|
|
int count = 0;
|
|
size_t line_size = 0;
|
|
while (maps && getline (&line, &line_size, maps) > 0) {
|
|
int ret;
|
|
//XXX: needs input sanitizing
|
|
unsigned long start;
|
|
unsigned long end;
|
|
char perm[6] = "";
|
|
unsigned long offset;
|
|
char name[PATH_MAX] = "";
|
|
ret = sscanf(line,
|
|
"%lx-%lx %6s %lx %*s %*x %" PATH_MAX_STRING(PATH_MAX) "s\n",
|
|
&start, &end, perm, &offset, name);
|
|
if (!strchr(perm, 'x')) {
|
|
// Ignore non executable entries
|
|
continue;
|
|
}
|
|
if (ret != 5 && ret != 4) {
|
|
LOG("Get maps line failed");
|
|
continue;
|
|
}
|
|
SharedLibrary shlib(start, end, offset, name);
|
|
info.AddSharedLibrary(shlib);
|
|
if (count > 10000) {
|
|
LOG("Get maps failed");
|
|
break;
|
|
}
|
|
count++;
|
|
}
|
|
free(line);
|
|
return info;
|
|
}
|