]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/globalizer.cpp
2 * Copyright (c) 2000-2004,2011-2012,2014 Apple 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 // globalizer - multiscope globalization services.
28 // This is a tentative, partial implementation.
30 // module scope: constructs, optional cleanup
31 // thread scope: constructs, optional cleanup
32 // process scope: not implemented (obsolete implementation, unused)
33 // system scope: not implemented (probably never will)
35 // @@@ Assumption: {bool,T*} atomic unless PTHREAD_STRICT
37 #include <security_utilities/globalizer.h>
38 #include <security_utilities/debugging.h>
43 // The Error class thrown if Nexus operations fail
45 GlobalNexus::Error::~Error() _NOEXCEPT
49 void ModuleNexusCommon::do_create(void *(*make
)())
63 void *ModuleNexusCommon::create(void *(*make
)())
65 dispatch_once(&once
, ^{do_create(make
);});
69 ModuleNexusError::throwMe();
77 // Process nexus operation
79 ProcessNexusBase::ProcessNexusBase(const char *identifier
)
81 const char *env
= getenv(identifier
);
82 if (env
== NULL
) { // perhaps we're first...
83 unique_ptr
<Store
> store(new Store
);
84 char form
[2*sizeof(Store
*) + 2];
85 sprintf(form
, "*%p", &store
);
86 setenv(identifier
, form
, 0); // do NOT overwrite...
87 env
= getenv(identifier
); // ... and refetch to resolve races
88 if (sscanf(env
, "*%p", &mStore
) != 1)
89 throw std::runtime_error("environment communication failed");
90 if (mStore
== store
.get()) // we won the race...
91 store
.release(); // ... so keep the store
93 if (sscanf(env
, "*%p", &mStore
) != 1)
94 throw std::runtime_error("environment communication failed");