# US 9,436,457 B2 · Generating and applying patches to computer program code concurrently with its execution

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 9,436,457 B2
- Document ID: US9436457B2
- Status: Granted
- Kind: B2
- Application number: 14/456,336
- Filed: 2014-08-11
- Published: 2014-11-27
- Granted: 2016-09-06
- Earliest claimed: 2008-01-23
- Assignees: International Business Machines Corporation
- Applicants: International Business Machines Corporation
- Inventors: Angel Nunez Mencias; Albert Schirmer; Christine Axnix; Stefan Usenbinz
- Web page: https://patentgrep.com/patent/US9436457B2

## CPC

- G06F 8/656: while running
- G06F 9/44557: {Code layout in executable memory}
- G06F 9/50: Allocation of resources, e.g. of the central processing unit [CPU]
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

A method and data processing system are disclosed for concurrently loading a plurality of new modules while code of a plurality of modules of an original (i.e., currently running) computer program is loaded and executed on a computer system. The method may include allocating a module thread local storage (TLS) block for each thread within an initial computer program, wherein the allocated module TLS blocks are large enough to hold all module thread variables that are loaded or to be loaded. The method further may include providing constant offsets between module TLS block pointers corresponding to the module TLS blocks and the module thread variables for all of the threads. The disclosed method may be used to add modules to the original computer program and/or to apply a concurrent patch by replacing one or more of the plurality of original computer program modules.

## Claims

### Claim 1

A method for concurrently loading a plurality of new modules while code of a plurality of modules of an original computer program is loaded and executed on a computer system, the method comprising:
allocating a module thread local storage (TLS) block for each thread within an initial computer program, wherein the module TLS blocks are large enough to hold all module thread variables that are loaded or to be loaded, and wherein the module TLS blocks are allocated consecutively, with the same layout for each thread;
providing constant offsets between module TLS block pointers corresponding to the module TLS blocks and the module thread variables for all of the threads;
reserving spare areas between the module TLS blocks for adding new module thread variables;
copying a TLS data segment from one module TLS block among the module TLS blocks to other module TLS blocks among the module TLS blocks; and
arranging at an end of the module TLS blocks a thread data template section for resetting threads or creating new threads.

### Claim 2 (depends on 1)

The method according to claim 1, further comprising loading the plurality of new modules by allocating memory dynamically.

### Claim 3 (depends on 2)

The method according to claim 2, further comprising relocating segments of the plurality of new modules via a concurrent loader before executing new code reflecting the plurality of new modules.

### Claim 4 (depends on 1)

The method according to claim 1, further comprising copying TLS data segment content to at least a portion of the module TLS blocks.

### Claim 5 (depends on 1)

The method according to claim 1, further comprising loading the plurality of new modules by replacing one or more of the plurality of modules of the original computer program with the plurality of new modules, wherein the loading step comprises:
determining which of the plurality of modules of the original computer program are to be replaced by the plurality of new modules;
initiating a dependency resolution process with respect to the modules to be replaced;
for each of the modules to be replaced, copying sections of each of the plurality of new modules to reserved memory sections of the computer system;
for each of the modules to be replaced, relocating all symbols and adding new static data variables and their initialization routines;
upon determining that there is no additional module to be replaced, bringing the computer system into a state where temporary data are irrelevant, wherein the temporary data include variables stored in a stack that are allocated as kernel thread variables;
relocating a global data section;
executing all initialization routines in the context of the code of the plurality of modules of the original computer program;
switching from the code of the plurality of modules of the original computer program to new code reflecting the plurality of new modules; and
executing all initialization routines in the context of the new code.

### Claim 6 (depends on 5)

The method according to claim 5, further comprising comparing sizes of variables referenced in a symbol table of the original computer program with sizes of variables referenced in a new symbol table of each of the plurality of new modules.

### Claim 7 (depends on 6)

The method according to claim 6, further comprising determining whether a transition routine for enlarging variable size or a transition routine for decreasing variable size is provided.

### Claim 8 (depends on 6)

The method according to claim 6, further comprising allocating new memory space for variables increased in size or for variables decreased in size.

### Claim 9 (depends on 7)

The method according to claim 7, further comprising calling a provided transition routine for enlarging variable size once in the context of the new code.

### Claim 10 (depends on 7)

The method according to claim 7, further comprising calling a provided transition routine for decreasing variable size once in the context of the code of the plurality of modules of the original computer program.

### Claim 11 (depends on 5)

The method according to claim 5, further comprising providing a process for safe deletion of function pointer references for functions that are removed as a result of the loading step.

### Claim 12 (depends on 5)

The method according to claim 5, wherein the dependency resolution process comprises:
determining dependent modules that depend on a specific module to be replaced;
marking all of the dependent modules as found;
loading the dependent modules in alternate code areas;
adapting the dependent modules to the specific module; and
relocating segments of the dependent modules.

