On Sat, Jul 15, 2017 at 02:42:42AM +0300, Dmitry V. Levin wrote:
> On Sat, Jul 15, 2017 at 01:56:43AM +0300, Victor Krapivensky wrote:
> > On Thu, Jul 13, 2017 at 09:24:03PM +0200, Eugene Syromiatnikov wrote:
> > > On Tue, Jul 11, 2017 at 02:48:48PM +0300, Victor Krapivensky wrote:
> [...]
> > > > +#define EXPOSE_FUNC(rettype, ptr, name, ...)                           
> > > >         \
> > > > +       do {                                                            
> > > >         \
> > > > +               rettype (*fptr_)(__VA_ARGS__) = ptr;                    
> > > >         \
> > > > +               lua_pushvalue(L, -1); /* L: table cast cast */          
> > > >         \
> > > > +               lua_pushstring(L, #rettype " (*)(" #__VA_ARGS__ ")");   
> > > >         \
> > > > +               /* L: table cast cast str */                            
> > > >         \
> > > > +               lua_pushlightuserdata(L, * (void **) (&fptr_));         
> > > >         \
> > > > +               /* L: table cast cast str ptr */                        
> > > >         \
> > > > +               assert_lua(lua_pcall(L, 2, 1, 0)); /* L: table cast 
> > > > value */    \
> > > > +               lua_setfield(L, -3, name); /* L: table cast */          
> > > >         \
> > > > +       } while (0)
> > > > +
> > > > +       EXPOSE_FUNC(bool, func_monitor, "monitor",
> > > > +               unsigned int, unsigned int, bool, bool);
> > > > +       EXPOSE_FUNC(struct tcb *, func_next_sc, "next_sc",
> > > > +               void);
> > > > +       EXPOSE_FUNC(bool, func_inject_signo, "inject_signo",
> > > > +               int);
> > > > +       EXPOSE_FUNC(bool, func_inject_retval, "inject_retval",
> > > > +               int);
> > > > +       EXPOSE_FUNC(int, func_umove, "umove",
> > > > +               kernel_ulong_t, size_t, void *);
> > > > +       EXPOSE_FUNC(int, func_umove_str, "umove_str",
> > > > +               kernel_ulong_t, size_t, char *);
> > > > +       EXPOSE_FUNC(bool, func_path_match_arr, "path_match_arr",
> > > > +               const char **, size_t);
> > > Taking into the account naming pattern, the duplication in ptr/name
> > > values can be avoided.
> > > 
> > Could you please elaborate on this one?
> 
> #define EXPOSE_FUNC(rettype, name, ...)                                       
>         \
>       do {                                                                    
> \
>               rettype (*fptr_)(__VA_ARGS__) = func_ ## name;                  
> \
>               lua_pushvalue(L, -1); /* L: table cast cast */                  
> \
>               lua_pushstring(L, #rettype " (*)(" #__VA_ARGS__ ")");           
> \
>               /* L: table cast cast str */                                    
> \
>               lua_pushlightuserdata(L, * (void **) (&fptr_));                 
> \
>               /* L: table cast cast str ptr */                                
> \
>               assert_lua(lua_pcall(L, 2, 1, 0)); /* L: table cast value */    
> \
>               lua_setfield(L, -3, #name); /* L: table cast */                 
> \
>       } while (0)
> 
>       EXPOSE_FUNC(bool, monitor, unsigned int, unsigned int, bool, bool);
>       EXPOSE_FUNC(struct tcb *, next_sc, void);
>       EXPOSE_FUNC(bool, inject_signo, int);
>       EXPOSE_FUNC(bool, inject_retval, int);
>       EXPOSE_FUNC(int, umove, kernel_ulong_t, size_t, void *);
>       EXPOSE_FUNC(int, umove_str, kernel_ulong_t, size_t, char *);
>       EXPOSE_FUNC(bool, path_match_arr, const char **, size_t);
And what if want to expose not a func_ wrapper, but an actual function?

> 
> btw, have you considered use of typeof here?
What for?  We need rettype/__VA_ARGS__ for generating a type string for
FFI anyway, and the fptr_ thing would give a warning if these types
mismatch.
The same goes for EXPOSE and its type argument.

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to