2 * Copyright 2001-2003 Ximian, Inc
3 * Copyright 2003-2010 Novell, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #define PIN_STAGING_AREA_SIZE 1024
26 static void* pin_staging_area [PIN_STAGING_AREA_SIZE];
27 static int pin_staging_area_index;
32 pin_staging_area_index = 0;
36 evacuate_pin_staging_area (void)
40 g_assert (pin_staging_area_index >= 0 && pin_staging_area_index <= PIN_STAGING_AREA_SIZE);
42 if (pin_staging_area_index == 0)
46 * The pinning addresses might come from undefined memory, this is normal. Since they
47 * are used in lots of functions, we make the memory defined here instead of having
48 * to add a supression for those functions.
50 VALGRIND_MAKE_MEM_DEFINED (pin_staging_area, pin_staging_area_index * sizeof (void*));
52 sort_addresses (pin_staging_area, pin_staging_area_index);
54 while (next_pin_slot + pin_staging_area_index > pin_queue_size)
57 pin_queue [next_pin_slot++] = pin_staging_area [0];
58 for (i = 1; i < pin_staging_area_index; ++i) {
59 void *p = pin_staging_area [i];
60 if (p != pin_queue [next_pin_slot - 1])
61 pin_queue [next_pin_slot++] = p;
64 g_assert (next_pin_slot <= pin_queue_size);
66 pin_staging_area_index = 0;
70 pin_stage_ptr (void *ptr)
72 if (pin_staging_area_index >= PIN_STAGING_AREA_SIZE)
73 evacuate_pin_staging_area ();
75 pin_staging_area [pin_staging_area_index++] = ptr;