### Claim 13

A computer program product for concurrently loading a plurality of new modules while code of a plurality of modules of an original computer program is loaded and executed on a computer system, the computer program product comprising a non-transitory computer-readable medium having computer-readable program code instructions stored therein comprising:
instructions for allocating a module thread local storage (TLS) block for each thread within an initial computer program, wherein the module TLS blocks are large enough to hold all module thread variables that are loaded or to be loaded, and wherein the module TLS blocks are allocated consecutively, with the same layout for each thread;
instructions for providing constant offsets between module TLS block pointers corresponding to the module TLS blocks and the module thread variables for all of the threads;
instructions for reserving spare areas between the module TLS blocks for adding new module thread variables;
instructions for copying a TLS data segment from one module TLS block among the module TLS blocks to other module TLS blocks among the module TLS blocks; and
instructions for arranging at an end of the module TLS blocks a thread data template section for resetting threads or creating new threads.

### Claim 14 (depends on 13)

The computer program product according to claim 13, wherein the computer-readable program code instructions further comprise instructions for loading the plurality of new modules by replacing one or more of the plurality of modules of the original computer program with the plurality of new modules, wherein the instructions for loading comprise:
instructions for determining which of the plurality of modules of the original computer program are to be replaced by the plurality of new modules;
instructions for initiating a dependency resolution process with respect to the modules to be replaced;
for each of the modules to be replaced, instructions for copying sections of each of the plurality of new modules to reserved memory sections of the computer system;
for each of the modules to be replaced, instructions for relocating all symbols and adding new static data variables and their initialization routines;
instructions for, upon determining that there is no additional module to be replaced, bringing the computer system into a state where temporary data are irrelevant, wherein the temporary data include variables stored in a stack that are allocated as kernel thread variables;
instructions for relocating a global data section;
instructions for executing all initialization routines in the context of the code of the plurality of modules of the original computer program;
instructions for switching from the code of the plurality of modules of the original computer program to new code reflecting the plurality of new modules; and
instructions for executing all initialization routines in the context of the new code.

### Claim 15 (depends on 13)

The computer program product according to claim 13, wherein the computer-readable program code instructions further comprise instructions for loading the plurality of new modules by allocating memory dynamically.

### Claim 16 (depends on 15)

The computer program product according to claim 15, wherein the computer-readable program code instructions further comprise instructions for relocating segments of the plurality of new modules via a concurrent loader before executing new code reflecting the plurality of new modules.

### Claim 17

A data processing system comprising:
a processor; and
a memory storing a program, which, when executed on the processor, performs an operation of concurrently loading a plurality of new modules while code of a plurality of modules of an original computer program is loaded and executed on a computer system, the operation comprising:
allocating a module thread local storage (TLS) block for each thread within an initial computer program, wherein the module TLS blocks are large enough to hold all module thread variables that are loaded or to be loaded, and wherein the module TLS blocks are allocated consecutively, with the same layout for each thread;
providing constant offsets between module TLS block pointers corresponding to the module TLS blocks and the module thread variables for all of the threads;
reserving spare areas between the module TLS blocks for adding new module thread variables;
copying a TLS data segment from one module TLS block among the module TLS blocks to other module TLS blocks among the module TLS blocks; and
arranging at an end of the module TLS blocks a thread data template section for resetting threads or creating new threads.

### Claim 18 (depends on 17)

The data processing system according to claim 17, wherein the operation further comprises loading the plurality of new modules by replacing one or more of the plurality of modules of the original computer program with the plurality of new modules, wherein the loading step comprises:
determining which of the plurality of modules of the original computer program are to be replaced by the plurality of new modules;
initiating a dependency resolution process with respect to the modules to be replaced;
for each of the modules to be replaced, copying sections of each of the plurality of new modules to reserved memory sections of the computer system;
for each of the modules to be replaced, relocating all symbols and adding new static data variables and their initialization routines;
upon determining that there is no additional module to be replaced, bringing the computer system into a state where temporary data are irrelevant, wherein the temporary data include variables stored in a stack that are allocated as kernel thread variables;
relocating a global data section;
executing all initialization routines in the context of the code of the plurality of modules of the original computer program;
switching from the code of the plurality of modules of the original computer program to new code reflecting the plurality of new modules; and
executing all initialization routines in the context of the new code.

### Claim 19 (depends on 17)

The data processing system according to claim 17, wherein the operation further comprises loading the plurality of new modules by allocating memory dynamically.

### Claim 20 (depends on 19)

The data processing system according to claim 19, wherein the operation further comprises relocating segments of the plurality of new modules via a concurrent loader before executing new code reflecting the plurality of new modules.
