~ubuntu-branches/ubuntu/trusty/sblim-sfcb/trusty-proposed

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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
/*
 * $Id: objectImplSwapI32toP32.c,v 1.17 2008/11/07 17:00:44 mchasal Exp $
 *
 * © Copyright IBM Corp. 2005, 2007
 *
 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
 * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
 * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
 *
 * You can obtain a current copy of the Eclipse Public License from
 * http://www.opensource.org/licenses/eclipse-1.0.php
 *
 * Author:        Frank Scheffler
 * Contributions: Adrian Schuur <schuur@de.ibm.com>
 *
 * Description:
 *
 * Converts a classSchemas file from 32 bit i386 format to 32 bit power format.
 * This code uses CLP32:* structures that anticipate alignemtn rules for the 32 bit power arch.
 *
*/



#include <byteswap.h>
#include <stdio.h>
#include <stdlib.h>
#include "utilft.h"
#include <sys/utsname.h>

#ifdef SETCLPFX
#undef SETCLPFX
#endif

#include "objectImpl.h"

#define CLP32
#define SETCLPFX CLP32_

#define CLP32_CMPIType CMPIType
#define CLP32_CMPIValueState CMPIValueState
#define CLP32_CMPIValue CMPIValue

typedef struct _CLP32_CMPIData {
   CLP32_CMPIType type;
   CLP32_CMPIValueState state;
   int fillP32;
   CLP32_CMPIValue value;
} CLP32_CMPIData;

#include "objectImpl.h"

typedef struct {
   unsigned short iUsed,iMax;
   int indexOffset;
   int *indexPtr;
   unsigned int bUsed, bMax;
   int fillP32;
   CLP32_CMPIData buf[1];
} CLP32_ClArrayBuf;

typedef struct {
   CLP32_ClString id;
   int fillP32;
   CLP32_CMPIData data;
} CLP32_ClQualifier;


typedef struct {
   CLP32_CMPIData data;
   CLP32_ClString id;
   CLP32_ClString refName;
   unsigned short flags;
   #ifndef SETCLPFX
    #define ClProperty_EmbeddedObjectAsString 1
    #define ClProperty_Deleted 2
   #endif 
   unsigned char quals;
   #ifndef SETCLPFX
    #define ClProperty_Q_Key 1
    #define ClProperty_Q_Propagated 2
    #define ClProperty_Q_EmbeddedObject 8
   #endif 
   unsigned char originId;
   CLP32_ClSection qualifiers;
   long            padP32;
} CLP32_ClProperty;

static CLP32_CMPIData copyI32toP32Data(ClObjectHdr * hdr, CMPIData *fd)
{
   CLP32_CMPIData td;
   
   td.value.sint64=0;
   td.fillP32=0;
   
   if (fd->state & 8) {
      td.value.sint32=bswap_32(fd->value.sint32);
      fd->state &= ~8;
   }

   else switch (fd->type) {
   case CMPI_boolean:
   case CMPI_uint8:
   case CMPI_sint8:
      td.value.sint8=fd->value.sint8;
      break;
   case CMPI_char16:
   case CMPI_uint16:
   case CMPI_sint16:
      td.value.sint16=bswap_16(fd->value.sint16);
      break;
   case CMPI_real32:
   case CMPI_uint32:
   case CMPI_sint32:
      td.value.sint32=bswap_32(fd->value.sint32);
      break;
   case CMPI_real64:
   case CMPI_uint64:
   case CMPI_sint64:
      td.value.sint64=bswap_64(fd->value.sint64);
      break;
   default:
      /*if ((fd->type & (CMPI_ENC | CMPI_ARRAY))==CMPI_ENC) {
         td.value.sint32=bswap_32(fd->value.sint32);
      }   
      else if ((fd->type & (CMPI_ENC | CMPI_ARRAY))==(CMPI_ENC | CMPI_ARRAY)) {
        if (fd->value.array) {
            CMPIData *av=(CMPIData*)ClObjectGetClArray(hdr, (ClArray*)&fd->value.array);
            av->state |= 8;
            td.value.sint32=bswap_32(fd->value.sint32);
         }
      }*/
      if((fd->type & CMPI_ARRAY) || (fd->type & CMPI_ENC)) {
      	td.value.sint32=bswap_32(fd->value.sint32);
      }
   }   

   td.type=bswap_16(fd->type);
   td.state=bswap_16(fd->state);
   return td;
}

