socsvn commit: r239715 - in soc2012/gmiller/locking-head: . include
lib/libwitness
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Mon Jul 23 20:22:15 UTC 2012
Author: gmiller
Date: Mon Jul 23 20:22:13 2012
New Revision: 239715
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=239715
Log:
r239755 at FreeBSD-dev: root | 2012-07-23 15:19:18 -0500
Handle memory allocation failures a bit more gracefully.
Modified:
soc2012/gmiller/locking-head/ (props changed)
soc2012/gmiller/locking-head/include/pthread_np.h
soc2012/gmiller/locking-head/lib/libwitness/graph.c
soc2012/gmiller/locking-head/lib/libwitness/lists.c
soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
soc2012/gmiller/locking-head/lib/libwitness/logs.c
soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
Modified: soc2012/gmiller/locking-head/include/pthread_np.h
==============================================================================
--- soc2012/gmiller/locking-head/include/pthread_np.h Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/include/pthread_np.h Mon Jul 23 20:22:13 2012 (r239715)
@@ -106,17 +106,17 @@
int pthread_switch_add_np(pthread_switch_routine_t);
int pthread_switch_delete_np(pthread_switch_routine_t);
int pthread_timedjoin_np(pthread_t, void **, const struct timespec *);
-void pthread_lor_begin_np(struct pthread_lor_np *);
+int pthread_lor_begin_np(struct pthread_lor_np *);
int pthread_lor_next_np(struct pthread_lor_np *);
void pthread_lor_end_np(struct pthread_lor_np *);
void pthread_lor_clear_np(void);
int pthread_lockorder_bless_np(void *, void *);
int pthread_lockorder_set_np(void *first, void *second);
void pthread_lockorder_reset_np(void);
-void pthread_lockorder_begin_np(struct pthread_lockorder_np *);
+int pthread_lockorder_begin_np(struct pthread_lockorder_np *);
int pthread_lockorder_next_np(struct pthread_lockorder_np *);
void pthread_lockorder_end_np(struct pthread_lockorder_np *);
-void pthread_setname_np(void *, const char *);
+int pthread_setname_np(void *, const char *);
#ifdef LOCK_PROFILING
Modified: soc2012/gmiller/locking-head/lib/libwitness/graph.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/lib/libwitness/graph.c Mon Jul 23 20:22:13 2012 (r239715)
@@ -62,7 +62,7 @@
int
insert_lock(struct lock_info *from, struct lock_info *to)
{
- if (from == to) {
+ if (from == to || from == NULL || to == NULL) {
return (0);
}
Modified: soc2012/gmiller/locking-head/lib/libwitness/lists.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lists.c Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/lib/libwitness/lists.c Mon Jul 23 20:22:13 2012 (r239715)
@@ -44,9 +44,17 @@
struct lock_entry *entry;
struct lock_entry *next;
+ if (lock == NULL) {
+ return;
+ }
+
next = SLIST_FIRST(&lock_head);
entry = malloc(sizeof(*entry));
+ if (entry == NULL) {
+ return;
+ }
+
entry->lock = lock;
if (reset_count > thread_reset_count) {
Modified: soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/lib/libwitness/lockinfo.c Mon Jul 23 20:22:13 2012 (r239715)
@@ -49,13 +49,16 @@
if (info == NULL) {
info = malloc(sizeof(struct lock_info));
- info->active = 1;
- info->lock = lock;
- info->child = NULL;
- info->sibling = NULL;
- info->name = NULL;
- SLIST_INIT(&info->bless_head);
- SLIST_INSERT_HEAD(&lock_info_head, info, lock_info_next);
+ if (info != NULL) {
+ info->active = 1;
+ info->lock = lock;
+ info->child = NULL;
+ info->sibling = NULL;
+ info->name = NULL;
+ SLIST_INIT(&info->bless_head);
+ SLIST_INSERT_HEAD(&lock_info_head, info,
+ lock_info_next);
+ }
}
return (info);
@@ -67,7 +70,9 @@
struct lock_info *info;
info = lookup_lock(lock);
- info->active = 0;
+ if (info != NULL) {
+ info->active = 0;
+ }
}
int
@@ -109,20 +114,30 @@
}
}
-void
+int
pthread_setname_np(void *lock, const char *name)
{
struct lock_info *info;
info = lookup_lock(lock);
- info->name = realloc(info->name, strlen(name) + 1);
+ if (info == NULL) {
+ return (ENOMEM);
+ }
+
+ info->name = reallocf(info->name, strlen(name) + 1);
+ if (info->name == NULL) {
+ return (errno);
+ }
+
strcpy(info->name, name);
+
+ return (0);
}
void
check_default_name(struct lock_info *lock, const char *prefix)
{
- if (lock->name == NULL) {
+ if (lock != NULL && lock->name == NULL) {
lock->name = malloc(MAX_DEFAULT_NAME_LENGTH + 1);
if (lock->name != NULL) {
snprintf(lock->name, MAX_DEFAULT_NAME_LENGTH, "%s%p",
@@ -131,9 +146,11 @@
}
}
-void
+int
pthread_lockorder_begin_np(struct pthread_lockorder_np *node)
{
+ int ret = 0;
+
/*
The lock isn't needed to prevent races, but it is needed to ensure
that any locks grabbed by malloc() don't get logged.
@@ -141,28 +158,37 @@
pthread_mutex_lock(&witness_mtx);
node->_pvt = malloc(sizeof(struct _pthread_lockorder_private));
- node->_pvt->last_record = NULL;
+ if (node->_pvt == NULL) {
+ ret = ENOMEM;
+ } else {
+ node->_pvt->last_record = NULL;
+ }
pthread_mutex_unlock(&witness_mtx);
+
+ return (ret);
}
int
pthread_lockorder_next_np(struct pthread_lockorder_np *node)
{
- if (node->_pvt->last_record == NULL) {
- node->_pvt->last_record = SLIST_FIRST(&lock_info_head);
- } else {
- node->_pvt->last_record = SLIST_NEXT(node->_pvt->last_record,
- lock_info_next);
- }
+ if (node->_pvt != NULL) {
+ if (node->_pvt->last_record == NULL) {
+ node->_pvt->last_record = SLIST_FIRST(&lock_info_head);
+ } else {
+ node->_pvt->last_record =
+ SLIST_NEXT(node->_pvt->last_record,
+ lock_info_next);
+ }
- if (node->_pvt->last_record != NULL) {
- node->lock = node->_pvt->last_record->lock;
+ if (node->_pvt->last_record != NULL) {
+ node->lock = node->_pvt->last_record->lock;
- return (1);
- } else {
- return (0);
+ return (1);
+ }
}
+
+ return (0);
}
void
Modified: soc2012/gmiller/locking-head/lib/libwitness/logs.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/lib/libwitness/logs.c Mon Jul 23 20:22:13 2012 (r239715)
@@ -45,15 +45,18 @@
struct lor_entry *entry;
entry = malloc(sizeof(struct lor_entry));
- entry->lock_first = previous;
- entry->lock_second = lock;
+ if (entry != NULL) {
+ entry->lock_first = previous;
+ entry->lock_second = lock;
- STAILQ_INSERT_TAIL(&lor_head, entry, lor_next);
+ STAILQ_INSERT_TAIL(&lor_head, entry, lor_next);
+ }
}
-void
+int
pthread_lor_begin_np(struct pthread_lor_np *lor)
{
+ int ret = 0;
/*
The lock isn't needed to prevent races, but it is needed to ensure
that any locks grabbed by malloc() don't get logged.
@@ -61,15 +64,21 @@
pthread_mutex_lock(&witness_mtx);
lor->_pvt = malloc(sizeof(struct _pthread_lor_private));
- lor->_pvt->last_record = NULL;
+ if (lor->_pvt == NULL) {
+ ret = ENOMEM;
+ } else {
+ lor->_pvt->last_record = NULL;
+ }
pthread_mutex_unlock(&witness_mtx);
+
+ return (ret);
}
int
pthread_lor_next_np(struct pthread_lor_np *lor)
{
- int res = 0;
+ int res = 0;
pthread_mutex_lock(&witness_mtx);
Modified: soc2012/gmiller/locking-head/lib/libwitness/wrappers.c
==============================================================================
--- soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Mon Jul 23 20:21:59 2012 (r239714)
+++ soc2012/gmiller/locking-head/lib/libwitness/wrappers.c Mon Jul 23 20:22:13 2012 (r239715)
@@ -53,7 +53,7 @@
int
pthread_mutex_lock(pthread_mutex_t *mutex)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -74,7 +74,7 @@
int
pthread_mutex_trylock(pthread_mutex_t *mutex)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -95,7 +95,7 @@
int
pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *ts)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -116,7 +116,7 @@
int
pthread_mutex_unlock(pthread_mutex_t *mutex)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -133,7 +133,7 @@
int
pthread_mutex_destroy(pthread_mutex_t *mutex)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -148,7 +148,7 @@
int
pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -169,7 +169,7 @@
int
pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -190,7 +190,7 @@
int
pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -211,7 +211,7 @@
int
pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -232,7 +232,7 @@
int
pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -253,7 +253,7 @@
int
pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -274,7 +274,7 @@
int
pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -291,7 +291,7 @@
int
pthread_rwlock_destroy(pthread_rwlock_t *rwlock)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -306,7 +306,7 @@
int
pthread_spin_lock(pthread_spinlock_t *spin)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -327,7 +327,7 @@
int
pthread_spin_trylock(pthread_spinlock_t *spin)
{
- int ret;
+ int ret;
struct lock_info *lock;
_pthread_mutex_lock(&witness_mtx);
@@ -348,7 +348,7 @@
int
pthread_spin_unlock(pthread_spinlock_t *spin)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -365,7 +365,7 @@
int
pthread_spin_destroy(pthread_spinlock_t *spin)
{
- int ret;
+ int ret;
_pthread_mutex_lock(&witness_mtx);
@@ -398,7 +398,7 @@
{
struct lock_info *first;
struct lock_info *second;
- struct blessing *first_bless;
+ struct blessing *first_bless = NULL;
struct blessing *second_bless = NULL;
int ret = 0;
@@ -408,15 +408,23 @@
second = lookup_lock(second_addr);
first_bless = malloc(sizeof(struct blessing));
- if (first_bless != NULL) {
- second_bless = malloc(sizeof(struct blessing));
- if (second_bless == NULL) {
- free(first_bless);
- }
- }
+ second_bless = malloc(sizeof(struct blessing));
- if (second_bless == NULL) {
+ if (first == NULL || second == NULL || first_bless == NULL ||
+ second_bless == NULL) {
ret = ENOMEM;
+
+ if (first != NULL) {
+ free(first);
+ }
+
+ if (second != NULL) {
+ free(second);
+ }
+
+ if (first_bless != NULL) {
+ free(first_bless);
+ }
} else {
first_bless->lock = second;
SLIST_INSERT_HEAD(&first->bless_head, first_bless, bless_next);
More information about the svn-soc-all
mailing list