Skip to content

Commit

Permalink
objc runtime 799.1
Browse files Browse the repository at this point in the history
  • Loading branch information
husihua committed Mar 27, 2020
1 parent 20d965f commit 57c4bc7
Show file tree
Hide file tree
Showing 70 changed files with 6,701 additions and 4,389 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# objc-runtime
objc runtime 756.2
objc runtime 799.1
148 changes: 148 additions & 0 deletions include/kern/restartable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2019 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/

#ifndef _KERN_RESTARTABLE_H_
#define _KERN_RESTARTABLE_H_

#include <sys/cdefs.h>
#include <mach/message.h>
#include <mach/task.h>

__BEGIN_DECLS

/*!
* @typedef task_restartable_range_t
*
* @brief
* Describes a userspace recoverable range.
*
* @field location
* The pointer to the beginning of a restartable section.
*
* @field length
* The length of the critical section anchored at location.
*
* @field recovery_offs
* The offset from the initial location that should be used for the recovery
* codepath.
*
* @field flags
* Currently unused, pass 0.
*/
typedef struct {
mach_vm_address_t location;
unsigned short length;
unsigned short recovery_offs;
unsigned int flags;
} task_restartable_range_t;

typedef task_restartable_range_t *task_restartable_range_array_t;

/*!
* @function task_restartable_ranges_register
*
* @brief
* Register a set of restartable ranges for the current task.
*
* @param task
* The task to operate on
*
* @param ranges
* An array of address ranges for which PC resets are performed.
*
* @param count
* The number of address ranges.
*
* @returns
* - KERN_SUCCESS on success
* - KERN_FAILURE if the task isn't the current one
* - KERN_INVALID_ARGUMENT for various invalid inputs
* - KERN_NOT_SUPPORTED the request is not supported (second registration on
* release kernels, registration when the task has gone wide)
* - KERN_RESOURCE_SHORTAGE if not enough memory
*/
extern kern_return_t task_restartable_ranges_register(
task_t task,
task_restartable_range_array_t ranges,
mach_msg_type_number_t count);

/*!
* @function task_restartable_ranges_synchronize
*
* @brief
* Require for all threads in the task to reset their PC
* if within a restartable range.
*
* @param task
* The task to operate on (needs to be current task)
*
* @returns
* - KERN_SUCCESS
* - KERN_FAILURE if the task isn't the current one
*/
extern kern_return_t task_restartable_ranges_synchronize(task_t task);

/*!
* @const TASK_RESTARTABLE_OFFSET_MAX
* The maximum value length / recovery_offs can have.
*/
#define TASK_RESTARTABLE_OFFSET_MAX 4096u

#ifdef KERNEL_PRIVATE

struct restartable_ranges;

/**
* @function restartable_init
*
* @brief
* Initializes the restartable module.
*/
extern void restartable_init(void);

/**
* @function restartable_ranges_release
*
* @brief
* Release a reference on a restartable range.
*/
extern void restartable_ranges_release(struct restartable_ranges *ranges);

/**
* @function thread_reset_pcs_ast
*
* @brief
* Perform the work at the AST boundary to reset thread PCS.
*/
extern void thread_reset_pcs_ast(struct thread *thread);

#endif // KERNEL_PRIVATE

__END_DECLS

#endif /* _KERN_RESTARTABLE_H_ */
156 changes: 93 additions & 63 deletions include/mach-o/dyld_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

#include <assert.h>
#include <stdbool.h>
#include <unistd.h>
#include <Availability.h>
#include <TargetConditionals.h>
#include <mach-o/dyld.h>
#include <mach-o/dyld_images.h>
#include <uuid/uuid.h>

#if __cplusplus
Expand All @@ -41,25 +41,11 @@ extern "C" {
//
// private interface between libSystem.dylib and dyld
//
extern void _dyld_atfork_prepare(void);
extern void _dyld_atfork_parent(void);
extern void _dyld_fork_child(void);


// DEPRECATED
enum dyld_image_states
{
dyld_image_state_mapped = 10, // No batch notification for this
dyld_image_state_dependents_mapped = 20, // Only batch notification for this
dyld_image_state_rebased = 30,
dyld_image_state_bound = 40,
dyld_image_state_dependents_initialized = 45, // Only single notification for this
dyld_image_state_initialized = 50,
dyld_image_state_terminated = 60 // Only single notification for this
};

// DEPRECATED
typedef const char* (*dyld_image_state_change_handler)(enum dyld_image_states state, uint32_t infoCount, const struct dyld_image_info info[]);



typedef void (*_dyld_objc_notify_mapped)(unsigned count, const char* const paths[], const struct mach_header* const mh[]);
typedef void (*_dyld_objc_notify_init)(const char* path, const struct mach_header* mh);
Expand All @@ -81,52 +67,6 @@ void _dyld_objc_notify_register(_dyld_objc_notify_mapped mapped,
_dyld_objc_notify_unmapped unmapped);



//
// Possible thread-local variable state changes for which you can register to be notified
//
enum dyld_tlv_states {
dyld_tlv_state_allocated = 10, // TLV range newly allocated
dyld_tlv_state_deallocated = 20 // TLV range about to be deallocated
};

//
// Info about thread-local variable storage.
//
typedef struct {
size_t info_size; // sizeof(dyld_tlv_info)
void * tlv_addr; // Base address of TLV storage
size_t tlv_size; // Byte size of TLV storage
} dyld_tlv_info;

#if __BLOCKS__

//
// Callback that notes changes to thread-local variable storage.
//
typedef void (^dyld_tlv_state_change_handler)(enum dyld_tlv_states state, const dyld_tlv_info *info);

//
// Register a handler to be called when a thread adds or removes storage for thread-local variables.
// The registered handler will only be called from and on behalf of the thread that owns the storage.
// The registered handler will NOT be called for any storage that was
// already allocated before dyld_register_tlv_state_change_handler() was
// called. Use dyld_enumerate_tlv_storage() to get that information.
// Exists in Mac OS X 10.7 and later
//
extern void
dyld_register_tlv_state_change_handler(enum dyld_tlv_states state, dyld_tlv_state_change_handler handler);

//
// Enumerate the current thread-local variable storage allocated for the current thread.
// Exists in Mac OS X 10.7 and later
//
extern void
dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler);

