]> git.saurik.com Git - apple/xnu.git/blame - libkern/os/ptrtools.h
xnu-6153.41.3.tar.gz
[apple/xnu.git] / libkern / os / ptrtools.h
CommitLineData
cb323159 1/* * Copyright (c) 2018 Apple Inc. All rights reserved.
5ba3f43e
A
2 *
3 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
4 *
5 * This file contains Original Code and/or Modifications of Original Code
6 * as defined in and that are subject to the Apple Public Source License
7 * Version 2.0 (the 'License'). You may not use this file except in
8 * compliance with the License. The rights granted to you under the License
9 * may not be used to create, or enable the creation or redistribution of,
10 * unlawful or unlicensed copies of an Apple operating system, or to
11 * circumvent, violate, or enable the circumvention or violation of, any
12 * terms of an Apple operating system software license agreement.
13 *
14 * Please obtain a copy of the License at
15 * http://www.opensource.apple.com/apsl/ and read it before using this file.
16 *
17 * The Original Code and all software distributed under the License are
18 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
22 * Please see the License for the specific language governing rights and
23 * limitations under the License.
24 *
25 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
3e170ce0 26 */
fe8ab488 27
cb323159
A
28#ifndef _OS_PTRTOOLS_H
29#define _OS_PTRTOOLS_H
30
31/* dereference unaligned pointer 'p' */
32#define os_unaligned_deref(p) ((__os_unaligned_type(p))(p))->val
33
34/* ensure the compiler emits at most one access to 'val' */
35#define os_access_once(val) (*((volatile __typeof__((val)) *)&(val)))
36
37#define __os_unaligned_type(p) struct { __typeof__(*(p)) val; } __attribute__((packed)) *
fe8ab488 38
cb323159 39#endif /* _OS_PTRTOOLS_H */