* nscd/mem.c (gc): Use alloca_count to get the real stack usage.
	* include/alloca.h (alloca_account): Define.
	* sysdeps/x86_64/stackinfo.h (stackinfo_get_sp): Define.
	(stackinfo_sub_sp): Define.
This commit is contained in:
Ulrich Drepper 2009-01-29 00:17:57 +00:00
parent 31d322a214
commit fd537e535f
4 changed files with 38 additions and 14 deletions

View File

@ -1,5 +1,11 @@
2009-01-28 Ulrich Drepper <drepper@redhat.com> 2009-01-28 Ulrich Drepper <drepper@redhat.com>
[BZ #9750]
* nscd/mem.c (gc): Use alloca_count to get the real stack usage.
* include/alloca.h (alloca_account): Define.
* sysdeps/x86_64/stackinfo.h (stackinfo_get_sp): Define.
(stackinfo_sub_sp): Define.
* nscd/connections.c (nscd_init): If database file access be * nscd/connections.c (nscd_init): If database file access be
opened check whether this is due to permission problems and bail opened check whether this is due to permission problems and bail
in that case. in that case.

View File

@ -46,4 +46,17 @@ extern int __libc_alloca_cutoff (size_t size) __attribute__ ((const));
__alloca (((len) = (newlen))) __alloca (((len) = (newlen)))
#endif #endif
#if defined stackinfo_get_sp && defined stackinfo_sub_sp
# define alloca_account(size, avar) \
({ void *old__ = stackinfo_get_sp (); \
void *m__ = __alloca (size); \
avar += stackinfo_sub_sp (old__); \
m__; })
#else
# define alloca_account(size, avar) \
({ size_t s__ = (size); \
avar += size__; \
__alloca (size__); })
#endif
#endif #endif

View File

@ -134,12 +134,11 @@ gc (struct database_dyn *db)
stack_used = 0; stack_used = 0;
size_t nmark = (db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS; size_t nmark = (db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS;
size_t memory_needed = nmark * sizeof (BITMAP_T); size_t memory_needed = nmark * sizeof (BITMAP_T);
if (stack_used + memory_needed <= MAX_STACK_USE) if (__builtin_expect (stack_used + memory_needed <= MAX_STACK_USE, 1))
{ {
mark = (BITMAP_T *) alloca (memory_needed); mark = (BITMAP_T *) alloca_account (memory_needed, stack_used);
mark_use_malloc = false; mark_use_malloc = false;
memset (mark, '\0', memory_needed); memset (mark, '\0', memory_needed);
stack_used += memory_needed;
} }
else else
{ {
@ -153,19 +152,17 @@ gc (struct database_dyn *db)
struct hashentry **he; struct hashentry **he;
struct hashentry **he_data; struct hashentry **he_data;
bool he_use_malloc; bool he_use_malloc;
if (stack_used + memory_needed <= MAX_STACK_USE) if (__builtin_expect (stack_used + memory_needed <= MAX_STACK_USE, 1))
{ {
he = alloca (db->head->nentries * sizeof (struct hashentry *)); he = alloca_account (memory_needed, stack_used);
he_data = alloca (db->head->nentries * sizeof (struct hashentry *));
he_use_malloc = false; he_use_malloc = false;
stack_used += memory_needed;
} }
else else
{ {
he = xmalloc (memory_needed); he = xmalloc (memory_needed);
he_data = &he[db->head->nentries];
he_use_malloc = true; he_use_malloc = true;
} }
he_data = &he[db->head->nentries];
size_t cnt = 0; size_t cnt = 0;
for (size_t idx = 0; idx < db->head->module; ++idx) for (size_t idx = 0; idx < db->head->module; ++idx)
@ -373,11 +370,9 @@ gc (struct database_dyn *db)
ref_t disp = off_alloc - off_free; ref_t disp = off_alloc - off_free;
struct moveinfo *new_move; struct moveinfo *new_move;
if (stack_used + sizeof (*new_move) <= MAX_STACK_USE) if (__builtin_expect (stack_used + sizeof (*new_move) <= MAX_STACK_USE,
{ 1))
new_move = alloca (sizeof (*new_move)); new_move = alloca_account (sizeof (*new_move), stack_used);
stack_used += sizeof (*new_move);
}
else else
new_move = obstack_alloc (&ob, sizeof (*new_move)); new_move = obstack_alloc (&ob, sizeof (*new_move));
new_move->from = db->data + off_alloc; new_move->from = db->data + off_alloc;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2001 Free Software Foundation, Inc. /* Copyright (C) 2001, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or The GNU C Library is free software; you can redistribute it and/or
@ -25,4 +25,14 @@
/* On x86_64 the stack grows down. */ /* On x86_64 the stack grows down. */
#define _STACK_GROWS_DOWN 1 #define _STACK_GROWS_DOWN 1
/* Access to the stack pointer. The macros are used in alloca_account
for which they need to act as barriers as well, hence the additional
(unnecessary) parameters. */
#define stackinfo_get_sp() \
({ void *p__; asm volatile ("mov %%rsp, %0" : "=r" (p__)); p__; })
#define stackinfo_sub_sp(ptr) \
({ ptrdiff_t d__; \
asm volatile ("sub %%rsp, %0" : "=r" (d__) : "0" (ptr)); \
d__; })
#endif /* stackinfo.h */ #endif /* stackinfo.h */