#endif


//
// get slide for a given loaded mach_header
// Mac OS X 10.6 and later
Expand Down Expand Up @@ -275,6 +215,10 @@ extern void dyld_get_image_versions(const struct mach_header* mh, void (^callbac

//@WATCHOS_VERSION_DEFS@

//@TVOS_VERSION_DEFS@

//@BRIDGEOS_VERSION_DEFS@

//
// This finds the SDK version a binary was built against.
// Returns zero on error, or if SDK version could not be determined.
Expand Down Expand Up @@ -370,6 +314,13 @@ extern const char* dyld_shared_cache_file_path(void);



//
// Returns if there are any inserted (via DYLD_INSERT_LIBRARIES) or interposing libraries.
//
// Exists in Mac OS X 10.15 and later
extern bool dyld_has_inserted_or_interposing_libraries(void);


//
// <rdar://problem/13820686> for OpenGL to tell dyld it is ok to deallocate a memory based image when done.
//
Expand Down Expand Up @@ -461,6 +412,28 @@ extern bool _dyld_get_shared_cache_uuid(uuid_t uuid);
extern const void* _dyld_get_shared_cache_range(size_t* length);


//
// Returns if the currently active dyld shared cache is optimized.
// Note: macOS does not use optimized caches and will always return false.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern bool _dyld_shared_cache_optimized(void);


//
// Returns if the currently active dyld shared cache was built locally.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern bool _dyld_shared_cache_is_locally_built(void);

//
// Returns if the given app needs a closure built.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern bool dyld_need_closure(const char* execPath, const char* tempDir);


struct dyld_image_uuid_offset {
Expand Down Expand Up @@ -492,6 +465,26 @@ extern void _dyld_register_for_image_loads(void (*func)(const struct mach_header




//
// Lets you register a callback which is called for bulk notifications of images loaded. During the call to
// _dyld_register_for_bulk_image_loads(), the callback is called once with all images currently loaded.
// Then later during dlopen() the callback is called once with all newly images.
//
// Exists in macOS 10.15 and later
// Exists in iOS 13.0 and later
extern void _dyld_register_for_bulk_image_loads(void (*func)(unsigned imageCount, const struct mach_header* mhs[], const char* paths[]));


//
// DriverKit main executables do not have an LC_MAIN. Instead DriverKit.framework's initializer calls
// _dyld_register_driverkit_main() with a function pointer that dyld should call into instead
// of using LC_MAIN.
//
extern void _dyld_register_driverkit_main(void (*mainFunc)(void));



//
// When dyld must terminate a process because of a required dependent dylib
// could not be loaded or a symbol is missing, dyld calls abort_with_reason()
Expand Down Expand Up @@ -537,6 +530,43 @@ extern void _dyld_initializer(void);
// never called from source code. Used by static linker to implement lazy binding
extern void dyld_stub_binder(void) __asm__("dyld_stub_binder");

// never call from source code. Used by closure builder to bind missing lazy symbols to
extern void _dyld_missing_symbol_abort(void);

// Called only by objc to see if dyld has uniqued this selector.
// Returns the value if dyld has uniqued it, or nullptr if it has not.
// Note, this function must be called after _dyld_objc_notify_register.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern const char* _dyld_get_objc_selector(const char* selName);


// Called only by objc to see if dyld has pre-optimized classes with this name.
// The callback will be called once for each class with the given name where
// isLoaded is true if that class is in a binary which has been previously passed
// to the objc load notifier.
// Note you can set stop to true to stop iterating.
// Also note, this function must be called after _dyld_objc_notify_register.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern void _dyld_for_each_objc_class(const char* className,
void (^callback)(void* classPtr, bool isLoaded, bool* stop));


// Called only by objc to see if dyld has pre-optimized protocols with this name.
// The callback will be called once for each protocol with the given name where
// isLoaded is true if that protocol is in a binary which has been previously passed
// to the objc load notifier.
// Note you can set stop to true to stop iterating.
// Also note, this function must be called after _dyld_objc_notify_register.
//
// Exists in Mac OS X 10.15 and later
// Exists in iOS 13.0 and later
extern void _dyld_for_each_objc_protocol(const char* protocolName,
void (^callback)(void* protocolPtr, bool isLoaded, bool* stop));


// called by exit() before it calls cxa_finalize() so that thread_local
// objects are destroyed before global objects.
Expand Down
Loading

0 comments on commit 57c4bc7

Please sign in to comment.