···11+/*
22+ * Copyright (c) 2011-2012 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_APACHE_LICENSE_HEADER_START@
55+ *
66+ * Licensed under the Apache License, Version 2.0 (the "License");
77+ * you may not use this file except in compliance with the License.
88+ * You may obtain a copy of the License at
99+ *
1010+ * http://www.apache.org/licenses/LICENSE-2.0
1111+ *
1212+ * Unless required by applicable law or agreed to in writing, software
1313+ * distributed under the License is distributed on an "AS IS" BASIS,
1414+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515+ * See the License for the specific language governing permissions and
1616+ * limitations under the License.
1717+ *
1818+ * @APPLE_APACHE_LICENSE_HEADER_END@
1919+ */
2020+2121+#ifndef __OS_OBJECT__
2222+#define __OS_OBJECT__
2323+2424+#ifdef __APPLE__
2525+#include <Availability.h>
2626+#endif
2727+2828+/*!
2929+ * @header
3030+ *
3131+ * @preprocinfo
3232+ * By default, libSystem objects such as GCD and XPC objects are declared as
3333+ * Objective-C types when building with an Objective-C compiler. This allows
3434+ * them to participate in ARC, in RR management by the Blocks runtime and in
3535+ * leaks checking by the static analyzer, and enables them to be added to Cocoa
3636+ * collections.
3737+ *
3838+ * NOTE: this requires explicit cancellation of dispatch sources and xpc
3939+ * connections whose handler blocks capture the source/connection object,
4040+ * resp. ensuring that such captures do not form retain cycles (e.g. by
4141+ * declaring the source as __weak).
4242+ *
4343+ * To opt-out of this default behavior, add -DOS_OBJECT_USE_OBJC=0 to your
4444+ * compiler flags.
4545+ *
4646+ * This mode requires a platform with the modern Objective-C runtime, the
4747+ * Objective-C GC compiler option to be disabled, and at least a Mac OS X 10.8
4848+ * deployment target.
4949+ */
5050+5151+#ifndef OS_OBJECT_HAVE_OBJC_SUPPORT
5252+#if defined(__OBJC2__) && !defined(__OBJC_GC__) && ( \
5353+ __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_8 || \
5454+ __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_6_0)
5555+#define OS_OBJECT_HAVE_OBJC_SUPPORT 1
5656+#else
5757+#define OS_OBJECT_HAVE_OBJC_SUPPORT 0
5858+#endif
5959+#endif
6060+6161+#if OS_OBJECT_HAVE_OBJC_SUPPORT
6262+#ifndef OS_OBJECT_USE_OBJC
6363+#define OS_OBJECT_USE_OBJC 1
6464+#endif
6565+#elif defined(OS_OBJECT_USE_OBJC) && OS_OBJECT_USE_OBJC
6666+/* Unsupported platform for OS_OBJECT_USE_OBJC=1 */
6767+#undef OS_OBJECT_USE_OBJC
6868+#define OS_OBJECT_USE_OBJC 0
6969+#else
7070+#define OS_OBJECT_USE_OBJC 0
7171+#endif
7272+7373+#if OS_OBJECT_USE_OBJC
7474+#import <Foundation/NSObject.h>
7575+#define OS_OBJECT_CLASS(name) OS_##name
7676+#define OS_OBJECT_DECL(name, ...) \
7777+ @protocol OS_OBJECT_CLASS(name) __VA_ARGS__ \
7878+ @end \
7979+ typedef NSObject<OS_OBJECT_CLASS(name)> *name##_t
8080+#define OS_OBJECT_DECL_SUBCLASS(name, super) \
8181+ OS_OBJECT_DECL(name, <OS_OBJECT_CLASS(super)>)
8282+#if defined(__has_attribute) && __has_attribute(ns_returns_retained)
8383+#define OS_OBJECT_RETURNS_RETAINED __attribute__((__ns_returns_retained__))
8484+#else
8585+#define OS_OBJECT_RETURNS_RETAINED
8686+#endif
8787+#if defined(__has_feature) && __has_feature(objc_arc)
8888+#define OS_OBJECT_BRIDGE __bridge
8989+#else
9090+#define OS_OBJECT_BRIDGE
9191+#endif
9292+#ifndef OS_OBJECT_USE_OBJC_RETAIN_RELEASE
9393+#if defined(__has_feature) && __has_feature(objc_arc) || \
9494+ defined(__clang_analyzer__)
9595+#define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 1
9696+#else
9797+#define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 0
9898+#endif
9999+#endif
100100+#else
101101+/*! @parseOnly */
102102+#define OS_OBJECT_RETURNS_RETAINED
103103+/*! @parseOnly */
104104+#define OS_OBJECT_BRIDGE
105105+#define OS_OBJECT_USE_OBJC_RETAIN_RELEASE 0
106106+#endif
107107+108108+#endif
+9-2
src/libsystem/init.c
···117117118118 if (!*x_argc)
119119 {
120120+ char* excl;
121121+120122 // Darling libdyld is not being used
121123 // to execute a Mach-O binary.
122124 // Use what the ELF loader gave us.
123123- *x_argc = argc;
124124- *x_argv = argv;
125125+ *x_argc = argc - 1;
126126+ *x_argv = argv + 1;
125127 *x_envp = envp;
128128+129129+ excl = strchr(argv[1], '!');
130130+ if (excl != NULL)
131131+ argv[1] = excl+1;
132132+126133 vars.NXArgcPtr = x_argc;
127134 vars.NXArgvPtr = x_argv;
128135 vars.environPtr = x_envp;