File: libpreload.c

package info (click to toggle)
eztrace 2.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,012 kB
  • sloc: ansic: 37,703; sh: 1,246; cpp: 1,181; perl: 910; makefile: 738; fortran: 327; f90: 320; python: 124
file content (41 lines) | stat: -rw-r--r-- 852 bytes parent folder | download | duplicates (6)
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
34
35
36
37
38
39
40
41
/* -*- c-file-style: "GNU" -*- */
/*
 * Copyright (C) CNRS, INRIA, Université Bordeaux 1, Télécom SudParis
 * See COPYING in top-level directory.
 *
 *
 * libpreload.c
 *
 *  Created on: 29 Sep. 2011
 *      Author: Damien Martin-Guillerez <damien.martin-guillerez@inria.fr>
 */

#include <dlfcn.h>
#include "hijacks.h"

int (*orig_foo)(int, int);
int (*orig_bar)();

int foo(int a, int b) {
  hijack_foo_intro(a, b);
  int r = orig_foo(a, b);
  hijack_foo_outro(a, b, r);
  return r;
}

int bar() {
  hijack_bar_intro();
  int r = orig_bar();
  hijack_bar_outro(r);
  return r;
}

void __hijack_init(void) __attribute__ ((constructor));
/* Initialize the current library */
void __hijack_init(void) {
  void* handle = dlopen("libalacon.so", RTLD_NOW);
  if (handle) {
    orig_foo = dlsym(handle, "foo");
    orig_bar = dlsym(handle, "bar");
  }
}