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 // transwalkers - server side transition data walking support
28 // These are data walker operators for securely marshaling and unmarshaling
29 // data structures across IPC. They are also in charge of fixing byte order
30 // inconsistencies between server and clients.
32 #include <transwalkers.h>
35 using LowLevelMemoryUtilities::increment
;
36 using LowLevelMemoryUtilities::difference
;
41 return Server::process().byteFlipped();
46 // CheckingRelocateWalkers
48 CheckingReconstituteWalker::CheckingReconstituteWalker(void *ptr
, void *base
, size_t size
, bool flip
)
49 : mBase(base
), mFlip(flip
)
52 Flippers::flip(mBase
); // came in reversed; fix for base use
53 mOffset
= difference(ptr
, mBase
);
54 mLimit
= increment(mBase
, size
);
61 void relocate(Context
&context
, void *base
, Context::Attr
*attrs
, uint32 attrSize
)
64 CheckingReconstituteWalker
relocator(attrs
, base
, attrSize
, flipClient());
65 context
.ContextAttributes
= attrs
; // fix context->attr vector link
66 for (uint32 n
= 0; n
< context
.attributesInUse(); n
++)
67 walk(relocator
, context
[n
]);
72 // Outbound flipping support
74 FlipWalker::~FlipWalker()
76 for (set
<Flipper
>::const_iterator it
= mFlips
.begin(); it
!= mFlips
.end(); it
++)
80 void FlipWalker::doFlips(bool active
)
83 secdebug("flipwalkers", "starting outbound flips");
84 for (set
<Flipper
>::const_iterator it
= mFlips
.begin(); it
!= mFlips
.end(); it
++)
86 secdebug("flipwalkers", "outbound flips done");
92 // Choose a Database from a choice of two sources, giving preference
93 // to persistent stores and to earlier sources.
95 Database
*pickDb(Database
*db1
, Database
*db2
)
97 // persistent db1 always wins
98 if (db1
&& !db1
->transient())
101 // persistent db2 is next choice
102 if (db2
&& !db2
->transient())
105 // pick any existing transient database
111 // none at all. use the canonical transient store
112 return Server::optionalDatabase(noDb
);