Patent ID: 8499289

Claim:
A method for realizing kernel online patching of an object file, comprising: loading a pre-generated patch file in an operating system, wherein the patch file comprises a patch function corresponding to a primitive function of a system kernel and a first corresponding relation between a source address of the primitive function and a destination address of the patch function, wherein the patch file is for patching the object file; setting a first breakpoint at an execution start position of the primitive function; and when a system thread executes the primitive function and a breakpoint exception occurs during the thread execution process due to the first breakpoint, modifying a returning execution address of the first breakpoint into the destination address of the patch function corresponding to the primitive function according to the first corresponding relation and removing the first breakpoint; wherein: the object file comprises symbolic information and relocation information of the patch function of a patch source code; the patch file further comprises shift relocation information corresponding to the symbolic information and the relocation information, a predetermined default patch loading address, and information about a size of a space required by the pre-generated patch file during running; and the loading of the pre-generated patch file in the operating system comprising: when a memory capacity of a patch region in the system is smaller than a size of a space required by the patch file during running, allocating a new memory including a new memory address to the patch region for the loading of the patch file; comparing the default patch loading address with the new memory address of the patch region; if the default patch loading address and the new memory address are identical, replicating patch data carried in the patch file to the new memory of the patch region; if the default patch loading address and the new memory address are not identical, relocating a destination address of the patch data carried in the patch file according to the shift relocation information and replicating relocated patch data to the new memory of the patch region; wherein the patch data comprises the patch function corresponding to the primitive function of the system kernel and the first corresponding relation between the source address of the primitive function and the destination address of the patch function.