<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10376">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">astobj2: Assert on attempt to lock object with no locking.<br><br>Add assertion when __ao2_lock or __ao2_trylock are called against an<br>object that does not contain a lock. No assertion is performed by<br>__adjust_lock as this is used by functions which use the OBJ_NOLOCK<br>flag. Inject OBJ_NOLOCK for standard ao2_container operations if the<br>container was allocated without locking.<br><br>Remove invalid locking of PJSIP CLI formatter registry.<br><br>Change-Id: I5518e55739769792a76f766ce25880d7d944f63b<br>---<br>M main/astobj2.c<br>M main/astobj2_container.c<br>M main/astobj2_private.h<br>M res/res_pjsip/pjsip_cli.c<br>4 files changed, 32 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/76/10376/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/main/astobj2.c b/main/astobj2.c</span><br><span>index 23109a6..13f4648 100644</span><br><span>--- a/main/astobj2.c</span><br><span>+++ b/main/astobj2.c</span><br><span>@@ -178,6 +178,16 @@</span><br><span> return !p || IS_AO2_MAGIC_BAD(p) ? 0 : 1;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int internal_ao2_nolock(void *user_data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct astobj2 *p = INTERNAL_OBJ(user_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(p != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return (p->priv_data.options & AO2_ALLOC_OPT_LOCK_MASK) == AO2_ALLOC_OPT_LOCK_NOLOCK</span><br><span style="color: hsl(120, 100%, 40%);">+ ? OBJ_NOLOCK : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void log_bad_ao2(void *user_data, const char *file, int line, const char *func)</span><br><span> {</span><br><span> struct astobj2 *p;</span><br><span>@@ -242,7 +252,8 @@</span><br><span> break;</span><br><span> case AO2_ALLOC_OPT_LOCK_NOLOCK:</span><br><span> /* The ao2 object has no lock. */</span><br><span style="color: hsl(0, 100%, 40%);">- break;</span><br><span style="color: hsl(120, 100%, 40%);">+ __ast_assert_failed(0, "ao2_lock called on object with no locking.", file, line, func);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> case AO2_ALLOC_OPT_LOCK_OBJ:</span><br><span> obj_lockobj = INTERNAL_OBJ_LOCKOBJ(user_data);</span><br><span> res = __ao2_lock(obj_lockobj->lockobj.lock, lock_how, file, func, line, var);</span><br><span>@@ -358,7 +369,8 @@</span><br><span> break;</span><br><span> case AO2_ALLOC_OPT_LOCK_NOLOCK:</span><br><span> /* The ao2 object has no lock. */</span><br><span style="color: hsl(0, 100%, 40%);">- return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ __ast_assert_failed(0, "ao2_trylock called on object with no locking.", file, line, func);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span> case AO2_ALLOC_OPT_LOCK_OBJ:</span><br><span> obj_lockobj = INTERNAL_OBJ_LOCKOBJ(user_data);</span><br><span> res = __ao2_trylock(obj_lockobj->lockobj.lock, lock_how, file, func, line, var);</span><br><span>@@ -433,6 +445,8 @@</span><br><span> ast_log(LOG_ERROR, "Invalid lock option on ao2 object %p\n", user_data);</span><br><span> /* Fall through */</span><br><span> case AO2_ALLOC_OPT_LOCK_NOLOCK:</span><br><span style="color: hsl(120, 100%, 40%);">+ /* No assertion for __adjust_lock, this is used internally by AO2 code</span><br><span style="color: hsl(120, 100%, 40%);">+ * that uses OBJ_NOLOCK. */</span><br><span> case AO2_ALLOC_OPT_LOCK_MUTEX:</span><br><span> orig_lock = AO2_LOCK_REQ_MUTEX;</span><br><span> break;</span><br><span>diff --git a/main/astobj2_container.c b/main/astobj2_container.c</span><br><span>index 9bea58f..88810dc 100644</span><br><span>--- a/main/astobj2_container.c</span><br><span>+++ b/main/astobj2_container.c</span><br><span>@@ -109,6 +109,7 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ flags |= internal_ao2_nolock(self);</span><br><span> if (flags & OBJ_NOLOCK) {</span><br><span> orig_lock = __adjust_lock(self, AO2_LOCK_REQ_WRLOCK, 1);</span><br><span> } else {</span><br><span>@@ -296,6 +297,7 @@</span><br><span> }</span><br><span> </span><br><span> /* avoid modifications to the content */</span><br><span style="color: hsl(120, 100%, 40%);">+ flags |= internal_ao2_nolock(self);</span><br><span> if (flags & OBJ_NOLOCK) {</span><br><span> if (flags & OBJ_UNLINK) {</span><br><span> orig_lock = __adjust_lock(self, AO2_LOCK_REQ_WRLOCK, 1);</span><br><span>@@ -489,6 +491,10 @@</span><br><span> .flags = flags</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (internal_ao2_nolock(c)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ a.flags |= AO2_ITERATOR_DONTLOCK;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_t_ref(c, +1, "Init iterator with container.");</span><br><span> </span><br><span> return a;</span><br><span>diff --git a/main/astobj2_private.h b/main/astobj2_private.h</span><br><span>index ef47ed7..9975112 100644</span><br><span>--- a/main/astobj2_private.h</span><br><span>+++ b/main/astobj2_private.h</span><br><span>@@ -61,6 +61,16 @@</span><br><span> #define is_ao2_object(user_data) \</span><br><span> __is_ao2_object(user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Determine if locking should be skipped.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval OBJ_NOLOCK if the object was allocated with AO2_ALLOC_OPT_LOCK_NOLOCK.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval 0 if the object has a lock.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note This function is not NULL safe and assumes \a user_data points to a valid object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * */</span><br><span style="color: hsl(120, 100%, 40%);">+int internal_ao2_nolock(void *user_data);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> enum ao2_lock_req __adjust_lock(void *user_data, enum ao2_lock_req lock_how, int keep_stronger);</span><br><span> </span><br><span> #endif /* ASTOBJ2_PRIVATE_H_ */</span><br><span>diff --git a/res/res_pjsip/pjsip_cli.c b/res/res_pjsip/pjsip_cli.c</span><br><span>index 4544a17..52b1f76 100644</span><br><span>--- a/res/res_pjsip/pjsip_cli.c</span><br><span>+++ b/res/res_pjsip/pjsip_cli.c</span><br><span>@@ -326,11 +326,9 @@</span><br><span> int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)</span><br><span> {</span><br><span> if (formatter) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_wrlock(formatter_registry);</span><br><span> if (ao2_ref(formatter, -1) == 2) {</span><br><span> ao2_unlink_flags(formatter_registry, formatter, OBJ_NOLOCK);</span><br><span> }</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_unlock(formatter_registry);</span><br><span> }</span><br><span> return 0;</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10376">change 10376</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/10376"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I5518e55739769792a76f766ce25880d7d944f63b </div>
<div style="display:none"> Gerrit-Change-Number: 10376 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>