File: README.md

package info (click to toggle)
libpulp 0.3.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,976 kB
  • sloc: ansic: 11,792; python: 1,216; sh: 881; makefile: 871; cpp: 582; asm: 387
file content (33 lines) | stat: -rw-r--r-- 1,159 bytes parent folder | download | duplicates (2)
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`.