static int p32SizeQualifiers(ClObjectHdr * hdr, ClSection * s)
{
   long sz;

   sz = s->used * sizeof(CLP32_ClQualifier);
   return ALIGN(sz,CLALIGN);
}

static int copyI32toP32Qualifiers(int ofs, char *to, CLP32_ClSection * ts,
                          ClObjectHdr * from, ClSection * fs)
{
   ClQualifier *fq = (ClQualifier *) ClObjectGetClSection(from, fs);
   CLP32_ClQualifier *tq = (CLP32_ClQualifier*)(to + ofs);
   int i, l = fs->used * sizeof(CLP32_ClQualifier);
   
   ts->max = bswap_16(fs->max);
   ts->used = bswap_16(fs->used);
   ts->sectionOffset = 0;
   
   if (l == 0) return 0;
   
   tq->fillP32=0;

   for (i = 0; i<fs->used; i++, tq++, fq++) {
      tq->id.id = bswap_32(fq->id.id);
      tq->data = copyI32toP32Data(from, &fq->data);
   }
   
   ts->sectionOffset = bswap_32(ofs);
   
   return ALIGN(l,CLALIGN);
}

static int p32SizeProperties(ClObjectHdr * hdr, ClSection * s)
{
   int l;
   long sz = s->used * sizeof(CLP32_ClProperty);
   ClProperty *p = (ClProperty *) ClObjectGetClSection(hdr, s);

   if (s->used == 0) return 0;
   
   for (l = s->used; l > 0; l--, p++) {
     if (p->qualifiers.used)
         sz += p32SizeQualifiers(hdr, &p->qualifiers);
   }      
   return ALIGN(sz,CLALIGN);
}

static int copyI32toP32Properties(int ofs, char *to, CLP32_ClSection * ts,
                           ClObjectHdr * from, ClSection * fs)
{
   ClProperty *fp = (ClProperty *) ClObjectGetClSection(from, fs);
   CLP32_ClProperty *tp = (CLP32_ClProperty *) (to + ofs);   
   int i, l = fs->used * sizeof(CLP32_ClProperty);
   
   if (l == 0) return 0;
   
   ts->max = bswap_16(fs->max);
   ts->used = bswap_16(fs->used);
   ts->sectionOffset = 0;

   if (l == 0) return 0;
   
   for (i = fs->used; i > 0; i--, fp++, tp++) {
      tp->padP32 = 0L;
      tp->id.id = bswap_32(fp->id.id);
      tp->refName.id = bswap_32(fp->refName.id);
      tp->data = copyI32toP32Data(from, &fp->data);
      tp->flags = bswap_16(fp->flags);     
      tp->quals = fp->quals;     
      tp->originId = fp->originId;
      if (fp->qualifiers.used) {
         l += copyI32toP32Qualifiers(ofs + l, to, &tp->qualifiers, from,
                             &fp->qualifiers);
      }
      else {
      	tp->qualifiers.used=0;
      	tp->qualifiers.max=0;
      	tp->qualifiers.sectionOffset=0;
      }
   }                          

   ts->sectionOffset = bswap_32(ofs);
   return ALIGN(l,CLALIGN);
}

static int p32SizeParameters(ClObjectHdr * hdr, ClSection * s)
{
   int l;
   long sz = s->used * sizeof(CLP32_ClParameter);
   ClParameter *p = (ClParameter *) ClObjectGetClSection(hdr, s);

   if (s->used ==0) return 0;
   
   for (l = s->used; l > 0; l--, p++) {
      if (p->qualifiers.used)
         sz += p32SizeQualifiers(hdr, &p->qualifiers);
   }      
   return ALIGN(sz,CLALIGN);
}

static long copyI32toP32Parameters(int ofs, char *to, CLP32_ClSection * ts,
                           ClObjectHdr * from, ClSection * fs)
{
   ClParameter *fp = (ClParameter *) ClObjectGetClSection(from, fs);
   CLP32_ClParameter *tp = (CLP32_ClParameter *) (to + ofs);
   int i,l = fs->used * sizeof(CLP32_ClParameter);
   
   ts->max = bswap_16(fs->max);
   ts->used = bswap_16(fs->used);
   ts->sectionOffset = 0;

   if (l == 0) return 0;
   
   tp->quals = fp->quals;
   
   for (i = fs->used; i > 0; i--, fp++, tp++) {
      tp->id.id = bswap_32(fp->id.id);
      tp->quals = bswap_16(fp->quals);
      tp->parameter.type=bswap_16(fp->parameter.type);
      tp->parameter.arraySize=bswap_32(fp->parameter.arraySize);
#if __WORDSIZE == 64
      tp->parameter.refName=(char*)bswap_64((unsigned long long)(fp->parameter.refName));
#else
      tp->parameter.refName=(void*)bswap_32((int)(fp->parameter.refName));
#endif
      if (fp->qualifiers.used)
         l += copyI32toP32Qualifiers(ofs + l, to, &tp->qualifiers, from, &fp->qualifiers);
   }                          

   ts->sectionOffset = bswap_32(ofs);
   return ALIGN(l,CLALIGN);
}

