Bug 422055 Remove alloca() call patch by Jason Evans a=mtschrep

This commit is contained in:
ginn.chen@sun.com 2008-05-07 22:36:40 -07:00
Родитель b38f2da754
Коммит d246dd1470
1 изменённых файлов: 13 добавлений и 22 удалений

Просмотреть файл

@ -211,7 +211,6 @@
#define STDERR_FILENO 2 #define STDERR_FILENO 2
#define PATH_MAX MAX_PATH #define PATH_MAX MAX_PATH
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#define alloca _alloca
#define assert(f) /* we can't assert in the CRT */ #define assert(f) /* we can't assert in the CRT */
static unsigned long tlsIndex = 0xffffffff; static unsigned long tlsIndex = 0xffffffff;
@ -3978,35 +3977,27 @@ isalloc_validate(const void *ptr)
if (chunk != ptr) { if (chunk != ptr) {
arena_t *arena; arena_t *arena;
unsigned i; unsigned i;
arena_t **arenas_snapshot = alloca(narenas * sizeof(arena_t*));
if (narenas == 1) { if (narenas > 1) {
/* /*
* Don't bother with the more expensive snapshotting * Use arenas_lock as a memory barrier in order to
* algorithm here, since there is only one arena, and * force an update of this processor's cache, so that
* there are no race conditions that allow arenas[0] to * the arenas vector is sufficiently current for us to
* be stale on this processor under any conditions that * be sure of searching all the arenas that existed
* even remotely resemble normal program behavior. * when ptr was allocated.
*/ *
arenas_snapshot[0] = arenas[0]; * Only do this when using multiple arenas, since when
} else { * there is only one arena, there are no race
/* * conditions that allow arenas[0] to be stale on this
* Make a copy of the arenas vector while holding * processor under any conditions that even remotely
* arenas_lock in order to assure that all elements are * resemble normal program behavior.
* up to date in this processor's cache. Do this
* outside the following loop in order to reduce lock
* acquisitions.
*/ */
malloc_spin_lock(&arenas_lock); malloc_spin_lock(&arenas_lock);
memcpy(&arenas_snapshot, arenas, sizeof(arena_t *) *
narenas);
malloc_spin_unlock(&arenas_lock); malloc_spin_unlock(&arenas_lock);
} }
/* Region. */
for (i = 0; i < narenas; i++) { for (i = 0; i < narenas; i++) {
arena = arenas_snapshot[i]; arena = arenas[i];
if (arena != NULL) { if (arena != NULL) {
/* Make sure ptr is within a chunk. */ /* Make sure ptr is within a chunk. */
malloc_spin_lock(&arena->lock); malloc_spin_lock(&arena->lock);