|
Download The Tcl Redirection Library
ddl-tclredir-3-Aug-2005.tar.gz (347 KB. Aug 3, 2005)
Documentation of the Tcl redirection library
The Tcl redirection library invokes "redirect_lookup", "redirect_definition" and "redirect_offset" methods defined in the Tcl program upon
every dynamic link resolution activity. "redirect_init" is also invoked at the
beginning of the execution of the program. These methods are invoked in a manner similar
to callback invocation. These methods can further invoke a large set of Tcl redirection
commands as given below. These commands are Tcl equivalent of the Redirection Library
API and the LinkDef library API.
Documentation of the Tcl extension commands for the Tcl redirection library
Name
of the Tcl Command
|
Action |
#
of Parameters
|
Parameter
1
|
Parameter
2
|
Parameter
3
|
Parameter
4
|
| Redirect2sym |
Redirects a symbol to another
symbol
|
4
|
link function name |
caller library name |
definiiton function name |
definition library name |
| Redirect2table |
Redirects a symbol to a table
|
4
|
link function name |
caller library name |
table definiiton function name |
table definition library name |
| Redirect_ignore_next |
Ignores redirection of the
specified function the next time
|
2
|
link function name |
caller library name |
|
|
| LinkDef_find_link |
Searches for a link entry in the
links' hash table
|
2
|
link function name |
caller library name |
|
|
| LinkDef_find_def |
Searches for a definition entry
in the definitions' hash table
|
2
|
definition function name
|
definition library name
|
|
|
| LinkDef_add_link |
Adds a link in the links' hash
table
|
2
|
link function name |
caller library name |
|
|
| LinkDef_add_def |
Adds a definition in the defs's
hash table
|
2
|
definition function name |
definition library name |
|
|
| LinkDef_add_table |
Adds a table definition in the
definitions' hash table
|
3
|
table name
|
table function name
|
table library name
|
|
| LinkDef_find_table |
Searches for a table definition
|
3
|
table name
|
table function name |
table library name |
|
| LinkDef_backlink_itr_begin |
Returns an iterator to the
beginning of the list of back links.
|
1
|
A ListElement pointing to a
definition
|
|
|
|
LinkDef_backlink_itr_at
|
Returns the ListElement pointed
to by the back link iterator
|
1
|
An iterator over the list of
back links
|
|
|
|
LinkDef_backlink_itr_next
|
Advances the back link itarator
|
1
|
An iterator over the list of
back links |
|
|
|
LinkDef_get_links_itr
|
Returns an iterator over the
links' hash table
|
0
|
|
|
|
|
LinkDef_get_defs_itr
|
Returns an itarator over the
definitions' hash table
|
0
|
|
|
|
|
LinkDef_free_itr
|
Frees the memory allocated to
the links' or definitions' hash table iterator
|
1
|
An iterator over the list of
back links |
|
|
|
LinkDef_itr_at
|
Returns the ListElement pointed
to by the links' iterator.
|
1
|
An iterator over the links' hash
table.
|
|
|
|
| LinkDef_itr_next |
Advances a links' iterator
or a definiitons' iterator
|
1
|
An iterator over the links' hash
table or the definitions' hash table. |
|
|
|
>>> To be documented <<<
int LinkDef_drop_linkfromdef(const char *link_funcname, const char *link_libname, const char *def_funcname, const char *def_libname); ListElement *LinkDef_getlink(const char *link_funcname, const char *link_libname); ListElement *LinkDef_getdef(const char *def_funcname, const char *def_libname); ListElement *LinkDef_getdefoflink(ListElement *link); int LinkDef_insert_linktodef(ListElement *link, ListElement *def); char *LinkDef_setlinkfname(ListElement *link, const char *fname); char *LinkDef_setlinklibname(ListElement *link, const char *libname); int LinkDef_setGOTaddr(ListElement *link, int GOTaddr); int LinkDef_setoffset(ListElement *link, int offset); char *LinkDef_setdefname(ListElement *def, const char *fname); char *LinkDef_setdeflibname(ListElement *def, const char *libname); int LinkDef_setfuncaddr(ListElement *def, int funcaddr); char *LinkDef_settablename(ListElement *def, const char *tablename); char *LinkDef_getlinkfname(ListElement *link); char *LinkDef_getlinklibname(ListElement *link); int LinkDef_getGOTaddr(ListElement *link); int LinkDef_getoffset(ListElement *link); char *LinkDef_getdefname(ListElement *def); char *LinkDef_getdeflibname(ListElement *def); int LinkDef_getfuncaddress(ListElement *def); char *LinkDef_gettablename(ListElement *def); int LinkDef_erase_link(const char *link_funcname, const char *link_libname); int LinkDef_erase_def(const char *def_funcname, const char *def_libname);
The Tcl redirection library also provides commands to iterate over all the links and definitions stored by the redirection library during the execution of the program. An example of how to use these functions is given in the following Tcl script.
A
sample Tcl script using the Tcl redirection commands
|
set Linkdef_hook_tid 0
set i 0
catch {destroy .a} {} ;# this destroys the old button
proc evt {d} { global i; incr i $d; puts "Event $i"}
pack [button .a -text "Event Increment" -command "evt 1"]
pack [button .b -text "Event Decrement" -command "evt -1"]
proc myputchar_begin {c} {
puts " "
puts "Inside Tcl procedure myputchar: $c"
}
set recurse_level 0
proc mydllmain_begin {a b c} {
puts "$::recurse_level dllmain $a $b ($c) ([string index $c 31])"
incr ::recurse_level
}
proc myputchar_end {c} {
puts "putchar ends"
}
#
# to putchar, recursion traverses third argument c (a string) until a
# character equal to b is found at front, then putchars the 31st char
# in c. the parameter a appears to play no role?
#
# To begin the recursion, the value passed in b is the first char in
# the string c, when a is 0? and b is a pointer? (found exception at
# dllmain(0,1073758408) recurses to dllmain(-87 -1) then
# dllmain -1 -87 then on and on down the string c until ?
# and
#
proc mydllmain_end {a b c} {
incr ::recurse_level -1
puts "dllmain_end $::recurse_level"
}
proc wrap_printf_begin {s n} {
puts "before printf ($s,$n)"
}
proc wrap_printf_end {dummy s} {
puts "after printf ($s)"
}
proc wrap_malloc_begin {numbytes} {
puts "BEFORE malloc $numbytes"
}
proc wrap_malloc_end {ptr numbytes} {
puts "after malloc $numbytes -> [format %x $ptr]"
}
proc wrap_free_begin {ptr} {
puts "before free [format %x $ptr]"
}
proc wrap_free_end {dummy ptr} {
puts "after free [format %x $ptr]"
}
proc redirect_init {} {
puts "TCL: redirect_init"
}
proc wrap_strcmp { s1 s2 } {
puts "$s1:$s2"
}
proc redirect_lookup {linkfname linklibname} {
global Linkdef_hook_tid;
puts "TCL: redirect_lookup: $linkfname, $linklibname, $Linkdef_hook_tid"
if { $linkfname == "exit" } {
set links_itr [LinkDef_get_links_itr]
while { $links_itr != 0 } {
set alink [LinkDef_itr_at $links_itr]
set fname [LinkDef_getlinkfname $alink]
set adef [LinkDef_getdefoflink $alink]
set deflibname [LinkDef_getdeflibname $adef]
puts "$fname: $deflibname"
set links_itr [LinkDef_itr_next $links_itr]
}
puts "Traversing backlink"
set mallocdef [LinkDef_getdef _jt_jumptable libstringtable.so]
set backlinks_itr [LinkDef_backlink_itr_begin $mallocdef]
while { $backlinks_itr != 0 } {
set alink [LinkDef_backlink_itr_at $backlinks_itr]
set fname [LinkDef_getlinkfname $alink]
puts $fname
set backlinks_itr [LinkDef_backlink_itr_next $backlinks_itr]
}
LinkDef_free_itr $links_itr
if { $linkfname == "malloc" } {
puts "Detected exit, redirecting"
Redirect2sym $linkfname * wrap_malloc libwrappers3.so
set result [Redirect2table printf main _jt_jumptable libstringtable.so]
puts "Result is: $result"
}
Redirect_ignore_next printf main
set printf_link [Linkdef_getlink printf main]
puts $Linkdef_hook_tid
}
proc redirect_offset {linkfname linklibname} {
puts "TCL: redirect_offset: $linkfname, $linklibname"
}
proc redirect_definition {new_funcname new_libname new_func_address
orig_funcname orig_libname orig_func_GOT_addr} {
puts "TCL: redirect_definition: $new_funcname, $new_libname"
set link [Linkdef_getlink strrchr main]
if { $link != "NULL" } {
puts $link
set gotaddr [Linkdef_getGOTaddr $link]
puts "GOT address = [format %x $gotaddr]"
}
}
proc redirect_symdef {symbol libname address caller_libname} {
puts "TCL: redirect_symdef: $symbol, $libname, [format %x $address], $caller_libname"
}
|
Last modified: August 3, 2005
|