Obtain proper initialized addresses of locks allocated by mutex_obj_alloc or rw_obj_alloc

Initialized addresses of locks allocated by mutex_obj_alloc or rw_obj_alloc
were not useful because the addresses were mutex_obj_alloc or rw_obj_alloc
itself. What we want to know are callers of them.
This commit is contained in:
ozaki-r 2018-02-05 04:25:04 +00:00
parent 74845a91b1
commit 5e1cf642fa
4 changed files with 36 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_mutex.c,v 1.70 2018/01/30 07:52:22 ozaki-r Exp $ */
/* $NetBSD: kern_mutex.c,v 1.71 2018/02/05 04:25:04 ozaki-r Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@ -40,7 +40,7 @@
#define __MUTEX_PRIVATE
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.70 2018/01/30 07:52:22 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.71 2018/02/05 04:25:04 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -327,8 +327,10 @@ mutex_abort(const char *func, size_t line, const kmutex_t *mtx, const char *msg)
* sleeps - see comments in mutex_vector_enter() about releasing
* mutexes unlocked.
*/
void _mutex_init(kmutex_t *, kmutex_type_t, int, uintptr_t);
void
mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
_mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl,
uintptr_t return_address)
{
bool dodebug;
@ -354,18 +356,17 @@ mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
switch (type) {
case MUTEX_NODEBUG:
dodebug = LOCKDEBUG_ALLOC(mtx, NULL,
(uintptr_t)__builtin_return_address(0));
dodebug = LOCKDEBUG_ALLOC(mtx, NULL, return_address);
MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
break;
case MUTEX_ADAPTIVE:
dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_adaptive_lockops,
(uintptr_t)__builtin_return_address(0));
return_address);
MUTEX_INITIALIZE_ADAPTIVE(mtx, dodebug);
break;
case MUTEX_SPIN:
dodebug = LOCKDEBUG_ALLOC(mtx, &mutex_spin_lockops,
(uintptr_t)__builtin_return_address(0));
return_address);
MUTEX_INITIALIZE_SPIN(mtx, dodebug, ipl);
break;
default:
@ -374,6 +375,13 @@ mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
}
}
void
mutex_init(kmutex_t *mtx, kmutex_type_t type, int ipl)
{
_mutex_init(mtx, type, ipl, (uintptr_t)__builtin_return_address(0));
}
/*
* mutex_destroy:
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_mutex_obj.c,v 1.5 2011/09/27 01:02:38 jym Exp $ */
/* $NetBSD: kern_mutex_obj.c,v 1.6 2018/02/05 04:25:04 ozaki-r Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.5 2011/09/27 01:02:38 jym Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_mutex_obj.c,v 1.6 2018/02/05 04:25:04 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -87,9 +87,11 @@ kmutex_t *
mutex_obj_alloc(kmutex_type_t type, int ipl)
{
struct kmutexobj *mo;
extern void _mutex_init(kmutex_t *, kmutex_type_t, int, uintptr_t);
mo = pool_cache_get(mutex_obj_cache, PR_WAITOK);
mutex_init(&mo->mo_lock, type, ipl);
_mutex_init(&mo->mo_lock, type, ipl,
(uintptr_t)__builtin_return_address(0));
mo->mo_refcnt = 1;
return (kmutex_t *)mo;

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_rwlock.c,v 1.49 2018/01/30 07:52:22 ozaki-r Exp $ */
/* $NetBSD: kern_rwlock.c,v 1.50 2018/02/05 04:25:04 ozaki-r Exp $ */
/*-
* Copyright (c) 2002, 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.49 2018/01/30 07:52:22 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.50 2018/02/05 04:25:04 ozaki-r Exp $");
#define __RWLOCK_PRIVATE
@ -197,18 +197,25 @@ rw_abort(const char *func, size_t line, krwlock_t *rw, const char *msg)
*
* Initialize a rwlock for use.
*/
void _rw_init(krwlock_t *, uintptr_t);
void
rw_init(krwlock_t *rw)
_rw_init(krwlock_t *rw, uintptr_t return_address)
{
bool dodebug;
memset(rw, 0, sizeof(*rw));
dodebug = LOCKDEBUG_ALLOC(rw, &rwlock_lockops,
(uintptr_t)__builtin_return_address(0));
dodebug = LOCKDEBUG_ALLOC(rw, &rwlock_lockops, return_address);
RW_SETDEBUG(rw, dodebug);
}
void
rw_init(krwlock_t *rw)
{
_rw_init(rw, (uintptr_t)__builtin_return_address(0));
}
/*
* rw_destroy:
*

View File

@ -1,4 +1,4 @@
/* $NetBSD: kern_rwlock_obj.c,v 1.3 2011/05/13 22:16:43 rmind Exp $ */
/* $NetBSD: kern_rwlock_obj.c,v 1.4 2018/02/05 04:25:04 ozaki-r Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock_obj.c,v 1.3 2011/05/13 22:16:43 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: kern_rwlock_obj.c,v 1.4 2018/02/05 04:25:04 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -87,9 +87,10 @@ krwlock_t *
rw_obj_alloc(void)
{
struct krwobj *ro;
extern void _rw_init(krwlock_t *, uintptr_t);
ro = pool_cache_get(rw_obj_cache, PR_WAITOK);
rw_init(&ro->ro_lock);
_rw_init(&ro->ro_lock, (uintptr_t)__builtin_return_address(0));
ro->ro_refcnt = 1;
return (krwlock_t *)ro;