]> git.saurik.com Git - apple/securityd.git/blob - src/transwalkers.cpp
50a54db3fc02776d4277469049c91b8707468f2b
[apple/securityd.git] / src / transwalkers.cpp
1 /*
2 * Copyright (c) 2003-2004 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25
26
27 //
28 // transwalkers - server side transition data walking support
29 //
30 // These are data walker operators for securely marshaling and unmarshaling
31 // data structures across IPC. They are also in charge of fixing byte order
32 // inconsistencies between server and clients.
33 //
34 #include <transwalkers.h>
35
36
37 using LowLevelMemoryUtilities::increment;
38 using LowLevelMemoryUtilities::difference;
39
40
41 bool flipClient()
42 {
43 return Server::process().byteFlipped();
44 }
45
46
47 //
48 // CheckingRelocateWalkers
49 //
50 CheckingReconstituteWalker::CheckingReconstituteWalker(void *ptr, void *base, size_t size, bool flip)
51 : mBase(base), mFlip(flip)
52 {
53 if (mFlip)
54 Flippers::flip(mBase); // came in reversed; fix for base use
55 mOffset = difference(ptr, mBase);
56 mLimit = increment(mBase, size);
57 }
58
59
60 //
61 // Relocation support
62 //
63 void relocate(Context &context, void *base, Context::Attr *attrs, uint32 attrSize)
64 {
65 flip(context);
66 CheckingReconstituteWalker relocator(attrs, base, attrSize, flipClient());
67 context.ContextAttributes = attrs; // fix context->attr vector link
68 for (uint32 n = 0; n < context.attributesInUse(); n++)
69 walk(relocator, context[n]);
70 }
71
72
73 //
74 // Outbound flipping support
75 //
76 FlipWalker::~FlipWalker()
77 {
78 for (set<Flipper>::const_iterator it = mFlips.begin(); it != mFlips.end(); it++)
79 delete it->impl;
80 }
81
82 void FlipWalker::doFlips(bool active)
83 {
84 if (active) {
85 secdebug("flipwalkers", "starting outbound flips");
86 for (set<Flipper>::const_iterator it = mFlips.begin(); it != mFlips.end(); it++)
87 it->impl->flip();
88 secdebug("flipwalkers", "outbound flips done");
89 }
90 }