MCPcopy Create free account
hub / github.com/F-Stack/f-stack / memtest_test_linux_anonymous_maps

Function memtest_test_linux_anonymous_maps

app/redis-6.2.6/src/debug.c:1647–1706  ·  view source on GitHub ↗

A non destructive memory test executed during segfault. */

Source from the content-addressed store, hash-verified

1645
1646/* A non destructive memory test executed during segfault. */
1647int memtest_test_linux_anonymous_maps(void) {
1648 FILE *fp;
1649 char line[1024];
1650 char logbuf[1024];
1651 size_t start_addr, end_addr, size;
1652 size_t start_vect[MEMTEST_MAX_REGIONS];
1653 size_t size_vect[MEMTEST_MAX_REGIONS];
1654 int regions = 0, j;
1655
1656 int fd = openDirectLogFiledes();
1657 if (!fd) return 0;
1658
1659 fp = fopen("/proc/self/maps","r");
1660 if (!fp) return 0;
1661 while(fgets(line,sizeof(line),fp) != NULL) {
1662 char *start, *end, *p = line;
1663
1664 start = p;
1665 p = strchr(p,'-');
1666 if (!p) continue;
1667 *p++ = '\0';
1668 end = p;
1669 p = strchr(p,' ');
1670 if (!p) continue;
1671 *p++ = '\0';
1672 if (strstr(p,"stack") ||
1673 strstr(p,"vdso") ||
1674 strstr(p,"vsyscall")) continue;
1675 if (!strstr(p,"00:00")) continue;
1676 if (!strstr(p,"rw")) continue;
1677
1678 start_addr = strtoul(start,NULL,16);
1679 end_addr = strtoul(end,NULL,16);
1680 size = end_addr-start_addr;
1681
1682 start_vect[regions] = start_addr;
1683 size_vect[regions] = size;
1684 snprintf(logbuf,sizeof(logbuf),
1685 "*** Preparing to test memory region %lx (%lu bytes)\n",
1686 (unsigned long) start_vect[regions],
1687 (unsigned long) size_vect[regions]);
1688 if (write(fd,logbuf,strlen(logbuf)) == -1) { /* Nothing to do. */ }
1689 regions++;
1690 }
1691
1692 int errors = 0;
1693 for (j = 0; j < regions; j++) {
1694 if (write(fd,".",1) == -1) { /* Nothing to do. */ }
1695 errors += memtest_preserving_test((void*)start_vect[j],size_vect[j],1);
1696 if (write(fd, errors ? "E" : "O",1) == -1) { /* Nothing to do. */ }
1697 }
1698 if (write(fd,"\n",1) == -1) { /* Nothing to do. */ }
1699
1700 /* NOTE: It is very important to close the file descriptor only now
1701 * because closing it before may result into unmapping of some memory
1702 * region that we are testing. */
1703 fclose(fp);
1704 closeDirectLogFiledes(fd);

Callers 1

doFastMemoryTestFunction · 0.85

Calls 8

openDirectLogFiledesFunction · 0.85
strchrFunction · 0.85
strstrFunction · 0.85
strtoulFunction · 0.85
snprintfFunction · 0.85
memtest_preserving_testFunction · 0.85
closeDirectLogFiledesFunction · 0.85
writeFunction · 0.70

Tested by

no test coverage detected