Initial revision

This commit is contained in:
Wez Furlong 2006-03-10 02:45:59 +00:00
parent 3f3cd30cf7
commit d7fe11594f
33 changed files with 10239 additions and 0 deletions

6
COPYRIGHT Normal file
View file

@ -0,0 +1,6 @@
The bulk of the library is Copyright 2004 Sun Microsystems, Inc.
Portions are Copyright 2006 OmniTI, Inc.
The library is distributed under the terms of the CDDL.
See the file OPENSOLARIS.LICENSE for more information.

385
OPENSOLARIS.LICENSE Normal file
View file

@ -0,0 +1,385 @@
Unless otherwise noted, all files in this distribution are released
under the Common Development and Distribution License (CDDL),
Version 1.0 only. Exceptions are noted within the associated
source files.
--------------------------------------------------------------------
COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0
1. Definitions.
1.1. "Contributor" means each individual or entity that creates
or contributes to the creation of Modifications.
1.2. "Contributor Version" means the combination of the Original
Software, prior Modifications used by a Contributor (if any),
and the Modifications made by that particular Contributor.
1.3. "Covered Software" means (a) the Original Software, or (b)
Modifications, or (c) the combination of files containing
Original Software with files containing Modifications, in
each case including portions thereof.
1.4. "Executable" means the Covered Software in any form other
than Source Code.
1.5. "Initial Developer" means the individual or entity that first
makes Original Software available under this License.
1.6. "Larger Work" means a work which combines Covered Software or
portions thereof with code not governed by the terms of this
License.
1.7. "License" means this document.
1.8. "Licensable" means having the right to grant, to the maximum
extent possible, whether at the time of the initial grant or
subsequently acquired, any and all of the rights conveyed
herein.
1.9. "Modifications" means the Source Code and Executable form of
any of the following:
A. Any file that results from an addition to, deletion from or
modification of the contents of a file containing Original
Software or previous Modifications;
B. Any new file that contains any part of the Original
Software or previous Modifications; or
C. Any new file that is contributed or otherwise made
available under the terms of this License.
1.10. "Original Software" means the Source Code and Executable
form of computer software code that is originally released
under this License.
1.11. "Patent Claims" means any patent claim(s), now owned or
hereafter acquired, including without limitation, method,
process, and apparatus claims, in any patent Licensable by
grantor.
1.12. "Source Code" means (a) the common form of computer software
code in which modifications are made and (b) associated
documentation included in or with such code.
1.13. "You" (or "Your") means an individual or a legal entity
exercising rights under, and complying with all of the terms
of, this License. For legal entities, "You" includes any
entity which controls, is controlled by, or is under common
control with You. For purposes of this definition,
"control" means (a) the power, direct or indirect, to cause
the direction or management of such entity, whether by
contract or otherwise, or (b) ownership of more than fifty
percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants.
2.1. The Initial Developer Grant.
Conditioned upon Your compliance with Section 3.1 below and
subject to third party intellectual property claims, the Initial
Developer hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Initial Developer, to use,
reproduce, modify, display, perform, sublicense and
distribute the Original Software (or portions thereof),
with or without Modifications, and/or as part of a Larger
Work; and
(b) under Patent Claims infringed by the making, using or
selling of Original Software, to make, have made, use,
practice, sell, and offer for sale, and/or otherwise
dispose of the Original Software (or portions thereof).
(c) The licenses granted in Sections 2.1(a) and (b) are
effective on the date Initial Developer first distributes
or otherwise makes the Original Software available to a
third party under the terms of this License.
(d) Notwithstanding Section 2.1(b) above, no patent license is
granted: (1) for code that You delete from the Original
Software, or (2) for infringements caused by: (i) the
modification of the Original Software, or (ii) the
combination of the Original Software with other software
or devices.
2.2. Contributor Grant.
Conditioned upon Your compliance with Section 3.1 below and
subject to third party intellectual property claims, each
Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Contributor to use, reproduce,
modify, display, perform, sublicense and distribute the
Modifications created by such Contributor (or portions
thereof), either on an unmodified basis, with other
Modifications, as Covered Software and/or as part of a
Larger Work; and
(b) under Patent Claims infringed by the making, using, or
selling of Modifications made by that Contributor either
alone and/or in combination with its Contributor Version
(or portions of such combination), to make, use, sell,
offer for sale, have made, and/or otherwise dispose of:
(1) Modifications made by that Contributor (or portions
thereof); and (2) the combination of Modifications made by
that Contributor with its Contributor Version (or portions
of such combination).
(c) The licenses granted in Sections 2.2(a) and 2.2(b) are
effective on the date Contributor first distributes or
otherwise makes the Modifications available to a third
party.
(d) Notwithstanding Section 2.2(b) above, no patent license is
granted: (1) for any code that Contributor has deleted
from the Contributor Version; (2) for infringements caused
by: (i) third party modifications of Contributor Version,
or (ii) the combination of Modifications made by that
Contributor with other software (except as part of the
Contributor Version) or other devices; or (3) under Patent
Claims infringed by Covered Software in the absence of
Modifications made by that Contributor.
3. Distribution Obligations.
3.1. Availability of Source Code.
Any Covered Software that You distribute or otherwise make
available in Executable form must also be made available in Source
Code form and that Source Code form must be distributed only under
the terms of this License. You must include a copy of this
License with every copy of the Source Code form of the Covered
Software You distribute or otherwise make available. You must
inform recipients of any such Covered Software in Executable form
as to how they can obtain such Covered Software in Source Code
form in a reasonable manner on or through a medium customarily
used for software exchange.
3.2. Modifications.
The Modifications that You create or to which You contribute are
governed by the terms of this License. You represent that You
believe Your Modifications are Your original creation(s) and/or
You have sufficient rights to grant the rights conveyed by this
License.
3.3. Required Notices.
You must include a notice in each of Your Modifications that
identifies You as the Contributor of the Modification. You may
not remove or alter any copyright, patent or trademark notices
contained within the Covered Software, or any notices of licensing
or any descriptive text giving attribution to any Contributor or
the Initial Developer.
3.4. Application of Additional Terms.
You may not offer or impose any terms on any Covered Software in
Source Code form that alters or restricts the applicable version
of this License or the recipients' rights hereunder. You may
choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of
Covered Software. However, you may do so only on Your own behalf,
and not on behalf of the Initial Developer or any Contributor.
You must make it absolutely clear that any such warranty, support,
indemnity or liability obligation is offered by You alone, and You
hereby agree to indemnify the Initial Developer and every
Contributor for any liability incurred by the Initial Developer or
such Contributor as a result of warranty, support, indemnity or
liability terms You offer.
3.5. Distribution of Executable Versions.
You may distribute the Executable form of the Covered Software
under the terms of this License or under the terms of a license of
Your choice, which may contain terms different from this License,
provided that You are in compliance with the terms of this License
and that the license for the Executable form does not attempt to
limit or alter the recipient's rights in the Source Code form from
the rights set forth in this License. If You distribute the
Covered Software in Executable form under a different license, You
must make it absolutely clear that any terms which differ from
this License are offered by You alone, not by the Initial
Developer or Contributor. You hereby agree to indemnify the
Initial Developer and every Contributor for any liability incurred
by the Initial Developer or such Contributor as a result of any
such terms You offer.
3.6. Larger Works.
You may create a Larger Work by combining Covered Software with
other code not governed by the terms of this License and
distribute the Larger Work as a single product. In such a case,
You must make sure the requirements of this License are fulfilled
for the Covered Software.
4. Versions of the License.
4.1. New Versions.
Sun Microsystems, Inc. is the initial license steward and may
publish revised and/or new versions of this License from time to
time. Each version will be given a distinguishing version number.
Except as provided in Section 4.3, no one other than the license
steward has the right to modify this License.
4.2. Effect of New Versions.
You may always continue to use, distribute or otherwise make the
Covered Software available under the terms of the version of the
License under which You originally received the Covered Software.
If the Initial Developer includes a notice in the Original
Software prohibiting it from being distributed or otherwise made
available under any subsequent version of the License, You must
distribute and make the Covered Software available under the terms
of the version of the License under which You originally received
the Covered Software. Otherwise, You may also choose to use,
distribute or otherwise make the Covered Software available under
the terms of any subsequent version of the License published by
the license steward.
4.3. Modified Versions.
When You are an Initial Developer and You want to create a new
license for Your Original Software, You may create and use a
modified version of this License if You: (a) rename the license
and remove any references to the name of the license steward
(except to note that the license differs from this License); and
(b) otherwise make it clear that the license contains terms which
differ from this License.
5. DISCLAIMER OF WARRANTY.
COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS"
BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED
SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR
PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND
PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY
COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE
INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY
NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF
WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS
DISCLAIMER.
6. TERMINATION.
6.1. This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to
cure such breach within 30 days of becoming aware of the breach.
Provisions which, by their nature, must remain in effect beyond
the termination of this License shall survive.
6.2. If You assert a patent infringement claim (excluding
declaratory judgment actions) against Initial Developer or a
Contributor (the Initial Developer or Contributor against whom You
assert such claim is referred to as "Participant") alleging that
the Participant Software (meaning the Contributor Version where
the Participant is a Contributor or the Original Software where
the Participant is the Initial Developer) directly or indirectly
infringes any patent, then any and all rights granted directly or
indirectly to You by such Participant, the Initial Developer (if
the Initial Developer is not the Participant) and all Contributors
under Sections 2.1 and/or 2.2 of this License shall, upon 60 days
notice from Participant terminate prospectively and automatically
at the expiration of such 60 day notice period, unless if within
such 60 day period You withdraw Your claim with respect to the
Participant Software against such Participant either unilaterally
or pursuant to a written agreement with Participant.
6.3. In the event of termination under Sections 6.1 or 6.2 above,
all end user licenses that have been validly granted by You or any
distributor hereunder prior to termination (excluding licenses
granted to You by any distributor) shall survive termination.
7. LIMITATION OF LIABILITY.
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE
INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF
COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE
LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT
LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK
STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL
INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT
APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO
NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR
CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT
APPLY TO YOU.
8. U.S. GOVERNMENT END USERS.
The Covered Software is a "commercial item," as that term is
defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial
computer software" (as that term is defined at 48
C.F.R. 252.227-7014(a)(1)) and "commercial computer software
documentation" as such terms are used in 48 C.F.R. 12.212
(Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48
C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all
U.S. Government End Users acquire Covered Software with only those
rights set forth herein. This U.S. Government Rights clause is in
lieu of, and supersedes, any other FAR, DFAR, or other clause or
provision that addresses Government rights in computer software
under this License.
9. MISCELLANEOUS.
This License represents the complete agreement concerning subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. This License shall be governed
by the law of the jurisdiction specified in a notice contained
within the Original Software (except to the extent applicable law,
if any, provides otherwise), excluding such jurisdiction's
conflict-of-law provisions. Any litigation relating to this
License shall be subject to the jurisdiction of the courts located
in the jurisdiction and venue specified in a notice contained
within the Original Software, with the losing party responsible
for costs, including, without limitation, court costs and
reasonable attorneys' fees and expenses. The application of the
United Nations Convention on Contracts for the International Sale
of Goods is expressly excluded. Any law or regulation which
provides that the language of a contract shall be construed
against the drafter shall not apply to this License. You agree
that You alone are responsible for compliance with the United
States export administration regulations (and the export control
laws and regulation of any other countries) when You use,
distribute or otherwise make available any Covered Software.
10. RESPONSIBILITY FOR CLAIMS.
As between Initial Developer and the Contributors, each party is
responsible for claims and damages arising, directly or
indirectly, out of its utilization of rights under this License
and You agree to work with Initial Developer and Contributors to
distribute such responsibility on an equitable basis. Nothing
herein is intended or shall be deemed to constitute any admission
of liability.
--------------------------------------------------------------------
NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND
DISTRIBUTION LICENSE (CDDL)
For Covered Software in this distribution, this License shall
be governed by the laws of the State of California (excluding
conflict-of-law provisions).
Any litigation relating to this License shall be subject to the
jurisdiction of the Federal Courts of the Northern District of
California and the state courts of the State of California, with
venue lying in Santa Clara County, California.

23
README Normal file
View file

@ -0,0 +1,23 @@
Portable libumem.
================
This is a port of Solaris libumem to non-Solaris systems.
The port was made while integrating libumem with our Ecelerity MTA product, so
your initial experience will not be 100% out-of-the-box, because there is no
standalone configure script for the library at this time. (patches welcome!)
In addition, since our deployment is threaded, we force the library into
threaded mode.
While the library is itself stable (it's the memory allocator used by the
Solaris OS), the port may have a few rough edges. We're shipping umem with
Linux and Windows versions of our product as we have found it to be stable.
We will continue to update this project as and when we make improvements, and
welcome third-party patches that improve the usability for everyone.
Wez Furlong,
OmniTI, Inc.

688
envvar.c Normal file
View file

@ -0,0 +1,688 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Portions Copyright 2006 OmniTI, Inc.
*/
/* #pragma ident "@(#)envvar.c 1.5 05/06/08 SMI" */
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#include "umem_base.h"
#include "vmem_base.h"
/*
* A umem environment variable, like UMEM_DEBUG, is set to a series
* of items, seperated by ',':
*
* UMEM_DEBUG="audit=10,guards,firewall=512"
*
* This structure describes items. Each item has a name, type, and
* description. During processing, an item read from the user may
* be either "valid" or "invalid".
*
* A valid item has an argument, if required, and it is of the right
* form (doesn't overflow, doesn't contain any unexpected characters).
*
* If the item is valid, item_flag_target != NULL, and:
* type is not CLEARFLAG, then (*item_flag_target) |= item_flag_value
* type is CLEARFLAG, then (*item_flag_target) &= ~item_flag_value
*/
#define UMEM_ENV_ITEM_MAX 512
struct umem_env_item;
typedef int arg_process_t(const struct umem_env_item *item, const char *value);
#define ARG_SUCCESS 0 /* processing successful */
#define ARG_BAD 1 /* argument had a bad value */
typedef struct umem_env_item {
const char *item_name; /* tag in environment variable */
const char *item_interface_stability;
enum {
ITEM_INVALID,
ITEM_FLAG, /* only a flag. No argument allowed */
ITEM_CLEARFLAG, /* only a flag, but clear instead of set */
ITEM_OPTUINT, /* optional integer argument */
ITEM_UINT, /* required integer argument */
ITEM_OPTSIZE, /* optional size_t argument */
ITEM_SIZE, /* required size_t argument */
ITEM_SPECIAL /* special argument processing */
} item_type;
const char *item_description;
uint_t *item_flag_target; /* the variable containing the flag */
uint_t item_flag_value; /* the value to OR in */
uint_t *item_uint_target; /* the variable to hold the integer */
size_t *item_size_target;
arg_process_t *item_special; /* callback for special handling */
} umem_env_item_t;
#ifndef UMEM_STANDALONE
static arg_process_t umem_backend_process;
#endif
static arg_process_t umem_log_process;
const char *____umem_environ_msg_options = "-- UMEM_OPTIONS --";
static umem_env_item_t umem_options_items[] = {
#ifndef UMEM_STANDALONE
{ "backend", "Evolving", ITEM_SPECIAL,
"=sbrk for sbrk(2), =mmap for mmap(2)",
NULL, 0, NULL, NULL,
&umem_backend_process
},
#endif
{ "concurrency", "Private", ITEM_UINT,
"Max concurrency",
NULL, 0, &umem_max_ncpus
},
{ "max_contention", "Private", ITEM_UINT,
"Maximum contention in a reap interval before the depot is "
"resized.",
NULL, 0, &umem_depot_contention
},
{ "nomagazines", "Private", ITEM_FLAG,
"no caches will be multithreaded, and no caching will occur.",
&umem_flags, UMF_NOMAGAZINE
},
{ "reap_interval", "Private", ITEM_UINT,
"Minimum time between reaps and updates, in seconds.",
NULL, 0, &umem_reap_interval
},
#ifndef _WIN32
#ifndef UMEM_STANDALONE
{ "sbrk_pagesize", "Private", ITEM_SIZE,
"The preferred page size for the sbrk(2) heap.",
NULL, 0, NULL, &vmem_sbrk_pagesize
},
#endif
#endif
{ NULL, "-- end of UMEM_OPTIONS --", ITEM_INVALID }
};
const char *____umem_environ_msg_debug = "-- UMEM_DEBUG --";
static umem_env_item_t umem_debug_items[] = {
{ "default", "Unstable", ITEM_FLAG,
"audit,contents,guards",
&umem_flags,
UMF_AUDIT | UMF_CONTENTS | UMF_DEADBEEF | UMF_REDZONE
},
{ "audit", "Unstable", ITEM_OPTUINT,
"Enable auditing. optionally =frames to set the number of "
"stored stack frames",
&umem_flags, UMF_AUDIT, &umem_stack_depth
},
{ "contents", "Unstable", ITEM_OPTSIZE,
"Enable contents storing. UMEM_LOGGING=contents also "
"required. optionally =bytes to set the number of stored "
"bytes",
&umem_flags, UMF_CONTENTS, NULL, &umem_content_maxsave
},
{ "guards", "Unstable", ITEM_FLAG,
"Enables guards and special patterns",
&umem_flags, UMF_DEADBEEF | UMF_REDZONE
},
{ "verbose", "Unstable", ITEM_FLAG,
"Enables writing error messages to stderr",
&umem_output, 1
},
{ "nosignal", "Private", ITEM_FLAG,
"Abort if called from a signal handler. Turns on 'audit'. "
"Note that this is not always a bug.",
&umem_flags, UMF_AUDIT | UMF_CHECKSIGNAL
},
{ "firewall", "Private", ITEM_SIZE,
"=minbytes. Every object >= minbytes in size will have its "
"end against an unmapped page",
&umem_flags, UMF_FIREWALL, NULL, &umem_minfirewall
},
{ "lite", "Private", ITEM_FLAG,
"debugging-lite",
&umem_flags, UMF_LITE
},
{ "maxverify", "Private", ITEM_SIZE,
"=maxbytes, Maximum bytes to check when 'guards' is active. "
"Normally all bytes are checked.",
NULL, 0, NULL, &umem_maxverify
},
{ "noabort", "Private", ITEM_CLEARFLAG,
"umem will not abort when a recoverable error occurs "
"(i.e. double frees, certain kinds of corruption)",
&umem_abort, 1
},
{ "mtbf", "Private", ITEM_UINT,
"=mtbf, the mean time between injected failures. Works best "
"if prime.\n",
NULL, 0, &umem_mtbf
},
{ "random", "Private", ITEM_FLAG,
"randomize flags on a per-cache basis",
&umem_flags, UMF_RANDOMIZE
},
{ "allverbose", "Private", ITEM_FLAG,
"Enables writing all logged messages to stderr",
&umem_output, 2
},
{ NULL, "-- end of UMEM_DEBUG --", ITEM_INVALID }
};
const char *____umem_environ_msg_logging = "-- UMEM_LOGGING --";
static umem_env_item_t umem_logging_items[] = {
{ "transaction", "Unstable", ITEM_SPECIAL,
"If 'audit' is set in UMEM_DEBUG, the audit structures "
"from previous transactions are entered into this log.",
NULL, 0, NULL,
&umem_transaction_log_size, &umem_log_process
},
{ "contents", "Unstable", ITEM_SPECIAL,
"If 'audit' is set in UMEM_DEBUG, the contents of objects "
"are recorded in this log as they are freed. If the "
"'contents' option is not set in UMEM_DEBUG, the first "
"256 bytes of each freed buffer will be saved.",
&umem_flags, UMF_CONTENTS, NULL,
&umem_content_log_size, &umem_log_process
},
{ "fail", "Unstable", ITEM_SPECIAL,
"Records are entered into this log for every failed "
"allocation.",
NULL, 0, NULL,
&umem_failure_log_size, &umem_log_process
},
{ "slab", "Private", ITEM_SPECIAL,
"Every slab created will be entered into this log.",
NULL, 0, NULL,
&umem_slab_log_size, &umem_log_process
},
{ NULL, "-- end of UMEM_LOGGING --", ITEM_INVALID }
};
typedef struct umem_envvar {
const char *env_name;
const char *env_func;
umem_env_item_t *env_item_list;
const char *env_getenv_result;
const char *env_func_result;
} umem_envvar_t;
static umem_envvar_t umem_envvars[] = {
{ "UMEM_DEBUG", "_umem_debug_init", umem_debug_items },
{ "UMEM_OPTIONS", "_umem_options_init", umem_options_items },
{ "UMEM_LOGGING", "_umem_logging_init", umem_logging_items },
{ NULL, NULL, NULL }
};
static umem_envvar_t *env_current;
#define CURRENT (env_current->env_name)
static int
empty(const char *str)
{
char c;
while ((c = *str) != '\0' && isspace(c))
str++;
return (*str == '\0');
}
static int
item_uint_process(const umem_env_item_t *item, const char *item_arg)
{
ulong_t result;
char *endptr = "";
int olderrno;
olderrno = errno;
errno = 0;
if (empty(item_arg)) {
goto badnumber;
}
result = strtoul(item_arg, &endptr, 10);
if (result == ULONG_MAX && errno == ERANGE) {
errno = olderrno;
goto overflow;
}
errno = olderrno;
if (*endptr != '\0')
goto badnumber;
if ((uint_t)result != result)
goto overflow;
(*item->item_uint_target) = (uint_t)result;
return (ARG_SUCCESS);
badnumber:
log_message("%s: %s: not a number\n", CURRENT, item->item_name);
return (ARG_BAD);
overflow:
log_message("%s: %s: overflowed\n", CURRENT, item->item_name);
return (ARG_BAD);
}
static int
item_size_process(const umem_env_item_t *item, const char *item_arg)
{
ulong_t result;
ulong_t result_arg;
char *endptr = "";
int olderrno;
if (empty(item_arg))
goto badnumber;
olderrno = errno;
errno = 0;
result_arg = strtoul(item_arg, &endptr, 10);
if (result_arg == ULONG_MAX && errno == ERANGE) {
errno = olderrno;
goto overflow;
}
errno = olderrno;
result = result_arg;
switch (*endptr) {
case 't':
case 'T':
result *= 1024;
if (result < result_arg)
goto overflow;
/*FALLTHRU*/
case 'g':
case 'G':
result *= 1024;
if (result < result_arg)
goto overflow;
/*FALLTHRU*/
case 'm':
case 'M':
result *= 1024;
if (result < result_arg)
goto overflow;
/*FALLTHRU*/
case 'k':
case 'K':
result *= 1024;
if (result < result_arg)
goto overflow;
endptr++; /* skip over the size character */
break;
default:
break; /* handled later */
}
if (*endptr != '\0')
goto badnumber;
(*item->item_size_target) = result;
return (ARG_SUCCESS);
badnumber:
log_message("%s: %s: not a number\n", CURRENT, item->item_name);
return (ARG_BAD);
overflow:
log_message("%s: %s: overflowed\n", CURRENT, item->item_name);
return (ARG_BAD);
}
static int
umem_log_process(const umem_env_item_t *item, const char *item_arg)
{
if (item_arg != NULL) {
int ret;
ret = item_size_process(item, item_arg);
if (ret != ARG_SUCCESS)
return (ret);
if (*item->item_size_target == 0)
return (ARG_SUCCESS);
} else
*item->item_size_target = 64*1024;
umem_logging = 1;
return (ARG_SUCCESS);
}
#ifndef UMEM_STANDALONE
static int
umem_backend_process(const umem_env_item_t *item, const char *item_arg)
{
const char *name = item->item_name;
if (item_arg == NULL)
goto fail;
if (strcmp(item_arg, "sbrk") == 0)
vmem_backend |= VMEM_BACKEND_SBRK;
else if (strcmp(item_arg, "mmap") == 0)
vmem_backend |= VMEM_BACKEND_MMAP;
else
goto fail;
return (ARG_SUCCESS);
fail:
log_message("%s: %s: must be %s=sbrk or %s=mmap\n",
CURRENT, name, name, name);
return (ARG_BAD);
}
#endif
static int
process_item(const umem_env_item_t *item, const char *item_arg)
{
int arg_required = 0;
arg_process_t *processor;
switch (item->item_type) {
case ITEM_FLAG:
case ITEM_CLEARFLAG:
case ITEM_OPTUINT:
case ITEM_OPTSIZE:
case ITEM_SPECIAL:
arg_required = 0;
break;
case ITEM_UINT:
case ITEM_SIZE:
arg_required = 1;
break;
}
switch (item->item_type) {
case ITEM_FLAG:
case ITEM_CLEARFLAG:
if (item_arg != NULL) {
log_message("%s: %s: does not take a value. ignored\n",
CURRENT, item->item_name);
return (1);
}
processor = NULL;
break;
case ITEM_UINT:
case ITEM_OPTUINT:
processor = item_uint_process;
break;
case ITEM_SIZE:
case ITEM_OPTSIZE:
processor = item_size_process;
break;
case ITEM_SPECIAL:
processor = item->item_special;
break;
default:
log_message("%s: %s: Invalid type. Ignored\n",
CURRENT, item->item_name);
return (1);
}
if (arg_required && item_arg == NULL) {
log_message("%s: %s: Required value missing\n",
CURRENT, item->item_name);
goto invalid;
}
if (item_arg != NULL || item->item_type == ITEM_SPECIAL) {
if (processor(item, item_arg) != ARG_SUCCESS)
goto invalid;
}
if (item->item_flag_target) {
if (item->item_type == ITEM_CLEARFLAG)
(*item->item_flag_target) &= ~item->item_flag_value;
else
(*item->item_flag_target) |= item->item_flag_value;
}
return (0);
invalid:
return (1);
}
#define ENV_SHORT_BYTES 10 /* bytes to print on error */
void
umem_process_value(umem_env_item_t *item_list, const char *beg, const char *end)
{
char buf[UMEM_ENV_ITEM_MAX];
char *argptr;
size_t count;
while (beg < end && isspace(*beg))
beg++;
while (beg < end && isspace(*(end - 1)))
end--;
if (beg >= end) {
log_message("%s: empty option\n", CURRENT);
return;
}
count = end - beg;
if (count + 1 > sizeof (buf)) {
char outbuf[ENV_SHORT_BYTES + 1];
/*
* Have to do this, since sprintf("%10s",...) calls malloc()
*/
(void) strncpy(outbuf, beg, ENV_SHORT_BYTES);
outbuf[ENV_SHORT_BYTES] = 0;
log_message("%s: argument \"%s...\" too long\n", CURRENT,
outbuf);
return;
}
(void) strncpy(buf, beg, count);
buf[count] = 0;
argptr = strchr(buf, '=');
if (argptr != NULL)
*argptr++ = 0;
for (; item_list->item_name != NULL; item_list++) {
if (strcmp(buf, item_list->item_name) == 0) {
(void) process_item(item_list, argptr);
return;
}
}
log_message("%s: '%s' not recognized\n", CURRENT, buf);
}
/*ARGSUSED*/
void
umem_setup_envvars(int invalid)
{
umem_envvar_t *cur_env;
static volatile enum {
STATE_START,
STATE_GETENV,
STATE_DLSYM,
STATE_FUNC,
STATE_DONE
} state = STATE_START;
#ifndef UMEM_STANDALONE
void *h;
#endif
if (invalid) {
const char *where;
/*
* One of the calls below invoked malloc() recursively. We
* remove any partial results and return.
*/
switch (state) {
case STATE_START:
where = "before getenv(3C) calls -- "
"getenv(3C) results ignored.";
break;
case STATE_GETENV:
where = "during getenv(3C) calls -- "
"getenv(3C) results ignored.";
break;
case STATE_DLSYM:
where = "during dlsym(3C) call -- "
"_umem_*() results ignored.";
break;
case STATE_FUNC:
where = "during _umem_*() call -- "
"_umem_*() results ignored.";
break;
case STATE_DONE:
where = "after dlsym() or _umem_*() calls.";
break;
default:
where = "at unknown point -- "
"_umem_*() results ignored.";
break;
}
log_message("recursive allocation %s\n", where);
for (cur_env = umem_envvars; cur_env->env_name != NULL;
cur_env++) {
if (state == STATE_GETENV)
cur_env->env_getenv_result = NULL;
if (state != STATE_DONE)
cur_env->env_func_result = NULL;
}
state = STATE_DONE;
return;
}
state = STATE_GETENV;
for (cur_env = umem_envvars; cur_env->env_name != NULL; cur_env++) {
cur_env->env_getenv_result = getenv(cur_env->env_name);
if (state == STATE_DONE)
return; /* recursed */
}
#ifndef UMEM_STANDALONE
#ifdef _WIN32
# define dlopen(a, b) GetModuleHandle(NULL)
# define dlsym(a, b) GetProcAddress((HANDLE)a, b)
# define dlclose(a) 0
# define dlerror() 0
#endif
/* get a handle to the "a.out" object */
if ((h = dlopen(0, RTLD_FIRST | RTLD_LAZY)) != NULL) {
for (cur_env = umem_envvars; cur_env->env_name != NULL;
cur_env++) {
const char *(*func)(void);
const char *value;
state = STATE_DLSYM;
func = (const char *(*)(void))dlsym(h,
cur_env->env_func);
if (state == STATE_DONE)
break; /* recursed */
state = STATE_FUNC;
if (func != NULL) {
value = func();
if (state == STATE_DONE)
break; /* recursed */
cur_env->env_func_result = value;
}
}
(void) dlclose(h);
} else {
(void) dlerror(); /* snarf dlerror() */
}
#endif /* UMEM_STANDALONE */
state = STATE_DONE;
}
/*
* Process the environment variables.
*/
void
umem_process_envvars(void)
{
const char *value;
const char *end, *next;
umem_envvar_t *cur_env;
for (cur_env = umem_envvars; cur_env->env_name != NULL; cur_env++) {
env_current = cur_env;
value = cur_env->env_getenv_result;
if (value == NULL)
value = cur_env->env_func_result;
/* ignore if missing or empty */
if (value == NULL)
continue;
for (end = value; *end != '\0'; value = next) {
end = strchr(value, ',');
if (end != NULL)
next = end + 1; /* skip the comma */
else
next = end = value + strlen(value);
umem_process_value(cur_env->env_item_list, value, end);
}
}
}

211
getpcstack.c Normal file
View file

@ -0,0 +1,211 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Portions Copyright 2006 OmniTI, Inc.
*/
/* #pragma ident "@(#)getpcstack.c 1.5 05/06/08 SMI" */
#include "config.h"
#include "misc.h"
#if HAVE_UCONTEXT_H
#include <ucontext.h>
#endif
#if HAVE_SYS_FRAME_H
#include <sys/frame.h>
#endif
#if HAVE_SYS_STACK_H
#include <sys/stack.h>
#endif
#include <stdio.h>
#if defined(__MACH__)
/*
* Darwin doesn't have any exposed frame info, so give it some space.
*/
#define UMEM_FRAMESIZE (2 * sizeof(long long))
#elif defined(__sparc) || defined(__sparcv9)
extern void flush_windows(void);
#define UMEM_FRAMESIZE MINFRAME
#elif defined(__i386) || defined(__amd64)
/*
* On x86, MINFRAME is defined to be 0, but we want to be sure we can
* dereference the entire frame structure.
*/
#define UMEM_FRAMESIZE (sizeof (struct frame))
#elif !defined(EC_UMEM_DUMMY_PCSTACK)
#error needs update for new architecture
#endif
/*
* Get a pc-only stacktrace. Used for kmem_alloc() buffer ownership tracking.
* Returns MIN(current stack depth, pcstack_limit).
*/
/*ARGSUSED*/
int
getpcstack(uintptr_t *pcstack, int pcstack_limit, int check_signal)
{
#ifdef EC_UMEM_DUMMY_PCSTACK
return 0;
#else
struct frame *fp;
struct frame *nextfp, *minfp;
int depth = 0;
uintptr_t base = 0;
size_t size = 0;
#ifndef UMEM_STANDALONE
int on_altstack = 0;
uintptr_t sigbase = 0;
size_t sigsize = 0;
stack_t st;
if (stack_getbounds(&st) != 0) {
if (thr_stksegment(&st) != 0 ||
(uintptr_t)st.ss_sp < st.ss_size) {
return (0); /* unable to get stack bounds */
}
/*
* thr_stksegment(3C) has a slightly different interface than
* stack_getbounds(3C) -- correct it
*/
st.ss_sp = (void *)(((uintptr_t)st.ss_sp) - st.ss_size);
st.ss_flags = 0; /* can't be on-stack */
}
on_altstack = (st.ss_flags & SS_ONSTACK);
if (st.ss_size != 0) {
base = (uintptr_t)st.ss_sp;
size = st.ss_size;
} else {
/*
* If size == 0, then ss_sp is the *top* of the stack.
*
* Since we only allow increasing frame pointers, and we
* know our caller set his up correctly, we can treat ss_sp
* as an upper bound safely.
*/
base = 0;
size = (uintptr_t)st.ss_sp;
}
if (check_signal != 0) {
void (*sigfunc)() = NULL;
int sigfuncsize = 0;
extern void thr_sighndlrinfo(void (**)(), int *);
thr_sighndlrinfo(&sigfunc, &sigfuncsize);
sigbase = (uintptr_t)sigfunc;
sigsize = sigfuncsize;
}
#else /* UMEM_STANDALONE */
base = (uintptr_t)umem_min_stack;
size = umem_max_stack - umem_min_stack;
#endif
/*
* shorten size so that fr_savfp and fr_savpc will be within the stack
* bounds.
*/
if (size >= UMEM_FRAMESIZE - 1)
size -= (UMEM_FRAMESIZE - 1);
else
size = 0;
#if defined(__sparc) || defined(__sparcv9)
flush_windows();
#endif
/* LINTED alignment */
fp = (struct frame *)((caddr_t)getfp() + STACK_BIAS);
minfp = fp;
if (((uintptr_t)fp - base) >= size)
return (0); /* the frame pointer isn't in our stack */
while (depth < pcstack_limit) {
uintptr_t tmp;
/* LINTED alignment */
nextfp = (struct frame *)((caddr_t)fp->fr_savfp + STACK_BIAS);
tmp = (uintptr_t)nextfp;
/*
* Check nextfp for validity. It must be properly aligned,
* increasing compared to the last %fp (or the top of the
* stack we just switched to), and it must be inside
* [base, base + size).
*/
if (tmp != SA(tmp))
break;
else if (nextfp <= minfp || (tmp - base) >= size) {
#ifndef UMEM_STANDALONE
if (tmp == NULL || !on_altstack)
break;
/*
* If we're on an alternate signal stack, try jumping
* to the main thread stack.
*
* If the main thread stack has an unlimited size, we
* punt, since we don't know where the frame pointer's
* been.
*
* (thr_stksegment() returns the *top of stack*
* in ss_sp, not the bottom)
*/
if (thr_stksegment(&st) == 0) {
if (st.ss_size >= (uintptr_t)st.ss_sp ||
st.ss_size < UMEM_FRAMESIZE - 1)
break;
on_altstack = 0;
base = (uintptr_t)st.ss_sp - st.ss_size;
size = st.ss_size - (UMEM_FRAMESIZE - 1);
minfp = (struct frame *)base;
continue; /* try again */
}
#endif
break;
}
#ifndef UMEM_STANDALONE
if (check_signal && (fp->fr_savpc - sigbase) <= sigsize)
umem_panic("called from signal handler");
#endif
pcstack[depth++] = fp->fr_savpc;
fp = nextfp;
minfp = fp;
}
return (depth);
#endif
}

72
i386_subr_sol.s Normal file
View file

@ -0,0 +1,72 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)asm_subr.s 1.4 05/06/08 SMI"
#include <sys/asm_linkage.h>
#if defined(lint)
void *
getfp(void)
{
return (NULL);
}
#ifndef UMEM_STANDALONE
void
_breakpoint(void)
{
return;
}
#endif
#else /* lint */
#if defined(__amd64)
ENTRY(getfp)
movq %rbp, %rax
ret
SET_SIZE(getfp)
#else /* __i386 */
ENTRY(getfp)
movl %ebp, %eax
ret
SET_SIZE(getfp)
#endif
#ifndef UMEM_STANDALONE
ENTRY(_breakpoint)
int $3
ret
SET_SIZE(_breakpoint)
#endif
#endif /* lint */

