diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-05-18 10:56:45 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2008-05-18 10:56:45 +0000 |
commit | 21032d9230e840a1f8b89d43e1e8d63ccf7c6eae (patch) | |
tree | 4d32b089580a63a332024e526938eb40613e7b27 /nscd | |
parent | 4681f435969ca9806da160d3ae564668ddfecfe2 (diff) | |
download | glibc-21032d9230e840a1f8b89d43e1e8d63ccf7c6eae.zip glibc-21032d9230e840a1f8b89d43e1e8d63ccf7c6eae.tar.gz glibc-21032d9230e840a1f8b89d43e1e8d63ccf7c6eae.tar.bz2 |
Updated to fedora-glibc-20080518T1017cvs/fedora-glibc-2_8_90-3
Diffstat (limited to 'nscd')
-rw-r--r-- | nscd/aicache.c | 37 | ||||
-rw-r--r-- | nscd/mem.c | 53 | ||||
-rw-r--r-- | nscd/nscd.h | 2 |
3 files changed, 55 insertions, 37 deletions
diff --git a/nscd/aicache.c b/nscd/aicache.c index 918efc9..7ae5a16 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -114,7 +114,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, char *tmpbuf6 = alloca (tmpbuf6len); size_t tmpbuf4len = 0; char *tmpbuf4 = NULL; - char *canon = NULL; int32_t ttl = INT32_MAX; ssize_t total = 0; char *key_copy = NULL; @@ -126,6 +125,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, int status[2] = { NSS_STATUS_UNAVAIL, NSS_STATUS_UNAVAIL }; int naddrs = 0; size_t addrslen = 0; + char *canon = NULL; size_t canonlen; nss_gethostbyname4_r fct4 = __nss_lookup_function (nip, @@ -136,9 +136,11 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, while (1) { rc6 = 0; - status[0] = DL_CALL_FCT (fct4, (key, &at, tmpbuf6, tmpbuf6len, + herrno = 0; + status[1] = DL_CALL_FCT (fct4, (key, &at, tmpbuf6, tmpbuf6len, &rc6, &herrno, &ttl)); - if (rc6 != ERANGE || herrno != NETDB_INTERNAL) + if (rc6 != ERANGE || (herrno != NETDB_INTERNAL + && herrno != TRY_AGAIN)) break; tmpbuf6 = extend_alloca (tmpbuf6, tmpbuf6len, 2 * tmpbuf6len); } @@ -146,22 +148,21 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, if (rc6 != 0 && herrno == NETDB_INTERNAL) goto out; - if (status[0] != NSS_STATUS_SUCCESS) + if (status[1] != NSS_STATUS_SUCCESS) goto next_nip; /* We found the data. Count the addresses and the size. */ - for (struct gaih_addrtuple *at2 = at; at2 != NULL; at2 = at2->next) + for (const struct gaih_addrtuple *at2 = at; at2 != NULL; + at2 = at2->next) { ++naddrs; - /* We handle unknown types here the best we can: assume - the maximum size for the address. */ + /* We do not handle anything other than IPv4 and IPv6 + addresses. The getaddrinfo implementation does not + either so it is not worth trying to do more. */ if (at2->family == AF_INET) addrslen += INADDRSZ; - else if (at2->family == AF_INET6 - && IN6ADDRSZ != sizeof (at2->addr)) + else if (at2->family == AF_INET6) addrslen += IN6ADDRSZ; - else - addrslen += sizeof (at2->addr); } canon = at->name; canonlen = strlen (canon) + 1; @@ -191,19 +192,17 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, } /* Fill in the address and address families. */ - char *addrs = (char *) (&dataset->resp + 1); + char *addrs = dataset->strdata; uint8_t *family = (uint8_t *) (addrs + addrslen); - for (struct gaih_addrtuple *at2 = at; at2 != NULL; at2 = at2->next) + for (const struct gaih_addrtuple *at2 = at; at2 != NULL; + at2 = at2->next) { *family++ = at2->family; if (at2->family == AF_INET) addrs = mempcpy (addrs, at2->addr, INADDRSZ); - else if (at2->family == AF_INET6 - && IN6ADDRSZ != sizeof (at2->addr)) + else if (at2->family == AF_INET6) addrs = mempcpy (addrs, at2->addr, IN6ADDRSZ); - else - addrs = mempcpy (addrs, at2->addr, sizeof (at2->addr)); } cp = family; @@ -373,7 +372,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, } /* Fill in the address and address families. */ - char *addrs = (char *) (&dataset->resp + 1); + char *addrs = dataset->strdata; uint8_t *family = (uint8_t *) (addrs + addrslen); for (int j = 0; j < 2; ++j) @@ -411,6 +410,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req, key_copy = memcpy (cp, key, req->key_len); + assert (cp == (char *) dataset + total); + /* Now we can determine whether on refill we have to create a new record or not. */ if (he != NULL) @@ -24,6 +24,7 @@ #include <inttypes.h> #include <libintl.h> #include <limits.h> +#include <obstack.h> #include <stdlib.h> #include <string.h> #include <unistd.h> @@ -79,6 +80,7 @@ static void markrange (BITMAP_T *mark, ref_t start, size_t len) { /* Adjust parameters for block alignment. */ + assert ((start & BLOCK_ALIGN_M1) == 0); start /= BLOCK_ALIGN; len = (len + BLOCK_ALIGN_M1) / BLOCK_ALIGN; @@ -93,7 +95,7 @@ markrange (BITMAP_T *mark, ref_t start, size_t len) return; } - mark[elem++] |= 0xff << (start % BITS); + mark[elem++] |= ALLBITS << (start % BITS); len -= BITS - (start % BITS); } @@ -130,14 +132,14 @@ gc (struct database_dyn *db) size_t stack_used = sizeof (bool) * db->head->module; if (__builtin_expect (stack_used > MAX_STACK_USE, 0)) stack_used = 0; - size_t memory_needed = ((db->head->first_free / BLOCK_ALIGN + BITS - 1) - / BITS) * sizeof (BITMAP_T); - if (memory_needed <= MAX_STACK_USE) + size_t nmark = (db->head->first_free / BLOCK_ALIGN + BITS - 1) / BITS; + size_t memory_needed = nmark * sizeof (BITMAP_T); + if (stack_used + memory_needed <= MAX_STACK_USE) { mark = (BITMAP_T *) alloca (memory_needed); mark_use_malloc = false; memset (mark, '\0', memory_needed); - stack_used = memory_needed; + stack_used += memory_needed; } else { @@ -156,6 +158,7 @@ gc (struct database_dyn *db) he = alloca (db->head->nentries * sizeof (struct hashentry *)); he_data = alloca (db->head->nentries * sizeof (struct hashentry *)); he_use_malloc = false; + stack_used += memory_needed; } else { @@ -212,11 +215,12 @@ gc (struct database_dyn *db) for (enum in_flight idx = IDX_result_data; idx < IDX_last && mrunp->block[idx].dbidx == db - dbs; ++idx) { - assert ((char *) mrunp->block[idx].blockaddr > db->data); - assert ((char *) mrunp->block[idx].blockaddr - + mrunp->block[0].blocklen <= db->data + db->memsize); - markrange (mark, (char *) mrunp->block[idx].blockaddr - db->data, - mrunp->block[idx].blocklen); + assert (mrunp->block[idx].blockoff >= 0); + assert (mrunp->block[idx].blocklen < db->memsize); + assert (mrunp->block[idx].blockoff + + mrunp->block[0].blocklen <= db->memsize); + markrange (mark, mrunp->block[idx].blockoff, + mrunp->block[idx].blocklen); } mrunp = mrunp->next; @@ -232,7 +236,7 @@ gc (struct database_dyn *db) qsort (he, cnt, sizeof (struct hashentry *), sort_he); /* Determine the highest used address. */ - size_t high = sizeof (mark); + size_t high = nmark; while (high > 0 && mark[high - 1] == 0) --high; @@ -303,6 +307,10 @@ gc (struct database_dyn *db) size_t size; struct moveinfo *next; } *moves = NULL; +#define obstack_chunk_alloc xmalloc +#define obstack_chunk_free free + struct obstack ob; + obstack_init (&ob); while (byte < high) { @@ -363,8 +371,14 @@ gc (struct database_dyn *db) displacement. */ ref_t disp = off_alloc - off_free; - struct moveinfo *new_move - = (struct moveinfo *) alloca (sizeof (*new_move)); + struct moveinfo *new_move; + if (stack_used + sizeof (*new_move) <= MAX_STACK_USE) + { + new_move = alloca (sizeof (*new_move)); + stack_used += sizeof (*new_move); + } + else + new_move = obstack_alloc (&ob, sizeof (*new_move)); new_move->from = db->data + off_alloc; new_move->to = db->data + off_free; new_move->size = off_allocend - off_alloc; @@ -524,6 +538,8 @@ gc (struct database_dyn *db) free (he); if (mark_use_malloc) free (mark); + + obstack_free (&ob, NULL); } @@ -589,15 +605,16 @@ mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx) } else { - db->head->first_free += len; - - db->last_alloc_failed = false; - /* Remember that we have allocated this memory. */ assert (idx >= 0 && idx < IDX_last); mem_in_flight.block[idx].dbidx = db - dbs; mem_in_flight.block[idx].blocklen = len; - mem_in_flight.block[idx].blockaddr = res; + mem_in_flight.block[idx].blockoff = db->head->first_free; + + db->head->first_free += len; + + db->last_alloc_failed = false; + } pthread_mutex_unlock (&db->memlock); diff --git a/nscd/nscd.h b/nscd/nscd.h index 66813e7..b024017 100644 --- a/nscd/nscd.h +++ b/nscd/nscd.h @@ -197,7 +197,7 @@ extern __thread struct mem_in_flight { int dbidx; nscd_ssize_t blocklen; - void *blockaddr; + nscd_ssize_t blockoff; } block[IDX_last]; struct mem_in_flight *next; |