From 162542af656df52467ada51cf172b2eb61949c23 Mon Sep 17 00:00:00 2001 From: John Polstra Date: Sun, 29 Jun 1997 20:43:33 +0000 Subject: Update the Modula-3 runtime's thread safe malloc to PHK's latest. This eliminates the malloc warnings brought about by the recent merging of calloc into malloc.c in -current's libc. This changes the minor version numbers of the Modula-3 shared libraries. The packages that depend on modula-3-lib will need to be rebuilt: net/cvsup print/virtualpaper --- lang/modula-3-lib/files/patch-ah | 2 +- lang/modula-3-lib/files/patch-bg | 618 +++++++++++++++------------------------ lang/modula-3-lib/pkg-plist | 80 ++--- lang/modula-3/Makefile | 4 +- lang/modula-3/pkg-plist | 6 +- 5 files changed, 282 insertions(+), 428 deletions(-) diff --git a/lang/modula-3-lib/files/patch-ah b/lang/modula-3-lib/files/patch-ah index 80ac70f977fd..b0cba113a278 100644 --- a/lang/modula-3-lib/files/patch-ah +++ b/lang/modula-3-lib/files/patch-ah @@ -195,7 +195,7 @@ Index: m3/m3build/templates/FreeBSD2 proc after_library_hooks(x) is local lib_a = format ("lib%s.a", x) - local lib_so = format ("lib%s.so.1.1", x) -+ local lib_so = format ("lib%s.so.4.1", x) ++ local lib_so = format ("lib%s.so.4.2", x) local dest = format ("%s%s%s%s%s", PKG_INSTALL, SL, BUILD_PACKAGE, SL, BUILD_DIR) diff --git a/lang/modula-3-lib/files/patch-bg b/lang/modula-3-lib/files/patch-bg index f690786444b6..898f23fc4b5a 100644 --- a/lang/modula-3-lib/files/patch-bg +++ b/lang/modula-3-lib/files/patch-bg @@ -43,9 +43,9 @@ Index: m3/m3core/src/runtime/FreeBSD2/m3makefile %% s_source (RTStackASM) Index: m3/m3core/src/runtime/FreeBSD2/malloc.c ---- malloc.c.orig Mon Oct 28 20:16:48 1996 -+++ malloc.c Tue Oct 29 08:57:53 1996 -@@ -0,0 +1,1286 @@ +--- malloc.c.orig Thu May 8 17:39:18 1997 ++++ malloc.c Sat Jun 28 10:59:29 1997 +@@ -0,0 +1,1140 @@ +/* + * ---------------------------------------------------------------------------- + * "THE BEER-WARE LICENSE" (Revision 42): @@ -54,39 +54,20 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp + * ---------------------------------------------------------------------------- + * -+ * From FreeBSD: malloc.c,v 1.15 1996/09/25 16:29:15 sos Exp -+ * Modified for Modula-3 thread-safety by jdp@polstra.com (John Polstra). ++ * From FreeBSD: malloc.c,v 1.26 1997/06/22 17:54:27 phk Exp ++ * Modified for Modula-3 thread safety by jdp@polstra.com (John Polstra). + * + */ + +/* -+ * Defining M3_THREAD_SAFE will enable the hooks into the Modula-3 runtime -+ * to permit thread-safe operation with that language system. Do that if -+ * you want to use this malloc as part of the "m3core" package. -+ * -+ * If you define M3_THREAD_SAFE, then do not define _THREAD_SAFE, -+ * which enables the pthreads tie-ins. They are mutually-exclusive. -+ */ -+#define M3_THREAD_SAFE -+ -+/* + * Defining EXTRA_SANITY will enable extra checks which are related + * to internal conditions and consistency in malloc.c. This has a + * noticeable runtime performance hit, and generally will not do you + * any good unless you fiddle with the internals of malloc or want + * to catch random pointer corruption as early as possible. + */ -+#undef EXTRA_SANITY -+ -+/* -+ * Defining MALLOC_STATS will enable you to call malloc_dump() and set -+ * the [dD] options in the MALLOC_OPTIONS environment variable. -+ * It has no run-time performance hit. -+ */ -+#define MALLOC_STATS -+ -+#if defined(EXTRA_SANITY) && !defined(MALLOC_STATS) -+# define MALLOC_STATS /* required for EXTRA_SANITY */ ++#ifndef MALLOC_EXTRA_SANITY ++#undef MALLOC_EXTRA_SANITY +#endif + +/* @@ -96,36 +77,62 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +#define SOME_JUNK 0xd0 /* as in "Duh" :-) */ + +/* -+ * If these weren't defined here, they would be calculated on the fly, -+ * with a noticeable performance hit. ++ * The basic parameters you can tweak. ++ * ++ * malloc_pageshift pagesize = 1 << malloc_pageshift ++ * It's probably best if this is the native ++ * page size, but it doesn't have to be. ++ * ++ * malloc_minsize minimum size of an allocation in bytes. ++ * If this is too small it's too much work ++ * to manage them. This is also the smallest ++ * unit of alignment used for the storage ++ * returned by malloc/realloc. ++ * + */ -+#if defined(__i386__) && defined(__FreeBSD__) -+# define malloc_pagesize 4096U ++ ++#if defined(__FreeBSD__) ++# if defined(__i386__) ++# define malloc_pageshift 12U ++# define malloc_minsize 16U ++# endif ++# if defined(_THREAD_SAFE) ++ extern int RT0u__inCritical; /* Flag set when in a critical region */ ++# define THREAD_LOCK() (++RT0u__inCritical) ++# define THREAD_UNLOCK() (--RT0u__inCritical) ++# endif ++#endif /* __FreeBSD__ */ ++ ++#if defined(__sparc__) || defined(sun) ++# define malloc_pageshirt 12U ++# define malloc_minsize 16U ++# define MAP_ANON (0) ++ static int fdzero; ++# define MMAP_FD fdzero ++# define INIT_MMAP() \ ++ { if ((fdzero=open("/dev/zero", O_RDWR, 0000)) == -1) \ ++ wrterror("open of /dev/zero"); } ++# define MADV_FREE MADV_DONTNEED ++#endif /* __sparc__ */ ++ ++/* Insert your combination here... */ ++#if defined(__FOOCPU__) && defined(__BAROS__) +# define malloc_pageshift 12U +# define malloc_minsize 16U -+# define malloc_maxsize ((malloc_pagesize)>>1) -+#endif /* __i386__ && __FreeBSD__ */ ++#endif /* __FOORCPU__ && __BAROS__ */ ++ + +/* + * No user serviceable parts behind this point. + */ -+ ++#include ++#include ++#include ++#include +#include +#include +#include +#include -+#include -+#include -+#include -+ -+#if 0 /* Disable the utrace stuff { */ -+#ifdef __FreeBSD__ /* Kludge to find out whether we have utrace() */ -+#include -+#ifdef SYS_utrace -+#define HAVE_UTRACE -+#endif /* SYS_utrace */ -+#endif /* __FreeBSD__ */ -+#endif /* } 0 */ + +/* + * This structure describes a page worth of chunks. @@ -138,7 +145,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + u_short shift; /* How far to shift for this size chunks */ + u_short free; /* How many free chunks */ + u_short total; /* How many chunk */ -+ u_long bits[1]; /* Which chunks are free */ ++ u_int bits[1]; /* Which chunks are free */ +}; + +/* @@ -150,14 +157,14 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + struct pgfree *prev; /* prev run of free pages */ + void *page; /* pointer to free pages */ + void *end; /* pointer to end of free pages */ -+ u_long size; /* number of bytes free */ ++ size_t size; /* number of bytes free */ +}; + +/* -+ * How many bits per u_long in the bitmap. ++ * How many bits per u_int in the bitmap. + * Change only if not 8 bits/byte + */ -+#define MALLOC_BITS (8*sizeof(u_long)) ++#define MALLOC_BITS (8*sizeof(u_int)) + +/* + * Magic values to put in the page_directory @@ -168,61 +175,25 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +#define MALLOC_FOLLOW ((struct pginfo*) 3) +#define MALLOC_MAGIC ((struct pginfo*) 4) + -+/* -+ * The i386 architecture has some very convenient instructions. -+ * We might as well use them. There are C-language backups, but -+ * they are considerably slower. -+ */ -+#if defined(__i386__) && defined(__GNUC__) -+#define ffs _ffs -+static __inline__ int -+_ffs(unsigned input) -+{ -+ int result; -+ __asm__("bsfl %1, %0" : "=r" (result) : "r" (input)); -+ return result+1; -+} -+ -+#define fls _fls -+static __inline__ int -+_fls(unsigned input) -+{ -+ int result; -+ __asm__("bsrl %1, %0" : "=r" (result) : "r" (input)); -+ return result+1; -+} -+ -+#define set_bit _set_bit -+static __inline__ void -+_set_bit(struct pginfo *pi, int bit) -+{ -+ __asm__("btsl %0, (%1)" : -+ : "r" (bit & (MALLOC_BITS-1)), "r" (pi->bits+(bit/MALLOC_BITS))); -+} ++#ifndef malloc_pageshift ++#define malloc_pageshift 12U ++#endif + -+#define clr_bit _clr_bit -+static __inline__ void -+_clr_bit(struct pginfo *pi, int bit) -+{ -+ __asm__("btcl %0, (%1)" : -+ : "r" (bit & (MALLOC_BITS-1)), "r" (pi->bits+(bit/MALLOC_BITS))); -+} ++#ifndef malloc_minsize ++#define malloc_minsize 16U ++#endif + -+#endif /* __i386__ && __GNUC__ */ ++#if !defined(malloc_pagesize) ++#define malloc_pagesize (1U<>1) ++#endif + +/* A mask for the offset inside a page. */ +#define malloc_pagemask ((malloc_pagesize)-1) @@ -230,45 +201,45 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +#define pageround(foo) (((foo) + (malloc_pagemask))&(~(malloc_pagemask))) +#define ptr2index(foo) (((u_long)(foo) >> malloc_pageshift)-malloc_origo) + -+/* malloc_pagesize == 1 << malloc_pageshift */ -+#ifndef malloc_pageshift -+static unsigned malloc_pageshift; -+#endif /* malloc_pageshift */ ++#ifndef THREAD_LOCK ++#define THREAD_LOCK() ++#endif + -+/* -+ * The smallest allocation we bother about. -+ * Must be power of two -+ */ -+#ifndef malloc_minsize -+static unsigned malloc_minsize; -+#endif /* malloc_minsize */ ++#ifndef THREAD_UNLOCK ++#define THREAD_UNLOCK() ++#endif + -+/* -+ * The largest chunk we care about. -+ * Must be smaller than pagesize -+ * Must be power of two -+ */ -+#ifndef malloc_maxsize -+static unsigned malloc_maxsize; -+#endif /* malloc_maxsize */ ++#ifndef MMAP_FD ++#define MMAP_FD (-1) ++#endif ++ ++#ifndef INIT_MMAP ++#define INIT_MMAP() ++#endif ++ ++/* Set when initialization has been done */ ++static unsigned malloc_started; ++ ++/* Recusion flag for public interface. */ ++static int malloc_active; + -+/* The minimum size (in pages) of the free page cache. */ -+static unsigned malloc_cache = 16; ++/* Number of free pages we cache */ ++static unsigned malloc_cache = 16; + +/* The offset from pagenumber to index into the page directory */ -+static u_long malloc_origo; ++static u_long malloc_origo; + +/* The last index in the page directory we care about */ -+static u_long last_index; ++static u_long last_index; + +/* Pointer to page directory. Allocated "as if with" malloc */ -+static struct pginfo **page_dir; ++static struct pginfo **page_dir; + +/* How many slots in the page directory */ -+static unsigned malloc_ninfo; ++static unsigned malloc_ninfo; + +/* Free pages line up here */ -+static struct pgfree free_list; ++static struct pgfree free_list; + +/* Abort(), user doesn't handle problems. */ +static int malloc_abort; @@ -276,35 +247,38 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +/* Are we trying to die ? */ +static int suicide; + -+#ifdef MALLOC_STATS -+/* dump statistics */ -+static int malloc_stats; -+#endif /* MALLOC_STATS */ -+ +/* always realloc ? */ +static int malloc_realloc; + +/* pass the kernel a hint on free pages ? */ +static int malloc_hint; + ++/* xmalloc behaviour ? */ ++static int malloc_xmalloc; ++ ++/* sysv behaviour for malloc(0) ? */ ++static int malloc_sysv; ++ +/* zero fill ? */ +static int malloc_zero; + +/* junk fill ? */ +static int malloc_junk; + -+#ifdef HAVE_UTRACE +/* utrace ? */ +static int malloc_utrace; + ++#ifdef HAS_UTRACE +struct ut { void *p; size_t s; void *r; }; + ++void utrace __P((struct ut *, int)); ++ +#define UTRACE(a, b, c) \ + if (malloc_utrace) \ + {struct ut u; u.p=a; u.s = b; u.r=c; utrace(&u, sizeof u);} -+#else /* !HAVE_UTRACE */ ++#else /* !HAS_UTRACE */ +#define UTRACE(a,b,c) -+#endif /* HAVE_UTRACE */ ++#endif + +/* my last break. */ +static void *malloc_brk; @@ -315,6 +289,14 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +/* compile-time options */ +char *malloc_options; + ++/* Name of the current public function */ ++static char *malloc_func; ++ ++/* Macro for mmap */ ++#define MMAP(size) \ ++ mmap((caddr_t)0, (size), PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, \ ++ MMAP_FD, 0); ++ +/* + * Necessary function declarations + */ @@ -323,105 +305,31 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +static void ifree(void *ptr); +static void *irealloc(void *ptr, size_t size); + -+#ifdef MALLOC_STATS -+void -+malloc_dump(FILE *fd) -+{ -+ struct pginfo **pd; -+ struct pgfree *pf; -+ int j; -+ -+ pd = page_dir; -+ -+ /* print out all the pages */ -+ for(j=0;j<=last_index;j++) { -+ fprintf(fd, "%08lx %5d ", (j+malloc_origo) << malloc_pageshift, j); -+ if (pd[j] == MALLOC_NOT_MINE) { -+ for(j++;j<=last_index && pd[j] == MALLOC_NOT_MINE;j++) -+ ; -+ j--; -+ fprintf(fd, ".. %5d not mine\n", j); -+ } else if (pd[j] == MALLOC_FREE) { -+ for(j++;j<=last_index && pd[j] == MALLOC_FREE;j++) -+ ; -+ j--; -+ fprintf(fd, ".. %5d free\n", j); -+ } else if (pd[j] == MALLOC_FIRST) { -+ for(j++;j<=last_index && pd[j] == MALLOC_FOLLOW;j++) -+ ; -+ j--; -+ fprintf(fd, ".. %5d in use\n", j); -+ } else if (pd[j] < MALLOC_MAGIC) { -+ fprintf(fd, "(%p)\n", pd[j]); -+ } else { -+ fprintf(fd, "%p %d (of %d) x %d @ %p --> %p\n", -+ pd[j], pd[j]->free, pd[j]->total, -+ pd[j]->size, pd[j]->page, pd[j]->next); -+ } -+ } -+ -+ for(pf=free_list.next; pf; pf=pf->next) { -+ fprintf(fd, "Free: @%p [%p...%p[ %ld ->%p <-%p\n", -+ pf, pf->page, pf->end, pf->size, pf->prev, pf->next); -+ if (pf == pf->next) { -+ fprintf(fd, "Free_list loops.\n"); -+ break; -+ } -+ } -+ -+ /* print out various info */ -+ fprintf(fd, "Minsize\t%d\n", malloc_minsize); -+ fprintf(fd, "Maxsize\t%d\n", malloc_maxsize); -+ fprintf(fd, "Pagesize\t%d\n", malloc_pagesize); -+ fprintf(fd, "Pageshift\t%d\n", malloc_pageshift); -+ fprintf(fd, "FirstPage\t%ld\n", malloc_origo); -+ fprintf(fd, "LastPage\t%ld %lx\n", last_index+malloc_pageshift, -+ (last_index + malloc_pageshift) << malloc_pageshift); -+ fprintf(fd, "Break\t%ld\n", (u_long)sbrk(0) >> malloc_pageshift); -+} -+#endif /* MALLOC_STATS */ -+ -+static char *malloc_func; ++extern char *__progname; + +static void +wrterror(char *p) +{ -+ char *q = "Malloc error: "; ++ char *q = " error: "; ++ write(STDERR_FILENO, __progname, strlen(__progname)); ++ write(STDERR_FILENO, malloc_func, strlen(malloc_func)); ++ write(STDERR_FILENO, q, strlen(q)); ++ write(STDERR_FILENO, p, strlen(p)); + suicide = 1; -+ write(2, q, strlen(q)); -+ write(2, malloc_func, strlen(malloc_func)); -+ write(2, p, strlen(p)); -+#ifdef MALLOC_STATS -+ if (malloc_stats) -+ malloc_dump(stderr); -+#endif /* MALLOC_STATS */ + abort(); +} + +static void +wrtwarning(char *p) +{ -+ char *q = "Malloc warning: "; ++ char *q = " warning: "; + if (malloc_abort) + wrterror(p); -+ write(2, q, strlen(q)); -+ write(2, malloc_func, strlen(malloc_func)); -+ write(2, p, strlen(p)); -+} -+ -+#ifdef EXTRA_SANITY -+static void -+malloc_exit() -+{ -+ FILE *fd = fopen("malloc.out", "a"); -+ char *q = "malloc() warning: Couldn't dump stats.\n"; -+ if (fd) { -+ malloc_dump(fd); -+ fclose(fd); -+ } else -+ write(2, q, strlen(q)); ++ write(STDERR_FILENO, __progname, strlen(__progname)); ++ write(STDERR_FILENO, malloc_func, strlen(malloc_func)); ++ write(STDERR_FILENO, q, strlen(q)); ++ write(STDERR_FILENO, p, strlen(p)); +} -+#endif /* EXTRA_SANITY */ + + +/* @@ -452,53 +360,6 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +} + +/* -+ * Set a bit in the bitmap -+ */ -+#ifndef set_bit -+static __inline__ void -+set_bit(struct pginfo *pi, int bit) -+{ -+ pi->bits[bit/MALLOC_BITS] |= 1<<(bit%MALLOC_BITS); -+} -+#endif /* set_bit */ -+ -+/* -+ * Clear a bit in the bitmap -+ */ -+#ifndef clr_bit -+static __inline__ void -+clr_bit(struct pginfo *pi, int bit) -+{ -+ pi->bits[bit/MALLOC_BITS] &= ~(1<<(bit%MALLOC_BITS)); -+} -+#endif /* clr_bit */ -+ -+#ifndef tst_bit -+/* -+ * Test a bit in the bitmap -+ */ -+static __inline__ int -+tst_bit(struct pginfo *pi, int bit) -+{ -+ return pi->bits[bit/MALLOC_BITS] & (1<<(bit%MALLOC_BITS)); -+} -+#endif /* tst_bit */ -+ -+/* -+ * Find last bit -+ */ -+#ifndef fls -+static __inline__ int -+fls(int size) -+{ -+ int i = 1; -+ while (size >>= 1) -+ i++; -+ return i; -+} -+#endif /* fls */ -+ -+/* + * Extend page directory + */ +static int @@ -531,8 +392,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + */ + + /* Get new pages */ -+ new = (struct pginfo**) mmap(0, i * malloc_pagesize, PROT_READ|PROT_WRITE, -+ MAP_ANON|MAP_PRIVATE, -1, 0); ++ new = (struct pginfo**) MMAP(i * malloc_pagesize); + if (new == (struct pginfo **)-1) + return 0; + @@ -561,6 +421,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + char *p, b[64]; + int i, j; + ++ INIT_MMAP(); + +#ifdef EXTRA_SANITY + malloc_junk = 1; @@ -575,7 +436,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + p = b; + } else if (i == 1) { + p = getenv("MALLOC_OPTIONS"); -+ } else if (i == 2) { ++ } else { + p = malloc_options; + } + for (; p && *p; p++) { @@ -584,22 +445,18 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + case '<': malloc_cache >>= 1; break; + case 'a': malloc_abort = 0; break; + case 'A': malloc_abort = 1; break; -+#ifdef MALLOC_STATS -+ case 'd': malloc_stats = 0; break; -+ case 'D': malloc_stats = 1; break; -+#endif /* MALLOC_STATS */ -+#ifdef MADV_FREE + case 'h': malloc_hint = 0; break; + case 'H': malloc_hint = 1; break; -+#endif /* MADV_FREE */ + case 'r': malloc_realloc = 0; break; + case 'R': malloc_realloc = 1; break; + case 'j': malloc_junk = 0; break; + case 'J': malloc_junk = 1; break; -+#ifdef HAVE_UTRACE + case 'u': malloc_utrace = 0; break; + case 'U': malloc_utrace = 1; break; -+#endif /* HAVE_UTRACE */ ++ case 'v': malloc_sysv = 0; break; ++ case 'V': malloc_sysv = 1; break; ++ case 'x': malloc_xmalloc = 0; break; ++ case 'X': malloc_xmalloc = 1; break; + case 'z': malloc_zero = 0; break; + case 'Z': malloc_zero = 1; break; + default: @@ -621,57 +478,9 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + if (malloc_zero) + malloc_junk=1; + -+#ifdef EXTRA_SANITY -+ if (malloc_stats) -+ atexit(malloc_exit); -+#endif /* EXTRA_SANITY */ -+ -+#ifndef malloc_pagesize -+ /* determine our pagesize */ -+ malloc_pagesize = getpagesize(); -+#endif /* malloc_pagesize */ -+ -+#ifndef malloc_maxsize -+ malloc_maxsize = malloc_pagesize >> 1; -+#endif /* malloc_maxsize */ -+ -+#ifndef malloc_pageshift -+ { -+ int i; -+ /* determine how much we shift by to get there */ -+ for (i = malloc_pagesize; i > 1; i >>= 1) -+ malloc_pageshift++; -+ } -+#endif /* malloc_pageshift */ -+ -+#ifndef malloc_minsize -+ { -+ int i; -+ /* -+ * find the smallest size allocation we will bother about. -+ * this is determined as the smallest allocation that can hold -+ * it's own pginfo; -+ */ -+ i = 2; -+ for(;;) { -+ int j; -+ -+ /* Figure out the size of the bits */ -+ j = malloc_pagesize/i; -+ j /= 8; -+ if (j < sizeof(u_long)) -+ j = sizeof (u_long); -+ if (sizeof(struct pginfo) + j - sizeof (u_long) <= i) -+ break; -+ i += i; -+ } -+ malloc_minsize = i; -+ } -+#endif /* malloc_minsize */ -+ + /* Allocate one page for the page directory */ -+ page_dir = (struct pginfo **) mmap(0, malloc_pagesize, PROT_READ|PROT_WRITE, -+ MAP_ANON|MAP_PRIVATE, -1, 0); ++ page_dir = (struct pginfo **) MMAP(malloc_pagesize); ++ + if (page_dir == (struct pginfo **) -1) + wrterror("mmap(2) failed, check limits.\n"); + @@ -685,7 +494,14 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + malloc_ninfo = malloc_pagesize / sizeof *page_dir; + + /* Been here, done that */ -+ initialized++; ++ malloc_started++; ++ ++ /* Recalculate the cache size in bytes, and make sure it's nonzero */ ++ ++ if (!malloc_cache) ++ malloc_cache++; ++ ++ malloc_cache <<= malloc_pageshift; + + /* + * This is a nice hack from Kaleb Keithly (kaleb@x.org). @@ -693,16 +509,12 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + */ + px = (struct pgfree *) imalloc (sizeof *px); + -+ if (!malloc_cache) -+ malloc_cache++; -+ -+ malloc_cache <<= malloc_pageshift; +} + +/* + * Allocate a number of complete pages + */ -+void * ++static void * +malloc_pages(size_t size) +{ + void *p, *delay_free = 0; @@ -713,6 +525,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + size = pageround(size); + + p = 0; ++ + /* Look for free pages before asking for more */ + for(pf = free_list.next; pf; pf = pf->next) { + @@ -809,8 +622,10 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + bp = (struct pginfo *)pp; + } else { + bp = (struct pginfo *)imalloc(l); -+ if (!bp) ++ if (!bp) { ++ ifree(pp); + return 0; ++ } + } + + bp->size = (1<total = bp->free = malloc_pagesize >> bits; + bp->page = pp; + -+ page_dir[ptr2index(pp)] = bp; -+ -+ bp->next = page_dir[bits]; -+ page_dir[bits] = bp; -+ -+ /* set all valid bits in the bits */ ++ /* set all valid bits in the bitmap */ + k = bp->total; + i = 0; + @@ -832,18 +642,27 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + bp->bits[i / MALLOC_BITS] = ~0; + + for(; i < k; i++) -+ set_bit(bp, i); ++ bp->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS); + + if (bp == bp->page) { + /* Mark the ones we stole for ourselves */ + for(i=0;l > 0;i++) { -+ clr_bit(bp, i); ++ bp->bits[i/MALLOC_BITS] &= ~(1<<(i%MALLOC_BITS)); + bp->free--; + bp->total--; + l -= (1 << bits); + } + } + ++ /* MALLOC_LOCK */ ++ ++ page_dir[ptr2index(pp)] = bp; ++ ++ bp->next = page_dir[bits]; ++ page_dir[bits] = bp; ++ ++ /* MALLOC_UNLOCK */ ++ + return 1; +} + @@ -853,17 +672,21 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +static void * +malloc_bytes(size_t size) +{ -+ int j; ++ int i,j; ++ u_int u; + struct pginfo *bp; + int k; -+ u_long *lp; ++ u_int *lp; + + /* Don't bother with anything less than this */ + if (size < malloc_minsize) + size = malloc_minsize; + + /* Find the right bucket */ -+ j = fls((size)-1); ++ j = 1; ++ i = size-1; ++ while (i >>= 1) ++ j++; + + /* If it's empty, make a page more of that size chunks */ + if (!page_dir[j] && !malloc_make_chunks(j)) @@ -876,8 +699,13 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + ; + + /* Find that bit, and tweak it */ -+ k = ffs(*lp) - 1; -+ *lp ^= 1<free) { @@ -890,9 +718,9 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + k <<= bp->shift; + + if (malloc_junk) -+ memset(bp->page + k, SOME_JUNK, bp->size); ++ memset((u_char*)bp->page + k, SOME_JUNK, bp->size); + -+ return bp->page + k; ++ return (u_char *)bp->page + k; +} + +/* @@ -903,13 +731,15 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +{ + void *result; + -+ if (!initialized) ++ if (!malloc_started) + malloc_init(); + + if (suicide) + abort(); + -+ if (size <= malloc_maxsize) ++ if ((size + malloc_pagesize) < size) /* Check for overflow */ ++ result = 0; ++ else if (size <= malloc_maxsize) + result = malloc_bytes(size); + else + result = malloc_pages(size); @@ -917,7 +747,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + if (malloc_abort && !result) + wrterror("allocation failed.\n"); + -+ if (malloc_zero) ++ if (malloc_zero && result) + memset(result, 0, size); + + return result; @@ -935,9 +765,9 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + int i; + + if (suicide) -+ return 0; ++ abort(); + -+ if (!initialized) { ++ if (!malloc_started) { + wrtwarning("malloc() has never been called.\n"); + return 0; + } @@ -986,7 +816,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + i = ((u_long)ptr & malloc_pagemask) >> (*mp)->shift; + + /* Verify that it isn't a free chunk already */ -+ if (tst_bit(*mp, i)) { ++ if ((*mp)->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) { + wrtwarning("chunk is already free.\n"); + return 0; + } @@ -1009,7 +839,9 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + + if (p) { + /* copy the lesser of the two sizes, and free the old one */ -+ if (osize < size) ++ if (!size || !osize) ++ ; ++ else if (osize < size) + memcpy(p, ptr, osize); + else + memcpy(p, ptr, size); @@ -1052,10 +884,13 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + + l = i << malloc_pageshift; + ++ if (malloc_junk) ++ memset(ptr, SOME_JUNK, l); ++ +#ifdef MADV_FREE + if (malloc_hint) + madvise(ptr, l, MADV_FREE); -+#endif /* MADV_FREE */ ++#endif + + tail = (char *)ptr+l; + @@ -1166,12 +1001,15 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + return; + } + -+ if (tst_bit(info, i)) { ++ if (info->bits[i/MALLOC_BITS] & (1<<(i%MALLOC_BITS))) { + wrtwarning("chunk is already free.\n"); + return; + } + -+ set_bit(info, i); ++ if (malloc_junk) ++ memset(ptr, SOME_JUNK, info->size); ++ ++ info->bits[i/MALLOC_BITS] |= 1<<(i%MALLOC_BITS); + info->free++; + + mp = page_dir + info->shift; @@ -1220,7 +1058,7 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + if (!ptr) + return; + -+ if (!initialized) { ++ if (!malloc_started) { + wrtwarning("malloc() has never been called.\n"); + return; + } @@ -1254,29 +1092,15 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + * These are the public exported interface routines. + */ + -+#ifdef _THREAD_SAFE -+#include -+#include "pthread_private.h" -+static int malloc_lock; -+#define THREAD_LOCK() _thread_kern_sig_block(&malloc_lock); -+#define THREAD_UNLOCK() _thread_kern_sig_unblock(&malloc_lock); -+#elif defined(M3_THREAD_SAFE) -+extern int RT0u__inCritical; /* Flag set when in a critical region */ -+#define THREAD_LOCK() (++RT0u__inCritical) -+#define THREAD_UNLOCK() (--RT0u__inCritical) -+#else -+#define THREAD_LOCK() -+#define THREAD_UNLOCK() -+#endif -+ -+static int malloc_active; + +void * +malloc(size_t size) +{ + register void *r; + -+ malloc_func = "malloc():"; ++ if (malloc_sysv && !size) ++ return (0); ++ malloc_func = " in malloc():"; + THREAD_LOCK(); + if (malloc_active++) { + wrtwarning("recursive call.\n"); @@ -1287,13 +1111,15 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c + UTRACE(0, size, r); + malloc_active--; + THREAD_UNLOCK(); ++ if (malloc_xmalloc && !r) ++ wrterror("out of memory.\n"); + return (r); +} + +void +free(void *ptr) +{ -+ malloc_func = "free():"; ++ malloc_func = " in free():"; + THREAD_LOCK(); + if (malloc_active++) { + wrtwarning("recursive call.\n"); @@ -1312,23 +1138,51 @@ Index: m3/m3core/src/runtime/FreeBSD2/malloc.c +{ + register void *r; + -+ malloc_func = "realloc():"; ++ malloc_func = " in realloc():"; + THREAD_LOCK(); + if (malloc_active++) { + wrtwarning("recursive call.\n"); + malloc_active--; + return (0); + } -+ if (!ptr) { -+ r = imalloc(size); -+ } else if (ptr && !size) { ++ if (malloc_sysv && !size) { + ifree(ptr); + r = 0; ++ } else if (!ptr) { ++ r = imalloc(size); + } else { + r = irealloc(ptr, size); + } + UTRACE(ptr, size, r); + malloc_active--; + THREAD_UNLOCK(); ++ if (malloc_xmalloc && !r) ++ wrterror("out of memory.\n"); ++ return (r); ++} ++ ++void * ++calloc(size_t num, size_t size) ++{ ++ register void *r; ++ ++ size *= num; ++ if (malloc_sysv && !size) ++ return (0); ++ malloc_func = " in calloc():"; ++ THREAD_LOCK(); ++ if (malloc_active++) { ++ wrtwarning("recursive call.\n"); ++ malloc_active--; ++ return (0); ++ } ++ r = imalloc(size); ++ UTRACE(0, size, r); ++ malloc_active--; ++ THREAD_UNLOCK(); ++ if (malloc_xmalloc && !r) ++ wrterror("out of memory.\n"); ++ if (r) ++ memset(r, 0, size); + return (r); +} diff --git a/lang/modula-3-lib/pkg-plist b/lang/modula-3-lib/pkg-plist index 02bc73a6e6f2..96d59d7f6aa1 100644 --- a/lang/modula-3-lib/pkg-plist +++ b/lang/modula-3-lib/pkg-plist @@ -1,43 +1,43 @@ etc/rc.d/50.m3.sh -lib/m3/FreeBSD2/libDiGraph.so.4.1 -lib/m3/FreeBSD2/libGeometry.so.4.1 -lib/m3/FreeBSD2/libImages.so.4.1 -lib/m3/FreeBSD2/libTempFiles.so.4.1 -lib/m3/FreeBSD2/libjvideo.so.4.1 -lib/m3/FreeBSD2/libm3.so.4.1 -lib/m3/FreeBSD2/libm3X11R4.so.4.1 -lib/m3/FreeBSD2/libm3core.so.4.1 -lib/m3/FreeBSD2/libm3formsvbt.so.4.1 -lib/m3/FreeBSD2/libm3formsvbtpixmaps.so.4.1 -lib/m3/FreeBSD2/libm3parseparams.so.4.1 -lib/m3/FreeBSD2/libm3tcp.so.4.1 -lib/m3/FreeBSD2/libm3tools.so.4.1 -lib/m3/FreeBSD2/libm3ui.so.4.1 -lib/m3/FreeBSD2/libm3vbtkit.so.4.1 -lib/m3/FreeBSD2/libset.so.4.1 -lib/m3/FreeBSD2/libtable-list.so.4.1 -lib/m3/FreeBSD2/libtcpextras.so.4.1 -lib/m3/FreeBSD2/libvideovbt.so.4.1 -lib/m3/FreeBSD2/libweb.so.4.1 -lib/m3/pkg/X11R4/FreeBSD2/libm3X11R4.so.4.1 -lib/m3/pkg/digraph/FreeBSD2/libDiGraph.so.4.1 -lib/m3/pkg/formsvbt/FreeBSD2/libm3formsvbt.so.4.1 -lib/m3/pkg/formsvbtpixmaps/FreeBSD2/libm3formsvbtpixmaps.so.4.1 -lib/m3/pkg/images/FreeBSD2/libImages.so.4.1 -lib/m3/pkg/jvideo/FreeBSD2/libjvideo.so.4.1 -lib/m3/pkg/libm3/FreeBSD2/libm3.so.4.1 -lib/m3/pkg/m3core/FreeBSD2/libm3core.so.4.1 -lib/m3/pkg/m3tools/FreeBSD2/libm3tools.so.4.1 -lib/m3/pkg/parseparams/FreeBSD2/libm3parseparams.so.4.1 -lib/m3/pkg/realgeometry/FreeBSD2/libGeometry.so.4.1 -lib/m3/pkg/set/FreeBSD2/libset.so.4.1 -lib/m3/pkg/table-list/FreeBSD2/libtable-list.so.4.1 -lib/m3/pkg/tcp/FreeBSD2/libm3tcp.so.4.1 -lib/m3/pkg/tcpextras/FreeBSD2/libtcpextras.so.4.1 -lib/m3/pkg/tempfiles/FreeBSD2/libTempFiles.so.4.1 -lib/m3/pkg/ui/FreeBSD2/libm3ui.so.4.1 -lib/m3/pkg/vbtkit/FreeBSD2/libm3vbtkit.so.4.1 -lib/m3/pkg/videovbt/FreeBSD2/libvideovbt.so.4.1 -lib/m3/pkg/web/FreeBSD2/libweb.so.4.1 +lib/m3/FreeBSD2/libDiGraph.so.4.2 +lib/m3/FreeBSD2/libGeometry.so.4.2 +lib/m3/FreeBSD2/libImages.so.4.2 +lib/m3/FreeBSD2/libTempFiles.so.4.2 +lib/m3/FreeBSD2/libjvideo.so.4.2 +lib/m3/FreeBSD2/libm3.so.4.2 +lib/m3/FreeBSD2/libm3X11R4.so.4.2 +lib/m3/FreeBSD2/libm3core.so.4.2 +lib/m3/FreeBSD2/libm3formsvbt.so.4.2 +lib/m3/FreeBSD2/libm3formsvbtpixmaps.so.4.2 +lib/m3/FreeBSD2/libm3parseparams.so.4.2 +lib/m3/FreeBSD2/libm3tcp.so.4.2 +lib/m3/FreeBSD2/libm3tools.so.4.2 +lib/m3/FreeBSD2/libm3ui.so.4.2 +lib/m3/FreeBSD2/libm3vbtkit.so.4.2 +lib/m3/FreeBSD2/libset.so.4.2 +lib/m3/FreeBSD2/libtable-list.so.4.2 +lib/m3/FreeBSD2/libtcpextras.so.4.2 +lib/m3/FreeBSD2/libvideovbt.so.4.2 +lib/m3/FreeBSD2/libweb.so.4.2 +lib/m3/pkg/X11R4/FreeBSD2/libm3X11R4.so.4.2 +lib/m3/pkg/digraph/FreeBSD2/libDiGraph.so.4.2 +lib/m3/pkg/formsvbt/FreeBSD2/libm3formsvbt.so.4.2 +lib/m3/pkg/formsvbtpixmaps/FreeBSD2/libm3formsvbtpixmaps.so.4.2 +lib/m3/pkg/images/FreeBSD2/libImages.so.4.2 +lib/m3/pkg/jvideo/FreeBSD2/libjvideo.so.4.2 +lib/m3/pkg/libm3/FreeBSD2/libm3.so.4.2 +lib/m3/pkg/m3core/FreeBSD2/libm3core.so.4.2 +lib/m3/pkg/m3tools/FreeBSD2/libm3tools.so.4.2 +lib/m3/pkg/parseparams/FreeBSD2/libm3parseparams.so.4.2 +lib/m3/pkg/realgeometry/FreeBSD2/libGeometry.so.4.2 +lib/m3/pkg/set/FreeBSD2/libset.so.4.2 +lib/m3/pkg/table-list/FreeBSD2/libtable-list.so.4.2 +lib/m3/pkg/tcp/FreeBSD2/libm3tcp.so.4.2 +lib/m3/pkg/tcpextras/FreeBSD2/libtcpextras.so.4.2 +lib/m3/pkg/tempfiles/FreeBSD2/libTempFiles.so.4.2 +lib/m3/pkg/ui/FreeBSD2/libm3ui.so.4.2 +lib/m3/pkg/vbtkit/FreeBSD2/libm3vbtkit.so.4.2 +lib/m3/pkg/videovbt/FreeBSD2/libvideovbt.so.4.2 +lib/m3/pkg/web/FreeBSD2/libweb.so.4.2 share/modula-3-lib/COPYRIGHT @exec /sbin/ldconfig -m %D/lib/m3/FreeBSD2 diff --git a/lang/modula-3/Makefile b/lang/modula-3/Makefile index e0b14a724cb7..f96e2cf407d7 100644 --- a/lang/modula-3/Makefile +++ b/lang/modula-3/Makefile @@ -3,7 +3,7 @@ # Date created: 18 Mar 1996 # Whom: John Polstra # -# $Id: Makefile,v 1.11 1997/03/28 04:38:36 jdp Exp $ +# $Id: Makefile,v 1.12 1997/05/09 20:44:54 jdp Exp $ # DISTNAME= modula-3-3.6 @@ -22,7 +22,7 @@ NO_BUILD= yes # Keep these in sync with the PLIST and with the library version numbers # in the modula-3-lib port. major= 4 -minor= 1 +minor= 2 # The Modula-3 build process insists on installing each individual # component immediately after that component is built. To avoid having diff --git a/lang/modula-3/pkg-plist b/lang/modula-3/pkg-plist index 7f4a54c5fdbc..f28435afdaab 100644 --- a/lang/modula-3/pkg-plist +++ b/lang/modula-3/pkg-plist @@ -3,7 +3,7 @@ bin/formsedit bin/m3browser bin/m3build bin/m3build-4 -bin/m3build-4.1 +bin/m3build-4.2 bin/m3bundle bin/m3pp bin/m3ship @@ -16,7 +16,7 @@ bin/replayheap bin/showheap bin/shownew bin/showthread -lib/m3/FreeBSD2/libm3configvars.so.4.1 +lib/m3/FreeBSD2/libm3configvars.so.4.2 lib/m3/FreeBSD2/m3 lib/m3/FreeBSD2/m3cgc1 lib/m3/FreeBSD2/m3mkdir @@ -313,7 +313,7 @@ lib/m3/pkg/m3configvars/FreeBSD2/.M3IMPTAB lib/m3/pkg/m3configvars/FreeBSD2/.M3WEB lib/m3/pkg/m3configvars/FreeBSD2/libm3configvars.a lib/m3/pkg/m3configvars/FreeBSD2/libm3configvars.m3x -lib/m3/pkg/m3configvars/FreeBSD2/libm3configvars.so.4.1 +lib/m3/pkg/m3configvars/FreeBSD2/libm3configvars.so.4.2 lib/m3/pkg/m3configvars/src/M3ConfigVars.i3 lib/m3/pkg/m3core/FreeBSD2/.M3EXPORTS lib/m3/pkg/m3core/FreeBSD2/.M3IMPTAB -- cgit v1.2.3