Browse Prior Art Database

Method and System for Dynamically Patching Hooks in a Source Code

IP.com Disclosure Number: IPCOM000198648D
Publication Date: 2010-Aug-11
Document File: 3 page(s) / 25K

Publishing Venue

The IP.com Prior Art Database

Abstract

A method and system is disclosed for dynamically patching hooks in a source code only when it is required to check for status of global state.

This text was extracted from a PDF file.
This is the abbreviated version, containing approximately 56% of the total text.

Page 1 of 3

Method and System for Dynamically Patching Hooks in a Source Code

A method and system is disclosed for dynamically patching hooks in a source code only when it is required to check for status of global state. This helps in minimizing performance impact that is caused to the source code due to the presence of the hooks in the source code even when no check for status of global state is required.

In accordance with the method and system a framework is provided that is built on compiler support. The compiler is configured with a new pragma. The pragma enables a programmer to dynamically patch hooks in a source code. The pragma allows a programmer to identify a patch location in a source code where a subsequent patch point is to be enabled or installed. The patch location has a label that allows look-up in the program's symbol table. Based on this, a hook is dynamically patched when needed, that is when the global state is set, for example when tracing is to be enabled or run-time error checking is to be enabled. The patch causes a branch to some trampoline code within the same c-sect but outside the source code. When the patch point is not enabled, the effect on the source code execution is minimal.

The following pseudo code illustrates an exemplary implementation of the method and system. In the pseudo code, the new pragma is called "patch

_

                                        point" and the programmer wishes to add a patch point inside a function "foo". The compiler provides support to jump to an unnamed trampoline function that subsequently invokes the actual tracing call (call

_tracing

_event3()) or the run time error checking call.

/

* Tracing header file */

/* Macro that hides the patching pragma and allows one to call a tracing hook

that takes 3 trace parameters plus a event

* word. This is just for simplification. Note that one can generate separate

macros for tracing, for runtime error checking

* for error injection to make this easier to use for the programmer

*

*

Alternativel

y, the pragma can be applied directly in the user code also.

*/

1

Page 2 of 3

#define DYN

_TRACE

_POINT2(

_

label, _t1, _t2, _t3, _t4

_

Pragma (

_

patch

_

poin

t

_label call

_tracing

_

event3(

_

)t1, _t2, _t3

)

no

_side

_

effects")

* tracing function that accepts 3 trace words */

/void call

_tracing

_event3(long even

_

word, long data1, long data2, long data3

);

/

* user program */

char *gvar

* G...