static int p32SizeMethods(ClObjectHdr * hdr, ClSection * s)
{
   int l;
   long sz = s->used * sizeof(CLP32_ClMethod);
   ClMethod *m = (ClMethod *) ClObjectGetClSection(hdr, s);

   if (s->used == 0) return 0;
   
   for (l = s->used; l > 0; l--, m++) {
      if (m->qualifiers.used) 
         sz += p32SizeQualifiers(hdr, &m->qualifiers);
      if (m->parameters.used)
         sz += p32SizeParameters(hdr, &m->parameters);
   }      
   return ALIGN(sz,CLALIGN);
}

static int copyI32toP32Methods(int ofs, char *to, CLP32_ClSection * ts,
                           ClObjectHdr * from, ClSection * fs)
{
   ClMethod *fm = (ClMethod *) ClObjectGetClSection(from, fs);
   CLP32_ClMethod *tm = (CLP32_ClMethod *) (to + ofs);
   int i, l = fs->used * sizeof(CLP32_ClMethod);
   
   ts->max = bswap_16(fs->max);
   ts->used = bswap_16(fs->used);
   ts->sectionOffset = 0;

   if (l == 0) return 0;
   
   tm->quals = fm->quals;
   tm->originId = fm->originId;
   
   for (i = fs->used; i > 0; i--, fm++, tm++) {
      tm->id.id = bswap_32(fm->id.id);
      tm->type = bswap_16(fm->type);
      tm->flags = bswap_16(fm->flags);
      if (fm->qualifiers.used)
         l += copyI32toP32Qualifiers(ofs + l, to, &tm->qualifiers, from,
                             &fm->qualifiers);
      if (fm->parameters.used)
         l += copyI32toP32Parameters(ofs + l, to, &tm->parameters, from,
                             &fm->parameters);
   }                          

   ts->sectionOffset = bswap_32(ofs);
   return ALIGN(l,CLALIGN);
}

static long p32SizeStringBuf(ClObjectHdr * hdr)
{
   ClStrBuf *buf;
   long sz = 0;
   
   if (hdr->strBufOffset == 0) return 0;

   buf = getStrBufPtr(hdr);   

   sz = sizeof(CLP32_ClStrBuf) + ALIGN(buf->bUsed,4) + (buf->iUsed * sizeof(*buf->indexPtr));

   return ALIGN(sz,CLALIGN);
}

static int copyI32toP32StringBuf(int ofs, CLP32_ClObjectHdr * th, ClObjectHdr * fh)
{
   ClStrBuf *fb = getStrBufPtr(fh);
   CLP32_ClStrBuf *tb = (CLP32_ClStrBuf *) (((char *) th) + ofs);
   int i,  l, il;
   unsigned short flags;
   
   if (fh->strBufOffset == 0) {
      th->strBufOffset = 0;
      return 0;
   }

   l = sizeof(CLP32_ClStrBuf) + ALIGN(fb->bUsed,4);
   il = fb->iUsed * sizeof(*fb->indexPtr);

   tb->bMax=bswap_32(fb->bUsed);
   tb->bUsed=bswap_32(fb->bUsed);  
    
   flags = fh->flags &= ~HDR_StrBufferMalloced; 
   th->flags = bswap_16(flags);
   
   th->strBufOffset=bswap_32(ofs);      
   memcpy(tb->buf, fb->buf, l - (sizeof(*fb)-1));
   
   tb->iMax=bswap_16(fb->iUsed);
   tb->iUsed=bswap_16(fb->iUsed);
    
   tb->indexPtr=(int*)(((char*)th) + ofs+l);  
   tb->indexOffset=bswap_32(ofs+l);
   
   for (i=0; i<fb->iUsed; i++)
      tb->indexPtr[i]=bswap_32(fb->indexPtr[i]);
     
   return ALIGN(l + il,CLALIGN);
}



