DITOOLS: Application-level Support for Dynamic
Extension and Flexible Composition
Albert Serra, Nacho Navarro, Toni Cortes
Program Adaptation p.1/22
Motivation
It would be nice to:
Easily re-use/change programs (Paradyn/Dyninst
is not easy!)....
Program Adaptation p.2/22
Motivation
It would be nice to:
Easily re-use/change programs (Paradyn/Dyninst
is not easy!)....
...without necessarily having the source code...
Program Adaptation p.2/22
Motivation
It would be nice to:
Easily re-use/change programs (Paradyn/Dyninst
is not easy!)....
...without necessarily having the source code...
...in user space.
Program Adaptation p.2/22
Examples
Re-routing remote file reads to the network.
int fs_write(int fd, char* b, int s) {
if (remote_fd(fd) ) {
a = build_remote_request(b,s);
r = send_request(server, WRITE, a);
} else {
r = base_fs_write(fd, b, s);
}
return r;
}
also,
(program, write) -> (mymodule, fs_write
Program Adaptation p.3/22
Interesting example
Replace
check_registration_code()
with
{ return true; }
!!!
Program Adaptation p.4/22
Execution Stages
EXECUTION STAGES INPUTS EXECUTION STAGES
(EXTENDED)
MAIN EXECUTABLE
LOADING LOADING
NEEDED MODULES
REFERENCE REFERENCE
RESOLUTION RESOLUTION
CONFIGURATION
EXECUTION EXTENSION
EXTENSIONS
TERMINATION BINDINGS BINDING
EXECUTION
TERMINATION
Static data CLEANUP
Dynamic data
Program Adaptation p.5/22
The DI TOOLS approach
Object code format is mostly the same.
Shared libraries/dynamic linking is common.
Extend loader and linker.
Relink everything at will - every possible
combination.
Program Adaptation p.6/22
Interposition
original definition
control flow
reference
A) DEFAULT BINDING
new definition original definition
B) OVERRIDING
new definition original definition
C) INTERPOSITION
SOURCE MODULE TARGET MODULE
Program Adaptation p.7/22
Extension Options
Binding
Needed code
WRAPPER MODE CALLBACK MODE
Extension code
reference definition reference definition
WRAPPER DISPATCHER
SERVICE INTERFACE
SERVICE INTERFACE
CALLBACK INTERFACE(S)
CALLBACK HANDLERS
Program Adaptation p.8/22
Implementation Characteristics
Interposition can be done both statically and
dynamically.
Modules are allowed to initialize, and cleanup.
Some checks to avoid errors.
The DITOOLS framework is inherited to forked
processes.
Program Adaptation p.9/22
Interposition examples
(program, read) -> (mymodule, myread)
Can also be done from within an (already loaded)
module:
...
di_rebind("program", "read",
"mymodule", "myread");
...
Interpositions done statically, can be re-bound during
run-time.
Program Adaptation p.10/22
Limitations(!)
Can handle only calls that are resolved during
dynamic linking.
Simple and easy but limited.
Dynamic rebinding is not safe.
Program Adaptation p.11/22
Performance
Of course, it slows down everything.
Efficiency is not the main goal.
Program Adaptation p.12/22
Conclusions
Dynamically change bindings between
dynamically linked modules.
No OS support needed.
Good for monitoring, trace collection purposes.
... a good hack.
Program Adaptation p.13/22
Type-Safe Delegation for Run-Time Component
Adaptation
Gunter Kniesel
Program Adaptation p.14/22
Motivation
OO programming eases code reuse with class
inheritance.
Component-oriented programming increases
reuse even more.
Usually, components cannot be reused as-is.
Sometimes, adaptation is not possible at the
source level.
Dynamic adaptation might be necessary/wanted.
Program Adaptation p.15/22
Adaptation techniques/problems
The writer of the original component needs to have
foreseen adaptation.
Time of adaptation. Dynamical is difficult.
Adapt the class or the objects?
Code modification - what if there is no source code
available?
Program Adaptation p.16/22
Self-problem
When replacing an object for a wrapper object, all
calls to the original must go to the wrapper.
Problem: even calls originating from the original.
Program Adaptation p.17/22
Self-Problem - Example
public class DM {
// ... private data, constructor ...
int amount() { return ... }
void foo() { ... [Link]() ... }
}
Program Adaptation p.18/22
Example (cont)
public class DMtoEURO {
// the wrapped component:
DM parent;
// constructor:
DMtoEURO(DM p) { parent = p }
//redefined method:
int amount() { return [Link]()
// forwarding method:
void foo() { [Link]() }
}
Program Adaptation p.19/22
Example (cont)
public class DMtoEURO: public DM {
// the wrapped component:
//DM parent;
// constructor:
DMtoEURO(DM p) { parent = p }
//redefined method:
int amount() { return [Link]()
// forwarding method:
void foo() { [Link]() }
}
Program Adaptation p.20/22
Delegation
Orthogonal to class inheritance.
Can be thought of as object-inheritance.
Can be changed dynamically.
Drawback: Safety.
Program Adaptation p.21/22
The End
Thank you for your time
Program Adaptation p.22/22