ret = __pagemap_scan_get_categories(fd, start, &r); if (ret < 0)
ksft_exit_fail_msg("PAGEMAP_SCAN failed: %s\n", strerror(errno)); if (ret == 0) return 0; return r.categories;
}
/* `start` is any valid address. */ staticbool pagemap_scan_supported(int fd, char *start)
{ staticint supported = -1; int ret;
if (supported != -1) return supported;
/* Provide an invalid address in order to trigger EFAULT. */
ret = __pagemap_scan_get_categories(fd, start, (struct page_region *) ~0UL); if (ret == 0)
ksft_exit_fail_msg("PAGEMAP_SCAN succeeded unexpectedly\n");
ret = snprintf(addr_pattern, MAX_LINE_LENGTH, "%08lx-",
(unsignedlong) addr); if (ret >= MAX_LINE_LENGTH)
ksft_exit_fail_msg("%s: Pattern is too long\n", __func__);
fp = fopen(SMAP_FILE_PATH, "r"); if (!fp)
ksft_exit_fail_msg("%s: Failed to open file %s\n", __func__, SMAP_FILE_PATH);
if (!check_for_pattern(fp, addr_pattern, buf, len)) goto err_out;
/* Fetch the pattern in the same block */ if (!check_for_pattern(fp, pattern, buf, len)) goto err_out;
/* Trim trailing newline */
entry = strchr(buf, '\n'); if (entry)
*entry = '\0';
/* If `ioctls' non-NULL, the allowed ioctls will be returned into the var */ int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls)
{ struct uffdio_register uffdio_register = { 0 };
uint64_t mode = 0; int ret = 0;
if (miss)
mode |= UFFDIO_REGISTER_MODE_MISSING; if (wp)
mode |= UFFDIO_REGISTER_MODE_WP; if (minor)
mode |= UFFDIO_REGISTER_MODE_MINOR;
/* New mappings are expected to be marked with VM_SOFTDIRTY (sd). */
addr = mmap(0, pagesize, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); if (!addr)
ksft_exit_fail_msg("mmap failed\n");
/* * Open an fd at /proc/$pid/maps and configure procmap_out ready for * PROCMAP_QUERY query. Returns 0 on success, or an error code otherwise.
*/ int open_procmap(pid_t pid, struct procmap_fd *procmap_out)
{ char path[256]; int ret = 0;
memset(procmap_out, '\0', sizeof(*procmap_out));
sprintf(path, "/proc/%d/maps", pid);
procmap_out->query.size = sizeof(procmap_out->query);
procmap_out->fd = open(path, O_RDONLY); if (procmap_out->fd < 0)
ret = -errno;
return ret;
}
/* Perform PROCMAP_QUERY. Returns 0 on success, or an error code otherwise. */ int query_procmap(struct procmap_fd *procmap)
{ int ret = 0;
if (ioctl(procmap->fd, PROCMAP_QUERY, &procmap->query) == -1)
ret = -errno;
return ret;
}
/* * Try to find the VMA at specified address, returns true if found, false if not * found, and the test is failed if any other error occurs. * * On success, procmap->query is populated with the results.
*/ bool find_vma_procmap(struct procmap_fd *procmap, void *address)
{ int err;
if (err != -ENOENT)
ksft_exit_fail_msg("%s: Error %d on ioctl(PROCMAP_QUERY)\n",
__func__, err); returnfalse;
}
/* * Close fd used by PROCMAP_QUERY mechanism. Returns 0 on success, or an error * code otherwise.
*/ int close_procmap(struct procmap_fd *procmap)
{ return close(procmap->fd);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.