Principle and Implementation of C program hot Patching Technology in Linux -- Requirements

Source: Internet
Author: User

In the first half of this year, we were working on a carrier project. The device specification was written by large manufacturers such as, which had requirements for hot Patching. The operator has high requirements on the running time of the device, so it does not need to restart the program to change a small problem. So there is a hot Patching requirement: requires that the program can change the behavior of the program during the running process.

There is not much information about the implementation of hot Patching in Linux, I only find one: http://www.cnblogs.com/WuCountry/archive/2010/02/22/1671537.html

There is a general implementation here for reference, but some problems need to be solved. I will write several articles, record the development process, and make a summary.

First, we need:

1. You must be able to change the behavior of the program while the program is running.

When the program is running, it is loaded into the memory. To change the program behavior, you must change the memory of the process. Here I use the ptrace function.

2. How to dynamically add new program behaviors to the process memory.

The new program is loaded to the memory in the form of a dynamic link library. There are two loading methods: one is to open up a piece of memory in the process, and then load the Dynamic Linked Library into the memory; instead, use the system function dlopen to load the Dynamic Linked Library into the program process.

3. How to replace the behavior of a function with a new behavior.

Use the BFD library to find the function address to be replaced and the new function address, and then change the original function start memory to the new function address of the JMP command.

4. Can I change the static function in this way?

5. How do new functions call other functions in the original process? How to access the original global variables? How do I access static functions and static global variables?

 

These details will be described later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.