File: README.md

package info (click to toggle)
libpulp 0.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,964 kB
  • sloc: ansic: 11,257; python: 1,110; sh: 881; makefile: 824; cpp: 582; asm: 124
file content (33 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Example: Calling private non-inlined non-externalized function available in original binary
## About

This example illustrates how we can access global variables -- private or
public -- as it may be necessary to create a livepatch. One case where such cases
may happen is to access global locks, as shown in this example.

In `test.cpp`, there is an accumulator that is protected by a mutex lock. A
livepatch that touches this critical section will have to lock it before doing
any modifications to the `sum` variable.

## The example

In this example we have two files: `test.cpp` and `a_livepatch1.cpp`. The
first file contains code to accumulate into a variable using multiple
threads. The second file contains a patch that set that variable to 0.

## Live Patching

In order to create this livepatch, we have to setup references to the global
variables that needs to be modified. On `a_livepatch.cpp`:
```
volatile long *sum_ptr = NULL;
pthread_mutex_t *sum_lock_ptr = NULL;
```
Then on .dsc:
```
#sum:sum_ptr
#sum_lock:sum_lock_ptr
```

with this, the pointers `sum_ptr` and `sum_lock_ptr` will be initialized with
the address of `sum` and `sum_lock`.