Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 223205
Collapse All | Expand All

(-)libc/nscd/aicache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for host lookup.
1
/* Cache handling for host lookup.
2
   Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
2
   Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
5
5
Lines 262-268 addhstaiX (struct database_dyn *db, int fd, request_header *req, Link Here
262
		{
262
		{
263
		  dataset = (struct dataset *) mempool_alloc (db,
263
		  dataset = (struct dataset *) mempool_alloc (db,
264
							      total
264
							      total
265
							      + req->key_len);
265
							      + req->key_len,
266
							      IDX_result_data);
266
		  if (dataset == NULL)
267
		  if (dataset == NULL)
267
		    ++db->head->addfailed;
268
		    ++db->head->addfailed;
268
		}
269
		}
Lines 338-344 addhstaiX (struct database_dyn *db, int fd, request_header *req, Link Here
338
		      struct dataset *newp
339
		      struct dataset *newp
339
			= (struct dataset *) mempool_alloc (db,
340
			= (struct dataset *) mempool_alloc (db,
340
							    total
341
							    total
341
							    + req->key_len);
342
							    + req->key_len,
343
							    IDX_result_data);
342
		      if (__builtin_expect (newp != NULL, 1))
344
		      if (__builtin_expect (newp != NULL, 1))
343
			{
345
			{
344
			  /* Adjust pointer into the memory block.  */
346
			  /* Adjust pointer into the memory block.  */
Lines 424-430 addhstaiX (struct database_dyn *db, int fd, request_header *req, Link Here
424
      if (fd != -1)
426
      if (fd != -1)
425
	TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
427
	TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
426
428
427
      dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
429
      dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
430
			       IDX_result_data);
428
      /* If we cannot permanently store the result, so be it.  */
431
      /* If we cannot permanently store the result, so be it.  */
429
      if (dataset != NULL)
432
      if (dataset != NULL)
