find-vdso-map.c 581 B

12345678910111213141516171819202122232425262728293031
  1. static int find_vdso_map(void **start, void **end)
  2. {
  3. FILE *maps;
  4. char line[128];
  5. int found = 0;
  6. maps = fopen("/proc/self/maps", "r");
  7. if (!maps) {
  8. fprintf(stderr, "vdso: cannot open maps\n");
  9. return -1;
  10. }
  11. while (!found && fgets(line, sizeof(line), maps)) {
  12. int m = -1;
  13. /* We care only about private r-x mappings. */
  14. if (2 != sscanf(line, "%p-%p r-xp %*x %*x:%*x %*u %n",
  15. start, end, &m))
  16. continue;
  17. if (m < 0)
  18. continue;
  19. if (!strncmp(&line[m], VDSO__MAP_NAME,
  20. sizeof(VDSO__MAP_NAME) - 1))
  21. found = 1;
  22. }
  23. fclose(maps);
  24. return !found;
  25. }