static long p32SizeArrayBuf(ClObjectHdr * hdr)
{
   ClArrayBuf *buf;
   long sz = 0;
   
   if (hdr->arrayBufOffset == 0) return 0;

   buf = getArrayBufPtr(hdr);   

   sz = sizeof(CLP32_ClArrayBuf) + (buf->bUsed * sizeof(CLP32_CMPIData)) +
       (buf->iUsed * sizeof(*buf->indexPtr));

   return ALIGN(sz,CLALIGN);
}

static int copyI32toP32ArrayBuf(int ofs, CLP32_ClObjectHdr * th, ClObjectHdr * fh)
{
   ClArrayBuf *fb = getArrayBufPtr(fh);
   CLP32_ClArrayBuf *tb = (CLP32_ClArrayBuf *) (((char *) th) + ofs);
   int i,  l, il;
   unsigned short flags;
   
   if (fh->arrayBufOffset == 0) {
      th->arrayBufOffset = 0;
      return 0;
   }

   l = sizeof(CLP32_ClArrayBuf) + (fb->bUsed * sizeof(CLP32_CMPIData));
   il = fb->iUsed * sizeof(*fb->indexPtr);

   tb->bMax=bswap_32(fb->bUsed);
   tb->bUsed=bswap_32(fb->bUsed); 
   tb->fillP32=0; 
     
   flags = fh->flags &= ~HDR_ArrayBufferMalloced;
   th->flags = bswap_16(flags);

   th->arrayBufOffset=bswap_32(ofs);
   for (i=0; i<fb->bUsed; i++)
      tb->buf[i]=copyI32toP32Data(fh, &fb->buf[i]);
   
   tb->iMax=bswap_16(fb->iUsed);
   tb->iUsed=bswap_16(fb->iUsed); 
   
   tb->indexPtr=(int*)(((char*)th) + ofs + l);  
   tb->indexOffset=bswap_32(ofs + l);
   
   for (i=0; i<fb->iUsed; i++)
      tb->indexPtr[i]=bswap_32(fb->indexPtr[i]);
     
   return ALIGN(l + il,CLALIGN);
}

static long p32SizeClassH(ClObjectHdr * hdr, ClClass * cls)
{
   long sz = sizeof(CLP32_ClClass);

   sz += p32SizeQualifiers(hdr, &cls->qualifiers);
   sz += p32SizeProperties(hdr, &cls->properties);
   sz += p32SizeMethods(hdr, &cls->methods);
   sz += p32SizeStringBuf(hdr);
   sz += p32SizeArrayBuf(hdr);

   return ALIGN(sz,CLALIGN);
}

static long p32SizeInstanceH(ClObjectHdr * hdr, ClInstance * inst)
{
   long sz = sizeof(CLP32_ClInstance);

   sz += p32SizeQualifiers(hdr, &inst->qualifiers);
   sz += p32SizeProperties(hdr, &inst->properties);
   sz += p32SizeStringBuf(hdr);
   sz += p32SizeArrayBuf(hdr);

   return ALIGN(sz,CLALIGN);
}

static long p32SizeQualifierH(ClObjectHdr * hdr, ClQualifierDeclaration * qual)
{
   long sz = sizeof(CLP32_ClQualifierDeclaration);

   sz += p32SizeQualifiers(hdr, &qual->qualifierData);
   sz += p32SizeStringBuf(hdr);
   sz += p32SizeArrayBuf(hdr);

   return ALIGN(sz,CLALIGN);
}

void *swapI32toP32Class(ClClass * cls, int *size)
{
   ClObjectHdr * hdr = &cls->hdr;
   int ofs = sizeof(CLP32_ClClass);
   int sz=p32SizeClassH(hdr,cls) + CLEXTRA;
   struct utsname uName;
   static int first=1;
   // char *cn;
   
   if (first) {
      uname(&uName);
   
      if (uName.machine[0]!='i' || strcmp(uName.machine+2,"86")!=0) {
         fprintf(stderr,"--- swapI32toP32Class can only execute on ix86 machines\n");
         exit(16);
      }
      first=0;
   }
   
   // cn=(char*)ClObjectGetClString(&cls->hdr, &cls->name);
   
   CLP32_ClClass *nc = (CLP32_ClClass *) calloc(1,sz);

   nc->hdr.size=bswap_32(sz);
   nc->hdr.flags=bswap_16(hdr->flags);
   nc->hdr.type=bswap_16(hdr->type);
   
   nc->quals=cls->quals;
   nc->parents=cls->parents;
   nc->reserved=bswap_16(cls->reserved);
   nc->name.id=bswap_32(cls->name.id);
   nc->parent.id=bswap_32(cls->parent.id);
   
   ofs += copyI32toP32Qualifiers(ofs, (char *) nc, &nc->qualifiers, hdr,
                         &cls->qualifiers);
   ofs += copyI32toP32Properties(ofs, (char *) nc, &nc->properties, hdr,
                         &cls->properties);
   ofs += copyI32toP32Methods(ofs,(char*)nc, &nc->methods, hdr,
                         &cls->methods);
                         
   ofs += copyI32toP32StringBuf(ofs, &nc->hdr, hdr);
   ofs += copyI32toP32ArrayBuf(ofs, &nc->hdr, hdr);
   
   *size = sz;
   if (CLEXTRA) memcpy(((char*)nc)+sz-4,"%%%%",4);
   
   return nc;
}