430
	{
433
	{
(-)libc/nscd/cache.c (-2 / +11 lines)
Lines 1-4 Link Here
1
/* Copyright (c) 1998, 1999, 2003-2006, 2007 Free Software Foundation, Inc.
1
/* Copyright (c) 1998, 1999, 2003-2007, 2008 Free Software Foundation, Inc.
2
   This file is part of the GNU C Library.
2
   This file is part of the GNU C Library.
3
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
3
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
4
Lines 155-165 cache_add (int type, const void *key, size_t len, struct datahead *packet, Link Here
155
  unsigned long int hash = __nis_hash (key, len) % table->head->module;
155
  unsigned long int hash = __nis_hash (key, len) % table->head->module;
156
  struct hashentry *newp;
156
  struct hashentry *newp;
157
157
158
  newp = mempool_alloc (table, sizeof (struct hashentry));
158
  newp = mempool_alloc (table, sizeof (struct hashentry), IDX_record_data);
159
  /* If we cannot allocate memory, just do not do anything.  */
159
  /* If we cannot allocate memory, just do not do anything.  */
160
  if (newp == NULL)
160
  if (newp == NULL)
161
    {
161
    {
162
      ++table->head->addfailed;
162
      ++table->head->addfailed;
163
164
      /* Mark the in-flight memory as unused.  */
165
      for (enum in_flight idx = 0; idx < IDX_record_data; ++idx)
166
	mem_in_flight.block[idx].dbidx = -1;
167
163
      return -1;
168
      return -1;
164
    }
169
    }
165
170
Lines 215-220 cache_add (int type, const void *key, size_t len, struct datahead *packet, Link Here
215
    else
220
    else
216
      next_wakeup = table->wakeup_time;
221
      next_wakeup = table->wakeup_time;
217
222
223
  /* Mark the in-flight memory as unused.  */
224
  for (enum in_flight idx = 0; idx < IDX_last; ++idx)
225
    mem_in_flight.block[idx].dbidx = -1;
226
218
  return 0;
227
  return 0;
219
}
228
}
220
229
(-)libc/nscd/connections.c (-3 / +44 lines)
Lines 225-230 static int sock; Link Here
225
/* Number of times clients had to wait.  */
225
/* Number of times clients had to wait.  */
226
unsigned long int client_queued;
226
unsigned long int client_queued;
227
227
228
/* Data structure for recording in-flight memory allocation.  */
229
__thread struct mem_in_flight mem_in_flight;
230
/* Global list of the mem_in_flight variables of all the threads.  */
231
struct mem_in_flight *mem_in_flight_list;
232
228
233
229
ssize_t
234
ssize_t
230
writeall (int fd, const void *buf, size_t len)
235
writeall (int fd, const void *buf, size_t len)
Lines 964-970 send_ro_fd (struct database_dyn *db, char *key, int fd) Link Here
964
969
965
/* Handle new request.  */
970
/* Handle new request.  */
966
static void
971
static void
967
handle_request (int fd, request_header *req, void *key, uid_t uid)
972
handle_request (int fd, request_header *req, void *key, uid_t uid, pid_t pid)
968
{
973
{
969
  if (__builtin_expect (req->version, NSCD_VERSION) != NSCD_VERSION)
974
  if (__builtin_expect (req->version, NSCD_VERSION) != NSCD_VERSION)
970
    {
975
    {
Lines 979-985 cannot handle old request version %d; current version is %d"), Link Here
979
  if (selinux_enabled && nscd_request_avc_has_perm (fd, req->type) != 0)
984
  if (selinux_enabled && nscd_request_avc_has_perm (fd, req->type) != 0)
980
    {
985
    {
981
      if (debug_level > 0)
986
      if (debug_level > 0)
982
	dbg_log (_("request not handled due to missing permission"));
987
	{
988
#ifdef SO_PEERCRED
989
# ifdef PATH_MAX
990
	  char buf[PATH_MAX];
991
# else
992
	  char buf[4096];
993
# endif
994
995
	  snprintf (buf, sizeof (buf), "/proc/%ld/exe", (long int) pid);
996
	  ssize_t n = readlink (buf, buf, sizeof (buf) - 1);
997
998
	  if (n <= 0)
999
	    dbg_log (_("\
1000
request from %ld not handled due to missing permission"), (long int) pid);
1001
	  else
1002
	    {
1003
	      buf[n] = '\0';
1004
	      dbg_log (_("\
1005
request from '%s' [%ld] not handled due to missing permission"),
1006
		       buf, (long int) pid);
1007
	    }
1008
#else
1009
	  dbg_log (_("request not handled due to missing permission"));
1010
#endif
1011
	}
983
      return;
1012
      return;
984
    }
1013
    }
985
1014
Lines 1426-1431 nscd_run_worker (void *p) Link Here
1426
{
1455
{
1427
  char buf[256];
1456
  char buf[256];
1428
1457
1458
  /* Initialize the memory-in-flight list.  */
1459
  for (enum in_flight idx = 0; idx < IDX_last; ++idx)
1460
    mem_in_flight.block[idx].dbidx = -1;
1461
  /* And queue this threads structure.  */
1462
  do
1463
    mem_in_flight.next = mem_in_flight_list;
1464
  while (atomic_compare_and_exchange_bool_acq (&mem_in_flight_list,
1465
					       &mem_in_flight,
1466
					       mem_in_flight.next) != 0);
1467
1429
  /* Initial locking.  */
1468
  /* Initial locking.  */
1430
  pthread_mutex_lock (&readylist_lock);
1469
  pthread_mutex_lock (&readylist_lock);
1431
1470
Lines 1491-1496 nscd_run_worker (void *p) Link Here
1491
	  if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &caller, &optlen) == 0)
1530
	  if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &caller, &optlen) == 0)
1492
	    pid = caller.pid;
1531
	    pid = caller.pid;
1493
	}
1532
	}
1533
#else
1534
      const pid_t pid = 0;
1494
#endif
1535
#endif
1495
1536
1496
      /* It should not be possible to crash the nscd with a silly
1537
      /* It should not be possible to crash the nscd with a silly
Lines 1531-1537 handle_request: request received (Version = %d)"), req.version); Link Here
1531
	    }
1572
	    }
1532
1573
1533
	  /* Phew, we got all the data, now process it.  */
1574
	  /* Phew, we got all the data, now process it.  */
1534
	  handle_request (fd, &req, keybuf, uid);
1575
	  handle_request (fd, &req, keybuf, uid, pid);
1535
	}
1576
	}
1536
1577
1537
    close_and_out:
1578
    close_and_out:
(-)libc/nscd/grpcache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for group lookup.
1
/* Cache handling for group lookup.
2
   Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc.
2
   Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
5
Lines 113-119 cache_addgr (struct database_dyn *db, int fd, request_header *req, Link Here
113
	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
113
	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
114
					      MSG_NOSIGNAL));
114
					      MSG_NOSIGNAL));
115
115
116
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
116
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
117
				   IDX_result_data);
117
	  /* If we cannot permanently store the result, so be it.  */
118
	  /* If we cannot permanently store the result, so be it.  */
118
	  if (dataset != NULL)
119
	  if (dataset != NULL)
119
	    {
120
	    {
Lines 204-210 cache_addgr (struct database_dyn *db, int fd, request_header *req, Link Here
204
205
205
      if (he == NULL)
206
      if (he == NULL)
206
	{
207
	{
207
	  dataset = (struct dataset *) mempool_alloc (db, total + n);
208
	  dataset = (struct dataset *) mempool_alloc (db, total + n,
209
						      IDX_result_data);
208
	  if (dataset == NULL)
210
	  if (dataset == NULL)
209
	    ++db->head->addfailed;
211
	    ++db->head->addfailed;
210
	}
212
	}
Lines 274-280 cache_addgr (struct database_dyn *db, int fd, request_header *req, Link Here
274
	      /* We have to create a new record.  Just allocate
276
	      /* We have to create a new record.  Just allocate
275
		 appropriate memory and copy it.  */
277
		 appropriate memory and copy it.  */
276
	      struct dataset *newp
278
	      struct dataset *newp
277
		= (struct dataset *) mempool_alloc (db, total + n);
279
		= (struct dataset *) mempool_alloc (db, total + n,
280
						    IDX_result_data);
278
	      if (newp != NULL)
281
	      if (newp != NULL)
279
		{
282
		{
280
		  /* Adjust pointers into the memory block.  */
283
		  /* Adjust pointers into the memory block.  */
(-)libc/nscd/hstcache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for host lookup.
1
/* Cache handling for host lookup.
2
   Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc.
2
   Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
5
Lines 121-127 cache_addhst (struct database_dyn *db, int fd, request_header *req, Link Here
121
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
121
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
122
						MSG_NOSIGNAL));
122
						MSG_NOSIGNAL));
123
123
124
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
124
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
125
				   IDX_result_data);
125
	  /* If we cannot permanently store the result, so be it.  */
126
	  /* If we cannot permanently store the result, so be it.  */
126
	  if (dataset != NULL)
127
	  if (dataset != NULL)
127
	    {
128
	    {
Lines 226-232 cache_addhst (struct database_dyn *db, int fd, request_header *req, Link Here
226
      if (he == NULL && h_addr_list_cnt == 1)
227
      if (he == NULL && h_addr_list_cnt == 1)
227
	{
228
	{
228
	  dataset = (struct dataset *) mempool_alloc (db,
229
	  dataset = (struct dataset *) mempool_alloc (db,
229
						      total + req->key_len);
230
						      total + req->key_len,
231
						      IDX_result_data);
230
	  if (dataset == NULL)
232
	  if (dataset == NULL)
231
	    ++db->head->addfailed;
233
	    ++db->head->addfailed;
232
	}
234
	}
Lines 312-318 cache_addhst (struct database_dyn *db, int fd, request_header *req, Link Here
312
		     appropriate memory and copy it.  */
314
		     appropriate memory and copy it.  */
313
		  struct dataset *newp
315
		  struct dataset *newp
314
		    = (struct dataset *) mempool_alloc (db,
316
		    = (struct dataset *) mempool_alloc (db,
315
							total + req->key_len);
317
							total + req->key_len,
318
							IDX_result_data);
316
		  if (newp != NULL)
319
		  if (newp != NULL)
317
		    {
320
		    {
318
		      /* Adjust pointers into the memory block.  */
321
		      /* Adjust pointers into the memory block.  */
(-)libc/nscd/initgrcache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for host lookup.
1
/* Cache handling for host lookup.
2
   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
2
   Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
5
5
Lines 197-203 addinitgroupsX (struct database_dyn *db, int fd, request_header *req, Link Here
197
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
197
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
198
						MSG_NOSIGNAL));
198
						MSG_NOSIGNAL));
199
199
200
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
200
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
201
				   IDX_result_data);
201
	  /* If we cannot permanently store the result, so be it.  */
202
	  /* If we cannot permanently store the result, so be it.  */
202
	  if (dataset != NULL)
203
	  if (dataset != NULL)
203
	    {
204
	    {
Lines 259-265 addinitgroupsX (struct database_dyn *db, int fd, request_header *req, Link Here
259
      if (he == NULL)
260
      if (he == NULL)
260
	{
261
	{
261
	  dataset = (struct dataset *) mempool_alloc (db,
262
	  dataset = (struct dataset *) mempool_alloc (db,
262
						      total + req->key_len);
263
						      total + req->key_len,
264
						      IDX_result_data);
263
	  if (dataset == NULL)
265
	  if (dataset == NULL)
264
	    ++db->head->addfailed;
266
	    ++db->head->addfailed;
265
	}
267
	}
Lines 329-335 addinitgroupsX (struct database_dyn *db, int fd, request_header *req, Link Here
329
	      /* We have to create a new record.  Just allocate
331
	      /* We have to create a new record.  Just allocate
330
		 appropriate memory and copy it.  */
332
		 appropriate memory and copy it.  */
331
	      struct dataset *newp
333
	      struct dataset *newp
332
		= (struct dataset *) mempool_alloc (db, total + req->key_len);
334
		= (struct dataset *) mempool_alloc (db, total + req->key_len,
335
						    IDX_result_data);
333
	      if (newp != NULL)
336
	      if (newp != NULL)
334
		{
337
		{
335
		  /* Adjust pointer into the memory block.  */
338
		  /* Adjust pointer into the memory block.  */
(-)libc/nscd/mem.c (-10 / +59 lines)
Lines 1-5 Link Here
1
/* Cache memory handling.
1
/* Cache memory handling.
2
   Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
2
   Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
4
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
5
5
Lines 24-29 Link Here
24
#include <inttypes.h>
24
#include <inttypes.h>
25
#include <libintl.h>
25
#include <libintl.h>
26
#include <limits.h>
26
#include <limits.h>
27
#include <obstack.h>
27
#include <stdlib.h>
28
#include <stdlib.h>
28
#include <string.h>
29
#include <string.h>
29
#include <unistd.h>
30
#include <unistd.h>
Lines 79-84 static void Link Here
79
markrange (BITMAP_T *mark, ref_t start, size_t len)
80
markrange (BITMAP_T *mark, ref_t start, size_t len)
80
{
81
{
81
  /* Adjust parameters for block alignment.  */
82
  /* Adjust parameters for block alignment.  */
83
  assert ((start & BLOCK_ALIGN_M1) == 0);
82
  start /= BLOCK_ALIGN;
84
  start /= BLOCK_ALIGN;
83
  len = (len + BLOCK_ALIGN_M1) / BLOCK_ALIGN;
85
  len = (len + BLOCK_ALIGN_M1) / BLOCK_ALIGN;
84
86
Lines 93-99 markrange (BITMAP_T *mark, ref_t start, size_t len) Link Here
93
	  return;
95
	  return;
94
	}
96
	}
95
97
96
      mark[elem++] |= 0xff << (start % BITS);
98
      mark[elem++] |= ALLBITS << (start % BITS);
97
      len -= BITS - (start % BITS);
99
      len -= BITS - (start % BITS);
98
    }
100
    }
99
101
Lines 130-143 gc (struct database_dyn *db) Link Here
130
  size_t stack_used = sizeof (bool) * db->head->module;
132
  size_t stack_used = sizeof (bool) * db->head->module;
131
  if (__builtin_expect (stack_used > MAX_STACK_USE, 0))
133
  if (__builtin_expect (stack_used > MAX_STACK_USE, 0))
132
    stack_used = 0;
134
    stack_used = 0;
133
  size_t memory_needed = ((db->head->first_free / BLOCK_ALIGN + BITS - 1)
135
  size_t nmark = (db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS;
134
			  / BITS) * sizeof (BITMAP_T);
136
  size_t memory_needed = nmark * sizeof (BITMAP_T);
135
  if (memory_needed <= MAX_STACK_USE)
137
  if (stack_used + memory_needed <= MAX_STACK_USE)
136
    {
138
    {
137
      mark = (BITMAP_T *) alloca (memory_needed);
139
      mark = (BITMAP_T *) alloca (memory_needed);
138
      mark_use_malloc = false;
140
      mark_use_malloc = false;
139
      memset (mark, '\0', memory_needed);
141
      memset (mark, '\0', memory_needed);
140
      stack_used = memory_needed;
142
      stack_used += memory_needed;
141
    }
143
    }
142
  else
144
  else
143
    {
145
    {
Lines 156-161 gc (struct database_dyn *db) Link Here
156
      he = alloca (db->head->nentries * sizeof (struct hashentry *));
158
      he = alloca (db->head->nentries * sizeof (struct hashentry *));
157
      he_data = alloca (db->head->nentries * sizeof (struct hashentry *));
159
      he_data = alloca (db->head->nentries * sizeof (struct hashentry *));
158
      he_use_malloc = false;
160
      he_use_malloc = false;
161
      stack_used += memory_needed;
159
    }
162
    }
160
  else
163
  else
161
    {
164
    {
Lines 197-202 gc (struct database_dyn *db) Link Here
197
    }
200
    }
198
  assert (cnt == db->head->nentries);
201
  assert (cnt == db->head->nentries);
199
202
203
  /* Go through the list of in-flight memory blocks.  */
204
  struct mem_in_flight *mrunp = mem_in_flight_list;
205
  while (mrunp != NULL)
206
    {
207
      /* NB: There can be no race between this test and another thread
208
        setting the field to the index we are looking for because
209
        this would require the other thread to also have the memlock
210
        for the database.
211
212
	NB2: we do not have to look at latter blocks (higher indices) if
213
	earlier blocks are not in flight.  They are always allocated in
214
	sequence.  */
215
      for (enum in_flight idx = IDX_result_data;
216
	   idx < IDX_last && mrunp->block[idx].dbidx == db - dbs; ++idx)
217
	{
218
	  assert (mrunp->block[idx].blockoff >= 0);
219
	  assert (mrunp->block[idx].blocklen < db->memsize);
220
	  assert (mrunp->block[idx].blockoff
221
		  + mrunp->block[0].blocklen <= db->memsize);
222
	  markrange (mark, mrunp->block[idx].blockoff,
223
		     mrunp->block[idx].blocklen);
224
	}
225
226
      mrunp = mrunp->next;
227
    }
228
200
  /* Sort the entries by the addresses of the referenced data.  All
229
  /* Sort the entries by the addresses of the referenced data.  All
201
     the entries pointing to the same DATAHEAD object will have the
230
     the entries pointing to the same DATAHEAD object will have the
202
     same key.  Stability of the sorting is unimportant.  */
231
     same key.  Stability of the sorting is unimportant.  */
Lines 206-213 gc (struct database_dyn *db) Link Here
206
  /* Sort the entries by their address.  */
235
  /* Sort the entries by their address.  */
207
  qsort (he, cnt, sizeof (struct hashentry *), sort_he);
236
  qsort (he, cnt, sizeof (struct hashentry *), sort_he);
208
237
238
#define obstack_chunk_alloc xmalloc
239
#define obstack_chunk_free free
240
  struct obstack ob;
241
  obstack_init (&ob);
242
209
  /* Determine the highest used address.  */
243
  /* Determine the highest used address.  */
210
  size_t high = sizeof (mark);
244
  size_t high = nmark;
211
  while (high > 0 && mark[high - 1] == 0)
245
  while (high > 0 && mark[high - 1] == 0)
212
    --high;
246
    --high;
213
247
Lines 338-345 gc (struct database_dyn *db) Link Here
338
	 displacement.  */
372
	 displacement.  */
339
      ref_t disp = off_alloc - off_free;
373
      ref_t disp = off_alloc - off_free;
340
374
341
      struct moveinfo *new_move
375
      struct moveinfo *new_move;
342
	= (struct moveinfo *) alloca (sizeof (*new_move));
376
      if (stack_used + sizeof (*new_move) <= MAX_STACK_USE)
377
	{
378
	  new_move = alloca (sizeof (*new_move));
379
	  stack_used += sizeof (*new_move);
380
	}
381
      else
382
	new_move = obstack_alloc (&ob, sizeof (*new_move));
343
      new_move->from = db->data + off_alloc;
383
      new_move->from = db->data + off_alloc;
344
      new_move->to = db->data + off_free;
384
      new_move->to = db->data + off_free;
345
      new_move->size = off_allocend - off_alloc;
385
      new_move->size = off_allocend - off_alloc;
Lines 499-509 gc (struct database_dyn *db) Link Here
499
    free (he);
539
    free (he);
500
  if (mark_use_malloc)
540
  if (mark_use_malloc)
501
    free (mark);
541
    free (mark);
542
543
  obstack_free (&ob, NULL);
502
}
544
}
503
545
504
546
505
void *
547
void *
506
mempool_alloc (struct database_dyn *db, size_t len)
548
mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
507
{
549
{
508
  /* Make sure LEN is a multiple of our maximum alignment so we can
550
  /* Make sure LEN is a multiple of our maximum alignment so we can
509
     keep track of used memory is multiples of this alignment value.  */
551
     keep track of used memory is multiples of this alignment value.  */
Lines 564-572 mempool_alloc (struct database_dyn *db, size_t len) Link Here
564
    }
606
    }
565
  else
607
  else
566
    {
608
    {
609
      /* Remember that we have allocated this memory.  */
610
      assert (idx >= 0 && idx < IDX_last);
611
      mem_in_flight.block[idx].dbidx = db - dbs;
612
      mem_in_flight.block[idx].blocklen = len;
613
      mem_in_flight.block[idx].blockoff = db->head->first_free;
614
567
      db->head->first_free += len;
615
      db->head->first_free += len;
568
616
569
      db->last_alloc_failed = false;
617
      db->last_alloc_failed = false;
618
570
    }
619
    }
571
620
572
  pthread_mutex_unlock (&db->memlock);
621
  pthread_mutex_unlock (&db->memlock);
(-)libc/nscd/nscd.h (-1 / +27 lines)
Lines 181-186 extern uid_t old_uid; Link Here
181
extern gid_t old_gid;
181
extern gid_t old_gid;
182
182
183
183
184
/* Memory allocation in flight.  Each thread can have a limited number
185
   of allocation in flight.  No need to create dynamic data
186
   structures.  We use fixed indices.  */
187
enum in_flight
188
  {
189
    IDX_result_data = 0,
190
    /* Keep the IDX_record_data entry last at all times.  */
191
    IDX_record_data = 1,
192
    IDX_last
193
  };
194
extern __thread struct mem_in_flight
195
{
196
  struct
197
  {
198
    int dbidx;
199
    nscd_ssize_t blocklen;
200
    nscd_ssize_t blockoff;
201
  } block[IDX_last];
202
203
  struct mem_in_flight *next;
204
} mem_in_flight;
205
/* Global list of the mem_in_flight variables of all the threads.  */
206
extern struct mem_in_flight *mem_in_flight_list;
207
208
184
/* Prototypes for global functions.  */
209
/* Prototypes for global functions.  */
185
210
186
/* nscd.c */
211
/* nscd.c */
Lines 271-277 extern void readdservbyport (struct database_dyn *db, struct hashentry *he, Link Here
271
			     struct datahead *dh);
296
			     struct datahead *dh);
272
297
273
/* mem.c */
298
/* mem.c */
274
extern void *mempool_alloc (struct database_dyn *db, size_t len);
299
extern void *mempool_alloc (struct database_dyn *db, size_t len,
300
			    enum in_flight idx);
275
extern void gc (struct database_dyn *db);
301
extern void gc (struct database_dyn *db);
276
302
277
303
(-)libc/nscd/pwdcache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for passwd lookup.
1
/* Cache handling for passwd lookup.
2
   Copyright (C) 1998-2005, 2006, 2007 Free Software Foundation, Inc.
2
   Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
5
Lines 120-126 cache_addpw (struct database_dyn *db, int fd, request_header *req, Link Here
120
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
120
	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
121
						MSG_NOSIGNAL));
121
						MSG_NOSIGNAL));
122
122
123
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
123
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
124
				   IDX_result_data);
124
	  /* If we cannot permanently store the result, so be it.  */
125
	  /* If we cannot permanently store the result, so be it.  */
125
	  if (dataset != NULL)
126
	  if (dataset != NULL)
126
	    {
127
	    {
Lines 199-205 cache_addpw (struct database_dyn *db, int fd, request_header *req, Link Here
199
200
200
      if (he == NULL)
201
      if (he == NULL)
201
	{
202
	{
202
	  dataset = (struct dataset *) mempool_alloc (db, total + n);
203
	  dataset = (struct dataset *) mempool_alloc (db, total + n,
204
						      IDX_result_data);
203
	  if (dataset == NULL)
205
	  if (dataset == NULL)
204
	    ++db->head->addfailed;
206
	    ++db->head->addfailed;
205
	}
207
	}
Lines 270-276 cache_addpw (struct database_dyn *db, int fd, request_header *req, Link Here
270
	      /* We have to create a new record.  Just allocate
272
	      /* We have to create a new record.  Just allocate
271
		 appropriate memory and copy it.  */
273
		 appropriate memory and copy it.  */
272
	      struct dataset *newp
274
	      struct dataset *newp
273
		= (struct dataset *) mempool_alloc (db, total + n);
275
		= (struct dataset *) mempool_alloc (db, total + n,
276
						    IDX_result_data);
274
	      if (newp != NULL)
277
	      if (newp != NULL)
275
		{
278
		{
276
		  /* Adjust pointer into the memory block.  */
279
		  /* Adjust pointer into the memory block.  */
(-)libc/nscd/servicescache.c (-4 / +7 lines)
Lines 1-5 Link Here
1
/* Cache handling for services lookup.
1
/* Cache handling for services lookup.
2
   Copyright (C) 2007 Free Software Foundation, Inc.
2
   Copyright (C) 2007, 2008 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
3
   This file is part of the GNU C Library.
4
   Contributed by Ulrich Drepper <drepper@drepper.com>, 2007.
4
   Contributed by Ulrich Drepper <drepper@drepper.com>, 2007.
5
5
Lines 103-109 cache_addserv (struct database_dyn *db, int fd, request_header *req, Link Here
103
	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
103
	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
104
					      MSG_NOSIGNAL));
104
					      MSG_NOSIGNAL));
105
105
106
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
106
	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
107
				   IDX_result_data);
107
	  /* If we cannot permanently store the result, so be it.  */
108
	  /* If we cannot permanently store the result, so be it.  */
108
	  if (dataset != NULL)
109
	  if (dataset != NULL)
109
	    {
110
	    {
Lines 190-196 cache_addserv (struct database_dyn *db, int fd, request_header *req, Link Here
190
      if (he == NULL)
191
      if (he == NULL)
191
	{
192
	{
192
	  dataset = (struct dataset *) mempool_alloc (db,
193
	  dataset = (struct dataset *) mempool_alloc (db,
193
						      total + req->key_len);
194
						      total + req->key_len,
195
						      IDX_result_data);
194
	  if (dataset == NULL)
196
	  if (dataset == NULL)
195
	    ++db->head->addfailed;
197
	    ++db->head->addfailed;
196
	}
198
	}
Lines 261-267 cache_addserv (struct database_dyn *db, int fd, request_header *req, Link Here
261
	      /* We have to create a new record.  Just allocate
263
	      /* We have to create a new record.  Just allocate
262
		 appropriate memory and copy it.  */
264
		 appropriate memory and copy it.  */
263
	      struct dataset *newp
265
	      struct dataset *newp
264
		= (struct dataset *) mempool_alloc (db, total + req->key_len);
266
		= (struct dataset *) mempool_alloc (db, total + req->key_len,
267
						    IDX_result_data);
265
	      if (newp != NULL)
268
	      if (newp != NULL)
266
		{
269
		{
267
		  /* Adjust pointers into the memory block.  */
270
		  /* Adjust pointers into the memory block.  */

Return to bug 223205