13e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm/* libunwind - a platform-independent unwind library 23e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm Copyright (C) 2004 Hewlett-Packard Co 33e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 43e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 53e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmThis file is part of libunwind. 63e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 73e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmPermission is hereby granted, free of charge, to any person obtaining 83e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidma copy of this software and associated documentation files (the 93e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm"Software"), to deal in the Software without restriction, including 103e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmwithout limitation the rights to use, copy, modify, merge, publish, 113e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmdistribute, sublicense, and/or sell copies of the Software, and to 123e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmpermit persons to whom the Software is furnished to do so, subject to 133e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmthe following conditions: 143e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 153e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmThe above copyright notice and this permission notice shall be 163e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmincluded in all copies or substantial portions of the Software. 173e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 183e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 193e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 203e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 213e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 223e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 233e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 243e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 253e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 263e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm/* This program creates lots of mappings such that on Linux the 273e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm reading of /proc/PID/maps gets very slow. With proper caching, 283e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm test-ptrace should still run at acceptable speed once 293e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm /proc/PID/maps has been scanned. If the program dies with a 303e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm SIGALRM, it means it was running unexpectedly slow. */ 313e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 323e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm#include <signal.h> 333e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm#include <stdio.h> 343e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm#include <stdlib.h> 353e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm#include <unistd.h> 363e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 373e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm#include <sys/mman.h> 383e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 39d7f51410753f67c0ae1caa5fbdb428f7718b99ecKonstantin Belousov#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) 40d7f51410753f67c0ae1caa5fbdb428f7718b99ecKonstantin Belousov# define MAP_ANONYMOUS MAP_ANON 41d7f51410753f67c0ae1caa5fbdb428f7718b99ecKonstantin Belousov#endif 42d7f51410753f67c0ae1caa5fbdb428f7718b99ecKonstantin Belousov 433e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidmint 4447a99b6f0007c69959d7d56e52243c1780102d80Tommi Rantalamain (void) 453e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm{ 463e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm long n = 0; 473e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 483e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm signal (SIGUSR1, SIG_IGN); 493e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm signal (SIGUSR2, SIG_IGN); 503e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 513e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm printf ("Starting mmap test...\n"); 523e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm for (n = 0; n < 30000; ++n) 533e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm { 54890e23eb9d3ffd9be2a025189a21794b5ed0e0ffTommi Rantala if (mmap (NULL, 1, (n & 1) ? PROT_READ : PROT_WRITE, 553e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 563e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm -1, 0) == MAP_FAILED) 573e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm { 583e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm printf ("Failed after %ld successful maps\n", n - 1); 593e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm exit (0); 603e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm } 613e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm } 623e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 630fa6b58f5dfdf5dc92707d7029b9d3b190c53faeNurdin Premji alarm (80); /* die if we don't finish in 80 seconds */ 643e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm 653e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm printf ("Turning on single-stepping...\n"); 663e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm kill (getpid (), SIGUSR1); /* tell test-ptrace to start single-stepping */ 673e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm printf ("Va bene?\n"); 683e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm kill (getpid (), SIGUSR2); /* tell test-ptrace to stop single-stepping */ 693e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm printf ("Turned single-stepping off...\n"); 703e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm return 0; 713e718ea00430a1c63819135e848bde86c23f63c8mostang.com!davidm} 72