Add xpc_dictionary_get_dictionary and new xpc_pointer type

xpc_pointer isn't documented *anywhere*, but it's used in Security. My best guess is that's it's just a pretty container for a pointer, which is fine for now, but I'll have to check the exact semantics later.
This commit is contained in:
Ariel Abreu 2020-07-16 14:32:32 -04:00
parent 3c456b6db0
commit 4802015f7d
No known key found for this signature in database
GPG Key ID: F4D43CC7053EA2B3
5 changed files with 95 additions and 3 deletions

View File

@ -319,6 +319,10 @@ __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_5_0)
XPC_EXPORT
const char *const _xpc_event_key_name;
#define XPC_TYPE_POINTER (&_xpc_type_pointer)
XPC_EXPORT
XPC_TYPE(_xpc_type_pointer);
#ifndef __XPC_BUILDING_XPC__
#include <xpc/endpoint.h>
#include <xpc/debug.h>
@ -1764,6 +1768,14 @@ XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL1
xpc_connection_t
xpc_array_create_connection(xpc_object_t xarray, size_t index);
XPC_EXPORT
void* _Nullable
xpc_array_get_pointer(xpc_object_t xarray, size_t index);
XPC_EXPORT
void
xpc_array_set_pointer(xpc_object_t xarray, size_t index, void* value);
#pragma mark Dictionary
/*!
* @typedef xpc_dictionary_applier_t
@ -2419,6 +2431,19 @@ XPC_EXPORT XPC_MALLOC XPC_RETURNS_RETAINED XPC_WARN_RESULT XPC_NONNULL_ALL
xpc_connection_t
xpc_dictionary_create_connection(xpc_object_t xdict, const char *key);
__OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0)
XPC_EXPORT XPC_WARN_RESULT XPC_NONNULL_ALL
xpc_object_t _Nullable
xpc_dictionary_get_dictionary(xpc_object_t xdict, const char *key);
XPC_EXPORT
void* _Nullable
xpc_dictionary_get_pointer(xpc_object_t xdict, const char* key);
XPC_EXPORT
void
xpc_dictionary_set_pointer(xpc_object_t xdict, const char* key, void* value);
#pragma mark Runtime
/*!
* @function xpc_main
@ -2530,6 +2555,16 @@ xpc_set_event_stream_handler(const char *stream, dispatch_queue_t targetq,
xpc_handler_t handler);
#endif // __BLOCKS__
#pragma mark XPC Pointer
XPC_EXPORT
xpc_object_t
xpc_pointer_create(void* value);
XPC_EXPORT
void* _Nullable
xpc_pointer_get_value(xpc_object_t xptr);
__END_DECLS
#endif // __XPC_H__

View File

@ -324,3 +324,16 @@ xpc_array_apply(xpc_object_t xarray, xpc_array_applier_t applier)
return (true);
}
void* xpc_array_get_pointer(xpc_object_t xarray, size_t index) {
struct xpc_object* xo = xpc_array_get_value(xarray, index);
if (xo)
return xpc_pointer_get_value(xo);
return NULL;
};
void xpc_array_set_pointer(xpc_object_t xarray, size_t index, void* value) {
struct xpc_object* xo = xpc_pointer_create(value);
xpc_array_set_value(xarray, index, xo);
xpc_release(xo);
};

View File

@ -314,3 +314,23 @@ xpc_dictionary_get_uuid(xpc_object_t xdict, const char *key)
{
return NULL;
}
xpc_object_t xpc_dictionary_get_dictionary(xpc_object_t xdict, const char* key) {
xpc_object_t xo = xpc_dictionary_get_value(xdict, key);
if (xo && xpc_get_type(xo) == XPC_TYPE_DICTIONARY)
return xo;
return NULL;
};
void* xpc_dictionary_get_pointer(xpc_object_t xdict, const char* key) {
xpc_object_t xo = xpc_dictionary_get_value(xdict, key);
if (xo)
return xpc_pointer_get_value(xo);
return NULL;
};
void xpc_dictionary_set_pointer(xpc_object_t xdict, const char* key, void* value) {
xpc_object_t xo = xpc_pointer_create(value);
xpc_dictionary_set_value(xdict, key, xo);
xpc_release(xo);
};

View File

@ -65,7 +65,8 @@
#define _XPC_TYPE_SHMEM 15
#define _XPC_TYPE_ERROR 16
#define _XPC_TYPE_DOUBLE 17
#define _XPC_TYPE_MAX _XPC_TYPE_DOUBLE
#define _XPC_TYPE_POINTER 18
#define _XPC_TYPE_MAX _XPC_TYPE_POINTER
#define XPC_SEQID "XPC sequence number"

View File

@ -52,6 +52,7 @@ xt _xpc_type_shmem;
xt _xpc_type_string;
xt _xpc_type_uuid;
xt _xpc_type_double;
xt _xpc_type_pointer;
struct _xpc_bool_s {
@ -82,7 +83,8 @@ static xpc_type_t xpc_typemap[] = {
XPC_TYPE_FD,
XPC_TYPE_SHMEM,
XPC_TYPE_ERROR,
XPC_TYPE_DOUBLE
XPC_TYPE_DOUBLE,
XPC_TYPE_POINTER,
};
static const char *xpc_typestr[] = {
@ -103,7 +105,8 @@ static const char *xpc_typestr[] = {
"fd",
"shmem",
"error",
"double"
"double",
"pointer",
};
__private_extern__ struct xpc_object *
@ -492,6 +495,8 @@ xpc_hash(xpc_object_t obj)
return ((bool)true);
});
return (hash);
case _XPC_TYPE_POINTER:
return ((size_t)xo->xo_u.ptr);
default:
return 0;
}
@ -505,3 +510,21 @@ _xpc_get_type_name(xpc_object_t obj)
xo = obj;
return (xpc_typestr[xo->xo_xpc_type]);
}
xpc_object_t xpc_pointer_create(void* value) {
xpc_u val;
val.ptr = (uintptr_t)value;
return _xpc_prim_create(_XPC_TYPE_POINTER, val, 1);
};
void* xpc_pointer_get_value(xpc_object_t xptr) {
struct xpc_object* xo = xptr;
if (xo == NULL)
return NULL;
if (xo->xo_xpc_type == _XPC_TYPE_POINTER)
return xo->xo_ptr;
return NULL;
};