From 02b6964a2b3861ff88d4f92e7106784c326b7968 Mon Sep 17 00:00:00 2001 From: Aaron Dierking Date: Thu, 12 Jul 2018 12:00:45 -0700 Subject: [PATCH] Remove generic_unix_stubs generic_unix_stubs.c seems to no longer be necessary. generic_unix_stubs.h still had some required definitions in it, so move those into shims.h and a new shims/mach.h. This also lets us remove some duplicated definitions in the Windows shims. --- src/CMakeLists.txt | 7 +--- src/shims.h | 12 +++++-- src/shims/generic_sys_queue.h | 5 --- src/shims/generic_unix_stubs.c | 57 -------------------------------- src/shims/generic_unix_stubs.h | 60 ---------------------------------- src/shims/generic_win_stubs.h | 18 +--------- src/shims/mach.h | 45 +++++++++++++++++++++++++ src/transform.c | 4 +-- 8 files changed, 59 insertions(+), 149 deletions(-) delete mode 100644 src/shims/generic_unix_stubs.c delete mode 100644 src/shims/generic_unix_stubs.h create mode 100644 src/shims/mach.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6b95a9b82..5673f77cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -54,12 +54,7 @@ add_library(dispatch shims/time.h shims/tsd.h shims/yield.h) -if(UNIX) - target_sources(dispatch - PRIVATE - shims/generic_unix_stubs.c - shims/generic_unix_stubs.h) -elseif(WIN32) +if(WIN32) target_sources(dispatch PRIVATE shims/generic_sys_queue.h diff --git a/src/shims.h b/src/shims.h index 32d2c85b1..85f4026b2 100644 --- a/src/shims.h +++ b/src/shims.h @@ -33,14 +33,16 @@ #if defined(_WIN32) #include "shims/generic_win_stubs.h" #include "shims/generic_sys_queue.h" -#elif defined(__unix__) -#include "shims/generic_unix_stubs.h" #endif #ifdef __ANDROID__ #include "shims/android_stubs.h" #endif +#if !HAVE_MACH +#include "shims/mach.h" +#endif + #include "shims/hw_config.h" #include "shims/priority.h" @@ -79,6 +81,12 @@ size_t strlcpy(char *dst, const char *src, size_t size); #endif // HAVE_STRLCPY +#ifndef TAILQ_FOREACH_SAFE +#define TAILQ_FOREACH_SAFE(var, head, field, temp) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((temp) = TAILQ_NEXT((var), field), 1); (var) = (temp)) +#endif + #if PTHREAD_WORKQUEUE_SPI_VERSION < 20140716 static inline int _pthread_workqueue_override_start_direct(mach_port_t thread, diff --git a/src/shims/generic_sys_queue.h b/src/shims/generic_sys_queue.h index 250abbfc2..1d9a18d0f 100644 --- a/src/shims/generic_sys_queue.h +++ b/src/shims/generic_sys_queue.h @@ -62,11 +62,6 @@ (var) != NULL; \ (var) = TAILQ_NEXT(var, field)) -#define TAILQ_FOREACH_SAFE(var, list, field, temp) \ - for ((var) = TAILQ_FIRST(list); \ - ((var) != NULL) && (temp = TAILQ_NEXT(var, field), 1); \ - (var) = (temp)) - #define TAILQ_REMOVE(list, elem, field) do { \ if (TAILQ_NEXT(elem, field) != NULL) { \ TAILQ_NEXT(elem, field)->field.te_prev = (elem)->field.te_prev; \ diff --git a/src/shims/generic_unix_stubs.c b/src/shims/generic_unix_stubs.c deleted file mode 100644 index 9197664b8..000000000 --- a/src/shims/generic_unix_stubs.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This source file is part of the Swift.org open source project - * - * Copyright (c) 2015 Apple Inc. and the Swift project authors - * - * Licensed under Apache License v2.0 with Runtime Library Exception - * - * See https://swift.org/LICENSE.txt for license information - * See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors - * - */ - -/* - * This file contains stubbed out functions we are using during - * the initial linux port. When the port is complete, this file - * should be empty (and thus removed). - */ - -#include -#if defined(__ANDROID__) || defined(__FreeBSD__) -#include -#else -#include -#endif /* __ANDROID__ || __FreeBSD__ */ - -#if __has_include() -#include -#else -#include -#endif - -#include "pthread.h" -#include "os/generic_unix_base.h" -#include "internal.h" - - -#undef LINUX_PORT_ERROR -#define LINUX_PORT_ERROR() do { printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",__FILE__,__LINE__,__FUNCTION__); abort(); } while (0) - - -/* - * Stubbed out static data - */ - -pthread_key_t dispatch_voucher_key; -pthread_key_t dispatch_pthread_root_queue_observer_hooks_key; - -unsigned short dispatch_timer__program_semaphore; -unsigned short dispatch_timer__wake_semaphore; -unsigned short dispatch_timer__fire_semaphore; -unsigned short dispatch_timer__configure_semaphore; -unsigned short dispatch_queue__pop_semaphore; -unsigned short dispatch_callout__entry_semaphore; -unsigned short dispatch_callout__return_semaphore; -unsigned short dispatch_queue__push_semaphore; -void (*_dispatch_block_special_invoke)(void*); -struct dispatch_queue_attr_s _dispatch_queue_attr_concurrent; diff --git a/src/shims/generic_unix_stubs.h b/src/shims/generic_unix_stubs.h deleted file mode 100644 index aca569fc9..000000000 --- a/src/shims/generic_unix_stubs.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This source file is part of the Swift.org open source project - * - * Copyright (c) 2015 Apple Inc. and the Swift project authors - * - * Licensed under Apache License v2.0 with Runtime Library Exception - * - * See https://swift.org/LICENSE.txt for license information - * See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors - * - */ - -// forward declarations for functions we are stubbing out -// in the intial linux port. - -#ifndef __DISPATCH__STUBS__INTERNAL -#define __DISPATCH__STUBS__INTERNAL - -#ifndef TAILQ_FOREACH_SAFE -#define TAILQ_FOREACH_SAFE(var, head, field, temp) \ - for ((var) = TAILQ_FIRST((head)); \ - (var) && ((temp) = TAILQ_NEXT((var), field), 1); (var) = (temp)) -#endif - -/* - * Stub out defines for some mach types and related macros - */ - -typedef uint32_t mach_port_t; - -#define MACH_PORT_NULL (0) -#define MACH_PORT_DEAD (-1) - -typedef uint32_t mach_error_t; - -typedef uint32_t mach_msg_return_t; - -typedef uint32_t mach_msg_bits_t; - -typedef void *dispatch_mach_msg_t; - -typedef uint64_t firehose_activity_id_t; - -typedef void *mach_msg_header_t; - -// Print a warning when an unported code path executes. -#define LINUX_PORT_ERROR() do { \ - printf("LINUX_PORT_ERROR_CALLED %s:%d: %s\n",\ - __FILE__,__LINE__,__FUNCTION__); } while (0) - -/* - * Stub out defines for other missing types - */ - -// SIZE_T_MAX should not be hardcoded like this here. -#ifndef SIZE_T_MAX -#define SIZE_T_MAX (~(size_t)0) -#endif - -#endif diff --git a/src/shims/generic_win_stubs.h b/src/shims/generic_win_stubs.h index 06801129a..c983cdcee 100644 --- a/src/shims/generic_win_stubs.h +++ b/src/shims/generic_win_stubs.h @@ -11,25 +11,9 @@ #include /* - * Stub out defines for some mach types and related macros + * Stub out defines for missing types */ -typedef uint32_t mach_port_t; - -#define MACH_PORT_NULL (0) - -typedef uint32_t mach_msg_bits_t; -typedef void *mach_msg_header_t; - -/* - * Stub out defines for other missing types - */ - -// SIZE_T_MAX should not be hardcoded like this here. -#ifndef SIZE_T_MAX -#define SIZE_T_MAX (~(size_t)0) -#endif - typedef __typeof__(_Generic((__SIZE_TYPE__)0, \ unsigned long long int : (long long int)0, \ unsigned long int : (long int)0, \ diff --git a/src/shims/mach.h b/src/shims/mach.h new file mode 100644 index 000000000..759f5f3a9 --- /dev/null +++ b/src/shims/mach.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Apple Inc. All rights reserved. + * + * @APPLE_APACHE_LICENSE_HEADER_START@ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * @APPLE_APACHE_LICENSE_HEADER_END@ + */ + +#ifndef __DISPATCH_SHIMS_MACH__ +#define __DISPATCH_SHIMS_MACH__ + +/* + * Stub out defines for some mach types and related macros + */ + +typedef uint32_t mach_port_t; + +#define MACH_PORT_NULL (0) +#define MACH_PORT_DEAD (-1) + +typedef uint32_t mach_error_t; + +typedef uint32_t mach_msg_return_t; + +typedef uint32_t mach_msg_bits_t; + +typedef void *dispatch_mach_msg_t; + +typedef uint64_t firehose_activity_id_t; + +typedef void *mach_msg_header_t; + +#endif diff --git a/src/transform.c b/src/transform.c index 7f2c55677..45d5669bb 100644 --- a/src/transform.c +++ b/src/transform.c @@ -662,7 +662,7 @@ _dispatch_transform_to_base32_with_table(dispatch_data_t data, const unsigned ch dest_size = howmany(total, 5); // // os_mul_overflow(dest_size, 8, &dest_size) - if (dest_size > SIZE_T_MAX / 8) { + if (dest_size > SIZE_MAX / 8) { return NULL; } dest_size *= 8; @@ -897,7 +897,7 @@ _dispatch_transform_to_base64(dispatch_data_t data) dest_size = howmany(total, 3); // // os_mul_overflow(dest_size, 4, &dest_size) - if (dest_size > SIZE_T_MAX / 4) { + if (dest_size > SIZE_MAX / 4) { return NULL; } dest_size *= 4;