| 22 | namespace dmCrash |
| 23 | { |
| 24 | void SetLoadAddrs(AppState* state) |
| 25 | { |
| 26 | FILE *fp = fopen("/proc/self/smaps", "rt"); |
| 27 | if (!fp) |
| 28 | { |
| 29 | dmLogWarning("Could not read /proc/self/smaps"); |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | int count = 0; |
| 34 | char line[1024]; |
| 35 | while (fgets(line, sizeof(line), fp)) |
| 36 | { |
| 37 | // example line, extract address and name of all module lines |
| 38 | // |
| 39 | // b6f54000-b6f55000 rw-p 00001000 b3:17 3478 /system/lib/libsigchain.so |
| 40 | int len = strlen(line); |
| 41 | int addr_break = len; |
| 42 | int perm_start = len; |
| 43 | int name_start = len; |
| 44 | for (int i=0;i<len;i++) |
| 45 | { |
| 46 | if (addr_break == len) |
| 47 | { |
| 48 | if (line[i] == '-') |
| 49 | addr_break = i; |
| 50 | } |
| 51 | else if (perm_start == len) |
| 52 | { |
| 53 | if (line[i] == ' ') |
| 54 | perm_start = i+1; |
| 55 | } |
| 56 | else |
| 57 | { |
| 58 | // pick the last / |
| 59 | if (line[i] == '/') |
| 60 | name_start = i + 1; |
| 61 | } |
| 62 | |
| 63 | if (line[i] == '\n') |
| 64 | line[i] = 0; |
| 65 | } |
| 66 | |
| 67 | if (addr_break < len && perm_start < len && name_start < len) |
| 68 | { |
| 69 | bool is_exec = false; |
| 70 | for (int p=perm_start;p<(perm_start+4) && p<len;p++) |
| 71 | { |
| 72 | if (line[p] == 'x') |
| 73 | { |
| 74 | is_exec = true; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (!is_exec) |
| 79 | { |
| 80 | continue; |
| 81 | } |
nothing calls this directly
no test coverage detected