Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (55 sloc) 2.695 kB
d950e7b @bkrpub patched license headers
authored
1 /*
2 This file is part of EngineRoom, Copyright (c) 2007-2010 Bjoern Kriews, Hamburg - All rights reserved.
3
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6
7 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8
9 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
10 in the documentation and/or other materials provided with the distribution.
11
12 Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this
13 software without specific prior written permission.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
16 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
17 SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
20 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 */
22
0d3b810 @bkrpub initial commit after restructuring
authored
23 #include <stdio.h>
24
25 void getoff(int *p1, int *p2)
26 {
27 void *frame = __builtin_frame_address(0);
28 void *vp1 = &p1;
29 void *vp2 = &p2;
30
31 printf("diff: %d, %d\n", vp1-frame, vp2-frame);
32
33 *p1 = ( vp1 > frame ? (int)(vp1-frame) : -(int)(frame-vp1) ) / sizeof(void*);
34 *p2 = ( vp2 > frame ? (int)(vp2-frame) : -(int)(frame-vp2) ) / sizeof(void*);
35
36 printf("frame: %p &p1: %p &p2: %p sovp: %d p1: %d p2: %d\n",
37 frame, vp1, vp2, sizeof(void*), *p1, *p2);
38
39
40 }
41
42 void func(void *a, char *b)
43 {
44 int f1, f2;
45 getoff(&f1, &f2);
46
47 void **frame = __builtin_frame_address(0);
48
49 printf("frame: %p &a: %p &b: %p a: %p b: %p frame[%d]: %p frame[%d]: %p\n",
50 frame, &a, &b, a, b, f1, frame[f1], f2, frame[f2]);
51
52 }
53
54 struct objc_args { void *self_arg; void *cmd_arg; };
55
56 void *retself(void *self, void *_cmd)
57 {
58 printf("retself: %p %p\n", self, _cmd);
59 return self;
60 }
61
62 void *getself(void *args)
63 {
64 __builtin_return( __builtin_apply((void (*)()) retself, args, 2 * sizeof(void*) ) );
65 }
66
67 void testself(void *self, char *_cmd)
68 {
69 void *myself = getself( __builtin_apply_args() );
70
71 printf("myself: %p\n", myself);
72 }
73
74 main()
75 {
76 testself((void*)0x23, (void*)0x42);
77
78 }
Something went wrong with that request. Please try again.