summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Kimmel <dan.kimmel@delphix.com>2016-08-18 15:52:20 -0700
committerMatthew Ahrens <mahrens@delphix.com>2016-08-19 15:01:59 -0700
commit831abf2c3ce98eddc86402eb1c97c92fa48c7349 (patch)
treefac62e5760f561547ed12ec0d07e80dd731a3f84
parentd420209d9c807f782c1d31f5683be74798142198 (diff)
downloadillumos-joyent-831abf2c3ce98eddc86402eb1c97c92fa48c7349.tar.gz
7236 libumem should be able to abort() when an allocation fails
Reviewed by: Alex Reece <alex@delphix.com> Reviewed by: Paul Dagnelie <pcd@delphix.com> Reviewed by: Basil Crow <basil.crow@delphix.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Dan McDonald <danmcd@omniti.com>
-rw-r--r--usr/src/cmd/mdb/common/modules/libumem/umem.c3
-rw-r--r--usr/src/lib/libumem/common/envvar.c5
-rw-r--r--usr/src/lib/libumem/common/umem.c6
-rw-r--r--usr/src/lib/libumem/common/umem_impl.h3
4 files changed, 15 insertions, 2 deletions
diff --git a/usr/src/cmd/mdb/common/modules/libumem/umem.c b/usr/src/cmd/mdb/common/modules/libumem/umem.c
index 250a090b12..65a06cb31c 100644
--- a/usr/src/cmd/mdb/common/modules/libumem/umem.c
+++ b/usr/src/cmd/mdb/common/modules/libumem/umem.c
@@ -25,7 +25,7 @@
/*
* Copyright 2012 Joyent, Inc. All rights reserved.
- * Copyright (c) 2013 by Delphix. All rights reserved.
+ * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
*/
#include "umem.h"
@@ -336,6 +336,7 @@ umem_debug_flags_t umem_status_flags[] = {
{ "nosignal", UMF_CHECKSIGNAL },
{ "firewall", UMF_FIREWALL },
{ "lite", UMF_LITE },
+ { "checknull", UMF_CHECKNULL },
{ NULL }
};
diff --git a/usr/src/lib/libumem/common/envvar.c b/usr/src/lib/libumem/common/envvar.c
index 0c4d872814..6c57d9553e 100644
--- a/usr/src/lib/libumem/common/envvar.c
+++ b/usr/src/lib/libumem/common/envvar.c
@@ -26,6 +26,7 @@
/*
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015 by Delphix. All rights reserved.
*/
#include <ctype.h>
@@ -226,6 +227,10 @@ static umem_env_item_t umem_debug_items[] = {
"Enables writing all logged messages to stderr",
&umem_output, 2
},
+ { "checknull", "Private", ITEM_FLAG,
+ "Abort if an allocation would return null",
+ &umem_flags, UMF_CHECKNULL
+ },
{ NULL, "-- end of UMEM_DEBUG --", ITEM_INVALID }
};
diff --git a/usr/src/lib/libumem/common/umem.c b/usr/src/lib/libumem/common/umem.c
index 00028e5f80..dbc738a049 100644
--- a/usr/src/lib/libumem/common/umem.c
+++ b/usr/src/lib/libumem/common/umem.c
@@ -26,6 +26,7 @@
/*
* Copyright (c) 2014 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015 by Delphix. All rights reserved.
*/
/*
@@ -1234,6 +1235,9 @@ umem_alloc_retry(umem_cache_t *cp, int umflag)
* Initialization failed. Do normal failure processing.
*/
}
+ if (umem_flags & UMF_CHECKNULL) {
+ umem_err_recoverable("umem: out of heap space");
+ }
if (umflag & UMEM_NOFAIL) {
int def_result = UMEM_CALLBACK_EXIT(255);
int result = def_result;
@@ -1377,7 +1381,7 @@ umem_log_enter(umem_log_header_t *lhp, void *data, size_t size)
static void
umem_log_event(umem_log_header_t *lp, umem_cache_t *cp,
- umem_slab_t *sp, void *addr)
+ umem_slab_t *sp, void *addr)
{
umem_bufctl_audit_t *bcp;
UMEM_LOCAL_BUFCTL_AUDIT(&bcp);
diff --git a/usr/src/lib/libumem/common/umem_impl.h b/usr/src/lib/libumem/common/umem_impl.h
index f63246e166..7d5056f172 100644
--- a/usr/src/lib/libumem/common/umem_impl.h
+++ b/usr/src/lib/libumem/common/umem_impl.h
@@ -26,6 +26,7 @@
/*
* Copyright (c) 2012 Joyent, Inc. All rights reserved.
+ * Copyright (c) 2015 by Delphix. All rights reserved.
*/
#ifndef _UMEM_IMPL_H
@@ -68,6 +69,8 @@ extern "C" {
#define UMF_RANDOMIZE 0x00000400 /* randomize other umem_flags */
#define UMF_PTC 0x00000800 /* cache has per-thread caching */
+#define UMF_CHECKNULL 0x00001000 /* heap exhaustion checking */
+
#define UMF_BUFTAG (UMF_DEADBEEF | UMF_REDZONE)
#define UMF_TOUCH (UMF_BUFTAG | UMF_LITE | UMF_CONTENTS)
#define UMF_RANDOM (UMF_TOUCH | UMF_AUDIT | UMF_NOMAGAZINE)