File: pddet.c

package info (click to toggle)
crashme 2.4-3
  • links: PTS
  • area: main
  • in suites: slink
  • size: 116 kB
  • ctags: 78
  • sloc: ansic: 871; makefile: 62; sh: 5
file content (359 lines) | stat: -rw-r--r-- 13,954 bytes parent folder | download | duplicates (4)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/*
 *             COPYRIGHT (c) 1994 BY             *
 *  GEORGE J. CARRETTE, CONCORD, MASSACHUSETTS.  *
 *             ALL RIGHTS RESERVED               *

Permission to use, copy, modify, distribute and sell this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all copies
and that both that copyright notice and this permission notice appear
in supporting documentation, and that the name of the author
not be used in advertising or publicity pertaining to distribution
of the software without specific, written prior permission.

THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

The purpose of this routine is to attempt to detect the use of
procedure descriptors by making a note of how far apart the
system allocates pointers to subroutines of different sizes.
If all the subroutines are the same distance apart then
procedure descriptors are probably in use on this architecture.

This file should be compiled without any compiler optimization
such as inlining that would confuse the test. Although base functions
have been made somewhat complex in order to avoid that in any case.

Now if a linker lays out procedures like this:

[DESCRIPTOR][CODE TEXT...][DESCRIPTOR][CODE TEXT...]

Then this code will be confused into thinking descriptors aren't used.
But usually the hallmark of a descriptor architecture is that descriptors
are in a table located away from the program code text.

The -examine <nbytes> argument lets you see in a crude way what
is contained in the pointer to a procedure data.

19-MAY-1994 GJC@WORLD.STD.COM

*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct v {long n;double *a;};

struct v *vcons(n,x)
     long n;
     double x;
{struct v *p;
 long j;
 p = (struct v *) malloc(sizeof(struct v));
 p->n = n;
 p->a = (double *) malloc(sizeof(double)*n);
 for(j=0;j<n;++j) p->a[j] = x;
 return(p);}

struct v *vprod(x,y)
     struct v *x,*y;
{struct v *z;
 long j;
 z = vcons(x->n);
 for(j=0;j<x->n;++j) z->a[j] = x->a[j] * y->a[j];
 return(z);}

double vsume(x)
     struct v *x;
{double sum = 0.0;
 long j;
 for(j=0;j<x->n;++j) sum += x->a[j];
 return(sum);}

double viprod(x,y)
     struct v *x,*y;
{return(vsume(vprod(x,y)));}

double vnorm(x)
     struct v *x;
{return(viprod(x,x));}

double case10()
{double acc = 0.0;
 acc += vnorm(vcons((long)vsume(vcons(0,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(1,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(2,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(3,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(4,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(5,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(6,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(7,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(8,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(9,1.0)),2.0));
 return(acc);}

double case20()
{double acc = 0.0;
 acc += vnorm(vcons((long)vsume(vcons(0,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(1,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(2,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(3,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(4,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(5,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(6,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(7,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(8,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(9,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(10,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(11,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(12,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(13,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(14,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(15,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(16,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(17,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(18,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(19,1.0)),2.0));
 return(acc);}

double case30()
{double acc = 0.0;
 acc += vnorm(vcons((long)vsume(vcons(0,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(1,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(2,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(3,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(4,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(5,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(6,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(7,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(8,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(9,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(10,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(11,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(12,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(13,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(14,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(15,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(16,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(17,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(18,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(19,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(20,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(21,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(22,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(23,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(24,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(25,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(26,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(27,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(28,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(29,1.0)),2.0));
 return(acc);}

double case40()
{double acc = 0.0;
 acc += vnorm(vcons((long)vsume(vcons(0,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(1,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(2,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(3,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(4,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(5,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(6,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(7,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(8,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(9,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(10,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(11,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(12,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(13,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(14,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(15,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(16,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(17,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(18,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(19,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(20,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(21,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(22,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(23,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(24,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(25,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(26,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(27,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(28,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(29,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(30,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(31,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(32,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(33,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(34,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(35,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(36,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(37,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(38,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(39,1.0)),2.0));
 return(acc);}

double case50()
{double acc = 0.0;
 acc += vnorm(vcons((long)vsume(vcons(0,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(1,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(2,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(3,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(4,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(5,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(6,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(7,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(8,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(9,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(10,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(11,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(12,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(13,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(14,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(15,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(16,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(17,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(18,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(19,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(20,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(21,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(22,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(23,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(24,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(25,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(26,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(27,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(28,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(29,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(30,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(31,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(32,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(33,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(34,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(35,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(36,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(37,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(38,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(39,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(40,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(41,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(42,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(43,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(44,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(45,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(46,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(47,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(48,1.0)),2.0));
 acc += vnorm(vcons((long)vsume(vcons(49,1.0)),2.0));
 return(acc);}

void sayarch(x)
     char *x;
{printf("This architecture %s procedure descriptors\n",x);}


struct apair {char *name;unsigned long addr;};
struct adelt {long delta; long count;};

int apairl(a,b)
     struct apair *a,*b;
{if (a->addr < b->addr) return(-1);
 else if (a->addr > b->addr) return(1);
 else return(0);}

int adeltl(a,b)
     struct adelt *a,*b;
{if (a->delta < b->delta) return(-1);
 else if (a->delta > b->delta) return(1);
 else return(0);}

main(argc,argv)
     int argc;
     char **argv;
{struct apair all[10];
 struct adelt deltas[10];
 long j,k,n=10,min_delta,max_delta,delta,d,ebytes=0;
 unsigned char *data,*prev_data;
 for(j=1;(j+1)<argc;j += 2)
   {if (strcmp(argv[j],"-examine") == 0)
      ebytes = atol(argv[j+1]);}
 for(j=0;j<n;++j)
   {deltas[j].delta = 0;
    deltas[j].count = 0;}
 all[0].name = "vcons";
 all[0].addr = (unsigned long) vcons;
 all[1].name = "vprod";
 all[1].addr = (unsigned long) vprod;
 all[2].name = "vsume";
 all[2].addr = (unsigned long) vsume;
 all[3].name = "viprod";
 all[3].addr = (unsigned long) viprod;
 all[4].name = "vnorm";
 all[4].addr = (unsigned long) vnorm;
 all[5].name = "case10";
 all[5].addr = (unsigned long) case10;
 all[6].name = "case20";
 all[6].addr = (unsigned long) case20;
 all[7].name = "case30";
 all[7].addr = (unsigned long) case30;
 all[8].name = "case40";
 all[8].addr = (unsigned long) case40;
 all[9].name = "case50";
 all[9].addr = (unsigned long) case50;
 if (ebytes > 0)
   {printf("%10s %10s %s\n","procedure","address","examine");
    for(j=0;j<n;++j)
      {printf("%10s %10d ",all[j].name,all[j].addr);
       data = (unsigned char *) all[j].addr;
       if (j > 0)
	 prev_data = (unsigned char *) all[j-1].addr;
       else
	 prev_data = NULL;
       for(k=0;k<ebytes;++k)
	 if (prev_data && (prev_data[k] == data[k]))
	   printf("..");
	 else
	   printf("%02X",data[k]);
       printf("\n");}}
 qsort(all,n,sizeof(struct apair),apairl);
 printf("%10s %10s %10s\n","procedure","address","delta");
 for(j=0;j<n;++j)
   {if (j>0)
      {delta = all[j].addr - all[j-1].addr;
       if (j == 1)
	 min_delta = max_delta = delta;
       else
	 {if (delta < min_delta) min_delta = delta;
	  if (delta > max_delta) max_delta = delta;}
       for(k=0;k<n;++k)
	 if(deltas[k].count == 0)
	   {deltas[k].delta = delta;
	    deltas[k].count = 1;
	    break;}
	 else if(deltas[k].delta == delta)
	   {++deltas[k].count;
	    break;}}
    else
      delta = 0;
    printf("%10s %10d %10d\n",all[j].name,all[j].addr,delta);}
 printf("min_delta = %d, max_delta = %d\n",min_delta,max_delta);
 if (min_delta == max_delta)
   sayarch("probably uses");
 else
   {qsort(deltas,n,sizeof(struct adelt),adeltl);
    printf("%10s %s\n","delta","count");
    for(d=0,k=0;k<n;++k)
      if (deltas[k].count > 0)
	{printf("%10d %d\n",deltas[k].delta,deltas[k].count);
	 ++d;}
    if (d > 4)
      sayarch("probably does not use");
    else
      sayarch("may be using");}}