|
2 | 2 |
|
3 | 3 | #define _GNU_SOURCE
|
4 | 4 | #include "../kselftest_harness.h"
|
| 5 | +#include <fcntl.h> |
5 | 6 | #include <stdio.h>
|
6 | 7 | #include <stdlib.h>
|
7 | 8 | #include <unistd.h>
|
8 | 9 | #include <sys/mman.h>
|
| 10 | +#include <sys/syscall.h> |
9 | 11 | #include <sys/wait.h>
|
| 12 | +#include <linux/perf_event.h> |
10 | 13 | #include "vm_util.h"
|
11 | 14 |
|
12 | 15 | FIXTURE(merge)
|
@@ -452,4 +455,44 @@ TEST_F(merge, forked_source_vma)
|
452 | 455 | ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr2 + 5 * page_size);
|
453 | 456 | }
|
454 | 457 |
|
| 458 | +TEST_F(merge, handle_uprobe_upon_merged_vma) |
| 459 | +{ |
| 460 | + const size_t attr_sz = sizeof(struct perf_event_attr); |
| 461 | + unsigned int page_size = self->page_size; |
| 462 | + const char *probe_file = "./foo"; |
| 463 | + char *carveout = self->carveout; |
| 464 | + struct perf_event_attr attr; |
| 465 | + unsigned long type; |
| 466 | + void *ptr1, *ptr2; |
| 467 | + int fd; |
| 468 | + |
| 469 | + fd = open(probe_file, O_RDWR|O_CREAT, 0600); |
| 470 | + ASSERT_GE(fd, 0); |
| 471 | + |
| 472 | + ASSERT_EQ(ftruncate(fd, page_size), 0); |
| 473 | + ASSERT_EQ(read_sysfs("/sys/bus/event_source/devices/uprobe/type", &type), 0); |
| 474 | + |
| 475 | + memset(&attr, 0, attr_sz); |
| 476 | + attr.size = attr_sz; |
| 477 | + attr.type = type; |
| 478 | + attr.config1 = (__u64)(long)probe_file; |
| 479 | + attr.config2 = 0x0; |
| 480 | + |
| 481 | + ASSERT_GE(syscall(__NR_perf_event_open, &attr, 0, -1, -1, 0), 0); |
| 482 | + |
| 483 | + ptr1 = mmap(&carveout[page_size], 10 * page_size, PROT_EXEC, |
| 484 | + MAP_PRIVATE | MAP_FIXED, fd, 0); |
| 485 | + ASSERT_NE(ptr1, MAP_FAILED); |
| 486 | + |
| 487 | + ptr2 = mremap(ptr1, page_size, 2 * page_size, |
| 488 | + MREMAP_MAYMOVE | MREMAP_FIXED, ptr1 + 5 * page_size); |
| 489 | + ASSERT_NE(ptr2, MAP_FAILED); |
| 490 | + |
| 491 | + ASSERT_NE(mremap(ptr2, page_size, page_size, |
| 492 | + MREMAP_MAYMOVE | MREMAP_FIXED, ptr1), MAP_FAILED); |
| 493 | + |
| 494 | + close(fd); |
| 495 | + remove(probe_file); |
| 496 | +} |
| 497 | + |
455 | 498 | TEST_HARNESS_MAIN
|
0 commit comments