| 1 |
/* external var test case - library helper |
| 2 |
* Copyright (C) 2009, Red Hat Inc. |
| 3 |
* |
| 4 |
* This file is part of systemtap, and is free software. You can |
| 5 |
* redistribute it and/or modify it under the terms of the GNU General |
| 6 |
* Public License (GPL); either version 2, or (at your option) any |
| 7 |
* later version. |
| 8 |
* |
| 9 |
* Tests that an external exported variable can be accessed. |
| 10 |
*/ |
| 11 |
|
| 12 |
#include <stdlib.h> |
| 13 |
|
| 14 |
struct libstruct |
| 15 |
{ |
| 16 |
int i; |
| 17 |
long l; |
| 18 |
char c; |
| 19 |
struct libstruct *s1; |
| 20 |
struct libstruct *s2; |
| 21 |
}; |
| 22 |
|
| 23 |
int libvar; |
| 24 |
struct libstruct *lib_s; |
| 25 |
|
| 26 |
static int stat_libvar; |
| 27 |
static struct libstruct *stat_lib_s; |
| 28 |
|
| 29 |
static void |
| 30 |
lib_call () |
| 31 |
{ |
| 32 |
asm(""); // dummy method, just to probe and extract. |
| 33 |
} |
| 34 |
|
| 35 |
void |
| 36 |
lib_main () |
| 37 |
{ |
| 38 |
libvar = 42; |
| 39 |
stat_libvar = libvar; |
| 40 |
asm ("nop" : "=r"(stat_libvar) : "r"(stat_libvar)); |
| 41 |
lib_s = (struct libstruct *) malloc(sizeof(struct libstruct)); |
| 42 |
lib_s->i = 1; |
| 43 |
lib_s->l = 2; |
| 44 |
lib_s->c = 3; |
| 45 |
lib_s->s1 = lib_s; |
| 46 |
lib_s->s2 = NULL; |
| 47 |
stat_lib_s = lib_s; |
| 48 |
asm ("nop" : "=r"(stat_lib_s) : "r"(stat_lib_s)); |
| 49 |
lib_call (); |
| 50 |
} |