104
init_lib.c Normal file
View file

@ -0,0 +1,104 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Portions Copyright 2006 OmniTI, Inc.
*/
/* #pragma ident "@(#)init_lib.c 1.2 05/06/08 SMI" */
/*
* Initialization routines for the library version of libumem.
*/
#include "config.h"
#include "umem_base.h"
#include "vmem_base.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
void
vmem_heap_init(void)
{
#ifdef _WIN32
vmem_backend = VMEM_BACKEND_MMAP;
#else
#if 0
void *handle = dlopen("libmapmalloc.so.1", RTLD_NOLOAD);
if (handle != NULL) {
#endif
log_message("sbrk backend disabled\n");
vmem_backend = VMEM_BACKEND_MMAP;
#if 0
}
#endif
#endif
if ((vmem_backend & VMEM_BACKEND_MMAP) != 0) {
vmem_backend = VMEM_BACKEND_MMAP;
(void) vmem_mmap_arena(NULL, NULL);
} else {
#ifndef _WIN32
vmem_backend = VMEM_BACKEND_SBRK;
(void) vmem_sbrk_arena(NULL, NULL);
#endif
}
}
/*ARGSUSED*/
void
umem_type_init(caddr_t start, size_t len, size_t pgsize)
{
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo(&info);
pagesize = info.dwPageSize;
#else
pagesize = _sysconf(_SC_PAGESIZE);
#endif
}
int
umem_get_max_ncpus(void)
{
#ifdef _SC_NPROCESSORS_ONLN
return (2 * sysconf(_SC_NPROCESSORS_ONLN));
#elif defined(_SC_NPROCESSORS_CONF)
return (2 * sysconf(_SC_NPROCESSORS_CONF));
#elif defined(_WIN32)
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
#else
/* XXX: determine CPU count on other platforms */
return (1);
#endif
}

65
init_stand.c Normal file
View file

@ -0,0 +1,65 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "@(#)init_stand.c 1.3 05/06/08 SMI"
/*
* Initialization routines for the standalone version of libumem.
*/
#include "config.h"
#include "umem_base.h"
#include "vmem_base.h"
#include "vmem_stand.h"
void
vmem_heap_init(void)
{
vmem_backend = VMEM_BACKEND_STAND;
(void) vmem_stand_arena(NULL, NULL);
}
void
umem_type_init(caddr_t base, size_t len, size_t pgsize)
{
pagesize = pgsize;
vmem_stand_init();
(void) vmem_stand_add(base, len);
}
int
umem_get_max_ncpus(void)
{
return (1);
}
int
umem_add(caddr_t base, size_t len)
{
return (vmem_stand_add(base, len));
}

70
linktest_stand.c Normal file
View file

@ -0,0 +1,70 @@
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the