void *swapI32toP32Instance(ClInstance * inst, int *size)
{
   ClObjectHdr * hdr = &inst->hdr;
   int ofs = sizeof(CLP32_ClInstance);
   int sz=p32SizeInstanceH(hdr,inst) + CLEXTRA;
   struct utsname uName;
   static int first=1;
   
   if (first) {
      uname(&uName);
   
      if (uName.machine[0]!='i' || strcmp(uName.machine+2,"86")!=0) {
         fprintf(stderr,"--- swapI32toP32Instance can only execute on ix86 machines\n");
         exit(16);
      }
      first=0;
   }
   
   CLP32_ClInstance *ni = (CLP32_ClInstance *) calloc(1,sz);

   ni->hdr.size=bswap_32(sz);
   ni->hdr.flags=bswap_16(hdr->flags);
   ni->hdr.type=bswap_16(hdr->type);
   
   ni->quals=inst->quals;
   ni->parents=inst->parents;
   ni->reserved=bswap_16(inst->reserved);
   ni->className.id=bswap_32(inst->className.id);
   ni->nameSpace.id=bswap_32(inst->nameSpace.id);
   ofs += copyI32toP32Qualifiers(ofs, (char *) ni, &ni->qualifiers, hdr,
                         &inst->qualifiers);
   ofs += copyI32toP32Properties(ofs, (char *) ni, &ni->properties, hdr,
                         &inst->properties);
                         
   ofs += copyI32toP32StringBuf(ofs, &ni->hdr, hdr);
   ofs += copyI32toP32ArrayBuf(ofs, &ni->hdr, hdr);
   
   *size = sz;
   if (CLEXTRA) memcpy(((char*)ni)+sz-4,"%%%%",4);
   
   return ni;
}

void *swapI32toP32QualifierDeclaration(ClQualifierDeclaration * qual, int *size)
{
   ClObjectHdr * hdr = &qual->hdr;
   int ofs = sizeof(CLP32_ClQualifierDeclaration);
   int sz=p32SizeQualifierH(hdr,qual) + CLEXTRA;
   struct utsname uName;
   static int first=1;
   
   if (first) {
      uname(&uName);
   
      if (uName.machine[0]!='i' || strcmp(uName.machine+2,"86")!=0) {
         fprintf(stderr,"--- swapI32toP32QualifierDeclaration can only execute on ix86 machines\n");
         exit(16);
      }
      first=0;
   }
   
   CLP32_ClQualifierDeclaration *nq = (CLP32_ClQualifierDeclaration *) calloc(1,sz);

   nq->hdr.size=bswap_32(sz);
   nq->hdr.flags=bswap_16(hdr->flags);
   nq->hdr.type=bswap_16(hdr->type);
   
   nq->flavor=qual->flavor;
   nq->scope=qual->scope;
   nq->type=bswap_16(qual->type);
   nq->arraySize=bswap_32(qual->arraySize);
   nq->qualifierName.id=bswap_32(qual->qualifierName.id);
   nq->nameSpace.id=bswap_32(qual->nameSpace.id);  
   
   ofs += copyI32toP32Qualifiers(ofs, (char *) nq, &nq->qualifierData, hdr,
                         &qual->qualifierData);
   ofs += copyI32toP32StringBuf(ofs, &nq->hdr, hdr);
   ofs += copyI32toP32ArrayBuf(ofs, &nq->hdr, hdr);
   
   *size = sz;
   if (CLEXTRA) memcpy(((char*)nq)+sz-4,"%%%%",4);
   
   return nq;
}