mirror of
https://github.com/darlinghq/darling-libxpc.git
synced 2024-11-23 03:39:40 +00:00
Merge pull request #6 from facekapow/remove-nv
Reimplement XPC packing/unpacking without `nvlist`/`nvpair`
This commit is contained in:
commit
5e02bdd435
@ -35,8 +35,6 @@ set(xpc_sources
|
||||
xpc_private.c
|
||||
xpc_type.c
|
||||
subr_sbuf.c
|
||||
subr_nvlist.c
|
||||
subr_nvpair.c
|
||||
xpc_pipe.c
|
||||
reboot3.c
|
||||
)
|
||||
|
478
nv.h
478
nv.h
@ -1,478 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2013 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NV_H_
|
||||
#define _NV_H_
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <uuid/uuid.h>
|
||||
#else
|
||||
#include <sys/uuid.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifndef _NVLIST_T_DECLARED
|
||||
#define _NVLIST_T_DECLARED
|
||||
struct nvlist;
|
||||
|
||||
typedef struct nvlist nvlist_t;
|
||||
#endif
|
||||
|
||||
#define NV_NAME_MAX 2048
|
||||
|
||||
#define NV_TYPE_NONE 0
|
||||
|
||||
#define NV_TYPE_NULL 1
|
||||
#define NV_TYPE_BOOL 2
|
||||
#define NV_TYPE_STRING 3
|
||||
#define NV_TYPE_DESCRIPTOR 4
|
||||
#define NV_TYPE_BINARY 5
|
||||
|
||||
#define NV_TYPE_NUMBER 6
|
||||
#define NV_TYPE_PTR 7
|
||||
#define NV_TYPE_UINT64 8
|
||||
#define NV_TYPE_INT64 9
|
||||
#define NV_TYPE_ENDPOINT 10
|
||||
#define NV_TYPE_DATE 11
|
||||
#define NV_TYPE_UUID 12
|
||||
|
||||
#define NV_TYPE_NVLIST 13
|
||||
#define NV_TYPE_NVLIST_ARRAY 14
|
||||
#define NV_TYPE_NVLIST_DICTIONARY 15
|
||||
|
||||
|
||||
/*
|
||||
* Perform case-insensitive lookups of provided names.
|
||||
*/
|
||||
#define NV_FLAG_IGNORE_CASE 0x01
|
||||
/*
|
||||
* Names don't have to be unique.
|
||||
*/
|
||||
#define NV_FLAG_NO_UNIQUE 0x02
|
||||
|
||||
#if defined(_KERNEL) && defined(MALLOC_DECLARE)
|
||||
MALLOC_DECLARE(M_NVLIST);
|
||||
#endif
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
nvlist_t *nvlist_create(int flags);
|
||||
nvlist_t *nvlist_create_array(int flags);
|
||||
nvlist_t *nvlist_create_dictionary(int flags);
|
||||
void nvlist_destroy(nvlist_t *nvl);
|
||||
int nvlist_error(const nvlist_t *nvl);
|
||||
bool nvlist_empty(const nvlist_t *nvl);
|
||||
int nvlist_flags(const nvlist_t *nvl);
|
||||
void nvlist_set_error(nvlist_t *nvl, int error);
|
||||
|
||||
nvlist_t *nvlist_clone(const nvlist_t *nvl);
|
||||
|
||||
#ifndef _KERNEL
|
||||
void nvlist_dump(const nvlist_t *nvl, int fd);
|
||||
void nvlist_fdump(const nvlist_t *nvl, FILE *fp);
|
||||
#endif
|
||||
|
||||
size_t nvlist_size(const nvlist_t *nvl);
|
||||
void *nvlist_pack(const nvlist_t *nvl, size_t *sizep);
|
||||
void *nvlist_pack_buffer(const nvlist_t *nvl, void *buf, size_t *sizep);
|
||||
nvlist_t *nvlist_unpack(const void *buf, size_t size);
|
||||
|
||||
int nvlist_send(int sock, const nvlist_t *nvl);
|
||||
nvlist_t *nvlist_recv(int sock);
|
||||
nvlist_t *nvlist_xfer(int sock, nvlist_t *nvl);
|
||||
|
||||
const char *nvlist_next(const nvlist_t *nvl, int *typep, void **cookiep);
|
||||
|
||||
const nvlist_t *nvlist_get_parent(const nvlist_t *nvl, void **cookiep);
|
||||
|
||||
/*
|
||||
* The nvlist_exists functions check if the given name (optionally of the given
|
||||
* type) exists on nvlist.
|
||||
*/
|
||||
|
||||
bool nvlist_exists(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_type(const nvlist_t *nvl, const char *name, int type);
|
||||
|
||||
bool nvlist_exists_null(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_bool(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_number(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_ptr(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_uint64(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_int64(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_endpoint(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_date(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_string(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_nvlist(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_nvlist_dictionary(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_nvlist_array(const nvlist_t *nvl, const char *name);
|
||||
#ifndef _KERNEL
|
||||
bool nvlist_exists_descriptor(const nvlist_t *nvl, const char *name);
|
||||
#endif
|
||||
bool nvlist_exists_binary(const nvlist_t *nvl, const char *name);
|
||||
bool nvlist_exists_uuid(const nvlist_t *nvl, const char *name);
|
||||
|
||||
/*
|
||||
* The nvlist_add functions add the given name/value pair.
|
||||
* If a pointer is provided, nvlist_add will internally allocate memory for the
|
||||
* given data (in other words it won't consume provided buffer).
|
||||
*/
|
||||
|
||||
void nvlist_add_null(nvlist_t *nvl, const char *name);
|
||||
void nvlist_add_bool(nvlist_t *nvl, const char *name, bool value);
|
||||
void nvlist_add_number(nvlist_t *nvl, const char *name, uint64_t value);
|
||||
void nvlist_add_ptr(nvlist_t *nvl, const char *name, uintptr_t value);
|
||||
void nvlist_add_int64(nvlist_t *nvl, const char *name, int64_t value);
|
||||
void nvlist_add_uint64(nvlist_t *nvl, const char *name, uint64_t value);
|
||||
void nvlist_add_endpoint(nvlist_t *nvl, const char *name, int value);
|
||||
void nvlist_add_date(nvlist_t *nvl, const char *name, uint64_t value);
|
||||
void nvlist_add_string(nvlist_t *nvl, const char *name, const char *value);
|
||||
void nvlist_add_stringf(nvlist_t *nvl, const char *name, const char *valuefmt, ...) __printflike(3, 4);
|
||||
#ifdef _VA_LIST_DECLARED
|
||||
void nvlist_add_stringv(nvlist_t *nvl, const char *name, const char *valuefmt, va_list valueap) __printflike(3, 0);
|
||||
#endif
|
||||
void nvlist_add_nvlist(nvlist_t *nvl, const char *name, const nvlist_t *value);
|
||||
void nvlist_add_nvlist_dictionary(nvlist_t *nvl, const char *name, const nvlist_t *value);
|
||||
void nvlist_add_nvlist_array(nvlist_t *nvl, const char *name, const nvlist_t *value);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_add_descriptor(nvlist_t *nvl, const char *name, int value);
|
||||
#endif
|
||||
void nvlist_add_binary(nvlist_t *nvl, const char *name, const void *value, size_t size);
|
||||
void nvlist_add_uuid(nvlist_t *nvl, const char *name, const uuid_t *value);
|
||||
|
||||
/*
|
||||
* The nvlist_move functions add the given name/value pair.
|
||||
* The functions consumes provided buffer.
|
||||
*/
|
||||
|
||||
void nvlist_move_string(nvlist_t *nvl, const char *name, char *value);
|
||||
void nvlist_move_nvlist(nvlist_t *nvl, const char *name, nvlist_t *value);
|
||||
void nvlist_move_nvlist_array(nvlist_t *nvl, const char *name, nvlist_t *value);
|
||||
void nvlist_move_nvlist_dictionary(nvlist_t *nvl, const char *name, nvlist_t *value);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_move_descriptor(nvlist_t *nvl, const char *name, int value);
|
||||
#endif
|
||||
void nvlist_move_binary(nvlist_t *nvl, const char *name, void *value, size_t size);
|
||||
void nvlist_move_uuid(nvlist_t *nvl, const char *name, uuid_t *value);
|
||||
|
||||
/*
|
||||
* The nvlist_get functions returns value associated with the given name.
|
||||
* If it returns a pointer, the pointer represents internal buffer and should
|
||||
* not be freed by the caller.
|
||||
*/
|
||||
|
||||
bool nvlist_get_bool(const nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_get_number(const nvlist_t *nvl, const char *name);
|
||||
uintptr_t nvlist_get_ptr(const nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_get_uint64(const nvlist_t *nvl, const char *name);
|
||||
int64_t nvlist_get_int64(const nvlist_t *nvl, const char *name);
|
||||
int nvlist_get_endpoint(const nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_get_date(const nvlist_t *nvl, const char *name);
|
||||
|
||||
const char *nvlist_get_string(const nvlist_t *nvl, const char *name);
|
||||
const nvlist_t *nvlist_get_nvlist(const nvlist_t *nvl, const char *name);
|
||||
const nvlist_t *nvlist_get_nvlist_array(const nvlist_t *nvl, const char *name);
|
||||
const nvlist_t *nvlist_get_nvlist_dictionary(const nvlist_t *nvl, const char *name);
|
||||
#ifndef _KERNEL
|
||||
int nvlist_get_descriptor(const nvlist_t *nvl, const char *name);
|
||||
#endif
|
||||
const void *nvlist_get_binary(const nvlist_t *nvl, const char *name, size_t *sizep);
|
||||
const uuid_t *nvlist_get_uuid(const nvlist_t *nvl, const char *name);
|
||||
|
||||
/*
|
||||
* The nvlist_take functions returns value associated with the given name and
|
||||
* remove the given entry from the nvlist.
|
||||
* The caller is responsible for freeing received data.
|
||||
*/
|
||||
|
||||
bool nvlist_take_bool(nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_take_number(nvlist_t *nvl, const char *name);
|
||||
uintptr_t nvlist_take_ptr(nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_take_uint64(nvlist_t *nvl, const char *name);
|
||||
int64_t nvlist_take_int64(nvlist_t *nvl, const char *name);
|
||||
int nvlist_take_endpoint(nvlist_t *nvl, const char *name);
|
||||
uint64_t nvlist_take_date(nvlist_t *nvl, const char *name);
|
||||
char *nvlist_take_string(nvlist_t *nvl, const char *name);
|
||||
nvlist_t *nvlist_take_nvlist(nvlist_t *nvl, const char *name);
|
||||
nvlist_t *nvlist_take_nvlist_array(nvlist_t *nvl, const char *name);
|
||||
nvlist_t *nvlist_take_nvlist_dictionary(nvlist_t *nvl, const char *name);
|
||||
|
||||
#ifndef _KERNEL
|
||||
int nvlist_take_descriptor(nvlist_t *nvl, const char *name);
|
||||
#endif
|
||||
void *nvlist_take_binary(nvlist_t *nvl, const char *name, size_t *sizep);
|
||||
uuid_t *nvlist_take_uuid(nvlist_t *nvl, const char *name);
|
||||
|
||||
/*
|
||||
* The nvlist_free functions removes the given name/value pair from the nvlist
|
||||
* and frees memory associated with it.
|
||||
*/
|
||||
|
||||
void nvlist_free(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_type(nvlist_t *nvl, const char *name, int type);
|
||||
|
||||
void nvlist_free_null(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_bool(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_number(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_ptr(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_uint64(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_int64(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_endpoint(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_date(nvlist_t *nvl, const char *name);
|
||||
|
||||
void nvlist_free_string(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_nvlist(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_nvlist_array(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_nvlist_dictionary(nvlist_t *nvl, const char *name);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_free_descriptor(nvlist_t *nvl, const char *name);
|
||||
#endif
|
||||
void nvlist_free_binary(nvlist_t *nvl, const char *name);
|
||||
void nvlist_free_uuid(nvlist_t *nvl, const char *name);
|
||||
|
||||
/*
|
||||
* Below are the same functions, but which operate on format strings and
|
||||
* variable argument lists.
|
||||
*
|
||||
* Functions that are not inserting a new pair into the nvlist cannot handle
|
||||
* a failure to allocate the memory to hold the new name. Therefore these
|
||||
* functions are not provided in the kernel.
|
||||
*/
|
||||
|
||||
#ifndef _KERNEL
|
||||
bool nvlist_existsf(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_type(const nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
|
||||
|
||||
bool nvlist_existsf_null(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_ptr(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_uint64(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_int64(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_endpoint(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_date(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_nvlist_array(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_nvlist_dictionary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_binary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
bool nvlist_existsf_uuid(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
bool nvlist_existsv(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_type(const nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
|
||||
bool nvlist_existsv_null(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_ptr(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_uint64(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_int64(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_endpoint(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_date(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_nvlist_array(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_nvlist_dictionary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_binary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
bool nvlist_existsv_uuid(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
#endif
|
||||
|
||||
void nvlist_addf_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_addf_bool(nvlist_t *nvl, bool value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_number(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_ptr(nvlist_t *nvl, uintptr_t value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_uint64(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_int64(nvlist_t *nvl, int64_t value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_endpoint(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_date(nvlist_t *nvl, uint64_t value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_string(nvlist_t *nvl, const char *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_nvlist_array(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_addf_nvlist_dictionary(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_addf_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
|
||||
#endif
|
||||
void nvlist_addf_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
|
||||
void nvlist_addf_uuid(nvlist_t *nvl, const uuid_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
|
||||
#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED)
|
||||
void nvlist_addv_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_addv_bool(nvlist_t *nvl, bool value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_number(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_ptr(nvlist_t *nvl, uintptr_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_uint64(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_int64(nvlist_t *nvl, int64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_endpoint(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_date(nvlist_t *nvl, uint64_t value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_string(nvlist_t *nvl, const char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_nvlist(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_nvlist_array(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_addv_nvlist_dictionary(nvlist_t *nvl, const nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_addv_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#endif
|
||||
void nvlist_addv_binary(nvlist_t *nvl, const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
|
||||
void nvlist_addv_uuid(nvlist_t *nvl, const uuid_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#endif
|
||||
|
||||
void nvlist_movef_string(nvlist_t *nvl, char *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_movef_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_movef_nvlist_array(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
void nvlist_movef_nvlist_dictionary(nvlist_t *nvl, nvlist_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_movef_descriptor(nvlist_t *nvl, int value, const char *namefmt, ...) __printflike(3, 4);
|
||||
#endif
|
||||
void nvlist_movef_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, ...) __printflike(4, 5);
|
||||
void nvlist_movef_uuid(nvlist_t *nvl, uuid_t *value, const char *namefmt, ...) __printflike(3, 4);
|
||||
|
||||
#if !defined(_KERNEL) || defined(_VA_LIST_DECLARED)
|
||||
void nvlist_movev_string(nvlist_t *nvl, char *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_movev_nvlist(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_movev_nvlist_array(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
void nvlist_movev_nvlist_dictionary(nvlist_t *nvl, nvlist_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#ifndef _KERNEL
|
||||
void nvlist_movev_descriptor(nvlist_t *nvl, int value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#endif
|
||||
void nvlist_movev_binary(nvlist_t *nvl, void *value, size_t size, const char *namefmt, va_list nameap) __printflike(4, 0);
|
||||
void nvlist_movev_uuid(nvlist_t *nvl, uuid_t *value, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
#endif
|
||||
|
||||
#ifndef _KERNEL
|
||||
bool nvlist_getf_bool(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_getf_number(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uintptr_t nvlist_getf_ptr(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_getf_uint64(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int64_t nvlist_getf_int64(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int nvlist_getf_endpoint(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_getf_date(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
const char *nvlist_getf_string(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
const nvlist_t *nvlist_getf_nvlist(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
const nvlist_t *nvlist_getf_nvlist_array(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
const nvlist_t *nvlist_getf_nvlist_dictionary(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int nvlist_getf_descriptor(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
const void *nvlist_getf_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
|
||||
const uuid_t *nvlist_getf_uuid(const nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
bool nvlist_getv_bool(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_getv_number(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uintptr_t nvlist_getv_ptr(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_getv_uint64(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int64_t nvlist_getv_int64(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int nvlist_getv_endpoint(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_getv_date(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
const char *nvlist_getv_string(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
const nvlist_t *nvlist_getv_nvlist(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
const nvlist_t *nvlist_getv_nvlist_array(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
const nvlist_t *nvlist_getv_nvlist_dictionary(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int nvlist_getv_descriptor(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
const void *nvlist_getv_binary(const nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
const uuid_t *nvlist_getv_uuid(const nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
|
||||
bool nvlist_takef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_takef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uintptr_t nvlist_takef_ptr(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_takef_uint64(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int64_t nvlist_takef_int64(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int nvlist_takef_endpoint(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
uint64_t nvlist_takef_date(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
char *nvlist_takef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvlist_t *nvlist_takef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvlist_t *nvlist_takef_nvlist_array(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvlist_t *nvlist_takef_nvlist_dictionary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
int nvlist_takef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void *nvlist_takef_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, ...) __printflike(3, 4);
|
||||
uuid_t *nvlist_takef_uuid(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
bool nvlist_takev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_takev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uintptr_t nvlist_takev_ptr(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_takev_uint64(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int64_t nvlist_takev_int64(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int nvlist_takev_endpoint(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
uint64_t nvlist_takev_date(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
char *nvlist_takev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvlist_t *nvlist_takev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvlist_t *nvlist_takev_nvlist_array(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvlist_t *nvlist_takev_nvlist_dictionary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
int nvlist_takev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void *nvlist_takev_binary(nvlist_t *nvl, size_t *sizep, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
uuid_t *nvlist_takev_uuid(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
|
||||
void nvlist_freef(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_type(nvlist_t *nvl, int type, const char *namefmt, ...) __printflike(3, 4);
|
||||
|
||||
void nvlist_freef_null(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_bool(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_number(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_ptr(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_uint64(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_int64(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_endpoint(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_date(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_string(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_nvlist(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_nvlist_array(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_nvlist_dictionary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_descriptor(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_binary(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
void nvlist_freef_uuid(nvlist_t *nvl, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
void nvlist_freev(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_type(nvlist_t *nvl, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
|
||||
void nvlist_freev_null(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_bool(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_number(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_ptr(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_uint64(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_int64(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_endpoint(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_date(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_string(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_nvlist(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_nvlist_array(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_nvlist_dictionary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_descriptor(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_binary(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
void nvlist_freev_uuid(nvlist_t *nvl, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
#endif /* _KERNEL */
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_NV_H_ */
|
172
nv_impl.h
172
nv_impl.h
@ -1,172 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2013 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NV_IMPL_H_
|
||||
#define _NV_IMPL_H_
|
||||
|
||||
#ifndef _NVPAIR_T_DECLARED
|
||||
#define _NVPAIR_T_DECLARED
|
||||
struct nvpair;
|
||||
|
||||
typedef struct nvpair nvpair_t;
|
||||
#endif
|
||||
|
||||
#define NV_TYPE_NVLIST_UP 255
|
||||
|
||||
#define NV_TYPE_FIRST NV_TYPE_NULL
|
||||
#define NV_TYPE_LAST NV_TYPE_NVLIST_DICTIONARY
|
||||
|
||||
#define NV_TYPE_NUMBER_MIN NV_TYPE_NUMBER
|
||||
#define NV_TYPE_NUMBER_MAX NV_TYPE_ENDPOINT
|
||||
#define NV_TYPE_NVLIST_MIN NV_TYPE_NVLIST
|
||||
#define NV_TYPE_NVLIST_MAX NV_TYPE_NVLIST_DICTIONARY
|
||||
|
||||
|
||||
|
||||
#define NV_FLAG_BIG_ENDIAN 0x80
|
||||
|
||||
#ifdef _KERNEL
|
||||
#define nv_malloc(size) malloc((size), M_NVLIST, M_NOWAIT)
|
||||
#define nv_calloc(n, size) malloc((n) * (size), M_NVLIST, \
|
||||
M_NOWAIT | M_ZERO)
|
||||
#define nv_realloc(buf, size) realloc((buf), (size), M_NVLIST, \
|
||||
M_NOWAIT)
|
||||
#define nv_free(buf) free((buf), M_NVLIST)
|
||||
#define nv_strdup(buf) strdup((buf), M_NVLIST)
|
||||
#define nv_vasprintf(ptr, ...) vasprintf(ptr, M_NVLIST, __VA_ARGS__)
|
||||
|
||||
#define SAVE_ERRNO(var) ((void)(var))
|
||||
#define RESTORE_ERRNO(var) ((void)(var))
|
||||
|
||||
#define ERRNO_OR_DEFAULT(default) (default)
|
||||
|
||||
#else
|
||||
|
||||
#define nv_malloc(size) malloc((size))
|
||||
#define nv_calloc(n, size) calloc((n), (size))
|
||||
#define nv_realloc(buf, size) realloc((buf), (size))
|
||||
#define nv_free(buf) free((buf))
|
||||
#define nv_strdup(buf) strdup((buf))
|
||||
#define nv_vasprintf(ptr, ...) vasprintf(ptr, __VA_ARGS__)
|
||||
|
||||
#define SAVE_ERRNO(var) (var) = errno
|
||||
#define RESTORE_ERRNO(var) errno = (var)
|
||||
|
||||
#define ERRNO_OR_DEFAULT(default) (errno == 0 ? (default) : errno)
|
||||
|
||||
#endif
|
||||
|
||||
int *nvlist_descriptors(const nvlist_t *nvl, size_t *nitemsp);
|
||||
size_t nvlist_ndescriptors(const nvlist_t *nvl);
|
||||
|
||||
nvpair_t *nvlist_first_nvpair(const nvlist_t *nvl);
|
||||
nvpair_t *nvlist_next_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
|
||||
nvpair_t *nvlist_prev_nvpair(const nvlist_t *nvl, const nvpair_t *nvp);
|
||||
|
||||
void nvlist_add_nvpair(nvlist_t *nvl, const nvpair_t *nvp);
|
||||
|
||||
void nvlist_move_nvpair(nvlist_t *nvl, nvpair_t *nvp);
|
||||
|
||||
void nvlist_set_parent(nvlist_t *nvl, nvpair_t *parent);
|
||||
|
||||
const nvpair_t *nvlist_get_nvpair(const nvlist_t *nvl, const char *name);
|
||||
|
||||
nvpair_t *nvlist_take_nvpair(nvlist_t *nvl, const char *name);
|
||||
|
||||
/* Function removes the given nvpair from the nvlist. */
|
||||
void nvlist_remove_nvpair(nvlist_t *nvl, nvpair_t *nvp);
|
||||
|
||||
void nvlist_free_nvpair(nvlist_t *nvl, nvpair_t *nvp);
|
||||
|
||||
int nvpair_type(const nvpair_t *nvp);
|
||||
const char *nvpair_name(const nvpair_t *nvp);
|
||||
|
||||
nvpair_t *nvpair_clone(const nvpair_t *nvp);
|
||||
|
||||
nvpair_t *nvpair_create_null(const char *name);
|
||||
nvpair_t *nvpair_create_bool(const char *name, bool value);
|
||||
nvpair_t *nvpair_create_number_type(const char *name, uint64_t value, int type);
|
||||
nvpair_t *nvpair_create_string(const char *name, const char *value);
|
||||
nvpair_t *nvpair_create_stringf(const char *name, const char *valuefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_create_stringv(const char *name, const char *valuefmt, va_list valueap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_create_nvlist_type(const char *name, const nvlist_t *value, int type);
|
||||
nvpair_t *nvpair_create_descriptor(const char *name, int value);
|
||||
nvpair_t *nvpair_create_binary(const char *name, const void *value, size_t size);
|
||||
nvpair_t *nvpair_create_uuid(const char *name, const uuid_t *value);
|
||||
|
||||
nvpair_t *nvpair_move_string(const char *name, char *value);
|
||||
nvpair_t *nvpair_move_nvlist(const char *name, nvlist_t *value);
|
||||
nvpair_t *nvpair_move_nvlist_type(const char *name, nvlist_t *value, int type);
|
||||
nvpair_t *nvpair_move_descriptor(const char *name, int value);
|
||||
nvpair_t *nvpair_move_binary(const char *name, void *value, size_t size);
|
||||
nvpair_t *nvpair_move_uuid(const char *name, uuid_t *value);
|
||||
|
||||
bool nvpair_get_bool(const nvpair_t *nvp);
|
||||
uint64_t nvpair_get_number(const nvpair_t *nvp);
|
||||
const char *nvpair_get_string(const nvpair_t *nvp);
|
||||
const nvlist_t *nvpair_get_nvlist(const nvpair_t *nvp);
|
||||
int nvpair_get_descriptor(const nvpair_t *nvp);
|
||||
const void *nvpair_get_binary(const nvpair_t *nvp, size_t *sizep);
|
||||
const uuid_t *nvpair_get_uuid(const nvpair_t *nvp);
|
||||
|
||||
void nvpair_free(nvpair_t *nvp);
|
||||
|
||||
nvpair_t *nvpair_createf_null(const char *namefmt, ...) __printflike(1, 2);
|
||||
nvpair_t *nvpair_createf_bool(bool value, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_createf_number_type(uint64_t value, int type, const char *namefmt, ...) __printflike(3, 4);
|
||||
nvpair_t *nvpair_createf_string(const char *value, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_createf_nvlist_type(const nvlist_t *value, int type, const char *namefmt, ...) __printflike(3, 4);
|
||||
nvpair_t *nvpair_createf_descriptor(int value, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_createf_binary(const void *value, size_t size, const char *namefmt, ...) __printflike(3, 4);
|
||||
nvpair_t *nvpair_createf_uuid(const uuid_t *value, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
nvpair_t *nvpair_createv_null(const char *namefmt, va_list nameap) __printflike(1, 0);
|
||||
nvpair_t *nvpair_createv_bool(bool value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_createv_number_type(uint64_t value, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
nvpair_t *nvpair_createv_string(const char *value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_createv_nvlist_type(const nvlist_t *value, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
nvpair_t *nvpair_createv_descriptor(int value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_createv_binary(const void *value, size_t size, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
nvpair_t *nvpair_createv_uuid(const uuid_t *value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
|
||||
nvpair_t *nvpair_movef_string(char *value, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_movef_nvlist_type(nvlist_t *value, int type, const char *namefmt, ...) __printflike(3, 4);
|
||||
nvpair_t *nvpair_movef_descriptor(int value, const char *namefmt, ...) __printflike(2, 3);
|
||||
nvpair_t *nvpair_movef_binary(void *value, size_t size, const char *namefmt, ...) __printflike(3, 4);
|
||||
nvpair_t *nvpair_movef_uuid(uuid_t *value, const char *namefmt, ...) __printflike(2, 3);
|
||||
|
||||
nvpair_t *nvpair_movev_string(char *value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_movev_nvlist_type(nvlist_t *value, int type, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
nvpair_t *nvpair_movev_descriptor(int value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
nvpair_t *nvpair_movev_binary(void *value, size_t size, const char *namefmt, va_list nameap) __printflike(3, 0);
|
||||
nvpair_t *nvpair_movev_uuid(uuid_t *value, const char *namefmt, va_list nameap) __printflike(2, 0);
|
||||
|
||||
#endif /* !_NV_IMPL_H_ */
|
@ -1,49 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2013 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NVLIST_IMPL_H_
|
||||
#define _NVLIST_IMPL_H_
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "nv.h"
|
||||
|
||||
void *nvlist_xpack(const nvlist_t *nvl, void *ubuf, int64_t *fdidxp, size_t *sizep);
|
||||
nvlist_t *nvlist_xunpack(const void *buf, size_t size, const int *fds,
|
||||
size_t nfds);
|
||||
|
||||
nvpair_t *nvlist_get_nvpair_parent(const nvlist_t *nvl);
|
||||
const unsigned char *nvlist_unpack_header(nvlist_t *nvl,
|
||||
const unsigned char *ptr, size_t nfds, bool *isbep, size_t *leftp);
|
||||
|
||||
#endif /* !_NVLIST_IMPL_H_ */
|
@ -1,94 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2013 The FreeBSD Foundation
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by Pawel Jakub Dawidek under sponsorship from
|
||||
* the FreeBSD Foundation.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _NVPAIR_IMPL_H_
|
||||
#define _NVPAIR_IMPL_H_
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
#ifndef _KERNEL
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#include "nv.h"
|
||||
|
||||
TAILQ_HEAD(nvl_head, nvpair);
|
||||
|
||||
void nvpair_assert(const nvpair_t *nvp);
|
||||
nvlist_t *nvpair_nvlist(const nvpair_t *nvp);
|
||||
nvpair_t *nvpair_next(const nvpair_t *nvp);
|
||||
nvpair_t *nvpair_prev(const nvpair_t *nvp);
|
||||
void nvpair_insert(struct nvl_head *head, nvpair_t *nvp, nvlist_t *nvl);
|
||||
void nvpair_remove(struct nvl_head *head, nvpair_t *nvp, const nvlist_t *nvl);
|
||||
size_t nvpair_header_size(void);
|
||||
size_t nvpair_size(const nvpair_t *nvp);
|
||||
const unsigned char *nvpair_unpack(bool isbe, const unsigned char *ptr,
|
||||
size_t *leftp, nvpair_t **nvpp);
|
||||
void nvpair_free_structure(nvpair_t *nvp);
|
||||
void nvpair_init_datasize(nvpair_t *nvp);
|
||||
const char *nvpair_type_string(int type);
|
||||
|
||||
/* Pack functions. */
|
||||
unsigned char *nvpair_pack_header(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_null(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_bool(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_number(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_string(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_descriptor(const nvpair_t *nvp, unsigned char *ptr,
|
||||
int64_t *fdidxp, size_t *leftp);
|
||||
unsigned char *nvpair_pack_binary(const nvpair_t *nvp, unsigned char *ptr,
|
||||
size_t *leftp);
|
||||
unsigned char *nvpair_pack_nvlist_up(unsigned char *ptr, size_t *leftp);
|
||||
|
||||
/* Unpack data functions. */
|
||||
const unsigned char *nvpair_unpack_header(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
const unsigned char *nvpair_unpack_null(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
const unsigned char *nvpair_unpack_bool(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
const unsigned char *nvpair_unpack_number(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
const unsigned char *nvpair_unpack_string(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
const unsigned char *nvpair_unpack_nvlist(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp, size_t nvlist, nvlist_t **child);
|
||||
const unsigned char *nvpair_unpack_descriptor(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp, const int *fds, size_t nfds);
|
||||
const unsigned char *nvpair_unpack_binary(bool isbe, nvpair_t *nvp,
|
||||
const unsigned char *ptr, size_t *leftp);
|
||||
|
||||
#endif /* !_NVPAIR_IMPL_H_ */
|
2578
subr_nvlist.c
2578
subr_nvlist.c
File diff suppressed because it is too large
Load Diff
1506
subr_nvpair.c
1506
subr_nvpair.c
File diff suppressed because it is too large
Load Diff
@ -85,6 +85,7 @@ xpc_array_append_value(xpc_object_t xarray, xpc_object_t value)
|
||||
|
||||
TAILQ_INSERT_TAIL(arr, (struct xpc_object *)value, xo_link);
|
||||
xpc_retain(value);
|
||||
++xo->xo_size;
|
||||
}
|
||||
|
||||
|
||||
|
198
xpc_dictionary.c
198
xpc_dictionary.c
@ -32,203 +32,6 @@
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
#define NVLIST_XPC_TYPE "__XPC_TYPE"
|
||||
|
||||
static void xpc2nv_primitive(nvlist_t *nv, const char *key, xpc_object_t value);
|
||||
|
||||
__private_extern__ void
|
||||
nv_release_entry(nvlist_t *nv, const char *key)
|
||||
{
|
||||
xpc_object_t tmp;
|
||||
|
||||
if (nvlist_exists_type(nv, key, NV_TYPE_PTR)) {
|
||||
tmp = (void *)nvlist_take_number(nv, key);
|
||||
xpc_release(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
struct xpc_object *
|
||||
nv2xpc(const nvlist_t *nv)
|
||||
{
|
||||
struct xpc_object *xo = NULL, *xotmp = NULL;
|
||||
void *cookiep;
|
||||
const char *key;
|
||||
int type;
|
||||
xpc_u val;
|
||||
const nvlist_t *nvtmp;
|
||||
|
||||
assert(nvlist_type(nv) == NV_TYPE_NVLIST_DICTIONARY ||
|
||||
nvlist_type(nv) == NV_TYPE_NVLIST_ARRAY);
|
||||
|
||||
if (nvlist_type(nv) == NV_TYPE_NVLIST_DICTIONARY)
|
||||
xo = xpc_dictionary_create(NULL, NULL, 0);
|
||||
|
||||
if (nvlist_type(nv) == NV_TYPE_NVLIST_ARRAY)
|
||||
xo = xpc_array_create(NULL, 0);
|
||||
|
||||
cookiep = NULL;
|
||||
while ((key = nvlist_next(nv, &type, &cookiep)) != NULL) {
|
||||
xotmp = NULL;
|
||||
|
||||
switch (type) {
|
||||
case NV_TYPE_BOOL:
|
||||
val.b = nvlist_get_bool(nv, key);
|
||||
xotmp = xpc_bool_create(val.b);
|
||||
break;
|
||||
|
||||
case NV_TYPE_STRING:
|
||||
val.str = nvlist_get_string(nv, key);
|
||||
xotmp = xpc_string_create(val.str);
|
||||
break;
|
||||
|
||||
case NV_TYPE_INT64:
|
||||
val.i = nvlist_get_int64(nv, key);
|
||||
xotmp = xpc_int64_create(val.i);
|
||||
break;
|
||||
|
||||
case NV_TYPE_UINT64:
|
||||
val.ui = nvlist_get_uint64(nv, key);
|
||||
xotmp = xpc_uint64_create(val.ui);
|
||||
break;
|
||||
|
||||
case NV_TYPE_DESCRIPTOR:
|
||||
val.fd = nvlist_get_descriptor(nv, key);
|
||||
xotmp = _xpc_prim_create(_XPC_TYPE_FD, val, 0);
|
||||
break;
|
||||
|
||||
case NV_TYPE_PTR:
|
||||
break;
|
||||
|
||||
case NV_TYPE_BINARY:
|
||||
break;
|
||||
|
||||
case NV_TYPE_UUID:
|
||||
memcpy(&val.uuid, nvlist_get_uuid(nv, key),
|
||||
sizeof(uuid_t));
|
||||
xotmp = _xpc_prim_create(_XPC_TYPE_UUID, val, 0);
|
||||
|
||||
case NV_TYPE_NVLIST_ARRAY:
|
||||
nvtmp = nvlist_get_nvlist_array(nv, key);
|
||||
xotmp = nv2xpc(nvtmp);
|
||||
break;
|
||||
|
||||
case NV_TYPE_NVLIST_DICTIONARY:
|
||||
nvtmp = nvlist_get_nvlist_dictionary(nv, key);
|
||||
xotmp = nv2xpc(nvtmp);
|
||||
break;
|
||||
}
|
||||
|
||||
if (xotmp) {
|
||||
if (nvlist_type(nv) == NV_TYPE_NVLIST_DICTIONARY)
|
||||
xpc_dictionary_set_value(xo, key, xotmp);
|
||||
|
||||
if (nvlist_type(nv) == NV_TYPE_NVLIST_ARRAY)
|
||||
xpc_array_append_value(xo, xotmp);
|
||||
}
|
||||
}
|
||||
|
||||
return (xo);
|
||||
}
|
||||
|
||||
static void
|
||||
xpc2nv_primitive(nvlist_t *nv, const char *key, xpc_object_t value)
|
||||
{
|
||||
struct xpc_object *xotmp = value;
|
||||
|
||||
switch (xotmp->xo_xpc_type) {
|
||||
case _XPC_TYPE_DICTIONARY:
|
||||
nvlist_add_nvlist_dictionary(nv, key, xpc2nv(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_ARRAY:
|
||||
nvlist_add_nvlist_array(nv, key, xpc2nv(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_BOOL:
|
||||
nvlist_add_bool(nv, key, xpc_bool_get_value(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_CONNECTION:
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_ENDPOINT:
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_INT64:
|
||||
nvlist_add_int64(nv, key, xpc_int64_get_value(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_UINT64:
|
||||
nvlist_add_uint64(nv, key, xpc_uint64_get_value(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_DATE:
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_DATA:
|
||||
nvlist_add_binary(nv, key,
|
||||
xpc_data_get_bytes_ptr(xotmp),
|
||||
xpc_data_get_length(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_STRING:
|
||||
nvlist_add_string(nv, key,
|
||||
xpc_string_get_string_ptr(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_UUID:
|
||||
nvlist_add_uuid(nv, key, (uuid_t*)xpc_uuid_get_bytes(xotmp));
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_FD:
|
||||
nvlist_add_descriptor(nv, key, xotmp->xo_fd);
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_SHMEM:
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_ERROR:
|
||||
break;
|
||||
|
||||
case _XPC_TYPE_DOUBLE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
nvlist_t *
|
||||
xpc2nv(struct xpc_object *xo)
|
||||
{
|
||||
nvlist_t *nv;
|
||||
struct xpc_object *xotmp;
|
||||
|
||||
if (xo->xo_xpc_type == _XPC_TYPE_DICTIONARY) {
|
||||
nv = nvlist_create_dictionary(0);
|
||||
debugf("nv = %p\n", nv);
|
||||
xpc_dictionary_apply(xo, ^(const char *k, xpc_object_t v) {
|
||||
xpc2nv_primitive(nv, k, v);
|
||||
return ((bool)true);
|
||||
});
|
||||
|
||||
return nv;
|
||||
}
|
||||
|
||||
if (xo->xo_xpc_type == _XPC_TYPE_ARRAY) {
|
||||
char *key = NULL;
|
||||
nv = nvlist_create_array(0);
|
||||
xpc_array_apply(xo, ^(size_t index, xpc_object_t v) {
|
||||
asprintf(&key, "%ld", index);
|
||||
xpc2nv_primitive(nv, key, v);
|
||||
free(key);
|
||||
return ((bool)true);
|
||||
});
|
||||
|
||||
return nv;
|
||||
}
|
||||
|
||||
assert(0 && "xpc_object not array or dictionary");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
xpc_object_t
|
||||
xpc_dictionary_create(const char * const *keys, const xpc_object_t *values,
|
||||
size_t count)
|
||||
@ -249,7 +52,6 @@ xpc_object_t
|
||||
xpc_dictionary_create_reply(xpc_object_t original)
|
||||
{
|
||||
struct xpc_object *xo, *xo_orig;
|
||||
nvlist_t *nv;
|
||||
xpc_u val;
|
||||
|
||||
if (xpc_get_type(original) != XPC_TYPE_DICTIONARY)
|
||||
|
@ -30,7 +30,6 @@
|
||||
|
||||
#include <sys/queue.h>
|
||||
#include "xpc/xpc.h"
|
||||
#include <nv.h>
|
||||
|
||||
#ifdef XPC_DEBUG
|
||||
#define debugf(...) \
|
||||
@ -150,7 +149,6 @@ struct xpc_service {
|
||||
TAILQ_HEAD(, xpc_connection) xs_connections;
|
||||
};
|
||||
|
||||
#define xo_nv xo_u.nv
|
||||
#define xo_str xo_u.str
|
||||
#define xo_bool xo_u.b
|
||||
#define xo_uint xo_u.ui
|
||||
@ -170,8 +168,6 @@ __private_extern__ struct xpc_object *_xpc_prim_create(int type, xpc_u value,
|
||||
__private_extern__ struct xpc_object *_xpc_prim_create_flags(int type,
|
||||
xpc_u value, size_t size, uint16_t flags);
|
||||
__private_extern__ const char *_xpc_get_type_name(xpc_object_t obj);
|
||||
__private_extern__ struct xpc_object *nv2xpc(const nvlist_t *nv);
|
||||
__private_extern__ nvlist_t *xpc2nv(struct xpc_object *xo);
|
||||
__private_extern__ void xpc_object_destroy(struct xpc_object *xo);
|
||||
__private_extern__ int xpc_pipe_send(xpc_object_t obj, mach_port_t dst,
|
||||
mach_port_t local, uint64_t id);
|
||||
|
476
xpc_misc.c
476
xpc_misc.c
@ -37,6 +37,7 @@
|
||||
#include <uuid/uuid.h>
|
||||
#include <stdio.h>
|
||||
#include "xpc_internal.h"
|
||||
#include <libkern/OSByteOrder.h>
|
||||
|
||||
#define RECV_BUFFER_SIZE 65536
|
||||
|
||||
@ -82,8 +83,6 @@ fail_log(const char *exp)
|
||||
//abort();
|
||||
}
|
||||
|
||||
static void nvlist_add_prim(nvlist_t *nv, const char *key, xpc_object_t xobj);
|
||||
|
||||
static void
|
||||
xpc_dictionary_destroy(struct xpc_object *dict)
|
||||
{
|
||||
@ -114,40 +113,457 @@ xpc_array_destroy(struct xpc_object *dict)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
xpc_pack(struct xpc_object *xo, void *buf, size_t *size)
|
||||
{
|
||||
nvlist_t *nv;
|
||||
void *packed;
|
||||
/**
|
||||
* encoded buffer layout for different types:
|
||||
* dictionary = { 0x01, { key, encode_entry(encode_size(sizeof(value))?, value) }... }
|
||||
* array = { 0x02, encode_entry(encode_size(sizeof(entry))?, entry)... }
|
||||
* bool = { 0x03 | ((value ? 0x01 : 0x00) << XPC_PACK_TYPE_BITS) }
|
||||
* connection = { 0x04 }
|
||||
* endpoint = { 0x05 }
|
||||
* null = { 0x06 }
|
||||
* activity = { 0x07 }
|
||||
* int64 = { encode_int(0x08, value, sizeof(int64_t)) }
|
||||
* uint64 = { encode_int(0x09, value, sizeof(uint64_t)) }
|
||||
* date = { encode_int(0x0a, value, sizeof(int64_t)) }
|
||||
* data = { 0x0b, values... }
|
||||
* string = { 0x0c, bytes... }
|
||||
* uuid = { encode_int(0x0d, value, 16) }
|
||||
* fd = { encode_int(0x0e, value, sizeof(int)) }
|
||||
* shmem = { 0x0f }
|
||||
* error = { 0x10 }
|
||||
* double = { encode_int(0x11, value, sizeof(double)) }
|
||||
*
|
||||
* where:
|
||||
* sizeof(x) = length of x in bytes
|
||||
* encode_int(type, x, max_bytes) = encodes the provided integer into the minimum number of bytes
|
||||
* possible. the high bit on each byte specifies whether the value has another byte.
|
||||
* an optimization is made that uses the unused bits in the type byte to encode the value.
|
||||
* encodes in little-endian.
|
||||
* encode_size(x) = encodes the provided integer into the minimum number of bytes
|
||||
* possible, much like `encode_int`. the difference is that it doesn't automatically
|
||||
* encode the type into the first byte.
|
||||
* encodes in little-endian.
|
||||
* encode_entry(size, value) = if the value is variable-length type:
|
||||
* { size[0] | value[0], size[1..], value[1..] }
|
||||
* otherwise:
|
||||
* { value }
|
||||
*
|
||||
* notes:
|
||||
* * integral values are laid out in little-endian
|
||||
* * many types that have variable length do not automatically include a stated length
|
||||
* * this is done to save precious bytes
|
||||
* * the only time size is explicitly specified is when variable-size structures are used
|
||||
* inside other variable-size structures (e.g. dictionary in an array, data in a dictionary, array in an array, etc.).
|
||||
* * this rule does *not* apply to strings and integral values, as they are technically not considered "variable-length"
|
||||
* * strings are null-terminated, so it's obvious when you've reached their end
|
||||
* * integral values encoded with encode_int likewise also already carry an indiciation
|
||||
* of their length as part of their format
|
||||
* * there may have been additional size optimization that could've been made that i didn't know about,
|
||||
* but i was also trying to find a balance between size-efficiency, computational-efficiency, and simplicity.
|
||||
*/
|
||||
|
||||
nv = xpc2nv(xo);
|
||||
#define XPC_PACK_TYPE_MASK 0x1f
|
||||
#define XPC_PACK_TYPE_BITS 5
|
||||
#define XPC_PACK_INT_INITIAL_BITS (8 - (XPC_PACK_TYPE_BITS + 1))
|
||||
#define XPC_PACK_INT_EXTRA_BYTES(x) (((x - (8 - XPC_PACK_TYPE_BITS)) + 7) / 8)
|
||||
|
||||
packed = nvlist_pack_buffer(nv, NULL, size);
|
||||
if (packed == NULL) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
XPC_INLINE bool xpc_pack_is_variable_length(uint8_t xo_xpc_type) {
|
||||
return xo_xpc_type == _XPC_TYPE_DICTIONARY || xo_xpc_type == _XPC_TYPE_ARRAY || xo_xpc_type == _XPC_TYPE_DATA;
|
||||
};
|
||||
|
||||
XPC_INLINE uint8_t xpc_pack_generate_mask(uint8_t bits, bool least_significant) {
|
||||
static const uint8_t lookup_table[] = {
|
||||
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff,
|
||||
};
|
||||
return lookup_table[bits] >> (least_significant ? (8 - bits) : 0);
|
||||
};
|
||||
|
||||
// buf must be little-endian
|
||||
XPC_INLINE size_t xpc_pack_encode_int_bits(const uint8_t* buf, size_t buf_size, bool raw) {
|
||||
while (buf_size > 0 && buf[buf_size - 1] == 0)
|
||||
--buf_size;
|
||||
|
||||
if (buf_size == 0)
|
||||
return 0;
|
||||
|
||||
uint8_t msb = buf[buf_size - 1];
|
||||
size_t leading_bit_count = 8;
|
||||
for (uint8_t i = 8; i > 0; --i) {
|
||||
if ((msb & (1 << (i - 1))) == 0) {
|
||||
--leading_bit_count;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buf != NULL)
|
||||
memcpy(buf, packed, *size);
|
||||
// number of bits needed for actual number
|
||||
size_t raw_bits = ((buf_size - 1) * 8) + leading_bit_count;
|
||||
|
||||
nvlist_destroy(nv);
|
||||
free(packed);
|
||||
return (0);
|
||||
}
|
||||
if (raw)
|
||||
return raw_bits;
|
||||
|
||||
static struct xpc_object *
|
||||
xpc_unpack(void *buf, size_t size)
|
||||
{
|
||||
struct xpc_object *xo;
|
||||
nvlist_t *nv;
|
||||
if (raw_bits <= XPC_PACK_INT_INITIAL_BITS)
|
||||
return XPC_PACK_INT_INITIAL_BITS + 1;
|
||||
|
||||
nv = nvlist_unpack(buf, size);
|
||||
xo = nv2xpc(nv);
|
||||
return raw_bits + ((raw_bits - XPC_PACK_INT_INITIAL_BITS) / 7) + 1;
|
||||
};
|
||||
|
||||
nvlist_destroy(nv);
|
||||
return (xo);
|
||||
}
|
||||
// buf must be little-endian
|
||||
XPC_INLINE void xpc_pack_encode_int(uint8_t* out, const uint8_t* buf, size_t buf_size) {
|
||||
if (buf_size == 0)
|
||||
return;
|
||||
|
||||
uint8_t initial_mask = xpc_pack_generate_mask(8 - XPC_PACK_TYPE_BITS - 1, true);
|
||||
out[0] = ((buf[0] & initial_mask) << XPC_PACK_TYPE_BITS) | out[0] & XPC_PACK_TYPE_MASK;
|
||||
|
||||
if ((buf[0] & ~initial_mask) == 0)
|
||||
return;
|
||||
|
||||
out[0] |= 1 << 7;
|
||||
|
||||
size_t raw_bits = xpc_pack_encode_int_bits(buf, buf_size, true) - (8 - (XPC_PACK_TYPE_BITS + 1));
|
||||
size_t leftover_bits = XPC_PACK_TYPE_BITS + 1;
|
||||
size_t buf_idx = 0;
|
||||
size_t out_idx = 1;
|
||||
|
||||
for (; raw_bits >= 7; raw_bits -= 7, ++out_idx) {
|
||||
if (leftover_bits == 8) {
|
||||
// 0x7f == 0b01111111
|
||||
out[out_idx] = (1 << 7) | buf[buf_idx] & 0x7f;
|
||||
leftover_bits = 1;
|
||||
} else {
|
||||
uint8_t prev_byte_mask = xpc_pack_generate_mask(leftover_bits, false);
|
||||
uint8_t bits_left_in_encoding_segment = 7 - leftover_bits;
|
||||
uint8_t next_byte_mask = xpc_pack_generate_mask(bits_left_in_encoding_segment, true);
|
||||
out[out_idx] = (1 << 7) | ((buf[buf_idx] & prev_byte_mask) >> (8 - leftover_bits)) | ((buf[buf_idx + 1] & next_byte_mask) << leftover_bits);
|
||||
leftover_bits = 8 - bits_left_in_encoding_segment;
|
||||
++buf_idx;
|
||||
}
|
||||
}
|
||||
|
||||
if (raw_bits == 0) {
|
||||
// no next byte; remove the indicator
|
||||
// 0x7f == 0b01111111
|
||||
out[out_idx - 1] &= 0x7f;
|
||||
} else {
|
||||
uint8_t prev_byte_mask = xpc_pack_generate_mask(leftover_bits, false);
|
||||
out[out_idx] = (buf[buf_idx] & prev_byte_mask) >> (8 - leftover_bits);
|
||||
if (leftover_bits < raw_bits) {
|
||||
uint8_t bits_left_in_encoding_segment = 7 - leftover_bits;
|
||||
uint8_t next_byte_mask = xpc_pack_generate_mask(bits_left_in_encoding_segment, true);
|
||||
out[out_idx] |= (buf[buf_idx + 1] & next_byte_mask) << leftover_bits;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
XPC_INLINE size_t xpc_unpack_decode_int(uint8_t* out, const uint8_t* buf) {
|
||||
// `>> 1` because we don't want to include the most significant bit
|
||||
uint8_t initial_mask = xpc_pack_generate_mask(8 - XPC_PACK_TYPE_BITS - 1, false) >> 1;
|
||||
out[0] = (buf[0] & initial_mask) >> XPC_PACK_TYPE_BITS;
|
||||
|
||||
if ((buf[0] & (1 << 7)) == 0)
|
||||
return 1;
|
||||
|
||||
size_t leftover_bits = XPC_PACK_TYPE_BITS + 1;
|
||||
size_t out_idx = 0;
|
||||
size_t buf_idx = 1;
|
||||
|
||||
while ((buf[buf_idx] & (1 << 7)) != 0) {
|
||||
if (leftover_bits == 8) {
|
||||
// 0x7f == 0b01111111
|
||||
out[out_idx] = buf[buf_idx] & 0x7f;
|
||||
leftover_bits = 1;
|
||||
} else {
|
||||
uint8_t prev_byte_mask = xpc_pack_generate_mask(leftover_bits, true);
|
||||
uint8_t bits_left_in_encoding_segment = 7 - leftover_bits;
|
||||
uint8_t next_byte_mask = xpc_pack_generate_mask(bits_left_in_encoding_segment, false) >> 1;
|
||||
out[out_idx] |= (buf[buf_idx] & prev_byte_mask) << (8 - leftover_bits);
|
||||
out[out_idx + 1] = (buf[buf_idx] & next_byte_mask) >> leftover_bits;
|
||||
leftover_bits = 8 - bits_left_in_encoding_segment;
|
||||
++out_idx;
|
||||
}
|
||||
++buf_idx;
|
||||
}
|
||||
|
||||
uint8_t prev_byte_mask = xpc_pack_generate_mask(leftover_bits, true);
|
||||
uint8_t bits_left_in_encoding_segment = 7 - leftover_bits;
|
||||
uint8_t next_byte_mask = xpc_pack_generate_mask(bits_left_in_encoding_segment, false) >> 1;
|
||||
out[out_idx] |= (buf[buf_idx] & prev_byte_mask) << (8 - leftover_bits);
|
||||
if ((buf[buf_idx] & next_byte_mask) != 0) {
|
||||
out[out_idx + 1] = (buf[buf_idx] & next_byte_mask) >> leftover_bits;
|
||||
}
|
||||
|
||||
return buf_idx + 1;
|
||||
};
|
||||
|
||||
XPC_INLINE int xpc_pack(struct xpc_object* xo, void* buf, size_t* final_size);
|
||||
XPC_INLINE struct xpc_object* xpc_unpack(const void* buf, size_t size, size_t* packed_size, uint8_t declared_type);
|
||||
|
||||
XPC_INLINE void xpc_pack_encode_entry(uint8_t* out, size_t* size, size_t* offset, struct xpc_object* val_xo) {
|
||||
size_t val_size = 0;
|
||||
xpc_pack(val_xo, out ? out + *offset : out, &val_size);
|
||||
if (xpc_pack_is_variable_length(val_xo->xo_xpc_type)) {
|
||||
size_t val_size_le = sizeof(size_t) == 4 ? OSSwapHostToLittleInt32(val_size) : OSSwapHostToLittleInt64(val_size);
|
||||
size_t size_bits = xpc_pack_encode_int_bits(&val_size_le, sizeof(size_t), false);
|
||||
size_t size_size = XPC_PACK_INT_EXTRA_BYTES(size_bits);
|
||||
if (out) {
|
||||
if (size_size > 0 && val_size > 1)
|
||||
memmove(out + *offset + 1 + size_size, out + *offset + 1, val_size);
|
||||
xpc_pack_encode_int(out + *offset, &val_size_le, sizeof(size_t));
|
||||
}
|
||||
*size += size_size;
|
||||
if (out)
|
||||
*offset += size_size;
|
||||
}
|
||||
*size += val_size;
|
||||
if (out)
|
||||
*offset += val_size;
|
||||
};
|
||||
|
||||
XPC_INLINE struct xpc_object* xpc_unpack_decode_entry(const uint8_t* in, size_t size, size_t* offset) {
|
||||
struct xpc_object* xo = NULL;
|
||||
uint8_t value_type = in[*offset] & XPC_PACK_TYPE_MASK;
|
||||
size_t val_packed_size = 0;
|
||||
if (xpc_pack_is_variable_length(value_type)) {
|
||||
size_t val_size_le = 0;
|
||||
// `- 1` because part of the size is encoded into the type byte
|
||||
size_t val_size_size = xpc_unpack_decode_int(&val_size_le, in + *offset) - 1;
|
||||
size_t val_size = sizeof(size_t) == 4 ? OSSwapLittleToHostInt32(val_size_le) : OSSwapLittleToHostInt64(val_size_le);
|
||||
*offset += val_size_size;
|
||||
xo = xpc_unpack(in + *offset, val_size, &val_packed_size, value_type);
|
||||
if (val_packed_size != val_size) {
|
||||
// something's up
|
||||
debugf("val_packed_size != val_size (%zu != %zu)", val_packed_size, val_size);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
xo = xpc_unpack(in + *offset, size - *offset, &val_packed_size, 0);
|
||||
}
|
||||
*offset += val_packed_size;
|
||||
return xo;
|
||||
};
|
||||
|
||||
XPC_INLINE int xpc_pack(struct xpc_object* xo, void* buf, size_t* final_size) {
|
||||
uint8_t* out = buf;
|
||||
__block size_t size = 1;
|
||||
|
||||
if (out)
|
||||
out[0] = xo->xo_xpc_type;
|
||||
|
||||
switch (xo->xo_xpc_type) {
|
||||
case _XPC_TYPE_DICTIONARY: {
|
||||
__block size_t offset = size;
|
||||
xpc_dictionary_apply(xo, ^bool(const char* key, xpc_object_t value) {
|
||||
struct xpc_object* val_xo = value;
|
||||
size_t key_size = strlen(key) + 1;
|
||||
size += key_size;
|
||||
if (out) {
|
||||
strncpy(out + offset, key, key_size - 1);
|
||||
offset += key_size;
|
||||
out[offset - 1] = '\0';
|
||||
}
|
||||
xpc_pack_encode_entry(out, &size, &offset, val_xo);
|
||||
return true;
|
||||
});
|
||||
} break;
|
||||
case _XPC_TYPE_ARRAY: {
|
||||
__block size_t offset = size;
|
||||
xpc_array_apply(xo, ^bool(size_t idx, xpc_object_t value) {
|
||||
struct xpc_object* val_xo = value;
|
||||
xpc_pack_encode_entry(out, &size, &offset, val_xo);
|
||||
return true;
|
||||
});
|
||||
} break;
|
||||
case _XPC_TYPE_BOOL: {
|
||||
if (out)
|
||||
out[0] |= (xpc_bool_get_value(xo) ? 1 : 0) << XPC_PACK_TYPE_BITS;
|
||||
} break;
|
||||
case _XPC_TYPE_DATE:
|
||||
case _XPC_TYPE_INT64: {
|
||||
int64_t val = xo->xo_xpc_type == _XPC_TYPE_DATE ? xpc_date_get_value(xo) : xpc_int64_get_value(xo);
|
||||
int64_t val_le = OSSwapHostToLittleInt64(val);
|
||||
size_t val_bits = xpc_pack_encode_int_bits(&val_le, sizeof(int64_t), false);
|
||||
size += XPC_PACK_INT_EXTRA_BYTES(val_bits);
|
||||
if (out)
|
||||
xpc_pack_encode_int(out, &val_le, sizeof(int64_t));
|
||||
} break;
|
||||
case _XPC_TYPE_UINT64: {
|
||||
uint64_t val = xpc_uint64_get_value(xo);
|
||||
uint64_t val_le = OSSwapHostToLittleInt64(val);
|
||||
size_t val_bits = xpc_pack_encode_int_bits(&val_le, sizeof(uint64_t), false);
|
||||
size += XPC_PACK_INT_EXTRA_BYTES(val_bits);
|
||||
if (out)
|
||||
xpc_pack_encode_int(out, &val_le, sizeof(uint64_t));
|
||||
} break;
|
||||
case _XPC_TYPE_DATA: {
|
||||
size_t len = xpc_data_get_length(xo);
|
||||
size += len;
|
||||
if (out)
|
||||
memcpy(out + 1, xpc_data_get_bytes_ptr(xo), len);
|
||||
} break;
|
||||
case _XPC_TYPE_STRING: {
|
||||
size_t len = xpc_string_get_length(xo);
|
||||
size += len + 1;
|
||||
if (out) {
|
||||
strncpy(out + 1, xpc_string_get_string_ptr(xo), len);
|
||||
out[1 + len] = '\0';
|
||||
}
|
||||
} break;
|
||||
// currently unimplemented
|
||||
//case _XPC_TYPE_UUID: {} break;
|
||||
case _XPC_TYPE_FD: {
|
||||
int val = xo->xo_u.port;
|
||||
int val_le = OSSwapHostToLittleInt32(val);
|
||||
size_t val_bits = xpc_pack_encode_int_bits(&val_le, sizeof(int), false);
|
||||
size += XPC_PACK_INT_EXTRA_BYTES(val_bits);
|
||||
if (out)
|
||||
xpc_pack_encode_int(out, &val_le, sizeof(int));
|
||||
} break;
|
||||
case _XPC_TYPE_DOUBLE: {
|
||||
// this is a rather simplistic implementation that assumes that the internal layout
|
||||
// of a double is the same on sender and reeceiver
|
||||
// that's never a good assumption.
|
||||
// (although from what i can tell, XPC is only used for communication between processes
|
||||
// on the same system, so this shouldn't be a problem)
|
||||
//
|
||||
// TODO: figure out how to encode the double portably
|
||||
double val = xpc_double_get_value(xo);
|
||||
uint64_t val_le = sizeof(double) == 4 ? (uint64_t)OSSwapHostToLittleInt32(*(uint32_t*)&val) : OSSwapHostToLittleInt64(*(uint64_t*)&val);
|
||||
size_t val_bits = xpc_pack_encode_int_bits(&val_le, sizeof(uint64_t), false);
|
||||
size += XPC_PACK_INT_EXTRA_BYTES(val_bits);
|
||||
if (out)
|
||||
xpc_pack_encode_int(out, &val_le, sizeof(uint64_t));
|
||||
} break;
|
||||
case _XPC_TYPE_NULL: break;
|
||||
default: {
|
||||
debugf("can't pack unsupported type: %d", xo->xo_xpc_type);
|
||||
} break;
|
||||
};
|
||||
|
||||
if (final_size)
|
||||
*final_size = size;
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
// initial calls (i.e. anyone using this function) should call it like so:
|
||||
// xpc_unpack(data, data_size, NULL, 0)
|
||||
// or
|
||||
// xpc_unpack(data, data_size, &packed_size, 0)
|
||||
// in other words, the `declared_type` parameter should always be 0
|
||||
XPC_INLINE struct xpc_object* xpc_unpack(const void* buf, size_t size, size_t* packed_size, uint8_t declared_type) {
|
||||
if (size == 0) {
|
||||
if (packed_size)
|
||||
*packed_size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const uint8_t* in = buf;
|
||||
uint8_t xo_xpc_type = declared_type == 0 ? in[0] & XPC_PACK_TYPE_MASK : declared_type;
|
||||
size_t offset = 0;
|
||||
struct xpc_object* xo = NULL;
|
||||
|
||||
switch (xo_xpc_type) {
|
||||
case _XPC_TYPE_DICTIONARY: {
|
||||
xo = xpc_dictionary_create(NULL, NULL, 0);
|
||||
++offset;
|
||||
|
||||
while (offset < size) {
|
||||
const char* key = in + offset;
|
||||
size_t key_size = strlen(key) + 1;
|
||||
offset += key_size;
|
||||
struct xpc_object* val = xpc_unpack_decode_entry(in, size, &offset);
|
||||
if (!val) {
|
||||
debugf("failed to unpack dictionary entry");
|
||||
xpc_release(xo);
|
||||
xo = NULL;
|
||||
offset = 0;
|
||||
break;
|
||||
}
|
||||
xpc_dictionary_set_value(xo, key, val);
|
||||
xpc_release(val);
|
||||
}
|
||||
} break;
|
||||
case _XPC_TYPE_ARRAY: {
|
||||
xo = xpc_array_create(NULL, 0);
|
||||
++offset;
|
||||
|
||||
while (offset < size) {
|
||||
struct xpc_object* val = xpc_unpack_decode_entry(in, size, &offset);
|
||||
if (!val) {
|
||||
debugf("failed to unpack array entry");
|
||||
xpc_release(xo);
|
||||
xo = NULL;
|
||||
offset = 0;
|
||||
break;
|
||||
}
|
||||
xpc_array_append_value(xo, val);
|
||||
xpc_release(val);
|
||||
}
|
||||
} break;
|
||||
case _XPC_TYPE_BOOL: {
|
||||
xo = xpc_bool_create(in[0] >> XPC_PACK_TYPE_BITS);
|
||||
++offset;
|
||||
} break;
|
||||
case _XPC_TYPE_DATE:
|
||||
case _XPC_TYPE_INT64: {
|
||||
int64_t val_le = 0;
|
||||
offset += xpc_unpack_decode_int(&val_le, in + offset);
|
||||
int64_t val = OSSwapLittleToHostInt64(val_le);
|
||||
xo = xo_xpc_type == _XPC_TYPE_DATE ? xpc_date_create(val) : xpc_int64_create(val);
|
||||
} break;
|
||||
case _XPC_TYPE_UINT64: {
|
||||
uint64_t val_le = 0;
|
||||
offset += xpc_unpack_decode_int(&val_le, in + offset);
|
||||
uint64_t val = OSSwapLittleToHostInt64(val_le);
|
||||
xo = xpc_uint64_create(val);
|
||||
} break;
|
||||
case _XPC_TYPE_DATA: {
|
||||
++offset;
|
||||
xo = xpc_data_create(in + offset, size - offset);
|
||||
offset += size - offset;
|
||||
} break;
|
||||
case _XPC_TYPE_STRING: {
|
||||
++offset;
|
||||
xo = xpc_string_create(in + offset);
|
||||
offset += strlen(in + offset) + 1;
|
||||
} break;
|
||||
case _XPC_TYPE_FD: {
|
||||
int val_le = 0;
|
||||
offset += xpc_unpack_decode_int(&val_le, in + offset);
|
||||
int val = OSSwapLittleToHostInt32(val_le);
|
||||
|
||||
xo = malloc(sizeof(struct xpc_object));
|
||||
if (xo) {
|
||||
xo->xo_size = sizeof(xo->xo_u.port);
|
||||
xo->xo_xpc_type = _XPC_TYPE_FD;
|
||||
xo->xo_flags = 0;
|
||||
xo->xo_u.port = val;
|
||||
xo->xo_refcnt = 1;
|
||||
xo->xo_audit_token = NULL;
|
||||
}
|
||||
} break;
|
||||
case _XPC_TYPE_DOUBLE: {
|
||||
uint64_t uval_le = 0;
|
||||
offset += xpc_unpack_decode_int(&uval_le, in + offset);
|
||||
uint64_t uval = OSSwapLittleToHostInt64(uval_le);
|
||||
double val = *(double*)&uval_le;
|
||||
xo = xpc_double_create(val);
|
||||
} break;
|
||||
case _XPC_TYPE_NULL: {
|
||||
xo = xpc_null_create();
|
||||
++offset;
|
||||
} break;
|
||||
default: {
|
||||
debugf("can't unpack unsupported type: %d", xo_xpc_type);
|
||||
} break;
|
||||
}
|
||||
|
||||
if (packed_size)
|
||||
*packed_size = offset;
|
||||
|
||||
return xo;
|
||||
};
|
||||
|
||||
void
|
||||
xpc_object_destroy(struct xpc_object *xo)
|
||||
@ -519,7 +935,7 @@ xpc_pipe_receive(mach_port_t local, mach_port_t *remote, xpc_object_t *result,
|
||||
*id = message.id;
|
||||
data_size = (int)message.size;
|
||||
LOG("unpacking data_size=%d", data_size);
|
||||
xo = xpc_unpack(&message.data, data_size);
|
||||
xo = xpc_unpack(message.data, data_size, NULL, 0);
|
||||
|
||||
tr = (mach_msg_trailer_t *)(((char *)&message) + request->msgh_size);
|
||||
auditp = &((mach_msg_audit_trailer_t *)tr)->msgh_audit;
|
||||
@ -582,7 +998,7 @@ xpc_pipe_try_receive(mach_port_t portset, xpc_object_t *requestobj, mach_port_t
|
||||
LOG("demux returned false\n");
|
||||
data_size = request->msgh_size;
|
||||
LOG("unpacking data_size=%d", data_size);
|
||||
xo = xpc_unpack(&message.data, data_size);
|
||||
xo = xpc_unpack(message.data, data_size, NULL, 0);
|
||||
/* is padding for alignment enforced in the kernel?*/
|
||||
tr = (mach_msg_trailer_t *)(((char *)&message) + request->msgh_size);
|
||||
auditp = &((mach_msg_audit_trailer_t *)tr)->msgh_audit;
|
||||
|
Loading…
Reference in New Issue
Block a user