Skip to content

Create a DISPATCH_PTR_SIZE macro and use it #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/event/event_kevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,7 @@ _dispatch_mach_notify_port_init(void *context DISPATCH_UNUSED)
kern_return_t kr;
#if HAVE_MACH_PORT_CONSTRUCT
mach_port_options_t opts = { .flags = MPO_CONTEXT_AS_GUARD | MPO_STRICT };
#ifdef __LP64__
#if DISPATCH_SIZEOF_PTR == 8
const mach_port_context_t guard = 0xfeed09071f1ca7edull;
#else
const mach_port_context_t guard = 0xff1ca7edull;
Expand Down
2 changes: 1 addition & 1 deletion src/object_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
.do_xref_cnt = DISPATCH_OBJECT_GLOBAL_REFCNT
#endif

#ifdef __LP64__
#if DISPATCH_SIZEOF_PTR == 8
// the bottom nibble must not be zero, the rest of the bits should be random
// we sign extend the 64-bit version so that a better instruction encoding is
// generated on Intel
Expand Down
7 changes: 2 additions & 5 deletions src/queue_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,6 @@ dispatch_queue_attr_t _dispatch_get_default_queue_attr(void);
void *dc_ctxt; \
void *dc_data; \
void *dc_other
#define _DISPATCH_SIZEOF_PTR 8
#elif OS_OBJECT_HAVE_OBJC1
#define DISPATCH_CONTINUATION_HEADER(x) \
dispatch_function_t dc_func; \
Expand All @@ -766,7 +765,6 @@ dispatch_queue_attr_t _dispatch_get_default_queue_attr(void);
void *dc_ctxt; \
void *dc_data; \
void *dc_other
#define _DISPATCH_SIZEOF_PTR 4
#else
#define DISPATCH_CONTINUATION_HEADER(x) \
union { \
Expand All @@ -784,17 +782,16 @@ dispatch_queue_attr_t _dispatch_get_default_queue_attr(void);
void *dc_ctxt; \
void *dc_data; \
void *dc_other
#define _DISPATCH_SIZEOF_PTR 4
#endif
#define _DISPATCH_CONTINUATION_PTRS 8
#if DISPATCH_HW_CONFIG_UP
// UP devices don't contend on continuations so we don't need to force them to
// occupy a whole cacheline (which is intended to avoid contention)
#define DISPATCH_CONTINUATION_SIZE \
(_DISPATCH_CONTINUATION_PTRS * _DISPATCH_SIZEOF_PTR)
(_DISPATCH_CONTINUATION_PTRS * DISPATCH_SIZEOF_PTR)
#else
#define DISPATCH_CONTINUATION_SIZE ROUND_UP_TO_CACHELINE_SIZE( \
(_DISPATCH_CONTINUATION_PTRS * _DISPATCH_SIZEOF_PTR))
(_DISPATCH_CONTINUATION_PTRS * DISPATCH_SIZEOF_PTR))
#endif
#define ROUND_UP_TO_CONTINUATION_SIZE(x) \
(((x) + (DISPATCH_CONTINUATION_SIZE - 1u)) & \
Expand Down
16 changes: 16 additions & 0 deletions src/shims/hw_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
#ifndef __DISPATCH_SHIMS_HW_CONFIG__
#define __DISPATCH_SHIMS_HW_CONFIG__

#ifdef __SIZEOF_POINTER__
#define DISPATCH_SIZEOF_PTR __SIZEOF_POINTER__
#elif defined(_WIN64)
#define DISPATCH_SIZEOF_PTR 8
#elif defined(_WIN32)
#define DISPATCH_SIZEOF_PTR 4
#elif defined(_MSC_VER)
#error "could not determine pointer size as a constant int for MSVC"
#elif defined(__LP64__) || defined(__LLP64__)
#define DISPATCH_SIZEOF_PTR 8
#elif defined(__ILP32__)
#define DISPATCH_SIZEOF_PTR 4
#else
#error "could not determine pointer size as a constant int"
#endif // __SIZEOF_POINTER__

#if !TARGET_OS_WIN32

typedef enum {
Expand Down
2 changes: 1 addition & 1 deletion tests/dispatch_queue_finalizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ main(void)
{
dispatch_test_start("Dispatch Queue Finalizer");

#ifdef __LP64__
#if DISPATCH_SIZEOF_PTR == 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that will not build will it?

ctxt_magic = (void*)((uintptr_t)arc4random() << 32 | arc4random());
#else
ctxt_magic = (void*)arc4random();
Expand Down