A non destructive memory test executed during segfault. */
| 1863 | |
| 1864 | /* A non destructive memory test executed during segfault. */ |
| 1865 | int memtest_test_linux_anonymous_maps(void) { |
| 1866 | FILE *fp; |
| 1867 | char line[1024]; |
| 1868 | char logbuf[1024]; |
| 1869 | size_t start_addr, end_addr, size; |
| 1870 | size_t start_vect[MEMTEST_MAX_REGIONS]; |
| 1871 | size_t size_vect[MEMTEST_MAX_REGIONS]; |
| 1872 | int regions = 0, j; |
| 1873 | |
| 1874 | int fd = openDirectLogFiledes(); |
| 1875 | if (!fd) return 0; |
| 1876 | |
| 1877 | fp = fopen("/proc/self/maps","r"); |
| 1878 | if (!fp) return 0; |
| 1879 | while(fgets(line,sizeof(line),fp) != NULL) { |
| 1880 | char *start, *end, *p = line; |
| 1881 | |
| 1882 | start = p; |
| 1883 | p = strchr(p,'-'); |
| 1884 | if (!p) continue; |
| 1885 | *p++ = '\0'; |
| 1886 | end = p; |
| 1887 | p = strchr(p,' '); |
| 1888 | if (!p) continue; |
| 1889 | *p++ = '\0'; |
| 1890 | if (strstr(p,"stack") || |
| 1891 | strstr(p,"vdso") || |
| 1892 | strstr(p,"vsyscall")) continue; |
| 1893 | if (!strstr(p,"00:00")) continue; |
| 1894 | if (!strstr(p,"rw")) continue; |
| 1895 | |
| 1896 | start_addr = strtoul(start,NULL,16); |
| 1897 | end_addr = strtoul(end,NULL,16); |
| 1898 | size = end_addr-start_addr; |
| 1899 | |
| 1900 | start_vect[regions] = start_addr; |
| 1901 | size_vect[regions] = size; |
| 1902 | snprintf(logbuf,sizeof(logbuf), |
| 1903 | "*** Preparing to test memory region %lx (%lu bytes)\n", |
| 1904 | (unsigned long) start_vect[regions], |
| 1905 | (unsigned long) size_vect[regions]); |
| 1906 | if (write(fd,logbuf,strlen(logbuf)) == -1) { /* Nothing to do. */ } |
| 1907 | regions++; |
| 1908 | } |
| 1909 | |
| 1910 | int errors = 0; |
| 1911 | for (j = 0; j < regions; j++) { |
| 1912 | if (write(fd,".",1) == -1) { /* Nothing to do. */ } |
| 1913 | errors += memtest_preserving_test((unsigned long*)start_vect[j],size_vect[j],1); |
| 1914 | if (write(fd, errors ? "E" : "O",1) == -1) { /* Nothing to do. */ } |
| 1915 | } |
| 1916 | if (write(fd,"\n",1) == -1) { /* Nothing to do. */ } |
| 1917 | |
| 1918 | /* NOTE: It is very important to close the file descriptor only now |
| 1919 | * because closing it before may result into unmapping of some memory |
| 1920 | * region that we are testing. */ |
| 1921 | fclose(fp); |
| 1922 | closeDirectLogFiledes(fd); |
no test coverage detected