find-vdso-map.c 617 B

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