summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-06-06 15:29:59 +0000
committerMiles Bader <miles@gnu.org>1996-06-06 15:29:59 +0000
commit02eec644310f0b262270c7966f31f79239118287 (patch)
tree5cb648d9d6f7eb53ac02623917f406e800c4dae9
parente550852065422984494fc47111ad4fca0fb0983c (diff)
downloadglibc-02eec644310f0b262270c7966f31f79239118287.tar.gz
*** empty log message ***
Thu Jun 6 07:32:14 1996 Miles Bader <miles@gnu.ai.mit.edu> * resolv/gethnamaddr.c (struct hstorage): Make NAME field a pointer. (_gethtbyname2): Remove ALIAS variable. Initialize NAME field of SELF and TARGET to 0. Add SELF_NAME_SIZE static variable. Add loop to call gethostname until the space we allocated is enough. Use malloced strings instead of fixed size buffers. <stdlib.h>, <unistd.h>: New includes. * sysdeps/generic/sys/socket.h (PF_INET6, AF_INET6): New macros. * sysdeps/mach/hurd/errlist.c (_sys_errlist): Add EILSEQ. (_sys_nerr): Initialize to 107. Update _HURD_ERRNOS consistency check. * stdlib/canonicalize.c (canonicalize): Use pathconf for PATH_MAX, not sysconf. * login/login.c [!PATH_MAX] (PATH_MAX): Define to be 1024 if not already defined. * sysdeps/mach/hurd/setitimer.c (timer_thread): Supply SIGCODE argument to __msg_sig_post_request. * hurd/hurdmalloc.c: Changes to bring in line with the hurd libthreads/malloc.c: (more_memory): Use assert_perror instead of MACH_CALL. "cthread_internals.h": Include removed. (realloc): Use LOG2_MIN_SIZE. (LOG2_MIN_SIZE): New macro. (realloc): Don't bother allocating a new block if the new size request fits in the old one and doesn't waste any space. Only free the old block if we successfully got a new one. [MCHECK] (struct header): New type. (union header): Only define if !MCHECK. (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros. [MCHECK] (MIN_SIZE): Add correct definition for this case. (more_memory, malloc, free, realloc): Use above macros, and add appropiate checks & frobs in MCHECK case.
-rw-r--r--ChangeLog40
-rw-r--r--hurd/hurdmalloc.c163
-rw-r--r--login/login.c4
-rw-r--r--resolv/gethnamaddr.c60
-rw-r--r--stdlib/canonicalize.c2
-rw-r--r--sysdeps/mach/hurd/errlist.c5
-rw-r--r--sysdeps/mach/hurd/setitimer.c2
7 files changed, 217 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index 783ff05288..f1712a5521 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,43 @@
+Thu Jun 6 07:32:14 1996 Miles Bader <miles@gnu.ai.mit.edu>
+
+ * resolv/gethnamaddr.c (struct hstorage): Make NAME field a pointer.
+ (_gethtbyname2): Remove ALIAS variable.
+ Initialize NAME field of SELF and TARGET to 0.
+ Add SELF_NAME_SIZE static variable.
+ Add loop to call gethostname until the space we allocated is enough.
+ Use malloced strings instead of fixed size buffers.
+ <stdlib.h>, <unistd.h>: New includes.
+ * sysdeps/generic/sys/socket.h (PF_INET6, AF_INET6): New macros.
+
+ * sysdeps/mach/hurd/errlist.c (_sys_errlist): Add EILSEQ.
+ (_sys_nerr): Initialize to 107.
+ Update _HURD_ERRNOS consistency check.
+
+ * stdlib/canonicalize.c (canonicalize): Use pathconf for PATH_MAX,
+ not sysconf.
+
+ * login/login.c [!PATH_MAX] (PATH_MAX): Define to be 1024 if not
+ already defined.
+
+ * sysdeps/mach/hurd/setitimer.c (timer_thread): Supply SIGCODE
+ argument to __msg_sig_post_request.
+
+ * hurd/hurdmalloc.c: Changes to bring in line with the hurd
+ libthreads/malloc.c:
+ (more_memory): Use assert_perror instead of MACH_CALL.
+ "cthread_internals.h": Include removed.
+ (realloc): Use LOG2_MIN_SIZE.
+ (LOG2_MIN_SIZE): New macro.
+ (realloc): Don't bother allocating a new block if the
+ new size request fits in the old one and doesn't waste any space.
+ Only free the old block if we successfully got a new one.
+ [MCHECK] (struct header): New type.
+ (union header): Only define if !MCHECK.
+ (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
+ [MCHECK] (MIN_SIZE): Add correct definition for this case.
+ (more_memory, malloc, free, realloc): Use above macros, and add
+ appropiate checks & frobs in MCHECK case.
+
Thu Jun 6 02:00:42 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
* Makerules (distinfo-vars): Don't write constant line to frob sources.
diff --git a/hurd/hurdmalloc.c b/hurd/hurdmalloc.c
index 1de887bb80..5f719df9c6 100644
--- a/hurd/hurdmalloc.c
+++ b/hurd/hurdmalloc.c
@@ -37,24 +37,39 @@
/*
* HISTORY
* $Log$
- * Revision 1.10 1995/02/13 22:04:34 roland
- * (malloc_init): Add self reference to avoid not only the `defined but not
- * used' warning, but also to avoid GCC optimizing out the entire function
- * (!).
+ * Revision 1.11 1996/06/06 15:13:47 miles
+ * Changes to bring in line with the hurd libthreads/malloc.c:
+ * (more_memory): Use assert_perror instead of MACH_CALL.
+ * "cthread_internals.h": Include removed.
+ * (realloc): Use LOG2_MIN_SIZE.
+ * (LOG2_MIN_SIZE): New macro.
+ * (realloc): Don't bother allocating a new block if the
+ * new size request fits in the old one and doesn't waste any space.
+ * Only free the old block if we successfully got a new one.
+ * [MCHECK] (struct header): New type.
+ * (union header): Only define if !MCHECK.
+ * (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
+ * [MCHECK] (MIN_SIZE): Add correct definition for this case.
+ * (more_memory, malloc, free, realloc): Use above macros, and add appropiate
+ * checks & frobs in MCHECK case.
*
- * Revision 1.9 1995/02/13 16:36:08 roland
- * Include string.h; #define bcopy using memcpy.
+ * Revision 1.6 1996/03/07 21:13:08 miles
+ * (realloc):
+ * Use LOG2_MIN_SIZE.
+ * Don't bother allocating a new block if the new size request fits in the old
+ * one and doesn't waste any space.
+ * Only free the old block if we successfully got a new one.
+ * (LOG2_MIN_SIZE): New macro.
*
- * Revision 1.8 1995/02/03 01:54:21 roland
- * Remove bogus bcopy decl.
+ * Revision 1.5 1996/03/06 23:51:04 miles
+ * [MCHECK] (struct header): New type.
+ * (union header): Only define if !MCHECK.
+ * (HEADER_SIZE, HEADER_NEXT, HEADER_FREE, HEADER_CHECK): New macros.
+ * [MCHECK] (MIN_SIZE): Add correct definition for this case.
+ * (more_memory, malloc, free, realloc):
+ * Use above macros, and add appropiate checks & frobs in MCHECK case.
*
- * Revision 1.7 1995/01/26 04:22:02 roland
- * Don't include gnu-stabs.h.
- *
- * Revision 1.6 1994/12/07 19:41:26 roland
- * (vm_allocate, vm_page_size): #define these to __ names at top.
- *
- * Revision 1.5 1994/06/04 01:48:44 roland
+ * Revision 1.4 1994/05/05 11:21:42 roland
* entered into RCS
*
* Revision 2.7 91/05/14 17:57:34 mrt
@@ -99,9 +114,11 @@
*/
+#include <assert.h>
+
#include <cthreads.h>
-#include "cthread_internals.h"
+#define MCHECK
/*
* Structure of memory block header.
@@ -109,12 +126,41 @@
* When allocated, fl points to free list.
* Size of header is 4 bytes, so minimum usable block size is 8 bytes.
*/
+
+#define CHECK_BUSY 0x8a3c743e
+#define CHECK_FREE 0x66688b92
+
+#ifdef MCHECK
+
+typedef struct header {
+ long check;
+ union {
+ struct header *next;
+ struct free_list *fl;
+ } u;
+} *header_t;
+
+#define HEADER_SIZE sizeof (struct header)
+#define HEADER_NEXT(h) ((h)->u.next)
+#define HEADER_FREE(h) ((h)->u.fl)
+#define HEADER_CHECK(h) ((h)->check)
+#define MIN_SIZE 16
+#define LOG2_MIN_SIZE 4
+
+#else /* ! MCHECK */
+
typedef union header {
union header *next;
struct free_list *fl;
} *header_t;
+#define HEADER_SIZE sizeof (union header)
+#define HEADER_NEXT(h) ((h)->next)
+#define HEADER_FREE(h) ((h)->fl)
#define MIN_SIZE 8 /* minimum block size */
+#define LOG2_MIN_SIZE 3
+
+#endif /* MCHECK */
typedef struct free_list {
spin_lock_t lock; /* spin lock for mutual exclusion */
@@ -125,10 +171,10 @@ typedef struct free_list {
} *free_list_t;
/*
- * Free list with index i contains blocks of size 2^(i+3) including header.
- * Smallest block size is 8, with 4 bytes available to user.
- * Size argument to malloc is a signed integer for sanity checking,
- * so largest block size is 2^31.
+ * Free list with index i contains blocks of size 2 ^ (i + LOG2_MIN_SIZE)
+ * including header. Smallest block size is MIN_SIZE, with MIN_SIZE -
+ * HEADER_SIZE bytes available to user. Size argument to malloc is a signed
+ * integer for sanity checking, so largest block size is 2^31.
*/
#define NBUCKETS 29
@@ -173,18 +219,23 @@ more_memory(size, fl)
if (size <= vm_page_size) {
amount = vm_page_size;
n = vm_page_size / size;
- /*
- * We lose vm_page_size - n*size bytes here. */
+ /* We lose vm_page_size - n*size bytes here. */
} else {
amount = size;
n = 1;
}
- MACH_CALL(vm_allocate(mach_task_self(), &where, (vm_size_t) amount, TRUE), r);
+
+ r = vm_allocate(mach_task_self(), &where, (vm_size_t) amount, TRUE);
+ assert_perror (r);
+
h = (header_t) where;
do {
- h->next = fl->head;
- fl->head = h;
- h = (header_t) ((char *) h + size);
+ HEADER_NEXT (h) = fl->head;
+#ifdef MCHECK
+ HEADER_CHECK (h) = CHECK_FREE;
+#endif
+ fl->head = h;
+ h = (header_t) ((char *) h + size);
} while (--n != 0);
}
@@ -199,7 +250,7 @@ malloc(size)
if ((int) size < 0) /* sanity check */
return 0;
- size += sizeof(union header);
+ size += HEADER_SIZE;
/*
* Find smallest power-of-two block size
* big enough to hold requested size plus header.
@@ -232,7 +283,13 @@ malloc(size)
/*
* Pop block from free list.
*/
- fl->head = h->next;
+ fl->head = HEADER_NEXT (h);
+
+#ifdef MCHECK
+ assert (HEADER_CHECK (h) == CHECK_FREE);
+ HEADER_CHECK (h) = CHECK_BUSY;
+#endif
+
#ifdef DEBUG
fl->in_use += 1;
#endif DEBUG
@@ -242,11 +299,11 @@ malloc(size)
* so we can figure out where it goes
* at free() time.
*/
- h->fl = fl;
+ HEADER_FREE (h) = fl;
/*
* Return pointer past the block header.
*/
- return ((char *) h) + sizeof(union header);
+ return ((char *) h) + HEADER_SIZE;
}
/* Declaration changed to standard one for GNU. */
@@ -263,8 +320,13 @@ free(base)
/*
* Find free list for block.
*/
- h = (header_t) (base - sizeof(union header));
- fl = h->fl;
+ h = (header_t) (base - HEADER_SIZE);
+
+#ifdef MCHECK
+ assert (HEADER_CHECK (h) == CHECK_BUSY);
+#endif
+
+ fl = HEADER_FREE (h);
i = fl - malloc_free_list;
/*
* Sanity checks.
@@ -281,7 +343,10 @@ free(base)
* Push block on free list.
*/
spin_lock(&fl->lock);
- h->next = fl->head;
+ HEADER_NEXT (h) = fl->head;
+#ifdef MCHECK
+ HEADER_CHECK (h) = CHECK_FREE;
+#endif
fl->head = h;
#ifdef DEBUG
fl->in_use -= 1;
@@ -308,8 +373,11 @@ realloc(old_base, new_size)
/*
* Find size of old block.
*/
- h = (header_t) (old_base - sizeof(union header));
- fl = h->fl;
+ h = (header_t) (old_base - HEADER_SIZE);
+#ifdef MCHECK
+ assert (HEADER_CHECK (h) == CHECK_BUSY);
+#endif
+ fl = HEADER_FREE (h);
i = fl - malloc_free_list;
/*
* Sanity checks.
@@ -323,16 +391,29 @@ realloc(old_base, new_size)
return 0;
}
/*
- * Free list with index i contains blocks of size 2^(i+3) including header.
+ * Free list with index i contains blocks of size
+ * 2 ^ (i + * LOG2_MIN_SIZE) including header.
*/
- old_size = (1 << (i+3)) - sizeof(union header);
+ old_size = (1 << (i + LOG2_MIN_SIZE)) - HEADER_SIZE;
+
+ if (new_size <= old_size
+ && new_size > (((old_size + HEADER_SIZE) >> 1) - HEADER_SIZE))
+ /* The new size still fits in the same block, and wouldn't fit in
+ the next smaller block! */
+ return old_base;
+
/*
* Allocate new block, copy old bytes, and free old block.
*/
new_base = malloc(new_size);
- if (new_base != 0)
- bcopy(old_base, new_base, (int) (old_size < new_size ? old_size : new_size));
- free(old_base);
+ if (new_base)
+ bcopy(old_base, new_base,
+ (int) (old_size < new_size ? old_size : new_size));
+
+ if (new_base || new_size == 0)
+ /* Free OLD_BASE, but only if the malloc didn't fail. */
+ free (old_base);
+
return new_base;
}
@@ -354,7 +435,7 @@ print_malloc_free_list()
spin_lock(&fl->lock);
if (fl->in_use != 0 || fl->head != 0) {
total_used += fl->in_use * size;
- for (n = 0, h = fl->head; h != 0; h = h->next, n += 1)
+ for (n = 0, h = fl->head; h != 0; h = HEADER_NEXT (h), n += 1)
;
total_free += n * size;
fprintf(stderr, "%10d %10d %10d %10d\n",
diff --git a/login/login.c b/login/login.c
index f74ce41ad8..446b6b927b 100644
--- a/login/login.c
+++ b/login/login.c
@@ -23,6 +23,10 @@ Boston, MA 02111-1307, USA. */
#include <unistd.h>
#include <utmp.h>
+/* XXX used for tty name array in login. */
+#ifndef PATH_MAX
+#define PATH_MAX 1024
+#endif
void
login (const struct utmp *ut)
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c
index 18f4764428..161060ebd6 100644
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -65,6 +65,8 @@ static char rcsid[] = "$Id$";
#include <arpa/nameser.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <netdb.h>
#include <resolv.h>
#include <ctype.h>
@@ -823,7 +825,7 @@ _gethtent()
}
struct hstorage {
- char name[MAXHOSTNAMELEN + 1]; /* canonical name */
+ char *name; /* canonical name */
char ** alp; /* address list pointer */
char * abp; /* address buffer pointer */
char * addr_list[MAXADDRS + 1]; /* address list storage */
@@ -891,20 +893,53 @@ _gethtbyname2(name, af)
* interface changes to make these functions
* reentrant.
*/
- static char * aliases[2];
- static char alias[MAXHOSTNAMELEN + 1];
- static struct hstorage self, target;
+ static char *aliases[2] = {0};
+ static struct hstorage self = {0}, target = {0};
+ static size_t self_name_size = 0; /* Allocated in self.name. */
static struct hostent ht;
int found;
+ if (aliases[0])
+ free (aliases[0]); /* Malloced in a prev call. */
aliases[0] = aliases[1] = 0;
- gethostname(self.name, sizeof(self.name));
+ /* Get current host name in a large enough buffer. */
+ do {
+ errno = 0;
+
+ if (self.name)
+ {
+ self_name_size += self_name_size;
+ self.name =
+ realloc (self.name, self_name_size);
+ } else {
+ self_name_size = 128; /* Initial guess */
+ self.name = malloc (self_name_size);
+ }
+
+ if (! self.name)
+ {
+ errno = ENOMEM;
+ return 0;
+ }
+ } while ((gethostname(self.name, self_name_size) == 0
+ && !memchr (self.name, '\0', self_name_size))
+ || errno == ENAMETOOLONG);
+
+ if (errno)
+ /* gethostname failed, abort. */
+ {
+ free (self.name);
+ self.name = 0;
+ }
+
self.alp = self.addr_list;
self.abp = self.addr_buf;
- strncpy(target.name, name, MAXHOSTNAMELEN);
- target.name[MAXHOSTNAMELEN] = '\0';
+ if (target.name)
+ free (target.name);
+ target.name = strdup (name);
+
target.alp = target.addr_list;
target.abp = target.addr_buf;
@@ -920,13 +955,10 @@ _gethtbyname2(name, af)
if (strcasecmp(*cp, name) == 0) {
found = 1;
if (!aliases[0]) {
- strcpy(target.name,
- p->h_name);
- strncpy(alias, name,
- MAXHOSTNAMELEN);
- alias[MAXHOSTNAMELEN]
- = '\0';
- aliases[0] = alias;
+ aliases[0] =
+ target.name;
+ target.name =
+ strdup (p->h_name);
}
break;
}
diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c
index 55ac1bcf1d..8008a28cc2 100644
--- a/stdlib/canonicalize.c
+++ b/stdlib/canonicalize.c
@@ -47,7 +47,7 @@ canonicalize (const char *name, char *resolved)
#ifdef PATH_MAX
path_max = PATH_MAX;
#else
- path_max = sysconf (_SC_PATH_MAX);
+ path_max = pathconf (name, _PC_PATH_MAX);
if (path_max <= 0)
path_max = 1024;
#endif
diff --git a/sysdeps/mach/hurd/errlist.c b/sysdeps/mach/hurd/errlist.c
index 5f40e04209..60a08cd613 100644
--- a/sysdeps/mach/hurd/errlist.c
+++ b/sysdeps/mach/hurd/errlist.c
@@ -113,12 +113,13 @@ const char *_sys_errlist[] =
"You really blew it this time", /* 103 = EGREGIOUS */
"Computer bought the farm", /* 104 = EIEIO */
"Gratuitous error", /* 105 = EGRATUITOUS */
+ "Invalid or incomplete multibyte or wide character", /* 106 = EILSEQ */
};
#include <errno.h>
-#if _HURD_ERRNOS != 106
+#if _HURD_ERRNOS != 107
#error errlist/errnos generation bug
#endif
-const int _sys_nerr = 106;
+const int _sys_nerr = 107;
weak_alias (_sys_errlist, sys_errlist)
weak_alias (_sys_nerr, sys_nerr)
diff --git a/sysdeps/mach/hurd/setitimer.c b/sysdeps/mach/hurd/setitimer.c
index 9ee33e0446..01c17f7725 100644
--- a/sysdeps/mach/hurd/setitimer.c
+++ b/sysdeps/mach/hurd/setitimer.c
@@ -88,7 +88,7 @@ timer_thread (void)
__msg_sig_post_request (_hurd_msgport,
_hurd_itimer_port,
MACH_MSG_TYPE_MAKE_SEND_ONCE,
- SIGALRM, __mach_task_self ());
+ SIGALRM, 0, __mach_task_self ());
break;
case MACH_RCV_INTERRUPTED: