Currently the hook function arguments aren't available to the probe
macros.  This patch adds it.  The function args are available within
the hook macros only with surrounding parens, so that is how they must
be passed to the probe macros.

The args are usable by probe macros only with some restrictions.
Consider this example probe macro that tries to call a function with
the hook arguments:

#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args) \
    ap_hook_probe_invoke(ud, #name, src, ap_hook_probe_arg1 args)

const void *ap_hook_probe_arg1(const void *arg1, ...);

This fails to even compile with hooks which have no arguments since
variable args only work with functions which have at least one
argument.  It won't compile cleanly with hooks that don't take a
pointer as the first argument.  Additional parameters (such as the
hook name) can't be passed earlier in the parameter list.  Thus, for
something like httpd with a variety of hook signatures and no common
theme, there are a couple of layers of unhappiness in trying to use
the args across the board (i.e., leaving the probe macros defined for
all hooks).  I blame the C preprocessor :)  (I never thought I'd miss
the PL/X macro language.)

Still, there's no need to prevent access since it can be used in some
limited circumstances.

I'll commit unless I hear objections soonish.  If someone is
interested in the issue and has time to try to attack the limitations
(which might mean a different apr_hooks patch), raise an objection ;)
I suspect that no one else cares.
Index: include/apr_hooks.h
===================================================================
--- include/apr_hooks.h (revision 1036647)
+++ include/apr_hooks.h (working copy)
@@ -63,8 +63,10 @@
  * this macro, and will be provided to the other hook probe macros.
  * @param ns The namespace prefix of the hook functions
  * @param name The name of the hook
+ * @param args The argument list to the hook functions, with enclosing
+ * parens.
  */
-#define APR_HOOK_PROBE_ENTRY(ud,ns,name)
+#define APR_HOOK_PROBE_ENTRY(ud,ns,name,args)
 /**
  * User-defined hook probe macro that is invoked after the hook
  * has run.
@@ -73,8 +75,10 @@
  * @param ns The namespace prefix of the hook functions
  * @param name The name of the hook
  * @param rv The return value of the hook, or 0 if the hook is void.
+ * @param args The argument list to the hook functions, with enclosing
+ * parens.
  */
-#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv)
+#define APR_HOOK_PROBE_RETURN(ud,ns,name,rv,args)
 /**
  * User-defined hook probe macro that is invoked before calling a
  * hook function.
@@ -84,8 +88,10 @@
  * @param name The name of the hook
  * @param src The value of apr_hook_debug_current at the time the function
  * was hooked (usually the source file implementing the hook function).
+ * @param args The argument list to the hook functions, with enclosing
+ * parens.
  */
-#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src)
+#define APR_HOOK_PROBE_INVOKE(ud,ns,name,src,args)
 /**
  * User-defined hook probe macro that is invoked after calling a
  * hook function.
@@ -96,8 +102,10 @@
  * @param src The value of apr_hook_debug_current at the time the function
  * was hooked (usually the source file implementing the hook function).
  * @param rv The return value of the hook function, or 0 if the hook is void.
+ * @param args The argument list to the hook functions, with enclosing
+ * parens.
  */
-#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv)
+#define APR_HOOK_PROBE_COMPLETE(ud,ns,name,src,rv,args)
 #endif
 
 /** @} */
@@ -176,20 +184,20 @@
     int n; \
     APR_HOOK_INT_DCL_UD; \
 \
-    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, 
args_use); \
            pHook[n].pFunc args_use; \
-            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 0); 
\
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 0, 
args_use); \
             } \
         } \
 \
-    APR_HOOK_PROBE_RETURN(ud, ns, name, 0); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, 0, args_use); \
 \
     }
 
@@ -220,23 +228,23 @@
     ret rv = ok; \
     APR_HOOK_INT_DCL_UD; \
 \
-    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, 
args_use); \
             rv=pHook[n].pFunc args_use; \
-            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 
rv); \
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, 
args_use); \
             if(rv != ok && rv != decline) \
                 break; \
             rv = ok; \
             } \
         } \
 \
-    APR_HOOK_PROBE_RETURN(ud, ns, name, rv); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \
 \
     return rv; \
     }
@@ -265,23 +273,23 @@
     ret rv = decline; \
     APR_HOOK_INT_DCL_UD; \
 \
-    APR_HOOK_PROBE_ENTRY(ud, ns, name); \
+    APR_HOOK_PROBE_ENTRY(ud, ns, name, args_use); \
 \
     if(_hooks.link_##name) \
         { \
         pHook=(ns##_LINK_##name##_t *)_hooks.link_##name->elts; \
         for(n=0 ; n < _hooks.link_##name->nelts ; ++n) \
             { \
-            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName); \
+            APR_HOOK_PROBE_INVOKE(ud, ns, name, (char *)pHook[n].szName, 
args_use); \
             rv=pHook[n].pFunc args_use; \
-            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, 
rv); \
+            APR_HOOK_PROBE_COMPLETE(ud, ns, name, (char *)pHook[n].szName, rv, 
args_use); \
 \
             if(rv != decline) \
                 break; \
             } \
         } \
 \
-    APR_HOOK_PROBE_RETURN(ud, ns, name, rv); \
+    APR_HOOK_PROBE_RETURN(ud, ns, name, rv, args_use); \
 \
     return rv; \
     }

Reply via email to