2 * Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 // process - track a single client process and its belongings
29 #include <security_utilities/memutils.h>
31 using namespace LowLevelMemoryUtilities
;
37 // The raw byte reversal flipper
39 void flip(void *addr
, size_t size
)
41 assert(size
> 1 && (size
% 2 == 0));
42 Byte
*word
= reinterpret_cast<uint8
*>(addr
);
43 for (size_t n
= 0; n
< size
/2; n
++) {
45 word
[n
] = word
[size
-1-n
];
54 void flip(uint32
&obj
) { flip(&obj
, sizeof(obj
)); }
55 void flip(uint16
&obj
) { flip(&obj
, sizeof(obj
)); }
56 void flip(sint32
&obj
) { flip(&obj
, sizeof(obj
)); }
57 void flip(sint16
&obj
) { flip(&obj
, sizeof(obj
)); }
61 // Flip a context attribute. This is heavily polymorphic.
63 void flip(CSSM_CONTEXT_ATTRIBUTE
&obj
)
65 flip(obj
.AttributeType
);
66 flip(obj
.AttributeLength
);
67 switch (obj
.AttributeType
& CSSM_ATTRIBUTE_TYPE_MASK
) {
68 case CSSM_ATTRIBUTE_DATA_UINT32
:
69 flip(obj
.Attribute
.Uint32
);
71 // all other alternatives are handled by CSSM_CONTEXT_ATTRIBUTE's walker
79 // Flip a CSSM_DB_ATTRIBUTE_INFO, also very polymorphic
81 void flip(CSSM_DB_ATTRIBUTE_INFO
&obj
)
83 bool flippedAttributeNameFormat
= false;
84 // check and see if obj is in host byte order. If not, flip it now
85 if (obj
.AttributeNameFormat
> CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER
)
87 flip(obj
.AttributeNameFormat
);
88 flippedAttributeNameFormat
= true;
91 switch (obj
.AttributeNameFormat
)
93 case CSSM_DB_ATTRIBUTE_NAME_AS_INTEGER
:
95 flip(obj
.Label
.AttributeID
);
100 flip (obj
.AttributeFormat
);
102 if (!flippedAttributeNameFormat
)
104 flip(obj
.AttributeNameFormat
);
110 // Automatically generated flippers
112 #include "flip_gen.cpp"
115 } // end namespace Flippers