~ubuntu-branches/ubuntu/karmic/valgrind/karmic

« back to all changes in this revision

Viewing changes to exp-ptrcheck/tests/syscall.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-03-05 18:27:01 UTC
  • mfrom: (1.1.9 upstream) (2.1.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090305182701-yag747u3f33y9g8y
Tags: 1:3.4.1-1ubuntu1
* Merge with Debian; remaining changes:
  - Add 91_build_with_fno_stack_protector.dpatch.
  - Add lpia to Architecture.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
#include <stdlib.h>
 
3
#include <unistd.h>
 
4
#include <sys/types.h>
 
5
#include <sys/stat.h>
 
6
#include <fcntl.h>
 
7
#include <sys/time.h>
 
8
 
 
9
// For some reason, the stack frame below __GI_write is disappearing.
 
10
// Therefore, if I don't want the write errors to be merged, I have to
 
11
// ensure they have a different stack trace.  I do this by using this
 
12
// function.  Weird.
 
13
__attribute__((noinline))
 
14
void mywrite(char* buf, int len)
 
15
{
 
16
   write(-1, buf, len);
 
17
}
 
18
 
 
19
__attribute__((noinline))
 
20
void mygetitimer(long arg1, struct itimerval* itval)
 
21
{
 
22
   getitimer(arg1, itval);
 
23
}
 
24
 
 
25
__attribute__((noinline))
 
26
void myopen(char* name, long flags)
 
27
{
 
28
   open(name, flags);
 
29
}
 
30
 
 
31
int main(void)
 
32
{
 
33
   char *buf = malloc(sizeof(char)*6), *buf2 = malloc(sizeof(char)*6);
 
34
   struct itimerval* itval = malloc(sizeof(struct itimerval) - 1);
 
35
   int diff = buf2 - buf;
 
36
   buf[0] = 'h';
 
37
   buf[1] = 'e';
 
38
   buf[2] = 'l';
 
39
   buf[3] = 'l';
 
40
   buf[4] = 'o';
 
41
   buf[5] = 'x';
 
42
 
 
43
   // error (read)  (will fail due to -1, as we want -- don't want any
 
44
   // unpredictable output to foul up the test)
 
45
   mywrite(buf+3, 5);      // error (read)
 
46
   mywrite(buf-1, 5);      // error (read)
 
47
   mywrite(buf+1, diff);   // error (read)
 
48
   myopen(buf+3, 0x0);     // error (read_asciiz)
 
49
 
 
50
   mygetitimer(0, itval);    // error (write)
 
51
 
 
52
   //----
 
53
   free(buf);
 
54
   mywrite(buf,   5);      // error
 
55
   mywrite(buf+3, 5);      // error
 
56
   mywrite(buf+1, diff);   // error (read)
 
57
 
 
58
   return 0;
 
59
}