summaryrefslogtreecommitdiff
path: root/usr/src/lib/libast/common/vmalloc
diff options
context:
space:
mode:
authorRoger A. Faulkner <Roger.Faulkner@Oracle.COM>2010-04-03 09:48:44 -0700
committerRoger A. Faulkner <Roger.Faulkner@Oracle.COM>2010-04-03 09:48:44 -0700
commit3e14f97f673e8a630f076077de35afdd43dc1587 (patch)
tree9828b6b676f58d7b27dd28e00202d3f3461a5cd8 /usr/src/lib/libast/common/vmalloc
parent4f60987df4dcaa54a88b596f861fbf4f3382c65e (diff)
downloadillumos-gate-3e14f97f673e8a630f076077de35afdd43dc1587.tar.gz
6939349 RFE: Update ksh93 to ast-ksh.2010-03-09
6877392 ksh93 regresses 'uniq -c' performance 6887363 Korn shell 93 sometimes mishandles return value of its child process 6900314 (while true ; do true|true ; done) hang in ioctl() with SIGTTOU 6904557 wc no longer counts number of bytes correctly 6904575 cut -d with multibyte character no longer works 6904597 paste -d no longer works with multibyte characters 6904780 /usr/bin/cksum changed output in snv_128 6904870 uniq -s does not skip multibyte characters correctly 6904878 join -t no longer works with multibyte char separator 6907460 EXIT trap handlers are sometimes executed twice 6909579 libast getopt solaris compatibility broken 6920072 ksh93 tail -f, with unconditional .25s sleep and line parsing, about 37x slower than cat 6932124 mktemp in ksh93 is broken Contributed by Olga Kryzhanovska <olga.kryzhanovska@gmail.com>
Diffstat (limited to 'usr/src/lib/libast/common/vmalloc')
-rw-r--r--usr/src/lib/libast/common/vmalloc/malloc.c611
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmbest.c167
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmclear.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmclose.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmdcheap.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmdebug.c45
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmdisc.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmexit.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmgetmem.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmhdr.h25
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmlast.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmmopen.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmopen.c8
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmpool.c4
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmprivate.c41
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmprofile.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmregion.c24
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmsegment.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmset.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmstat.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmstrdup.c2
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmtrace.c3
-rw-r--r--usr/src/lib/libast/common/vmalloc/vmwalk.c11
23 files changed, 573 insertions, 392 deletions
diff --git a/usr/src/lib/libast/common/vmalloc/malloc.c b/usr/src/lib/libast/common/vmalloc/malloc.c
index da4a839ecd..84f61120ad 100644
--- a/usr/src/lib/libast/common/vmalloc/malloc.c
+++ b/usr/src/lib/libast/common/vmalloc/malloc.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -88,21 +88,39 @@ typedef struct ______mstats Mstats_t;
#define _AST_std_malloc 1
#endif
-#if ( !_std_malloc || !_BLD_ast ) && !_AST_std_malloc
-
-/* malloc compatibility functions.
-** These are aware of debugging/profiling and driven by the environment variables:
-** VMETHOD: select an allocation method by name.
+/* malloc compatibility functions
+**
+** These are aware of debugging/profiling and are driven by the
+** VMALLOC_OPTIONS environment variable which is a space-separated
+** list of [no]name[=value] options:
**
-** VMPROFILE: if is a file name, write profile data to it.
-** VMTRACE: if is a file name, write trace data to it.
-** The pattern %p in a file name will be replaced by the process ID.
+** abort if Vmregion==Vmdebug then VM_DBABORT is set,
+** otherwise _BLD_debug enabled assertions abort()
+** on failure
+** check if Vmregion==Vmbest then the region is checked every op
+** method=m sets Vmregion=m if not defined, m (Vm prefix optional)
+** may be one of { best debug last profile }
+** mmap prefer mmap() over brk() for region allocation
+** period=n sets Vmregion=Vmdebug if not defined, if
+** Vmregion==Vmdebug the region is checked every n ops
+** profile=f sets Vmregion=Vmprofile if not set, if
+** Vmregion==Vmprofile then profile info printed to file f
+** region if Vmregion==Vmbest then block free verifies
+** that the block belongs to the region
+** start=n sets Vmregion=Vmdebug if not defined, if
+** Vmregion==Vmdebug region checking starts after n ops
+** trace=f enables tracing to file f
+** warn=f sets Vmregion=Vmdebug if not defined, if
+** Vmregion==Vmdebug then warnings printed to file f
+** watch=a sets Vmregion=Vmdebug if not defined, if
+** Vmregion==Vmdebug then address a is watched
**
-** VMDEBUG:
-** a: abort on any warning.
-** w[decimal]: file descriptor for warnings.
-** [decimal]: period to check arena.
-** 0x[hexadecimal]: address to watch.
+** Output files are created if they don't exist. &n and /dev/fd/n name
+** the file descriptor n which must be open for writing. The pattern %p
+** in a file name is replaced by the process ID.
+**
+** VMALLOC_OPTIONS combines the features of these previously used env vars:
+** { VMDEBUG VMETHOD VMPROFILE VMTRACE }
**
** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
*/
@@ -118,6 +136,13 @@ typedef struct ______mstats Mstats_t;
#define CREAT_MODE 0644
#endif
+static Vmulong_t _Vmdbstart = 0;
+static Vmulong_t _Vmdbcheck = 0;
+static Vmulong_t _Vmdbtime = 0;
+static int _Vmpffd = -1;
+
+#if ( !_std_malloc || !_BLD_ast ) && !_AST_std_malloc
+
#if !_map_malloc
#undef calloc
#undef cfree
@@ -182,44 +207,7 @@ lcl_getenv(const char* s)
#define extern extern __EXPORT__
#endif
-#if __STD_C
-static Vmulong_t atou(char** sp)
-#else
-static Vmulong_t atou(sp)
-char** sp;
-#endif
-{
- char* s = *sp;
- Vmulong_t v = 0;
-
- if(s[0] == '0' && (s[1] == 'x' || s[1] == 'X') )
- { for(s += 2; *s; ++s)
- { if(*s >= '0' && *s <= '9')
- v = (v << 4) + (*s - '0');
- else if(*s >= 'a' && *s <= 'f')
- v = (v << 4) + (*s - 'a') + 10;
- else if(*s >= 'A' && *s <= 'F')
- v = (v << 4) + (*s - 'A') + 10;
- else break;
- }
- }
- else
- { for(; *s; ++s)
- { if(*s >= '0' && *s <= '9')
- v = v*10 + (*s - '0');
- else break;
- }
- }
-
- *sp = s;
- return v;
-}
-
static int _Vmflinit = 0;
-static Vmulong_t _Vmdbstart = 0;
-static Vmulong_t _Vmdbcheck = 0;
-static Vmulong_t _Vmdbtime = 0;
-static int _Vmpffd = -1;
#define VMFLINIT() \
{ if(!_Vmflinit) vmflinit(); \
if(_Vmdbcheck) \
@@ -232,99 +220,11 @@ static int _Vmpffd = -1;
}
#if __STD_C
-static char* insertpid(char* begs, char* ends)
-#else
-static char* insertpid(begs,ends)
-char* begs;
-char* ends;
-#endif
-{ int pid;
- char* s;
-
- if((pid = getpid()) < 0)
- return NIL(char*);
-
- s = ends;
- do
- { if(s == begs)
- return NIL(char*);
- *--s = '0' + pid%10;
- } while((pid /= 10) > 0);
- while(s < ends)
- *begs++ = *s++;
-
- return begs;
-}
-
-#if __STD_C
-static int createfile(char* file)
-#else
-static int createfile(file)
-char* file;
-#endif
-{
- char buf[1024];
- char *next, *endb;
-
- next = buf;
- endb = buf + sizeof(buf);
- while(*file)
- { if(*file == '%')
- { switch(file[1])
- {
- case 'p' :
- if(!(next = insertpid(next,endb)) )
- return -1;
- file += 2;
- break;
- default :
- goto copy;
- }
- }
- else
- { copy:
- *next++ = *file++;
- }
-
- if(next >= endb)
- return -1;
- }
-
- *next = '\0';
-#if _PACKAGE_ast
- { int fd;
- fd = open(buf,O_WRONLY|O_CREAT|O_TRUNC,CREAT_MODE);
-#ifdef FD_CLOEXEC
- if (fd >= 0)
- fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
- return fd;
- }
-#else
- return creat(buf,CREAT_MODE);
-#endif
-}
-
-#if __STD_C
-static void pfprint(void)
-#else
-static void pfprint()
-#endif
-{
- if(Vmregion->meth.meth == VM_MTPROFILE)
- vmprofile(Vmregion,_Vmpffd);
-}
-
-#if __STD_C
static int vmflinit(void)
#else
static int vmflinit()
#endif
{
- char* env;
- Vmalloc_t* vm;
- int fd;
- Vmulong_t addr;
char* file;
int line;
Void_t* func;
@@ -333,82 +233,8 @@ static int vmflinit()
_Vmflinit = 1;
VMFLF(Vmregion,file,line,func);
- /* if getenv() calls malloc(), the eventual region may not see this */
- vm = NIL(Vmalloc_t*);
- if((env = getenv("VMETHOD")) )
- { if(strcmp(env,"Vmdebug") == 0 || strcmp(env,"vmdebug") == 0)
- vm = vmopen(Vmdcsbrk,Vmdebug,0);
- else if(strcmp(env,"Vmprofile") == 0 || strcmp(env,"vmprofile") == 0 )
- vm = vmopen(Vmdcsbrk,Vmprofile,0);
- else if(strcmp(env,"Vmlast") == 0 || strcmp(env,"vmlast") == 0 )
- vm = vmopen(Vmdcsbrk,Vmlast,0);
- else if(strcmp(env,"Vmbest") == 0 || strcmp(env,"vmbest") == 0 )
- vm = Vmheap;
- }
-
- if((!vm || vm->meth.meth == VM_MTDEBUG) &&
- (env = getenv("VMDEBUG")) && env[0] )
- { if(vm || (vm = vmopen(Vmdcsbrk,Vmdebug,0)) )
- { reg int setcheck = 0;
-
- while(*env)
- { if(*env == 'a')
- { vmset(vm,VM_DBABORT,1);
- env += 1;
- }
- else if(*env =='w')
- { env += 1;
- if((fd = atou(&env)) >= 0 )
- vmdebug(fd);
- }
- else if(*env < '0' || *env > '9')
- env += 1;
- else if(env[0] == '0' && (env[1] == 'x' || env[1] == 'X') )
- { if((addr = atou(&env)) != 0)
- vmdbwatch((Void_t*)addr);
- }
- else
- { _Vmdbcheck = atou(&env);
- setcheck = 1;
- if(*env == ',')
- { env += 1;
- _Vmdbstart = atou(&env);
- }
- }
- }
- if(!setcheck)
- _Vmdbcheck = 1;
- }
- }
-
- if((!vm || vm->meth.meth == VM_MTPROFILE) &&
- (env = getenv("VMPROFILE")) && env[0] )
- { _Vmpffd = createfile(env);
- if(!vm)
- vm = vmopen(Vmdcsbrk,Vmprofile,0);
- }
-
- /* slip in the new region now so that malloc() will work fine */
- if(vm)
- Vmregion = vm;
-
- /* turn on tracing if requested */
- if((env = getenv("VMTRACE")) && env[0] && (fd = createfile(env)) >= 0)
- { vmset(Vmregion,VM_TRACE,1);
- vmtrace(fd);
- }
-
- /* make sure that profile data is output upon exiting */
- if(vm && vm->meth.meth == VM_MTPROFILE)
- { if(_Vmpffd < 0)
- _Vmpffd = 2;
- /* this may wind up calling malloc(), but region is ok now */
- atexit(pfprint);
- }
- else if(_Vmpffd >= 0)
- { close(_Vmpffd);
- _Vmpffd = -1;
- }
+ /* if getenv() calls malloc(), the options may not affect the eventual region */
+ VMOPTIONS();
/* reset file and line number to correct values for the call */
Vmregion->file = file;
@@ -938,4 +764,359 @@ extern Mstats_t F0(_ast_mstats, void) { return mstats(); }
#endif /*!_std_malloc*/
+#if __STD_C
+static Vmulong_t atou(char** sp)
+#else
+static Vmulong_t atou(sp)
+char** sp;
+#endif
+{
+ char* s = *sp;
+ Vmulong_t v = 0;
+
+ if(s[0] == '0' && (s[1] == 'x' || s[1] == 'X') )
+ { for(s += 2; *s; ++s)
+ { if(*s >= '0' && *s <= '9')
+ v = (v << 4) + (*s - '0');
+ else if(*s >= 'a' && *s <= 'f')
+ v = (v << 4) + (*s - 'a') + 10;
+ else if(*s >= 'A' && *s <= 'F')
+ v = (v << 4) + (*s - 'A') + 10;
+ else break;
+ }
+ }
+ else
+ { for(; *s; ++s)
+ { if(*s >= '0' && *s <= '9')
+ v = v*10 + (*s - '0');
+ else break;
+ }
+ }
+
+ *sp = s;
+ return v;
+}
+
+#if __STD_C
+static char* insertpid(char* begs, char* ends)
+#else
+static char* insertpid(begs,ends)
+char* begs;
+char* ends;
+#endif
+{ int pid;
+ char* s;
+
+ if((pid = getpid()) < 0)
+ return NIL(char*);
+
+ s = ends;
+ do
+ { if(s == begs)
+ return NIL(char*);
+ *--s = '0' + pid%10;
+ } while((pid /= 10) > 0);
+ while(s < ends)
+ *begs++ = *s++;
+
+ return begs;
+}
+
+#if __STD_C
+static int createfile(char* file)
+#else
+static int createfile(file)
+char* file;
+#endif
+{
+ char buf[1024];
+ char *next, *endb;
+ int fd;
+
+ next = buf;
+ endb = buf + sizeof(buf);
+ while(*file)
+ { if(*file == '%')
+ { switch(file[1])
+ {
+ case 'p' :
+ if(!(next = insertpid(next,endb)) )
+ return -1;
+ file += 2;
+ break;
+ default :
+ goto copy;
+ }
+ }
+ else
+ { copy:
+ *next++ = *file++;
+ }
+
+ if(next >= endb)
+ return -1;
+ }
+
+ *next = '\0';
+ file = buf;
+ if (*file == '&' && *(file += 1) || strncmp(file, "/dev/fd/", 8) == 0 && *(file += 8))
+ fd = dup((int)atou(&file));
+ else if (*file)
+#if _PACKAGE_ast
+ fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, CREAT_MODE);
+#else
+ fd = creat(file, CREAT_MODE);
+#endif
+ else
+ return -1;
+#if _PACKAGE_ast
+#ifdef FD_CLOEXEC
+ if (fd >= 0)
+ fcntl(fd, F_SETFD, FD_CLOEXEC);
+#endif
+#endif
+ return fd;
+}
+
+#if __STD_C
+static void pfprint(void)
+#else
+static void pfprint()
+#endif
+{
+ if(Vmregion->meth.meth == VM_MTPROFILE)
+ vmprofile(Vmregion,_Vmpffd);
+}
+
+/*
+ * initialize runtime options from the VMALLOC_OPTIONS env var
+ */
+
+#define COPY(t,e,f) while ((*t = *f++) && t < e) t++
+
+#if __STD_C
+void _vmoptions(void)
+#else
+void _vmoptions()
+#endif
+{
+ Vmalloc_t* vm = 0;
+ char* trace = 0;
+ char* s;
+ char* t;
+ char* v;
+ Vmulong_t n;
+ int fd;
+ char buf[1024];
+
+ _Vmoptions = 1;
+ t = buf;
+ v = &buf[sizeof(buf)-1];
+ if (s = getenv("VMALLOC_OPTIONS"))
+ COPY(t, v, s);
+#if 1 /* backwards compatibility until 2011 */
+ else
+ {
+ char* p;
+
+ if (s = getenv("VMDEBUG"))
+ {
+ switch (*s++)
+ {
+ case 0:
+ break;
+ case 'a':
+ p = " abort";
+ COPY(t, v, p);
+ break;
+ case 'w':
+ p = " warn";
+ COPY(t, v, p);
+ break;
+ case '0':
+ if (*s-- == 'x')
+ {
+ p = " watch=";
+ COPY(t, v, p);
+ COPY(t, v, s);
+ break;
+ }
+ /*FALLTHROUGH*/
+ default:
+ p = " period=";
+ COPY(t, v, p);
+ COPY(t, v, s);
+ break;
+ }
+ }
+ if ((s = getenv("VMETHOD")) && *s)
+ {
+ p = " method=";
+ COPY(t, v, p);
+ COPY(t, v, s);
+ }
+ if ((s = getenv("VMPROFILE")) && *s)
+ {
+ p = " profile=";
+ COPY(t, v, p);
+ COPY(t, v, s);
+ }
+ if ((s = getenv("VMTRACE")) && *s)
+ {
+ p = " trace=";
+ COPY(t, v, p);
+ COPY(t, v, s);
+ }
+ }
+#endif
+ if (t > buf)
+ {
+ *t = 0;
+ s = buf;
+ for (;;)
+ {
+ while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n')
+ s++;
+ if (!*(t = s))
+ break;
+ v = 0;
+ while (*s)
+ if (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n')
+ {
+ *s++ = 0;
+ break;
+ }
+ else if (!v && *s == '=')
+ {
+ *s++ = 0;
+ if (!*(v = s))
+ v = 0;
+ }
+ else
+ s++;
+ if (t[0] == 'n' && t[1] == 'o')
+ continue;
+ switch (t[0])
+ {
+ case 'a': /* abort */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ if (vm && vm->meth.meth == VM_MTDEBUG)
+ vmset(vm, VM_DBABORT, 1);
+ else
+ _Vmassert |= VM_abort;
+ break;
+ case 'c': /* check */
+ _Vmassert |= VM_check;
+ break;
+ case 'm':
+ switch (t[1])
+ {
+ case 'e': /* method=<method> */
+ if (v && !vm)
+ {
+ if ((v[0] == 'V' || v[0] == 'v') && (v[1] == 'M' || v[1] == 'm'))
+ v += 2;
+ if (strcmp(v, "debug") == 0)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ else if (strcmp(v, "profile") == 0)
+ vm = vmopen(Vmdcsbrk, Vmprofile, 0);
+ else if (strcmp(v, "last") == 0)
+ vm = vmopen(Vmdcsbrk, Vmlast, 0);
+ else if (strcmp(v, "best") == 0)
+ vm = Vmheap;
+ }
+ break;
+ case 'm': /* mmap */
+#if _mem_mmap_anon || _mem_mmap_zero
+ _Vmassert |= VM_mmap;
+#endif
+ break;
+ }
+ break;
+ case 'p':
+ if (v)
+ switch (t[1])
+ {
+ case 'e': /* period=<count> */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ if (vm && vm->meth.meth == VM_MTDEBUG)
+ _Vmdbcheck = atou(&v);
+ break;
+ case 'r': /* profile=<path> */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmprofile, 0);
+ if (v && vm && vm->meth.meth == VM_MTPROFILE)
+ _Vmpffd = createfile(v);
+ break;
+ }
+ break;
+ case 'r': /* region */
+ _Vmassert |= VM_region;
+ break;
+ case 's': /* start=<count> */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ if (v && vm && vm->meth.meth == VM_MTDEBUG)
+ _Vmdbstart = atou(&v);
+ break;
+ case 't': /* trace=<path> */
+ trace = v;
+ break;
+ case 'w':
+ if (t[1] == 'a')
+ switch (t[2])
+ {
+ case 'r': /* warn=<path> */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ if (v && vm && vm->meth.meth == VM_MTDEBUG && (fd = createfile(v)) >= 0)
+ vmdebug(fd);
+ break;
+ case 't': /* watch=<addr> */
+ if (!vm)
+ vm = vmopen(Vmdcsbrk, Vmdebug, 0);
+ if (v && vm && vm->meth.meth == VM_MTDEBUG && (n = atou(&v)) >= 0)
+ vmdbwatch((Void_t*)n);
+ break;
+ }
+ break;
+ }
+ }
+ }
+
+ /* slip in the new region now so that malloc() will work fine */
+
+ if (vm)
+ {
+ if (vm->meth.meth == VM_MTDEBUG)
+ _Vmdbcheck = 1;
+ Vmregion = vm;
+ }
+
+ /* enable tracing */
+
+ if (trace && (fd = createfile(trace)) >= 0)
+ {
+ vmset(Vmregion, VM_TRACE, 1);
+ vmtrace(fd);
+ }
+
+ /* make sure that profile data is output upon exiting */
+
+ if (vm && vm->meth.meth == VM_MTPROFILE)
+ {
+ if (_Vmpffd < 0)
+ _Vmpffd = 2;
+ /* this may wind up calling malloc(), but region is ok now */
+ atexit(pfprint);
+ }
+ else if (_Vmpffd >= 0)
+ {
+ close(_Vmpffd);
+ _Vmpffd = -1;
+ }
+}
+
#endif /*_UWIN*/
diff --git a/usr/src/lib/libast/common/vmalloc/vmbest.c b/usr/src/lib/libast/common/vmalloc/vmbest.c
index 35b24fa678..a9c622d2ad 100644
--- a/usr/src/lib/libast/common/vmalloc/vmbest.c
+++ b/usr/src/lib/libast/common/vmalloc/vmbest.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -46,6 +46,12 @@ static int N_reclaim; /* # of bestreclaim calls */
#define VM_TRUST 0
#endif /*DEBUG*/
+#if _BLD_posix
+#define logmsg(d,a ...) logsrc(d,__FILE__,__LINE__,a)
+
+extern int logsrc(int, const char*, int, const char*, ...);
+#endif /*_BLD_posix*/
+
#define COMPACT 8 /* factor to decide when to compact */
/* Check to see if a block is in the free tree */
@@ -421,6 +427,13 @@ int c;
if(ISPFREE(size)) /* backward merge */
{ fp = LAST(fp);
+#if _BLD_posix
+ if (fp < (Block_t*)0x00120000)
+ {
+ logmsg(0, "bestreclaim fp=%p", fp);
+ ASSERT(!fp);
+ }
+#endif
s = SIZE(fp); /**/ASSERT(!(s&BITS));
REMOVE(vd,fp,INDEX(s),t,bestsearch);
size = (size&~BITS) + s + sizeof(Head_t);
@@ -429,6 +442,13 @@ int c;
for(;;) /* forward merge */
{ np = (Block_t*)((Vmuchar_t*)fp+size+sizeof(Head_t));
+#if _BLD_posix
+ if (np < (Block_t*)0x00120000)
+ {
+ logmsg(0, "bestreclaim np=%p", np);
+ ASSERT(!np);
+ }
+#endif
s = SIZE(np); /**/ASSERT(s > 0);
if(!ISBUSY(s))
{ /**/ASSERT((s&BITS) == 0);
@@ -641,61 +661,8 @@ reg size_t size; /* desired block size */
reg int local, inuse;
size_t orgsize = 0;
- if(!(_Vmassert & VM_init))
- { char *chk = getenv("VMCHECK");
- _Vmassert = VM_init;
- if(chk)
- { int set = 1;
- for(;; set ? (_Vmassert |= n) : (_Vmassert &= ~n))
- {
- switch (*chk++)
- {
- case 0:
- break;
- case '-':
- case '!':
- set = 0;
- n = 0;
- continue;
- case '+':
- set = 1;
- n = 0;
- continue;
- case '1':
- n = VM_check;
- continue;
- case '2':
- n = VM_abort;
- continue;
- case '3':
- n = VM_check|VM_abort;
- continue;
- case 'a':
- case 'A':
- n = VM_abort;
- continue;
- case 'c':
- case 'C':
- n = VM_check;
- continue;
-#if _mem_mmap_anon || _mem_mmap_zero
- case 'm':
- case 'M':
- n = VM_mmap;
-#endif
- continue;
- case 'r':
- case 'R':
- n = VM_region;
- continue;
- default:
- n = 0;
- continue;
- }
- break;
- }
- }
- }
+ VMOPTIONS();
+
/**/COUNT(N_alloc);
SETINUSE(vd, inuse);
@@ -1386,72 +1353,66 @@ Vmdisc_t* disc; /* discipline structure */
#endif /* _mem_sbrk */
#if _mem_mmap_anon /* anonymous mmap */
- {
- addr = (Vmuchar_t*)mmap(0, nsize, PROT_READ|PROT_WRITE,
- MAP_ANON|MAP_PRIVATE, -1, 0);
- if(addr && addr != (Vmuchar_t*)MAP_FAILED)
- { if(okaddr(addr,nsize) >= 0)
- return addr;
- (void)munmap(addr, nsize); /* release reserved address */
- }
+ addr = (Vmuchar_t*)mmap(0, nsize, PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_PRIVATE, -1, 0);
+ if(addr && addr != (Vmuchar_t*)MAP_FAILED)
+ { if(okaddr(addr,nsize) >= 0)
+ return addr;
+ (void)munmap((char*)addr, nsize); /* release reserved address */
}
#endif /* _mem_mmap_anon */
#if _mem_mmap_zero /* mmap from /dev/zero */
- {
- if(mmdc->fd < 0)
- { int fd;
- if(mmdc->fd != -1)
- return NIL(Void_t*);
- if((fd = open("/dev/zero", O_RDONLY)) < 0 )
- { mmdc->fd = -2;
- return NIL(Void_t*);
- }
- if(fd >= OPEN_PRIVATE || (mmdc->fd = dup2(fd,OPEN_PRIVATE)) < 0 )
- mmdc->fd = fd;
- else close(fd);
+ if(mmdc->fd < 0)
+ { int fd;
+ if(mmdc->fd != -1)
+ return NIL(Void_t*);
+ if((fd = open("/dev/zero", O_RDONLY)) < 0 )
+ { mmdc->fd = -2;
+ return NIL(Void_t*);
+ }
+ if(fd >= OPEN_PRIVATE || (mmdc->fd = dup2(fd,OPEN_PRIVATE)) < 0 )
+ mmdc->fd = fd;
+ else close(fd);
#ifdef FD_CLOEXEC
- fcntl(mmdc->fd, F_SETFD, FD_CLOEXEC);
+ fcntl(mmdc->fd, F_SETFD, FD_CLOEXEC);
#endif
+ }
+ addr = (Vmuchar_t*)mmap(0, nsize, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE, mmdc->fd, mmdc->offset);
+ if(addr && addr != (Vmuchar_t*)MAP_FAILED)
+ { if(okaddr(addr, nsize) >= 0)
+ { mmdc->offset += nsize;
+ return addr;
}
- addr = (Vmuchar_t*)mmap(0, nsize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE, mmdc->fd, mmdc->offset);
- if(addr && addr != (Vmuchar_t*)MAP_FAILED)
- { if(okaddr(addr, nsize) >= 0)
- { mmdc->offset += nsize;
- return addr;
- }
- (void)munmap(addr, nsize); /* release reserved address */
- }
+ (void)munmap((char*)addr, nsize); /* release reserved address */
}
#endif /* _mem_mmap_zero */
return NIL(Void_t*);
}
else
- { addr = caddr; /* in case !_mem_sbrk */
+ {
#if _mem_sbrk
- {
- addr = (Vmuchar_t*)sbrk(0);
- if(!addr || addr == (Vmuchar_t*)BRK_FAILED)
- addr = caddr;
- else if(((Vmuchar_t*)caddr+csize) == addr) /* in sbrk-space */
- { if(nsize <= csize)
- addr -= csize-nsize;
- else if((addr += nsize-csize) < (Vmuchar_t*)caddr)
- return NIL(Void_t*); /* wrapped around address */
- else return brk(addr) == 0 ? caddr : NIL(Void_t*);
- }
+ addr = (Vmuchar_t*)sbrk(0);
+ if(!addr || addr == (Vmuchar_t*)BRK_FAILED)
+ addr = caddr;
+ else if(((Vmuchar_t*)caddr+csize) == addr) /* in sbrk-space */
+ { if(nsize <= csize)
+ addr -= csize-nsize;
+ else if((addr += nsize-csize) < (Vmuchar_t*)caddr)
+ return NIL(Void_t*); /* wrapped around address */
+ else return brk(addr) == 0 ? caddr : NIL(Void_t*);
}
+#else
+ addr = caddr;
#endif /* _mem_sbrk */
#if _mem_mmap_zero || _mem_mmap_anon
- {
- if(((Vmuchar_t*)caddr+csize) > addr) /* in mmap-space */
- if(nsize == 0 && munmap(caddr,csize) == 0)
- return caddr;
- }
+ if(((Vmuchar_t*)caddr+csize) > addr) /* in mmap-space */
+ if(nsize == 0 && munmap(caddr,csize) == 0)
+ return caddr;
#endif /* _mem_mmap_zero || _mem_mmap_anon */
return NIL(Void_t*);
diff --git a/usr/src/lib/libast/common/vmalloc/vmclear.c b/usr/src/lib/libast/common/vmalloc/vmclear.c
index bca98e669a..fd3f17f8f4 100644
--- a/usr/src/lib/libast/common/vmalloc/vmclear.c
+++ b/usr/src/lib/libast/common/vmalloc/vmclear.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmclose.c b/usr/src/lib/libast/common/vmalloc/vmclose.c
index 67b63c7723..39ff5dc603 100644
--- a/usr/src/lib/libast/common/vmalloc/vmclose.c
+++ b/usr/src/lib/libast/common/vmalloc/vmclose.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmdcheap.c b/usr/src/lib/libast/common/vmalloc/vmdcheap.c
index 892de4ae18..59ed6bfed1 100644
--- a/usr/src/lib/libast/common/vmalloc/vmdcheap.c
+++ b/usr/src/lib/libast/common/vmalloc/vmdcheap.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmdebug.c b/usr/src/lib/libast/common/vmalloc/vmdebug.c
index dede7d0469..3cb1e3963e 100644
--- a/usr/src/lib/libast/common/vmalloc/vmdebug.c
+++ b/usr/src/lib/libast/common/vmalloc/vmdebug.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -177,7 +177,7 @@ int type; /* operation being done */
bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(func),-1), ':');
}
- *bufp++ = '\n';
+ *(bufp - 1) = '\n';
*bufp = '\0';
vmdbwarn(vm,buf,(bufp-buf));
@@ -463,9 +463,9 @@ Void_t* data;
vmdbcheck(vm);
if((offset = KPVADDR(vm,data,dbaddr)) != 0)
- { if(vm->disc->exceptf)
+ { dbwarn(vm,(Vmuchar_t*)data,offset == -1L ? 0 : 1,file,line,func,DB_FREE);
+ if(vm->disc->exceptf)
(void)(*vm->disc->exceptf)(vm,VM_BADADDR,data,vm->disc);
- dbwarn(vm,(Vmuchar_t*)data,offset == -1L ? 0 : 1,file,line,func,DB_FREE);
CLRLOCK(vd,0);
CLRINUSE(vd, inuse);
return -1;
@@ -537,9 +537,9 @@ int type; /* !=0 for movable, >0 for copy */
vmdbcheck(vm);
if((offset = KPVADDR(vm,addr,dbaddr)) != 0)
- { if(vm->disc->exceptf)
+ { dbwarn(vm,(Vmuchar_t*)addr,offset == -1L ? 0 : 1,file,line,func,DB_RESIZE);
+ if(vm->disc->exceptf)
(void)(*vm->disc->exceptf)(vm,VM_BADADDR,addr,vm->disc);
- dbwarn(vm,(Vmuchar_t*)addr,offset == -1L ? 0 : 1,file,line,func,DB_RESIZE);
CLRLOCK(vd,0);
CLRINUSE(vd, inuse);
return NIL(Void_t*);
@@ -744,6 +744,39 @@ done:
return (Void_t*)data;
}
+/* print statistics of region vm. If vm is NULL, use Vmregion */
+#if __STD_C
+ssize_t vmdbstat(Vmalloc_t* vm)
+#else
+ssize_t vmdbstat(vm)
+Vmalloc_t* vm;
+#endif
+{ Vmstat_t st;
+ char buf[1024], *bufp;
+
+ vmstat(vm ? vm : Vmregion, &st);
+ bufp = buf;
+ bufp = (*_Vmstrcpy)(bufp, "n_busy", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)((Vmulong_t)st.n_busy,-1), ',');
+ bufp = (*_Vmstrcpy)(bufp, " s_busy", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(st.s_busy),-1), '\n');
+ bufp = (*_Vmstrcpy)(bufp, "n_free", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)((Vmulong_t)st.n_free,-1), ',');
+ bufp = (*_Vmstrcpy)(bufp, " s_free", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(st.s_free),-1), '\n');
+ bufp = (*_Vmstrcpy)(bufp, "m_busy", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(st.m_busy),-1), ',');
+ bufp = (*_Vmstrcpy)(bufp, " m_free", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(st.m_free),-1), '\n');
+ bufp = (*_Vmstrcpy)(bufp, "n_segment", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)((Vmulong_t)st.n_seg,-1), ',');
+ bufp = (*_Vmstrcpy)(bufp, " extent", '=');
+ bufp = (*_Vmstrcpy)(bufp, (*_Vmitoa)(VLONG(st.extent),-1), '\n');
+ *bufp = 0;
+ write(Dbfd, buf, strlen(buf));
+ return strlen(buf);
+}
+
static Vmethod_t _Vmdebug =
{
dballoc,
diff --git a/usr/src/lib/libast/common/vmalloc/vmdisc.c b/usr/src/lib/libast/common/vmalloc/vmdisc.c
index 719d2c4194..139b34b423 100644
--- a/usr/src/lib/libast/common/vmalloc/vmdisc.c
+++ b/usr/src/lib/libast/common/vmalloc/vmdisc.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmexit.c b/usr/src/lib/libast/common/vmalloc/vmexit.c
index 946a2f9519..ea81177546 100644
--- a/usr/src/lib/libast/common/vmalloc/vmexit.c
+++ b/usr/src/lib/libast/common/vmalloc/vmexit.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmgetmem.c b/usr/src/lib/libast/common/vmalloc/vmgetmem.c
index e7a66f740b..607c10f280 100644
--- a/usr/src/lib/libast/common/vmalloc/vmgetmem.c
+++ b/usr/src/lib/libast/common/vmalloc/vmgetmem.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmhdr.h b/usr/src/lib/libast/common/vmalloc/vmhdr.h
index 7fe3d64917..d1b04f7505 100644
--- a/usr/src/lib/libast/common/vmalloc/vmhdr.h
+++ b/usr/src/lib/libast/common/vmalloc/vmhdr.h
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -71,6 +71,10 @@
#define _npt_sbrk 1
#endif
+#ifndef integralof
+#define integralof(x) (((char*)(x))-((char*)0))
+#endif
+
#endif /*_PACKAGE_ast*/
#include "FEATURE/vmalloc"
@@ -130,7 +134,6 @@ typedef int ssize_t;
#define VM_abort 0x0002 /* abort() on assertion failure */
#define VM_region 0x0004 /* enable region segment checks */
#define VM_mmap 0x0010 /* favor mmap allocation */
-#define VM_init 0x8000 /* VMCHECK env var checked */
#if _UWIN
#include <ast_windows.h>
@@ -334,7 +337,7 @@ struct _tiny_s
#define TINY(vd) ((vd)->tiny)
#define CACHE(vd) ((vd)->cache)
-typedef struct _vmdata_s
+struct _vmdata_s
{ int mode; /* current mode for region */
size_t incr; /* allocate in multiple of this */
size_t pool; /* size of an elt in a Vmpool region */
@@ -344,13 +347,8 @@ typedef struct _vmdata_s
Block_t* root; /* root of free tree */
Block_t* tiny[S_TINY]; /* small blocks */
Block_t* cache[S_CACHE+1]; /* delayed free blocks */
-} Vmdata_t;
-
-/* private parts of Vmalloc_t */
-#define _VM_PRIVATE_ \
- Vmdisc_t* disc; /* discipline to get space */ \
- Vmdata_t* data; /* the real region data */ \
- Vmalloc_t* next; /* linked list of regions */
+};
+/* Vmdata_t typedef in <vmalloc.h> */
#include "vmalloc.h"
@@ -363,7 +361,7 @@ typedef struct _vmdata_s
/* segment structure */
struct _seg_s
-{ Vmalloc_t* vm; /* the region that holds this */
+{ Vmdata_t* vmdt; /* the data region holding this */
Seg_t* next; /* next segment */
Void_t* addr; /* starting segment address */
size_t extent; /* extent of segment */
@@ -492,6 +490,7 @@ typedef struct _vmextern_
Vmuchar_t*, Vmuchar_t*, size_t, size_t));
void (*vm_pfclose)_ARG_((Vmalloc_t*));
int vm_assert;
+ int vm_options;
} Vmextern_t;
#define _Vmextend (_Vmextern.vm_extend)
@@ -502,7 +501,11 @@ typedef struct _vmextern_
#define _Vmtrace (_Vmextern.vm_trace)
#define _Vmpfclose (_Vmextern.vm_pfclose)
#define _Vmassert (_Vmextern.vm_assert)
+#define _Vmoptions (_Vmextern.vm_options)
+
+#define VMOPTIONS() do { if (!_Vmoptions) { _vmoptions(); } } while (0)
+extern void _vmoptions _ARG_((void));
extern int _vmbestcheck _ARG_((Vmdata_t*, Block_t*));
_BEGIN_EXTERNS_
diff --git a/usr/src/lib/libast/common/vmalloc/vmlast.c b/usr/src/lib/libast/common/vmalloc/vmlast.c
index 2463f24e09..a9c5e2171a 100644
--- a/usr/src/lib/libast/common/vmalloc/vmlast.c
+++ b/usr/src/lib/libast/common/vmalloc/vmlast.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmmopen.c b/usr/src/lib/libast/common/vmalloc/vmmopen.c
index b5ccff821c..1f1653da23 100644
--- a/usr/src/lib/libast/common/vmalloc/vmmopen.c
+++ b/usr/src/lib/libast/common/vmalloc/vmmopen.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmopen.c b/usr/src/lib/libast/common/vmalloc/vmopen.c
index 0e92089ddf..d0ce57987d 100644
--- a/usr/src/lib/libast/common/vmalloc/vmopen.c
+++ b/usr/src/lib/libast/common/vmalloc/vmopen.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -90,7 +90,7 @@ int mode; /* type of region */
vd = (Vmdata_t*)addr;
if((vd->mode&meth->meth) != 0)
{ vm->data = vd;
- return vm;
+ goto done;
}
else
{ open_error:
@@ -140,7 +140,7 @@ int mode; /* type of region */
seg = vd->seg;
seg->next = NIL(Seg_t*);
- seg->vm = vm;
+ seg->vmdt = vd;
seg->addr = (Void_t*)(addr - (a ? ALIGN-a : 0));
seg->extent = s;
seg->baddr = addr + s - (a ? ALIGN : 0);
@@ -166,7 +166,7 @@ int mode; /* type of region */
vm->data = vd;
- /* put into linked list of regions */
+done: /* add to the linked list of regions */
vm->next = Vmheap->next;
Vmheap->next = vm;
diff --git a/usr/src/lib/libast/common/vmalloc/vmpool.c b/usr/src/lib/libast/common/vmalloc/vmpool.c
index 3195a03e65..965712cf9b 100644
--- a/usr/src/lib/libast/common/vmalloc/vmpool.c
+++ b/usr/src/lib/libast/common/vmalloc/vmpool.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -54,7 +54,7 @@ reg size_t size;
if(size <= 0)
return NIL(Void_t*);
- else if(size != vd->pool)
+ if(size != vd->pool)
{ if(vd->pool <= 0)
vd->pool = size;
else return NIL(Void_t*);
diff --git a/usr/src/lib/libast/common/vmalloc/vmprivate.c b/usr/src/lib/libast/common/vmalloc/vmprivate.c
index d1dd774442..96d93d75c6 100644
--- a/usr/src/lib/libast/common/vmalloc/vmprivate.c
+++ b/usr/src/lib/libast/common/vmalloc/vmprivate.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -27,18 +27,7 @@ void _STUB_vmprivate(){}
#include "vmhdr.h"
-static char* Version = "\n@(#)$Id: Vmalloc (AT&T Research) 2009-06-19 $\0\n";
-
-#if _sys_stat
-#include <sys/stat.h>
-#endif
-#include <fcntl.h>
-
-#ifdef S_IRUSR
-#define CREAT_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
-#else
-#define CREAT_MODE 0644
-#endif
+static char* Version = "\n@(#)$Id: Vmalloc (AT&T Research) 2010-01-01 $\0\n";
/* Private code used in the vmalloc library
**
@@ -67,13 +56,7 @@ Vmsearch_f searchf; /* tree search function */
#if DEBUG /* trace all allocation calls through the heap */
if(!_Vmtrace && vm == Vmheap && (vd->mode&VM_TRUST) )
- { char *env;
- int fd;
- vd->mode = (vd->mode&~VM_TRUST)|VM_TRACE;
- if((fd = vmtrace(-1)) >= 0 ||
- ((env = getenv("VMTRACE")) && (fd = creat(env, CREAT_MODE)) >= 0 ) )
- vmtrace(fd);
- }
+ VMOPTIONS();
#endif
if(vd->incr <= 0) /* this is just _Vmheap on the first call */
@@ -135,11 +118,12 @@ Vmsearch_f searchf; /* tree search function */
if(seg)
{ /* extending current segment */
- bp = BLOCK(seg->baddr); /**/ ASSERT((SIZE(bp)&~BITS) == 0);
- /**/ ASSERT(SEG(bp) == seg);
+ bp = BLOCK(seg->baddr);
if(vd->mode&(VM_MTBEST|VM_MTDEBUG|VM_MTPROFILE) )
- { if(!ISPFREE(SIZE(bp)) )
+ { /**/ ASSERT((SIZE(bp)&~BITS) == 0);
+ /**/ ASSERT(SEG(bp) == seg);
+ if(!ISPFREE(SIZE(bp)) )
SIZE(bp) = size - sizeof(Head_t);
else
{ /**/ ASSERT(searchf);
@@ -156,7 +140,10 @@ Vmsearch_f searchf; /* tree search function */
seg->free = NIL(Block_t*);
SIZE(bp) += size;
}
- else SIZE(bp) = size - sizeof(Head_t);
+ else
+ { SEG(bp) = seg;
+ SIZE(bp) = size - sizeof(Head_t);
+ }
}
seg->size += size;
@@ -171,7 +158,7 @@ Vmsearch_f searchf; /* tree search function */
addr += ALIGN-s;
seg = (Seg_t*)addr;
- seg->vm = vm;
+ seg->vmdt = vd;
seg->addr = (Void_t*)(addr - (s ? ALIGN-s : 0));
seg->extent = size;
seg->baddr = addr + size - (s ? 2*ALIGN : 0);
@@ -247,8 +234,8 @@ int exact;
less = _Vmpagesize;
less = (size/less)*less;
less = (less/vd->incr)*vd->incr;
- if(less > 0 && size > less && (size-less) < sizeof(Block_t) )
- less = less <= vd->incr ? 0 : less - vd->incr;
+ if(less > 0 && size > (size_t)less && (size-(size_t)less) < sizeof(Block_t) )
+ less = (size_t)less <= vd->incr ? 0 : (size_t)less - vd->incr;
}
if(less <= 0 ||
diff --git a/usr/src/lib/libast/common/vmalloc/vmprofile.c b/usr/src/lib/libast/common/vmalloc/vmprofile.c
index c8381e1913..6651865844 100644
--- a/usr/src/lib/libast/common/vmalloc/vmprofile.c
+++ b/usr/src/lib/libast/common/vmalloc/vmprofile.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmregion.c b/usr/src/lib/libast/common/vmalloc/vmregion.c
index ad468388b0..cfdbb67016 100644
--- a/usr/src/lib/libast/common/vmalloc/vmregion.c
+++ b/usr/src/lib/libast/common/vmalloc/vmregion.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -28,17 +28,31 @@ void _STUB_vmregion(){}
#include "vmhdr.h"
/* Return the containing region of an allocated piece of memory.
-** Beware: this only works with Vmbest and Vmtrace.
+** Beware: this only works with Vmbest, Vmdebug and Vmprofile.
+**
+** 10/31/2009: Add handling of shared/persistent memory regions.
**
** Written by Kiem-Phong Vo, kpv@research.att.com, 01/16/94.
*/
#if __STD_C
-Vmalloc_t* vmregion(reg Void_t* addr)
+Vmalloc_t* vmregion(Void_t* addr)
#else
Vmalloc_t* vmregion(addr)
-reg Void_t* addr;
+Void_t* addr;
#endif
-{ return addr ? VM(BLOCK(addr)) : NIL(Vmalloc_t*);
+{
+ Vmalloc_t *vm;
+ Vmdata_t *vd;
+
+ if(!addr)
+ return NIL(Vmalloc_t*);
+
+ vd = SEG(BLOCK(addr))->vmdt;
+ for(vm = Vmheap; vm; vm = vm->next)
+ if(vm->data == vd)
+ break;
+
+ return vm;
}
#endif
diff --git a/usr/src/lib/libast/common/vmalloc/vmsegment.c b/usr/src/lib/libast/common/vmalloc/vmsegment.c
index b5fca2d604..7d7dbad275 100644
--- a/usr/src/lib/libast/common/vmalloc/vmsegment.c
+++ b/usr/src/lib/libast/common/vmalloc/vmsegment.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmset.c b/usr/src/lib/libast/common/vmalloc/vmset.c
index de80405e8e..7997f8e1e3 100644
--- a/usr/src/lib/libast/common/vmalloc/vmset.c
+++ b/usr/src/lib/libast/common/vmalloc/vmset.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmstat.c b/usr/src/lib/libast/common/vmalloc/vmstat.c
index 6ee4de7e3c..9693c460b3 100644
--- a/usr/src/lib/libast/common/vmalloc/vmstat.c
+++ b/usr/src/lib/libast/common/vmalloc/vmstat.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmstrdup.c b/usr/src/lib/libast/common/vmalloc/vmstrdup.c
index e5c0d4a5ef..211666621a 100644
--- a/usr/src/lib/libast/common/vmalloc/vmstrdup.c
+++ b/usr/src/lib/libast/common/vmalloc/vmstrdup.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
diff --git a/usr/src/lib/libast/common/vmalloc/vmtrace.c b/usr/src/lib/libast/common/vmalloc/vmtrace.c
index 2e18ede92f..7ecbb5490f 100644
--- a/usr/src/lib/libast/common/vmalloc/vmtrace.c
+++ b/usr/src/lib/libast/common/vmalloc/vmtrace.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -219,6 +219,7 @@ long n2;
if (n2)
bufp = trstrcpy(bufp, tritoa(n2, 0), ':');
}
+ bufp = trstrcpy(bufp, tritoa((long)getpid(), 1), ':');
*bufp++ = '\n';
write(2,buf,(bufp-buf));
}
diff --git a/usr/src/lib/libast/common/vmalloc/vmwalk.c b/usr/src/lib/libast/common/vmalloc/vmwalk.c
index f2628a4594..7336d65589 100644
--- a/usr/src/lib/libast/common/vmalloc/vmwalk.c
+++ b/usr/src/lib/libast/common/vmalloc/vmwalk.c
@@ -1,7 +1,7 @@
/***********************************************************************
* *
* This software is part of the ast package *
-* Copyright (c) 1985-2009 AT&T Intellectual Property *
+* Copyright (c) 1985-2010 AT&T Intellectual Property *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Intellectual Property *
@@ -33,11 +33,12 @@ void _STUB_vmwalk(){}
*/
#if __STD_C
-int vmwalk(Vmalloc_t* vm, int(*segf)(Vmalloc_t*, Void_t*, size_t, Vmdisc_t*) )
+int vmwalk(Vmalloc_t* vm, int(*segf)(Vmalloc_t*, Void_t*, size_t, Vmdisc_t*, Void_t*), Void_t* handle )
#else
-int vmwalk(vm, segf)
+int vmwalk(vm, segf, handle)
Vmalloc_t* vm;
int(* segf)(/* Vmalloc_t*, Void_t*, size_t, Vmdisc_t* */);
+Void_t* handle;
#endif
{
reg Seg_t* seg;
@@ -50,7 +51,7 @@ int(* segf)(/* Vmalloc_t*, Void_t*, size_t, Vmdisc_t* */);
SETLOCK(vm->data,0);
for(seg = vm->data->seg; seg; seg = seg->next)
- { rv = (*segf)(vm, seg->addr, seg->extent, vm->disc);
+ { rv = (*segf)(vm, seg->addr, seg->extent, vm->disc, handle);
if(rv < 0)
return rv;
}
@@ -63,7 +64,7 @@ int(* segf)(/* Vmalloc_t*, Void_t*, size_t, Vmdisc_t* */);
SETLOCK(vm->data,0);
for(seg = vm->data->seg; seg; seg = seg->next)
- { rv = (*segf)(vm, seg->addr, seg->extent, vm->disc);
+ { rv = (*segf)(vm, seg->addr, seg->extent, vm->disc, handle);
if(rv < 0)
return rv;
}