├── .gitattributes ├── .gitignore ├── .gitmodules ├── LICENSE ├── Makefile ├── README.md ├── apple-include ├── Availability.h ├── AvailabilityInternal.h ├── AvailabilityMacros.h ├── AvailabilityVersions.h ├── architecture │ └── byte_order.h ├── arm │ ├── _types.h │ └── arch.h ├── i386 │ ├── _types.h │ └── eflags.h ├── libkern │ ├── OSByteOrder.h │ ├── _OSByteOrder.h │ ├── arm │ │ └── OSByteOrder.h │ └── machine │ │ └── OSByteOrder.h ├── mach-o │ ├── loader.h │ ├── nlist.h │ └── reloc.h ├── mach │ ├── arm │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── boolean.h │ ├── i386 │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── fp_reg.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── kern_return.h │ ├── machine.h │ ├── machine │ │ ├── _structs.h │ │ ├── boolean.h │ │ ├── kern_return.h │ │ ├── thread_state.h │ │ ├── thread_status.h │ │ └── vm_types.h │ ├── message.h │ ├── port.h │ ├── vm_prot.h │ └── vm_types.h ├── machine │ └── _types.h └── sys │ ├── _posix_availability.h │ ├── _pthread │ └── _pthread_types.h │ ├── _symbol_aliasing.h │ ├── _types.h │ ├── _types │ ├── _mach_port_t.h │ └── _os_inline.h │ ├── appleapiopts.h │ └── cdefs.h ├── drivers ├── Makefile ├── dt │ ├── Makefile │ ├── dtree.c │ └── dtree_getprop.c ├── framebuffer │ ├── Makefile │ ├── fb.c │ └── fb.h ├── plat │ ├── Makefile │ ├── s8000.c │ ├── t8010.c │ └── t8015.c ├── tz │ ├── Makefile │ ├── tz.c │ └── tz.h └── xnu │ ├── Makefile │ ├── xnu.S │ ├── xnu.c │ └── xnu.h ├── include ├── common.h ├── font8x8_basic.h ├── kerninfo.h ├── mac.h └── offsetfinder.h ├── kernel ├── Makefile ├── command.c ├── entry.S ├── fakemm.c ├── lowlevel.c ├── offsetfinder.c └── printf.c ├── kpf ├── Makefile ├── main.c └── shellcode.S ├── lib ├── Makefile ├── atoi.c ├── bzero.c ├── errno.c ├── isalpha.c ├── isdigit.c ├── isspace.c ├── isupper.c ├── memcmp.c ├── memmem.c ├── memmove.c ├── memset.c ├── puts.c ├── strcat.c ├── strchr.c ├── strcmp.c ├── strcpy.c ├── strlen.c ├── strncmp.c ├── strncpy.c ├── strstr.c ├── strtoimax.c ├── strtoul.c └── strtoull.c ├── payload.c ├── printf.h ├── sym_order.txt └── vmacho.c /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .DS_Store 3 | .irecovery 4 | irecovery 5 | vmacho 6 | txt 7 | *.bin 8 | *.o 9 | boot 10 | a9rwx.s 11 | *.dSYM 12 | 13 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/palera1n/magicalcatnyan/2d234bbe44ba83179119666bfdad36650e6126b1/.gitmodules -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC = xcrun -sdk iphoneos clang 2 | CC_FOR_BUILD = clang 3 | CFLAGS_FOR_BUILD += -Os -Wall -Wextra 4 | LDFLAGS_FOR_BUILD ?= -flto=thin 5 | 6 | SRC_ROOT = $(shell pwd) 7 | SUBDIRS = kernel lib drivers kpf 8 | 9 | OBJCOPY = /opt/homebrew/opt/binutils/bin/gobjcopy 10 | DRIVERS = plat dt framebuffer xnu tz 11 | 12 | CFLAGS = -I$(SRC_ROOT)/include -I$(SRC_ROOT)/apple-include -I$(SRC_ROOT) -DDER_TAG_SIZE=8 -target arm64-apple-ios12.0 -g -ffreestanding -flto=thin 13 | CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-incompatible-library-redeclaration -fno-stack-protector -nostdlib -static -nostdlibinc 14 | LDFLAGS = -Wl,-preload -Wl,-no_uuid -Wl,-e,start -Wl,-order_file,sym_order.txt -Wl,-sectalign,__DATA,__common,0x8 -Wl,-segalign,0x4000 15 | 16 | ifneq ($(DEV_BUILD),) 17 | CFLAGS += -DDEV_BUILD=$(DEV_BUILD) -Og 18 | OBJECTS = kernel/command.o 19 | else 20 | CFLAGS += -Os 21 | endif 22 | 23 | MAGICALCATNYAN_VERSION ?= 1.1.1-$(shell git rev-parse HEAD | cut -c1-8) 24 | P = ) 25 | 26 | CFLAGS += -DMAGICALCATNYAN_VERSION='"$(MAGICALCATNYAN_VERSION)"' 27 | # CFLAGS += -DXNU_PF_DUMP_JIT -DDEBUG_DOUNMOUNT -DDEBUG_MM -DXNU_PF_DEBUG_SPAM 28 | OBJ = payload 29 | 30 | OBJECTS += \ 31 | kernel/lowlevel.o \ 32 | kernel/fakemm.o \ 33 | kernel/printf.o \ 34 | kernel/offsetfinder.o \ 35 | kernel/entry.o \ 36 | kpf/main.o \ 37 | kpf/shellcode.S.o \ 38 | drivers/dt/dtree.o \ 39 | drivers/dt/dtree_getprop.o \ 40 | drivers/framebuffer/fb.o \ 41 | drivers/xnu/xnu.o \ 42 | drivers/xnu/xnu.S.o \ 43 | drivers/tz/tz.o \ 44 | lib/memset.o \ 45 | lib/memmem.o \ 46 | lib/memmove.o \ 47 | lib/memcmp.o \ 48 | lib/strstr.o \ 49 | lib/strcmp.o \ 50 | lib/strlen.o \ 51 | lib/strcpy.o \ 52 | lib/strncpy.o \ 53 | lib/strchr.o \ 54 | lib/strncmp.o \ 55 | lib/isalpha.o \ 56 | lib/isdigit.o \ 57 | lib/isspace.o \ 58 | lib/isupper.o \ 59 | lib/strtoull.o \ 60 | lib/strcat.o \ 61 | lib/puts.o \ 62 | lib/bzero.o \ 63 | lib/strtoul.o \ 64 | lib/errno.o \ 65 | lib/strtoimax.o 66 | 67 | export DRIVERS CC CFLAGS 68 | 69 | all: payload 70 | 71 | vmacho: vmacho.c 72 | $(CC_FOR_BUILD) $(CFLAGS_FOR_BUILD) $(LDFLAGS_FOR_BUILD) -o vmacho vmacho.c 73 | 74 | payload: $(OBJ)_s8000.bin $(OBJ)_t8010.bin $(OBJ)_t8015.bin 75 | 76 | %.o: %.c 77 | $(CC) -c $(CFLAGS) $< 78 | 79 | $(SUBDIRS): 80 | $(MAKE) -C "$@" 81 | 82 | payload_%.o: $(SUBDIRS) 83 | $(CC) -DPAYLOAD_$* -Wl,-image_base,$(shell if [ "$*" = "t8015" ]; then echo 0x800F00000; else echo 0x800700000; fi) payload.c drivers/plat/$*.o -DBUILDING_PAYLOAD $(OBJECTS) $(CFLAGS) $(LDFLAGS) -o $(OBJ)_$*.o 84 | 85 | payload_%.bin: payload_%.o vmacho 86 | ./vmacho -fM 0x80000 $(OBJ)_$*.o $(OBJ)_$*.bin 87 | 88 | clean: 89 | find . -name '*.bin' -type f -delete 90 | find . -name '*.o' -type f -delete 91 | 92 | distclean: clean 93 | rm -f vmacho 94 | 95 | .PHONY: all distclean clean payload $(SUBDIRS) 96 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # magicalcatnyan 2 | 3 | nya~ 4 | 5 |   ∧_∧__ 6 |   /(´・ω・`) /\ 7 |  /| ̄ ̄ ̄ ̄|\/ 8 |   |    |/ 9 |     ̄ ̄ ̄ ̄ 10 | 11 | ## features 12 | - kernel patch finder 13 | - setting boot args at runtime 14 | - devicetree patcher 15 | - boot framebuffer 16 | - trustzone information 17 | 18 | ## building 19 | 20 | to build a release run ``make all`` 21 | 22 | to build a development payload run ``make DEV_BUILD=1 all`` 23 | -------------------------------------------------------------------------------- /apple-include/AvailabilityVersions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 by Apple Inc.. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | 24 | #ifndef __AVAILABILITY_VERSIONS__ 25 | #define __AVAILABILITY_VERSIONS__ 26 | 27 | #define __MAC_10_0 1000 28 | #define __MAC_10_1 1010 29 | #define __MAC_10_2 1020 30 | #define __MAC_10_3 1030 31 | #define __MAC_10_4 1040 32 | #define __MAC_10_5 1050 33 | #define __MAC_10_6 1060 34 | #define __MAC_10_7 1070 35 | #define __MAC_10_8 1080 36 | #define __MAC_10_9 1090 37 | #define __MAC_10_10 101000 38 | #define __MAC_10_10_2 101002 39 | #define __MAC_10_10_3 101003 40 | #define __MAC_10_11 101100 41 | #define __MAC_10_11_2 101102 42 | #define __MAC_10_11_3 101103 43 | #define __MAC_10_11_4 101104 44 | #define __MAC_10_12 101200 45 | #define __MAC_10_12_1 101201 46 | #define __MAC_10_12_2 101202 47 | #define __MAC_10_12_4 101204 48 | #define __MAC_10_13 101300 49 | #define __MAC_10_13_1 101301 50 | #define __MAC_10_13_2 101302 51 | #define __MAC_10_13_4 101304 52 | #define __MAC_10_14 101400 53 | #define __MAC_10_14_1 101401 54 | #define __MAC_10_14_4 101404 55 | #define __MAC_10_14_6 101406 56 | #define __MAC_10_15 101500 57 | #define __MAC_10_15_1 101501 58 | #define __MAC_10_15_4 101504 59 | #define __MAC_10_16 101600 60 | #define __MAC_11_0 110000 61 | #define __MAC_11_1 110100 62 | /* __MAC_NA is not defined to a value but is used as a token by macros to indicate that the API is unavailable */ 63 | 64 | #define __IPHONE_2_0 20000 65 | #define __IPHONE_2_1 20100 66 | #define __IPHONE_2_2 20200 67 | #define __IPHONE_3_0 30000 68 | #define __IPHONE_3_1 30100 69 | #define __IPHONE_3_2 30200 70 | #define __IPHONE_4_0 40000 71 | #define __IPHONE_4_1 40100 72 | #define __IPHONE_4_2 40200 73 | #define __IPHONE_4_3 40300 74 | #define __IPHONE_5_0 50000 75 | #define __IPHONE_5_1 50100 76 | #define __IPHONE_6_0 60000 77 | #define __IPHONE_6_1 60100 78 | #define __IPHONE_7_0 70000 79 | #define __IPHONE_7_1 70100 80 | #define __IPHONE_8_0 80000 81 | #define __IPHONE_8_1 80100 82 | #define __IPHONE_8_2 80200 83 | #define __IPHONE_8_3 80300 84 | #define __IPHONE_8_4 80400 85 | #define __IPHONE_9_0 90000 86 | #define __IPHONE_9_1 90100 87 | #define __IPHONE_9_2 90200 88 | #define __IPHONE_9_3 90300 89 | #define __IPHONE_10_0 100000 90 | #define __IPHONE_10_1 100100 91 | #define __IPHONE_10_2 100200 92 | #define __IPHONE_10_3 100300 93 | #define __IPHONE_11_0 110000 94 | #define __IPHONE_11_1 110100 95 | #define __IPHONE_11_2 110200 96 | #define __IPHONE_11_3 110300 97 | #define __IPHONE_11_4 110400 98 | #define __IPHONE_12_0 120000 99 | #define __IPHONE_12_1 120100 100 | #define __IPHONE_12_2 120200 101 | #define __IPHONE_12_3 120300 102 | #define __IPHONE_12_4 120400 103 | #define __IPHONE_13_0 130000 104 | #define __IPHONE_13_1 130100 105 | #define __IPHONE_13_2 130200 106 | #define __IPHONE_13_3 130300 107 | #define __IPHONE_13_4 130400 108 | #define __IPHONE_13_5 130500 109 | #define __IPHONE_13_6 130600 110 | #define __IPHONE_13_7 130700 111 | #define __IPHONE_14_0 140000 112 | #define __IPHONE_14_1 140100 113 | #define __IPHONE_14_2 140200 114 | #define __IPHONE_14_3 140300 115 | /* __IPHONE_NA is not defined to a value but is used as a token by macros to indicate that the API is unavailable */ 116 | 117 | #define __TVOS_9_0 90000 118 | #define __TVOS_9_1 90100 119 | #define __TVOS_9_2 90200 120 | #define __TVOS_10_0 100000 121 | #define __TVOS_10_0_1 100001 122 | #define __TVOS_10_1 100100 123 | #define __TVOS_10_2 100200 124 | #define __TVOS_11_0 110000 125 | #define __TVOS_11_1 110100 126 | #define __TVOS_11_2 110200 127 | #define __TVOS_11_3 110300 128 | #define __TVOS_11_4 110400 129 | #define __TVOS_12_0 120000 130 | #define __TVOS_12_1 120100 131 | #define __TVOS_12_2 120200 132 | #define __TVOS_12_3 120300 133 | #define __TVOS_12_4 120400 134 | #define __TVOS_13_0 130000 135 | #define __TVOS_13_2 130200 136 | #define __TVOS_13_3 130300 137 | #define __TVOS_13_4 130400 138 | #define __TVOS_14_0 140000 139 | #define __TVOS_14_1 140100 140 | #define __TVOS_14_2 140200 141 | #define __TVOS_14_3 140300 142 | 143 | #define __WATCHOS_1_0 10000 144 | #define __WATCHOS_2_0 20000 145 | #define __WATCHOS_2_1 20100 146 | #define __WATCHOS_2_2 20200 147 | #define __WATCHOS_3_0 30000 148 | #define __WATCHOS_3_1 30100 149 | #define __WATCHOS_3_1_1 30101 150 | #define __WATCHOS_3_2 30200 151 | #define __WATCHOS_4_0 40000 152 | #define __WATCHOS_4_1 40100 153 | #define __WATCHOS_4_2 40200 154 | #define __WATCHOS_4_3 40300 155 | #define __WATCHOS_5_0 50000 156 | #define __WATCHOS_5_1 50100 157 | #define __WATCHOS_5_2 50200 158 | #define __WATCHOS_5_3 50300 159 | #define __WATCHOS_6_0 60000 160 | #define __WATCHOS_6_1 60100 161 | #define __WATCHOS_6_2 60200 162 | #define __WATCHOS_7_0 70000 163 | #define __WATCHOS_7_1 70100 164 | #define __WATCHOS_7_2 70200 165 | 166 | /* 167 | * Set up standard Mac OS X versions 168 | */ 169 | 170 | #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) 171 | 172 | #define MAC_OS_X_VERSION_10_0 1000 173 | #define MAC_OS_X_VERSION_10_1 1010 174 | #define MAC_OS_X_VERSION_10_2 1020 175 | #define MAC_OS_X_VERSION_10_3 1030 176 | #define MAC_OS_X_VERSION_10_4 1040 177 | #define MAC_OS_X_VERSION_10_5 1050 178 | #define MAC_OS_X_VERSION_10_6 1060 179 | #define MAC_OS_X_VERSION_10_7 1070 180 | #define MAC_OS_X_VERSION_10_8 1080 181 | #define MAC_OS_X_VERSION_10_9 1090 182 | #define MAC_OS_X_VERSION_10_10 101000 183 | #define MAC_OS_X_VERSION_10_10_2 101002 184 | #define MAC_OS_X_VERSION_10_10_3 101003 185 | #define MAC_OS_X_VERSION_10_11 101100 186 | #define MAC_OS_X_VERSION_10_11_2 101102 187 | #define MAC_OS_X_VERSION_10_11_3 101103 188 | #define MAC_OS_X_VERSION_10_11_4 101104 189 | #define MAC_OS_X_VERSION_10_12 101200 190 | #define MAC_OS_X_VERSION_10_12_1 101201 191 | #define MAC_OS_X_VERSION_10_12_2 101202 192 | #define MAC_OS_X_VERSION_10_12_4 101204 193 | #define MAC_OS_X_VERSION_10_13 101300 194 | #define MAC_OS_X_VERSION_10_13_1 101301 195 | #define MAC_OS_X_VERSION_10_13_2 101302 196 | #define MAC_OS_X_VERSION_10_13_4 101304 197 | #define MAC_OS_X_VERSION_10_14 101400 198 | #define MAC_OS_X_VERSION_10_14_1 101401 199 | #define MAC_OS_X_VERSION_10_14_4 101404 200 | #define MAC_OS_X_VERSION_10_14_6 101406 201 | #define MAC_OS_X_VERSION_10_15 101500 202 | #define MAC_OS_X_VERSION_10_15_1 101501 203 | #define MAC_OS_X_VERSION_10_16 101600 204 | #define MAC_OS_VERSION_11_0 110000 205 | 206 | #endif /* #if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE) */ 207 | 208 | #define __DRIVERKIT_19_0 190000 209 | #define __DRIVERKIT_20_0 200000 210 | 211 | #endif /* __AVAILABILITY_VERSIONS__ */ 212 | 213 | -------------------------------------------------------------------------------- /apple-include/architecture/byte_order.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2008 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. Please obtain a copy of the License at 10 | * http://www.opensource.apple.com/apsl/ and read it before using this 11 | * file. 12 | * 13 | * The Original Code and all software distributed under the License are 14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 | * Please see the License for the specific language governing rights and 19 | * limitations under the License. 20 | * 21 | * @APPLE_LICENSE_HEADER_END@ 22 | */ 23 | /* 24 | * Copyright (c) 1992 NeXT Computer, Inc. 25 | * 26 | * Byte ordering conversion. 27 | * 28 | */ 29 | 30 | #ifndef _ARCHITECTURE_BYTE_ORDER_H_ 31 | #define _ARCHITECTURE_BYTE_ORDER_H_ 32 | 33 | /* 34 | * Please note that the byte ordering functions in this file are deprecated. 35 | * A replacement API exists in libkern/OSByteOrder.h 36 | */ 37 | 38 | #include 39 | 40 | typedef unsigned long NXSwappedFloat; 41 | typedef unsigned long long NXSwappedDouble; 42 | 43 | static __inline__ __attribute__((deprecated)) 44 | unsigned short 45 | NXSwapShort( 46 | unsigned short inv 47 | ) 48 | { 49 | return (unsigned short)OSSwapInt16((uint16_t)inv); 50 | } 51 | 52 | static __inline__ __attribute__((deprecated)) 53 | unsigned int 54 | NXSwapInt( 55 | unsigned int inv 56 | ) 57 | { 58 | return (unsigned int)OSSwapInt32((uint32_t)inv); 59 | } 60 | 61 | static __inline__ __attribute__((deprecated)) 62 | unsigned long 63 | NXSwapLong( 64 | unsigned long inv 65 | ) 66 | { 67 | return (unsigned long)OSSwapInt32((uint32_t)inv); 68 | } 69 | 70 | static __inline__ __attribute__((deprecated)) 71 | unsigned long long 72 | NXSwapLongLong( 73 | unsigned long long inv 74 | ) 75 | { 76 | return (unsigned long long)OSSwapInt64((uint64_t)inv); 77 | } 78 | 79 | static __inline__ __attribute__((deprecated)) 80 | NXSwappedFloat 81 | NXConvertHostFloatToSwapped(float x) 82 | { 83 | union fconv { 84 | float number; 85 | NXSwappedFloat sf; 86 | } u; 87 | u.number = x; 88 | return u.sf; 89 | } 90 | 91 | static __inline__ __attribute__((deprecated)) 92 | float 93 | NXConvertSwappedFloatToHost(NXSwappedFloat x) 94 | { 95 | union fconv { 96 | float number; 97 | NXSwappedFloat sf; 98 | } u; 99 | u.sf = x; 100 | return u.number; 101 | } 102 | 103 | static __inline__ __attribute__((deprecated)) 104 | NXSwappedDouble 105 | NXConvertHostDoubleToSwapped(double x) 106 | { 107 | union dconv { 108 | double number; 109 | NXSwappedDouble sd; 110 | } u; 111 | u.number = x; 112 | return u.sd; 113 | } 114 | 115 | static __inline__ __attribute__((deprecated)) 116 | double 117 | NXConvertSwappedDoubleToHost(NXSwappedDouble x) 118 | { 119 | union dconv { 120 | double number; 121 | NXSwappedDouble sd; 122 | } u; 123 | u.sd = x; 124 | return u.number; 125 | } 126 | 127 | static __inline__ __attribute__((deprecated)) 128 | NXSwappedFloat 129 | NXSwapFloat(NXSwappedFloat x) 130 | { 131 | return (NXSwappedFloat)OSSwapInt32((uint32_t)x); 132 | } 133 | 134 | static __inline__ __attribute__((deprecated)) 135 | NXSwappedDouble 136 | NXSwapDouble(NXSwappedDouble x) 137 | { 138 | return (NXSwappedDouble)OSSwapInt64((uint64_t)x); 139 | } 140 | 141 | /* 142 | * Identify the byte order 143 | * of the current host. 144 | */ 145 | 146 | enum NXByteOrder { 147 | NX_UnknownByteOrder, 148 | NX_LittleEndian, 149 | NX_BigEndian 150 | }; 151 | 152 | static __inline__ 153 | enum NXByteOrder 154 | NXHostByteOrder(void) 155 | { 156 | #if defined(__LITTLE_ENDIAN__) 157 | return NX_LittleEndian; 158 | #elif defined(__BIG_ENDIAN__) 159 | return NX_BigEndian; 160 | #else 161 | return NX_UnknownByteOrder; 162 | #endif 163 | } 164 | 165 | static __inline__ __attribute__((deprecated)) 166 | unsigned short 167 | NXSwapBigShortToHost( 168 | unsigned short x 169 | ) 170 | { 171 | return (unsigned short)OSSwapBigToHostInt16((uint16_t)x); 172 | } 173 | 174 | static __inline__ __attribute__((deprecated)) 175 | unsigned int 176 | NXSwapBigIntToHost( 177 | unsigned int x 178 | ) 179 | { 180 | return (unsigned int)OSSwapBigToHostInt32((uint32_t)x); 181 | } 182 | 183 | static __inline__ __attribute__((deprecated)) 184 | unsigned long 185 | NXSwapBigLongToHost( 186 | unsigned long x 187 | ) 188 | { 189 | return (unsigned long)OSSwapBigToHostInt32((uint32_t)x); 190 | } 191 | 192 | static __inline__ __attribute__((deprecated)) 193 | unsigned long long 194 | NXSwapBigLongLongToHost( 195 | unsigned long long x 196 | ) 197 | { 198 | return (unsigned long long)OSSwapBigToHostInt64((uint64_t)x); 199 | } 200 | 201 | static __inline__ __attribute__((deprecated)) 202 | double 203 | NXSwapBigDoubleToHost( 204 | NXSwappedDouble x 205 | ) 206 | { 207 | return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapBigToHostInt64((uint64_t)x)); 208 | } 209 | 210 | static __inline__ __attribute__((deprecated)) 211 | float 212 | NXSwapBigFloatToHost( 213 | NXSwappedFloat x 214 | ) 215 | { 216 | return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapBigToHostInt32((uint32_t)x)); 217 | } 218 | 219 | static __inline__ __attribute__((deprecated)) 220 | unsigned short 221 | NXSwapHostShortToBig( 222 | unsigned short x 223 | ) 224 | { 225 | return (unsigned short)OSSwapHostToBigInt16((uint16_t)x); 226 | } 227 | 228 | static __inline__ __attribute__((deprecated)) 229 | unsigned int 230 | NXSwapHostIntToBig( 231 | unsigned int x 232 | ) 233 | { 234 | return (unsigned int)OSSwapHostToBigInt32((uint32_t)x); 235 | } 236 | 237 | static __inline__ __attribute__((deprecated)) 238 | unsigned long 239 | NXSwapHostLongToBig( 240 | unsigned long x 241 | ) 242 | { 243 | return (unsigned long)OSSwapHostToBigInt32((uint32_t)x); 244 | } 245 | 246 | static __inline__ __attribute__((deprecated)) 247 | unsigned long long 248 | NXSwapHostLongLongToBig( 249 | unsigned long long x 250 | ) 251 | { 252 | return (unsigned long long)OSSwapHostToBigInt64((uint64_t)x); 253 | } 254 | 255 | static __inline__ __attribute__((deprecated)) 256 | NXSwappedDouble 257 | NXSwapHostDoubleToBig( 258 | double x 259 | ) 260 | { 261 | return (NXSwappedDouble)OSSwapHostToBigInt64((uint64_t)NXConvertHostDoubleToSwapped(x)); 262 | } 263 | 264 | static __inline__ __attribute__((deprecated)) 265 | NXSwappedFloat 266 | NXSwapHostFloatToBig( 267 | float x 268 | ) 269 | { 270 | return (NXSwappedFloat)OSSwapHostToBigInt32((uint32_t)NXConvertHostFloatToSwapped(x)); 271 | } 272 | 273 | static __inline__ __attribute__((deprecated)) 274 | unsigned short 275 | NXSwapLittleShortToHost( 276 | unsigned short x 277 | ) 278 | { 279 | return (unsigned short)OSSwapLittleToHostInt16((uint16_t)x); 280 | } 281 | 282 | static __inline__ __attribute__((deprecated)) 283 | unsigned int 284 | NXSwapLittleIntToHost( 285 | unsigned int x 286 | ) 287 | { 288 | return (unsigned int)OSSwapLittleToHostInt32((uint32_t)x); 289 | } 290 | 291 | static __inline__ __attribute__((deprecated)) 292 | unsigned long 293 | NXSwapLittleLongToHost( 294 | unsigned long x 295 | ) 296 | { 297 | return (unsigned long)OSSwapLittleToHostInt32((uint32_t)x); 298 | } 299 | 300 | static __inline__ __attribute__((deprecated)) 301 | unsigned long long 302 | NXSwapLittleLongLongToHost( 303 | unsigned long long x 304 | ) 305 | { 306 | return (unsigned long long)OSSwapLittleToHostInt64((uint64_t)x); 307 | } 308 | 309 | static __inline__ __attribute__((deprecated)) 310 | double 311 | NXSwapLittleDoubleToHost( 312 | NXSwappedDouble x 313 | ) 314 | { 315 | return NXConvertSwappedDoubleToHost((NXSwappedDouble)OSSwapLittleToHostInt64((uint64_t)x)); 316 | } 317 | 318 | static __inline__ __attribute__((deprecated)) 319 | float 320 | NXSwapLittleFloatToHost( 321 | NXSwappedFloat x 322 | ) 323 | { 324 | return NXConvertSwappedFloatToHost((NXSwappedFloat)OSSwapLittleToHostInt32((uint32_t)x)); 325 | } 326 | 327 | static __inline__ __attribute__((deprecated)) 328 | unsigned short 329 | NXSwapHostShortToLittle( 330 | unsigned short x 331 | ) 332 | { 333 | return (unsigned short)OSSwapHostToLittleInt16((uint16_t)x); 334 | } 335 | 336 | static __inline__ __attribute__((deprecated)) 337 | unsigned int 338 | NXSwapHostIntToLittle( 339 | unsigned int x 340 | ) 341 | { 342 | return (unsigned int)OSSwapHostToLittleInt32((uint32_t)x); 343 | } 344 | 345 | static __inline__ __attribute__((deprecated)) 346 | unsigned long 347 | NXSwapHostLongToLittle( 348 | unsigned long x 349 | ) 350 | { 351 | return (unsigned long)OSSwapHostToLittleInt32((uint32_t)x); 352 | } 353 | 354 | static __inline__ __attribute__((deprecated)) 355 | unsigned long long 356 | NXSwapHostLongLongToLittle( 357 | unsigned long long x 358 | ) 359 | { 360 | return (unsigned long long)OSSwapHostToLittleInt64((uint64_t)x); 361 | } 362 | 363 | static __inline__ __attribute__((deprecated)) 364 | NXSwappedDouble 365 | NXSwapHostDoubleToLittle( 366 | double x 367 | ) 368 | { 369 | return (NXSwappedDouble)OSSwapHostToLittleInt64((uint64_t)NXConvertHostDoubleToSwapped(x)); 370 | } 371 | 372 | static __inline__ __attribute__((deprecated)) 373 | NXSwappedFloat 374 | NXSwapHostFloatToLittle( 375 | float x 376 | ) 377 | { 378 | return (NXSwappedFloat)OSSwapHostToLittleInt32((uint32_t)NXConvertHostFloatToSwapped(x)); 379 | } 380 | 381 | #endif /* _ARCHITECTURE_BYTE_ORDER_H_ */ 382 | -------------------------------------------------------------------------------- /apple-include/arm/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | */ 4 | #ifndef _BSD_ARM__TYPES_H_ 5 | #define _BSD_ARM__TYPES_H_ 6 | 7 | /* 8 | * This header file contains integer types. It's intended to also contain 9 | * flotaing point and other arithmetic types, as needed, later. 10 | */ 11 | 12 | #ifdef __GNUC__ 13 | typedef __signed char __int8_t; 14 | #else /* !__GNUC__ */ 15 | typedef char __int8_t; 16 | #endif /* !__GNUC__ */ 17 | typedef unsigned char __uint8_t; 18 | typedef short __int16_t; 19 | typedef unsigned short __uint16_t; 20 | typedef int __int32_t; 21 | typedef unsigned int __uint32_t; 22 | typedef long long __int64_t; 23 | typedef unsigned long long __uint64_t; 24 | 25 | typedef long __darwin_intptr_t; 26 | typedef unsigned int __darwin_natural_t; 27 | 28 | /* 29 | * The rune type below is declared to be an ``int'' instead of the more natural 30 | * ``unsigned long'' or ``long''. Two things are happening here. It is not 31 | * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, 32 | * it looks like 10646 will be a 31 bit standard. This means that if your 33 | * ints cannot hold 32 bits, you will be in trouble. The reason an int was 34 | * chosen over a long is that the is*() and to*() routines take ints (says 35 | * ANSI C), but they use __darwin_ct_rune_t instead of int. By changing it 36 | * here, you lose a bit of ANSI conformance, but your programs will still 37 | * work. 38 | * 39 | * NOTE: rune_t is not covered by ANSI nor other standards, and should not 40 | * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and 41 | * rune_t must be the same type. Also wint_t must be no narrower than 42 | * wchar_t, and should also be able to hold all members of the largest 43 | * character set plus one extra value (WEOF). wint_t must be at least 16 bits. 44 | */ 45 | 46 | typedef int __darwin_ct_rune_t; /* ct_rune_t */ 47 | 48 | /* 49 | * mbstate_t is an opaque object to keep conversion state, during multibyte 50 | * stream conversions. The content must not be referenced by user programs. 51 | */ 52 | typedef union { 53 | char __mbstate8[128]; 54 | long long _mbstateL; /* for alignment */ 55 | } __mbstate_t; 56 | 57 | typedef __mbstate_t __darwin_mbstate_t; /* mbstate_t */ 58 | 59 | #if defined(__PTRDIFF_TYPE__) 60 | typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 61 | #elif defined(__LP64__) 62 | typedef long __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 63 | #else 64 | typedef int __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 65 | #endif /* __GNUC__ */ 66 | 67 | #if defined(__SIZE_TYPE__) 68 | typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ 69 | #else 70 | typedef unsigned long __darwin_size_t; /* sizeof() */ 71 | #endif 72 | 73 | #if (__GNUC__ > 2) 74 | typedef __builtin_va_list __darwin_va_list; /* va_list */ 75 | #else 76 | typedef void * __darwin_va_list; /* va_list */ 77 | #endif 78 | 79 | #if defined(__WCHAR_TYPE__) 80 | typedef __WCHAR_TYPE__ __darwin_wchar_t; /* wchar_t */ 81 | #else 82 | typedef __darwin_ct_rune_t __darwin_wchar_t; /* wchar_t */ 83 | #endif 84 | 85 | typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 86 | 87 | #if defined(__WINT_TYPE__) 88 | typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 89 | #else 90 | typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */ 91 | #endif 92 | 93 | typedef unsigned long __darwin_clock_t; /* clock() */ 94 | typedef __uint32_t __darwin_socklen_t; /* socklen_t (duh) */ 95 | typedef long __darwin_ssize_t; /* byte count or error */ 96 | typedef long __darwin_time_t; /* time() */ 97 | 98 | #endif /* _BSD_ARM__TYPES_H_ */ 99 | -------------------------------------------------------------------------------- /apple-include/arm/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _ARM_ARCH_H 29 | #define _ARM_ARCH_H 30 | 31 | /* Collect the __ARM_ARCH_*__ compiler flags into something easier to use. */ 32 | #if defined (__ARM_ARCH_7A__) || defined (__ARM_ARCH_7S__) || defined (__ARM_ARCH_7F__) || defined (__ARM_ARCH_7K__) 33 | #define _ARM_ARCH_7 34 | #endif 35 | 36 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6K__) || defined (__ARM_ARCH_6ZK__) 37 | #define _ARM_ARCH_6K 38 | #endif 39 | 40 | #if defined (_ARM_ARCH_7) || defined (__ARM_ARCH_6Z__) || defined (__ARM_ARCH_6ZK__) 41 | #define _ARM_ARCH_6Z 42 | #endif 43 | 44 | #if defined (__ARM_ARCH_6__) || defined (__ARM_ARCH_6J__) || \ 45 | defined (_ARM_ARCH_6Z) || defined (_ARM_ARCH_6K) 46 | #define _ARM_ARCH_6 47 | #endif 48 | 49 | #if defined (_ARM_ARCH_6) || defined (__ARM_ARCH_5E__) || \ 50 | defined (__ARM_ARCH_5TE__) || defined (__ARM_ARCH_5TEJ__) 51 | #define _ARM_ARCH_5E 52 | #endif 53 | 54 | #if defined (_ARM_ARCH_5E) || defined (__ARM_ARCH_5__) || \ 55 | defined (__ARM_ARCH_5T__) 56 | #define _ARM_ARCH_5 57 | #endif 58 | 59 | #if defined (_ARM_ARCH_5) || defined (__ARM_ARCH_4T__) 60 | #define _ARM_ARCH_4T 61 | #endif 62 | 63 | #if defined (_ARM_ARCH_4T) || defined (__ARM_ARCH_4__) 64 | #define _ARM_ARCH_4 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /apple-include/i386/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _BSD_I386__TYPES_H_ 29 | #define _BSD_I386__TYPES_H_ 30 | 31 | /* 32 | * This header file contains integer types. It's intended to also contain 33 | * flotaing point and other arithmetic types, as needed, later. 34 | */ 35 | 36 | #ifdef __GNUC__ 37 | typedef __signed char __int8_t; 38 | #else /* !__GNUC__ */ 39 | typedef char __int8_t; 40 | #endif /* !__GNUC__ */ 41 | typedef unsigned char __uint8_t; 42 | typedef short __int16_t; 43 | typedef unsigned short __uint16_t; 44 | typedef int __int32_t; 45 | typedef unsigned int __uint32_t; 46 | #if !defined(__GNU_LIBRARY__) 47 | typedef long long __int64_t; 48 | typedef unsigned long long __uint64_t; 49 | #endif 50 | 51 | typedef long __darwin_intptr_t; 52 | typedef unsigned int __darwin_natural_t; 53 | 54 | /* 55 | * The rune type below is declared to be an ``int'' instead of the more natural 56 | * ``unsigned long'' or ``long''. Two things are happening here. It is not 57 | * unsigned so that EOF (-1) can be naturally assigned to it and used. Also, 58 | * it looks like 10646 will be a 31 bit standard. This means that if your 59 | * ints cannot hold 32 bits, you will be in trouble. The reason an int was 60 | * chosen over a long is that the is*() and to*() routines take ints (says 61 | * ANSI C), but they use __darwin_ct_rune_t instead of int. By changing it 62 | * here, you lose a bit of ANSI conformance, but your programs will still 63 | * work. 64 | * 65 | * NOTE: rune_t is not covered by ANSI nor other standards, and should not 66 | * be instantiated outside of lib/libc/locale. Use wchar_t. wchar_t and 67 | * rune_t must be the same type. Also wint_t must be no narrower than 68 | * wchar_t, and should also be able to hold all members of the largest 69 | * character set plus one extra value (WEOF). wint_t must be at least 16 bits. 70 | */ 71 | 72 | typedef int __darwin_ct_rune_t; /* ct_rune_t */ 73 | 74 | /* 75 | * mbstate_t is an opaque object to keep conversion state, during multibyte 76 | * stream conversions. The content must not be referenced by user programs. 77 | */ 78 | typedef union { 79 | char __mbstate8[128]; 80 | long long _mbstateL; /* for alignment */ 81 | } ___mbstate_t; 82 | 83 | typedef ___mbstate_t __darwin_mbstate_t; /* mbstate_t */ 84 | 85 | #if defined(__PTRDIFF_TYPE__) 86 | typedef __PTRDIFF_TYPE__ __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 87 | #elif defined(__LP64__) 88 | typedef long __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 89 | #else 90 | typedef int __darwin_ptrdiff_t; /* ptr1 - ptr2 */ 91 | #endif /* __GNUC__ */ 92 | 93 | #if defined(__SIZE_TYPE__) 94 | typedef __SIZE_TYPE__ __darwin_size_t; /* sizeof() */ 95 | #else 96 | typedef unsigned long __darwin_size_t; /* sizeof() */ 97 | #endif 98 | 99 | #if (__GNUC__ > 2) 100 | typedef __builtin_va_list __darwin_va_list; /* va_list */ 101 | #else 102 | typedef void * __darwin_va_list; /* va_list */ 103 | #endif 104 | 105 | #if defined(__WCHAR_TYPE__) 106 | typedef __WCHAR_TYPE__ __darwin_wchar_t; /* wchar_t */ 107 | #else 108 | typedef __darwin_ct_rune_t __darwin_wchar_t; /* wchar_t */ 109 | #endif 110 | 111 | typedef __darwin_wchar_t __darwin_rune_t; /* rune_t */ 112 | 113 | #if defined(__WINT_TYPE__) 114 | typedef __WINT_TYPE__ __darwin_wint_t; /* wint_t */ 115 | #else 116 | typedef __darwin_ct_rune_t __darwin_wint_t; /* wint_t */ 117 | #endif 118 | 119 | typedef unsigned long __darwin_clock_t; /* clock() */ 120 | typedef __uint32_t __darwin_socklen_t; /* socklen_t (duh) */ 121 | typedef long __darwin_ssize_t; /* byte count or error */ 122 | typedef long __darwin_time_t; /* time() */ 123 | 124 | #endif /* _BSD_I386__TYPES_H_ */ 125 | -------------------------------------------------------------------------------- /apple-include/i386/eflags.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | #ifndef _I386_EFLAGS_H_ 60 | #define _I386_EFLAGS_H_ 61 | 62 | /* 63 | * i386 flags register 64 | */ 65 | 66 | #ifndef EFL_CF 67 | #define EFL_CF 0x00000001 /* carry */ 68 | #define EFL_PF 0x00000004 /* parity of low 8 bits */ 69 | #define EFL_AF 0x00000010 /* carry out of bit 3 */ 70 | #define EFL_ZF 0x00000040 /* zero */ 71 | #define EFL_SF 0x00000080 /* sign */ 72 | #define EFL_TF 0x00000100 /* trace trap */ 73 | #define EFL_IF 0x00000200 /* interrupt enable */ 74 | #define EFL_DF 0x00000400 /* direction */ 75 | #define EFL_OF 0x00000800 /* overflow */ 76 | #define EFL_IOPL 0x00003000 /* IO privilege level: */ 77 | #define EFL_IOPL_KERNEL 0x00000000 /* kernel */ 78 | #define EFL_IOPL_USER 0x00003000 /* user */ 79 | #define EFL_NT 0x00004000 /* nested task */ 80 | #define EFL_RF 0x00010000 /* resume without tracing */ 81 | #define EFL_VM 0x00020000 /* virtual 8086 mode */ 82 | #define EFL_AC 0x00040000 /* alignment check */ 83 | #define EFL_VIF 0x00080000 /* virtual interrupt flag */ 84 | #define EFL_VIP 0x00100000 /* virtual interrupt pending */ 85 | #define EFL_ID 0x00200000 /* cpuID instruction */ 86 | #endif 87 | 88 | #define EFL_CLR 0xfff88028 89 | #define EFL_SET 0x00000002 90 | 91 | #define EFL_USER_SET (EFL_IF) 92 | #define EFL_USER_CLEAR (EFL_IOPL|EFL_NT|EFL_RF) 93 | 94 | #endif /* _I386_EFLAGS_H_ */ 95 | -------------------------------------------------------------------------------- /apple-include/libkern/_OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _OS__OSBYTEORDER_H 30 | #define _OS__OSBYTEORDER_H 31 | 32 | /* 33 | * This header is normally included from . However, 34 | * also includes this in the case of little-endian 35 | * architectures, so that we can map OSByteOrder routines to the hton* and ntoh* 36 | * macros. This results in the asymmetry below; we only include 37 | * for little-endian architectures. 38 | */ 39 | 40 | #include 41 | 42 | /* Macros for swapping constant values in the preprocessing stage. */ 43 | #define __DARWIN_OSSwapConstInt16(x) \ 44 | ((__uint16_t)((((__uint16_t)(x) & 0xff00U) >> 8) | \ 45 | (((__uint16_t)(x) & 0x00ffU) << 8))) 46 | 47 | #define __DARWIN_OSSwapConstInt32(x) \ 48 | ((__uint32_t)((((__uint32_t)(x) & 0xff000000U) >> 24) | \ 49 | (((__uint32_t)(x) & 0x00ff0000U) >> 8) | \ 50 | (((__uint32_t)(x) & 0x0000ff00U) << 8) | \ 51 | (((__uint32_t)(x) & 0x000000ffU) << 24))) 52 | 53 | #define __DARWIN_OSSwapConstInt64(x) \ 54 | ((__uint64_t)((((__uint64_t)(x) & 0xff00000000000000ULL) >> 56) | \ 55 | (((__uint64_t)(x) & 0x00ff000000000000ULL) >> 40) | \ 56 | (((__uint64_t)(x) & 0x0000ff0000000000ULL) >> 24) | \ 57 | (((__uint64_t)(x) & 0x000000ff00000000ULL) >> 8) | \ 58 | (((__uint64_t)(x) & 0x00000000ff000000ULL) << 8) | \ 59 | (((__uint64_t)(x) & 0x0000000000ff0000ULL) << 24) | \ 60 | (((__uint64_t)(x) & 0x000000000000ff00ULL) << 40) | \ 61 | (((__uint64_t)(x) & 0x00000000000000ffULL) << 56))) 62 | 63 | #if defined(__GNUC__) 64 | 65 | #if !defined(__DARWIN_OS_INLINE) 66 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 67 | # define __DARWIN_OS_INLINE static inline 68 | # elif defined(__MWERKS__) || defined(__cplusplus) 69 | # define __DARWIN_OS_INLINE static inline 70 | # else 71 | # define __DARWIN_OS_INLINE static __inline__ 72 | # endif 73 | #endif 74 | 75 | 76 | #if defined (__arm__) || defined(__arm64__) 77 | #include 78 | #endif 79 | 80 | 81 | #define __DARWIN_OSSwapInt16(x) \ 82 | ((__uint16_t)(__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt16(x) : _OSSwapInt16(x))) 83 | 84 | #define __DARWIN_OSSwapInt32(x) \ 85 | (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt32(x) : _OSSwapInt32(x)) 86 | 87 | #define __DARWIN_OSSwapInt64(x) \ 88 | (__builtin_constant_p(x) ? __DARWIN_OSSwapConstInt64(x) : _OSSwapInt64(x)) 89 | 90 | #else /* ! __GNUC__ */ 91 | 92 | 93 | #define __DARWIN_OSSwapInt16(x) _OSSwapInt16(x) 94 | 95 | #define __DARWIN_OSSwapInt32(x) _OSSwapInt32(x) 96 | 97 | #define __DARWIN_OSSwapInt64(x) _OSSwapInt64(x) 98 | 99 | #endif /* __GNUC__ */ 100 | 101 | #endif /* ! _OS__OSBYTEORDER_H */ 102 | -------------------------------------------------------------------------------- /apple-include/libkern/arm/OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999-2007 Apple Inc. All rights reserved. 3 | */ 4 | 5 | #ifndef _OS_OSBYTEORDERARM_H 6 | #define _OS_OSBYTEORDERARM_H 7 | 8 | #include 9 | #include /* for _ARM_ARCH_6 */ 10 | 11 | /* Generic byte swapping functions. */ 12 | 13 | __DARWIN_OS_INLINE 14 | uint16_t 15 | _OSSwapInt16( 16 | uint16_t _data 17 | ) 18 | { 19 | /* Reduces to 'rev16' with clang */ 20 | return (uint16_t)(_data << 8 | _data >> 8); 21 | } 22 | 23 | __DARWIN_OS_INLINE 24 | uint32_t 25 | _OSSwapInt32( 26 | uint32_t _data 27 | ) 28 | { 29 | #if defined(__llvm__) 30 | _data = __builtin_bswap32(_data); 31 | #else 32 | /* This actually generates the best code */ 33 | _data = (((_data ^ (_data >> 16 | (_data << 16))) & 0xFF00FFFF) >> 8) ^ (_data >> 8 | _data << 24); 34 | #endif 35 | 36 | return _data; 37 | } 38 | 39 | __DARWIN_OS_INLINE 40 | uint64_t 41 | _OSSwapInt64( 42 | uint64_t _data 43 | ) 44 | { 45 | #if defined(__llvm__) 46 | return __builtin_bswap64(_data); 47 | #else 48 | union { 49 | uint64_t _ull; 50 | uint32_t _ul[2]; 51 | } _u; 52 | 53 | /* This actually generates the best code */ 54 | _u._ul[0] = (uint32_t)(_data >> 32); 55 | _u._ul[1] = (uint32_t)(_data & 0xffffffff); 56 | _u._ul[0] = _OSSwapInt32(_u._ul[0]); 57 | _u._ul[1] = _OSSwapInt32(_u._ul[1]); 58 | return _u._ull; 59 | #endif 60 | } 61 | 62 | /* Functions for byte reversed loads. */ 63 | 64 | struct _OSUnalignedU16 { 65 | volatile uint16_t __val; 66 | } __attribute__((__packed__)); 67 | 68 | struct _OSUnalignedU32 { 69 | volatile uint32_t __val; 70 | } __attribute__((__packed__)); 71 | 72 | struct _OSUnalignedU64 { 73 | volatile uint64_t __val; 74 | } __attribute__((__packed__)); 75 | 76 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 77 | __DARWIN_OS_INLINE 78 | uint16_t 79 | _OSReadSwapInt16( 80 | const volatile void * _base, 81 | uintptr_t _offset 82 | ) 83 | { 84 | return _OSSwapInt16(((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val); 85 | } 86 | #else 87 | __DARWIN_OS_INLINE 88 | uint16_t 89 | OSReadSwapInt16( 90 | const volatile void * _base, 91 | uintptr_t _offset 92 | ) 93 | { 94 | return _OSSwapInt16(((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val); 95 | } 96 | #endif 97 | 98 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 99 | __DARWIN_OS_INLINE 100 | uint32_t 101 | _OSReadSwapInt32( 102 | const volatile void * _base, 103 | uintptr_t _offset 104 | ) 105 | { 106 | return _OSSwapInt32(((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val); 107 | } 108 | #else 109 | __DARWIN_OS_INLINE 110 | uint32_t 111 | OSReadSwapInt32( 112 | const volatile void * _base, 113 | uintptr_t _offset 114 | ) 115 | { 116 | return _OSSwapInt32(((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val); 117 | } 118 | #endif 119 | 120 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 121 | __DARWIN_OS_INLINE 122 | uint64_t 123 | _OSReadSwapInt64( 124 | const volatile void * _base, 125 | uintptr_t _offset 126 | ) 127 | { 128 | return _OSSwapInt64(((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val); 129 | } 130 | #else 131 | __DARWIN_OS_INLINE 132 | uint64_t 133 | OSReadSwapInt64( 134 | const volatile void * _base, 135 | uintptr_t _offset 136 | ) 137 | { 138 | return _OSSwapInt64(((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val); 139 | } 140 | #endif 141 | 142 | /* Functions for byte reversed stores. */ 143 | 144 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 145 | __DARWIN_OS_INLINE 146 | void 147 | _OSWriteSwapInt16( 148 | volatile void * _base, 149 | uintptr_t _offset, 150 | uint16_t _data 151 | ) 152 | { 153 | ((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt16(_data); 154 | } 155 | #else 156 | __DARWIN_OS_INLINE 157 | void 158 | OSWriteSwapInt16( 159 | volatile void * _base, 160 | uintptr_t _offset, 161 | uint16_t _data 162 | ) 163 | { 164 | ((struct _OSUnalignedU16 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt16(_data); 165 | } 166 | #endif 167 | 168 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 169 | __DARWIN_OS_INLINE 170 | void 171 | _OSWriteSwapInt32( 172 | volatile void * _base, 173 | uintptr_t _offset, 174 | uint32_t _data 175 | ) 176 | { 177 | ((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt32(_data); 178 | } 179 | #else 180 | __DARWIN_OS_INLINE 181 | void 182 | OSWriteSwapInt32( 183 | volatile void * _base, 184 | uintptr_t _offset, 185 | uint32_t _data 186 | ) 187 | { 188 | ((struct _OSUnalignedU32 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt32(_data); 189 | } 190 | #endif 191 | 192 | #if defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) 193 | __DARWIN_OS_INLINE 194 | void 195 | _OSWriteSwapInt64( 196 | volatile void * _base, 197 | uintptr_t _offset, 198 | uint64_t _data 199 | ) 200 | { 201 | ((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt64(_data); 202 | } 203 | #else 204 | __DARWIN_OS_INLINE 205 | void 206 | OSWriteSwapInt64( 207 | volatile void * _base, 208 | uintptr_t _offset, 209 | uint64_t _data 210 | ) 211 | { 212 | ((struct _OSUnalignedU64 *)((uintptr_t)_base + _offset))->__val = _OSSwapInt64(_data); 213 | } 214 | #endif 215 | 216 | #endif /* ! _OS_OSBYTEORDERARM_H */ 217 | -------------------------------------------------------------------------------- /apple-include/libkern/machine/OSByteOrder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _OS_OSBYTEORDERMACHINE_H 30 | #define _OS_OSBYTEORDERMACHINE_H 31 | 32 | #include 33 | 34 | #if !defined(OS_INLINE) 35 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 36 | # define OS_INLINE static inline 37 | # elif defined(__MWERKS__) || defined(__cplusplus) 38 | # define OS_INLINE static inline 39 | # else 40 | # define OS_INLINE static __inline__ 41 | # endif 42 | #endif 43 | 44 | /* Generic byte swapping functions. */ 45 | 46 | OS_INLINE 47 | uint16_t 48 | _OSSwapInt16( 49 | uint16_t data 50 | ) 51 | { 52 | return OSSwapConstInt16(data); 53 | } 54 | 55 | OS_INLINE 56 | uint32_t 57 | _OSSwapInt32( 58 | uint32_t data 59 | ) 60 | { 61 | return OSSwapConstInt32(data); 62 | } 63 | 64 | OS_INLINE 65 | uint64_t 66 | _OSSwapInt64( 67 | uint64_t data 68 | ) 69 | { 70 | return OSSwapConstInt64(data); 71 | } 72 | 73 | /* Functions for byte reversed loads. */ 74 | 75 | OS_INLINE 76 | uint16_t 77 | OSReadSwapInt16( 78 | const volatile void * base, 79 | uintptr_t byteOffset 80 | ) 81 | { 82 | uint16_t data = *(volatile uint16_t *)((uintptr_t)base + byteOffset); 83 | return _OSSwapInt16(data); 84 | } 85 | 86 | OS_INLINE 87 | uint32_t 88 | OSReadSwapInt32( 89 | const volatile void * base, 90 | uintptr_t byteOffset 91 | ) 92 | { 93 | uint32_t data = *(volatile uint32_t *)((uintptr_t)base + byteOffset); 94 | return _OSSwapInt32(data); 95 | } 96 | 97 | OS_INLINE 98 | uint64_t 99 | OSReadSwapInt64( 100 | const volatile void * base, 101 | uintptr_t byteOffset 102 | ) 103 | { 104 | uint64_t data = *(volatile uint64_t *)((uintptr_t)base + byteOffset); 105 | return _OSSwapInt64(data); 106 | } 107 | 108 | /* Functions for byte reversed stores. */ 109 | 110 | OS_INLINE 111 | void 112 | OSWriteSwapInt16( 113 | volatile void * base, 114 | uintptr_t byteOffset, 115 | uint16_t data 116 | ) 117 | { 118 | *(volatile uint16_t *)((uintptr_t)base + byteOffset) = _OSSwapInt16(data); 119 | } 120 | 121 | OS_INLINE 122 | void 123 | OSWriteSwapInt32( 124 | volatile void * base, 125 | uintptr_t byteOffset, 126 | uint32_t data 127 | ) 128 | { 129 | *(volatile uint32_t *)((uintptr_t)base + byteOffset) = _OSSwapInt32(data); 130 | } 131 | 132 | OS_INLINE 133 | void 134 | OSWriteSwapInt64( 135 | volatile void * base, 136 | uintptr_t byteOffset, 137 | uint64_t data 138 | ) 139 | { 140 | *(volatile uint64_t *)((uintptr_t)base + byteOffset) = _OSSwapInt64(data); 141 | } 142 | 143 | #endif /* ! _OS_OSBYTEORDERMACHINE_H */ 144 | -------------------------------------------------------------------------------- /apple-include/mach/arm/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for ARM. 63 | */ 64 | 65 | #ifndef _MACH_ARM_BOOLEAN_H_ 66 | #define _MACH_ARM_BOOLEAN_H_ 67 | 68 | typedef int boolean_t; 69 | 70 | #endif /* _MACH_ARM_BOOLEAN_H_ */ 71 | -------------------------------------------------------------------------------- /apple-include/mach/arm/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_ARM_KERN_RETURN_H_ 68 | #define _MACH_ARM_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_ARM_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/arm/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_ARM_THREAD_STATE_H_ 33 | #define _MACH_ARM_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in words */ 36 | #define ARM_THREAD_STATE_MAX (1296) /* Size of biggest state possible */ 37 | 38 | #if defined (__arm__) || defined(__arm64__) 39 | #define THREAD_STATE_MAX ARM_THREAD_STATE_MAX 40 | #else 41 | #error Unsupported arch 42 | #endif 43 | 44 | #endif /* _MACH_ARM_THREAD_STATE_H_ */ 45 | -------------------------------------------------------------------------------- /apple-include/mach/arm/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: vm_types.h 61 | * Author: Avadis Tevanian, Jr. 62 | * Date: 1985 63 | * 64 | * Header file for VM data types. ARM version. 65 | */ 66 | 67 | #ifndef _MACH_ARM_VM_TYPES_H_ 68 | #define _MACH_ARM_VM_TYPES_H_ 69 | 70 | #ifndef ASSEMBLER 71 | 72 | #include 73 | #include 74 | #include 75 | 76 | /* 77 | * natural_t and integer_t are Mach's legacy types for machine- 78 | * independent integer types (unsigned, and signed, respectively). 79 | * Their original purpose was to define other types in a machine/ 80 | * compiler independent way. 81 | * 82 | * They also had an implicit "same size as pointer" characteristic 83 | * to them (i.e. Mach's traditional types are very ILP32 or ILP64 84 | * centric). We will likely support x86 ABIs that do not follow 85 | * either ofthese models (specifically LP64). Therefore, we had to 86 | * make a choice between making these types scale with pointers or stay 87 | * tied to integers. Because their use is predominantly tied to 88 | * to the size of an integer, we are keeping that association and 89 | * breaking free from pointer size guarantees. 90 | * 91 | * New use of these types is discouraged. 92 | */ 93 | typedef __darwin_natural_t natural_t; 94 | typedef int integer_t; 95 | 96 | /* 97 | * A vm_offset_t is a type-neutral pointer, 98 | * e.g. an offset into a virtual memory space. 99 | */ 100 | #ifdef __LP64__ 101 | typedef uintptr_t vm_offset_t; 102 | typedef uintptr_t vm_size_t; 103 | 104 | typedef uint64_t mach_vm_address_t; 105 | typedef uint64_t mach_vm_offset_t; 106 | typedef uint64_t mach_vm_size_t; 107 | 108 | typedef uint64_t vm_map_offset_t; 109 | typedef uint64_t vm_map_address_t; 110 | typedef uint64_t vm_map_size_t; 111 | #else 112 | typedef natural_t vm_offset_t; 113 | /* 114 | * A vm_size_t is the proper type for e.g. 115 | * expressing the difference between two 116 | * vm_offset_t entities. 117 | */ 118 | typedef natural_t vm_size_t; 119 | 120 | /* 121 | * This new type is independent of a particular vm map's 122 | * implementation size - and represents appropriate types 123 | * for all possible maps. This is used for interfaces 124 | * where the size of the map is not known - or we don't 125 | * want to have to distinguish. 126 | */ 127 | #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0) 128 | typedef uint32_t mach_vm_address_t; 129 | typedef uint32_t mach_vm_offset_t; 130 | typedef uint32_t mach_vm_size_t; 131 | #else 132 | typedef uint64_t mach_vm_address_t; 133 | typedef uint64_t mach_vm_offset_t; 134 | typedef uint64_t mach_vm_size_t; 135 | #endif 136 | 137 | typedef uint32_t vm_map_offset_t; 138 | typedef uint32_t vm_map_address_t; 139 | typedef uint32_t vm_map_size_t; 140 | #endif /* __LP64__ */ 141 | 142 | 143 | typedef uint32_t vm32_offset_t; 144 | typedef uint32_t vm32_address_t; 145 | typedef uint32_t vm32_size_t; 146 | 147 | typedef vm_offset_t mach_port_context_t; 148 | 149 | 150 | #endif /* ASSEMBLER */ 151 | 152 | /* 153 | * If composing messages by hand (please do not) 154 | */ 155 | #define MACH_MSG_TYPE_INTEGER_T MACH_MSG_TYPE_INTEGER_32 156 | 157 | #endif /* _MACH_ARM_VM_TYPES_H_ */ 158 | -------------------------------------------------------------------------------- /apple-include/mach/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | /* 59 | * File: mach/boolean.h 60 | * 61 | * Boolean data type. 62 | * 63 | */ 64 | 65 | #ifndef _MACH_BOOLEAN_H_ 66 | #define _MACH_BOOLEAN_H_ 67 | 68 | /* 69 | * Pick up "boolean_t" type definition 70 | */ 71 | 72 | #ifndef ASSEMBLER 73 | #include 74 | #endif /* ASSEMBLER */ 75 | 76 | /* 77 | * Define TRUE and FALSE if not defined. 78 | */ 79 | 80 | #ifndef TRUE 81 | #define TRUE 1 82 | #endif /* TRUE */ 83 | 84 | #ifndef FALSE 85 | #define FALSE 0 86 | #endif /* FALSE */ 87 | 88 | #endif /* _MACH_BOOLEAN_H_ */ 89 | -------------------------------------------------------------------------------- /apple-include/mach/i386/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: boolean.h 61 | * 62 | * Boolean type, for I386. 63 | */ 64 | 65 | #ifndef _MACH_I386_BOOLEAN_H_ 66 | #define _MACH_I386_BOOLEAN_H_ 67 | 68 | #if defined(__x86_64__) && !defined(KERNEL) 69 | typedef unsigned int boolean_t; 70 | #else 71 | typedef int boolean_t; 72 | #endif 73 | 74 | #endif /* _MACH_I386_BOOLEAN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/i386/fp_reg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1992-1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | #ifndef _I386_FP_SAVE_H_ 60 | #define _I386_FP_SAVE_H_ 61 | 62 | /* 63 | * Control register 64 | */ 65 | #define FPC_IE 0x0001 /* enable invalid operation 66 | * exception */ 67 | #define FPC_IM FPC_IE 68 | #define FPC_DE 0x0002 /* enable denormalized operation 69 | * exception */ 70 | #define FPC_DM FPC_DE 71 | #define FPC_ZE 0x0004 /* enable zero-divide exception */ 72 | #define FPC_ZM FPC_ZE 73 | #define FPC_OE 0x0008 /* enable overflow exception */ 74 | #define FPC_OM FPC_OE 75 | #define FPC_UE 0x0010 /* enable underflow exception */ 76 | #define FPC_PE 0x0020 /* enable precision exception */ 77 | #define FPC_PC 0x0300 /* precision control: */ 78 | #define FPC_PC_24 0x0000 /* 24 bits */ 79 | #define FPC_PC_53 0x0200 /* 53 bits */ 80 | #define FPC_PC_64 0x0300 /* 64 bits */ 81 | #define FPC_RC 0x0c00 /* rounding control: */ 82 | #define FPC_RC_RN 0x0000 /* round to nearest or even */ 83 | #define FPC_RC_RD 0x0400 /* round down */ 84 | #define FPC_RC_RU 0x0800 /* round up */ 85 | #define FPC_RC_CHOP 0x0c00 /* chop */ 86 | #define FPC_IC 0x1000 /* infinity control (obsolete) */ 87 | #define FPC_IC_PROJ 0x0000 /* projective infinity */ 88 | #define FPC_IC_AFF 0x1000 /* affine infinity (std) */ 89 | 90 | /* 91 | * Status register 92 | */ 93 | #define FPS_IE 0x0001 /* invalid operation */ 94 | #define FPS_DE 0x0002 /* denormalized operand */ 95 | #define FPS_ZE 0x0004 /* divide by zero */ 96 | #define FPS_OE 0x0008 /* overflow */ 97 | #define FPS_UE 0x0010 /* underflow */ 98 | #define FPS_PE 0x0020 /* precision */ 99 | #define FPS_SF 0x0040 /* stack flag */ 100 | #define FPS_ES 0x0080 /* error summary */ 101 | #define FPS_C0 0x0100 /* condition code bit 0 */ 102 | #define FPS_C1 0x0200 /* condition code bit 1 */ 103 | #define FPS_C2 0x0400 /* condition code bit 2 */ 104 | #define FPS_TOS 0x3800 /* top-of-stack pointer */ 105 | #define FPS_TOS_SHIFT 11 106 | #define FPS_C3 0x4000 /* condition code bit 3 */ 107 | #define FPS_BUSY 0x8000 /* FPU busy */ 108 | 109 | /* 110 | * Kind of floating-point support provided by kernel. 111 | */ 112 | #define FP_NO 0 /* no floating point */ 113 | #define FP_SOFT 1 /* software FP emulator */ 114 | #define FP_287 2 /* 80287 */ 115 | #define FP_387 3 /* 80387 or 80486 */ 116 | #define FP_FXSR 4 /* Fast save/restore SIMD Extension */ 117 | 118 | #endif /* _I386_FP_SAVE_H_ */ 119 | -------------------------------------------------------------------------------- /apple-include/mach/i386/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: kern_return.h 61 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 62 | * Date: 1985 63 | * 64 | * Machine-dependent kernel return definitions. 65 | */ 66 | 67 | #ifndef _MACH_I386_KERN_RETURN_H_ 68 | #define _MACH_I386_KERN_RETURN_H_ 69 | 70 | #ifndef ASSEMBLER 71 | typedef int kern_return_t; 72 | #endif /* ASSEMBLER */ 73 | 74 | #endif /* _MACH_I386_KERN_RETURN_H_ */ 75 | -------------------------------------------------------------------------------- /apple-include/mach/i386/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | 32 | #ifndef _MACH_I386_THREAD_STATE_H_ 33 | #define _MACH_I386_THREAD_STATE_H_ 34 | 35 | /* Size of maximum exported thread state in 32-bit words */ 36 | #define I386_THREAD_STATE_MAX (614) /* Size of biggest state possible */ 37 | 38 | #if defined (__i386__) || defined(__x86_64__) 39 | #define THREAD_STATE_MAX I386_THREAD_STATE_MAX 40 | #endif 41 | 42 | #endif /* _MACH_I386_THREAD_STATE_H_ */ 43 | -------------------------------------------------------------------------------- /apple-include/mach/i386/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2016 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | 59 | /* 60 | * File: vm_types.h 61 | * Author: Avadis Tevanian, Jr. 62 | * Date: 1985 63 | * 64 | * Header file for VM data types. I386 version. 65 | */ 66 | 67 | #ifndef _MACH_I386_VM_TYPES_H_ 68 | #define _MACH_I386_VM_TYPES_H_ 69 | 70 | #ifndef ASSEMBLER 71 | 72 | #include 73 | #include 74 | 75 | /* 76 | * natural_t and integer_t are Mach's legacy types for machine- 77 | * independent integer types (unsigned, and signed, respectively). 78 | * Their original purpose was to define other types in a machine/ 79 | * compiler independent way. 80 | * 81 | * They also had an implicit "same size as pointer" characteristic 82 | * to them (i.e. Mach's traditional types are very ILP32 or ILP64 83 | * centric). We support x86 ABIs that do not follow either of 84 | * these models (specifically LP64). Therefore, we had to make a 85 | * choice between making these types scale with pointers or stay 86 | * tied to integers. Because their use is predominantly tied to 87 | * to the size of an integer, we are keeping that association and 88 | * breaking free from pointer size guarantees. 89 | * 90 | * New use of these types is discouraged. 91 | */ 92 | typedef __darwin_natural_t natural_t; 93 | typedef int integer_t; 94 | 95 | /* 96 | * A vm_offset_t is a type-neutral pointer, 97 | * e.g. an offset into a virtual memory space. 98 | */ 99 | #ifdef __LP64__ 100 | typedef uintptr_t vm_offset_t; 101 | #else /* __LP64__ */ 102 | typedef natural_t vm_offset_t; 103 | #endif /* __LP64__ */ 104 | 105 | /* 106 | * A vm_size_t is the proper type for e.g. 107 | * expressing the difference between two 108 | * vm_offset_t entities. 109 | */ 110 | #ifdef __LP64__ 111 | typedef uintptr_t vm_size_t; 112 | #else /* __LP64__ */ 113 | typedef natural_t vm_size_t; 114 | #endif /* __LP64__ */ 115 | 116 | /* 117 | * This new type is independent of a particular vm map's 118 | * implementation size - and represents appropriate types 119 | * for all possible maps. This is used for interfaces 120 | * where the size of the map is not known - or we don't 121 | * want to have to distinguish. 122 | */ 123 | typedef uint64_t mach_vm_address_t; 124 | typedef uint64_t mach_vm_offset_t; 125 | typedef uint64_t mach_vm_size_t; 126 | 127 | typedef uint64_t vm_map_offset_t; 128 | typedef uint64_t vm_map_address_t; 129 | typedef uint64_t vm_map_size_t; 130 | 131 | typedef mach_vm_address_t mach_port_context_t; 132 | 133 | 134 | #endif /* ASSEMBLER */ 135 | 136 | /* 137 | * If composing messages by hand (please do not) 138 | */ 139 | #define MACH_MSG_TYPE_INTEGER_T MACH_MSG_TYPE_INTEGER_32 140 | 141 | #endif /* _MACH_I386_VM_TYPES_H_ */ 142 | -------------------------------------------------------------------------------- /apple-include/mach/machine/_structs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE__STRUCTS_H_ 30 | #define _MACH_MACHINE__STRUCTS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/_structs.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/_structs.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE__STRUCTS_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/boolean.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_BOOLEAN_H_ 30 | #define _MACH_MACHINE_BOOLEAN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/boolean.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/boolean.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_BOOLEAN_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/kern_return.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_KERN_RETURN_H_ 30 | #define _MACH_MACHINE_KERN_RETURN_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/kern_return.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/kern_return.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_KERN_RETURN_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/thread_state.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATE_H_ 30 | #define _MACH_MACHINE_THREAD_STATE_H_ 31 | 32 | #if defined (__arm__) || defined (__arm64__) 33 | #include "mach/arm/thread_state.h" 34 | #else 35 | #error architecture not supported 36 | #endif 37 | 38 | #endif /* _MACH_MACHINE_THREAD_STATE_H_ */ 39 | -------------------------------------------------------------------------------- /apple-include/mach/machine/thread_status.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_THREAD_STATUS_H_ 30 | #define _MACH_MACHINE_THREAD_STATUS_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/thread_status.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/thread_status.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_THREAD_STATUS_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/machine/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _MACH_MACHINE_VM_TYPES_H_ 30 | #define _MACH_MACHINE_VM_TYPES_H_ 31 | 32 | #if defined (__i386__) || defined(__x86_64__) 33 | #include "mach/i386/vm_types.h" 34 | #elif defined (__arm__) || defined (__arm64__) 35 | #include "mach/arm/vm_types.h" 36 | #else 37 | #error architecture not supported 38 | #endif 39 | 40 | #endif /* _MACH_MACHINE_VM_TYPES_H_ */ 41 | -------------------------------------------------------------------------------- /apple-include/mach/vm_prot.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | */ 31 | /* 32 | * Mach Operating System 33 | * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University 34 | * All Rights Reserved. 35 | * 36 | * Permission to use, copy, modify and distribute this software and its 37 | * documentation is hereby granted, provided that both the copyright 38 | * notice and this permission notice appear in all copies of the 39 | * software, derivative works or modified versions, and any portions 40 | * thereof, and that both notices appear in supporting documentation. 41 | * 42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 45 | * 46 | * Carnegie Mellon requests users of this software to return to 47 | * 48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 49 | * School of Computer Science 50 | * Carnegie Mellon University 51 | * Pittsburgh PA 15213-3890 52 | * 53 | * any improvements or extensions that they make and grant Carnegie Mellon 54 | * the rights to redistribute these changes. 55 | */ 56 | /* 57 | */ 58 | /* 59 | * File: mach/vm_prot.h 60 | * Author: Avadis Tevanian, Jr., Michael Wayne Young 61 | * 62 | * Virtual memory protection definitions. 63 | * 64 | */ 65 | 66 | #ifndef _MACH_VM_PROT_H_ 67 | #define _MACH_VM_PROT_H_ 68 | 69 | /* 70 | * Types defined: 71 | * 72 | * vm_prot_t VM protection values. 73 | */ 74 | 75 | typedef int vm_prot_t; 76 | 77 | /* 78 | * Protection values, defined as bits within the vm_prot_t type 79 | */ 80 | 81 | #define VM_PROT_NONE ((vm_prot_t) 0x00) 82 | 83 | #define VM_PROT_READ ((vm_prot_t) 0x01) /* read permission */ 84 | #define VM_PROT_WRITE ((vm_prot_t) 0x02) /* write permission */ 85 | #define VM_PROT_EXECUTE ((vm_prot_t) 0x04) /* execute permission */ 86 | 87 | /* 88 | * The default protection for newly-created virtual memory 89 | */ 90 | 91 | #define VM_PROT_DEFAULT (VM_PROT_READ|VM_PROT_WRITE) 92 | 93 | /* 94 | * The maximum privileges possible, for parameter checking. 95 | */ 96 | 97 | #define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) 98 | 99 | /* 100 | * An invalid protection value. 101 | * Used only by memory_object_lock_request to indicate no change 102 | * to page locks. Using -1 here is a bad idea because it 103 | * looks like VM_PROT_ALL and then some. 104 | */ 105 | 106 | #define VM_PROT_NO_CHANGE ((vm_prot_t) 0x08) 107 | 108 | /* 109 | * When a caller finds that he cannot obtain write permission on a 110 | * mapped entry, the following flag can be used. The entry will 111 | * be made "needs copy" effectively copying the object (using COW), 112 | * and write permission will be added to the maximum protections 113 | * for the associated entry. 114 | */ 115 | 116 | #define VM_PROT_COPY ((vm_prot_t) 0x10) 117 | 118 | 119 | /* 120 | * Another invalid protection value. 121 | * Used only by memory_object_data_request upon an object 122 | * which has specified a copy_call copy strategy. It is used 123 | * when the kernel wants a page belonging to a copy of the 124 | * object, and is only asking the object as a result of 125 | * following a shadow chain. This solves the race between pages 126 | * being pushed up by the memory manager and the kernel 127 | * walking down the shadow chain. 128 | */ 129 | 130 | #define VM_PROT_WANTS_COPY ((vm_prot_t) 0x10) 131 | 132 | 133 | /* 134 | * Another invalid protection value. 135 | * Indicates that the other protection bits are to be applied as a mask 136 | * against the actual protection bits of the map entry. 137 | */ 138 | #define VM_PROT_IS_MASK ((vm_prot_t) 0x40) 139 | 140 | /* 141 | * Another invalid protection value to support execute-only protection. 142 | * VM_PROT_STRIP_READ is a special marker that tells mprotect to not 143 | * set VM_PROT_READ. We have to do it this way because existing code 144 | * expects the system to set VM_PROT_READ if VM_PROT_EXECUTE is set. 145 | * VM_PROT_EXECUTE_ONLY is just a convenience value to indicate that 146 | * the memory should be executable and explicitly not readable. It will 147 | * be ignored on platforms that do not support this type of protection. 148 | */ 149 | #define VM_PROT_STRIP_READ ((vm_prot_t) 0x80) 150 | #define VM_PROT_EXECUTE_ONLY (VM_PROT_EXECUTE|VM_PROT_STRIP_READ) 151 | 152 | 153 | #endif /* _MACH_VM_PROT_H_ */ 154 | -------------------------------------------------------------------------------- /apple-include/mach/vm_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000-2018 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | /* 29 | * @OSF_COPYRIGHT@ 30 | * 31 | */ 32 | #ifndef _MACH_VM_TYPES_H_ 33 | #define _MACH_VM_TYPES_H_ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | typedef vm_offset_t pointer_t; 41 | typedef vm_offset_t vm_address_t; 42 | 43 | /* 44 | * We use addr64_t for 64-bit addresses that are used on both 45 | * 32 and 64-bit machines. On PPC, they are passed and returned as 46 | * two adjacent 32-bit GPRs. We use addr64_t in places where 47 | * common code must be useable both on 32 and 64-bit machines. 48 | */ 49 | typedef uint64_t addr64_t; /* Basic effective address */ 50 | 51 | /* 52 | * We use reg64_t for addresses that are 32 bits on a 32-bit 53 | * machine, and 64 bits on a 64-bit machine, but are always 54 | * passed and returned in a single GPR on PPC. This type 55 | * cannot be used in generic 32-bit c, since on a 64-bit 56 | * machine the upper half of the register will be ignored 57 | * by the c compiler in 32-bit mode. In c, we can only use the 58 | * type in prototypes of functions that are written in and called 59 | * from assembly language. This type is basically a comment. 60 | */ 61 | typedef uint32_t reg64_t; 62 | 63 | /* 64 | * To minimize the use of 64-bit fields, we keep some physical 65 | * addresses (that are page aligned) as 32-bit page numbers. 66 | * This limits the physical address space to 16TB of RAM. 67 | */ 68 | typedef uint32_t ppnum_t; /* Physical page number */ 69 | #define PPNUM_MAX UINT32_MAX 70 | 71 | 72 | 73 | typedef mach_port_t vm_map_t, vm_map_read_t, vm_map_inspect_t; 74 | 75 | 76 | #define VM_MAP_NULL ((vm_map_t) 0) 77 | #define VM_MAP_INSPECT_NULL ((vm_map_inspect_t) 0) 78 | #define VM_MAP_READ_NULL ((vm_map_read_t) 0) 79 | 80 | /* 81 | * Evolving definitions, likely to change. 82 | */ 83 | 84 | typedef uint64_t vm_object_offset_t; 85 | typedef uint64_t vm_object_size_t; 86 | 87 | 88 | 89 | 90 | typedef mach_port_t upl_t; 91 | typedef mach_port_t vm_named_entry_t; 92 | 93 | 94 | #define UPL_NULL ((upl_t) 0) 95 | #define VM_NAMED_ENTRY_NULL ((vm_named_entry_t) 0) 96 | 97 | #endif /* _MACH_VM_TYPES_H_ */ 98 | -------------------------------------------------------------------------------- /apple-include/machine/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #ifndef _BSD_MACHINE__TYPES_H_ 29 | #define _BSD_MACHINE__TYPES_H_ 30 | 31 | #if defined (__i386__) || defined(__x86_64__) 32 | #include "i386/_types.h" 33 | #elif defined (__arm__) || defined (__arm64__) 34 | #include "arm/_types.h" 35 | #else 36 | #error architecture not supported 37 | #endif 38 | 39 | #endif /* _BSD_MACHINE__TYPES_H_ */ 40 | -------------------------------------------------------------------------------- /apple-include/sys/_posix_availability.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2010 Apple Inc. All rights reserved. 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@ 26 | */ 27 | 28 | #ifndef _CDEFS_H_ 29 | # error "Never use directly. Use instead." 30 | #endif 31 | 32 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 198808L 33 | #define ___POSIX_C_DEPRECATED_STARTING_198808L __deprecated 34 | #else 35 | #define ___POSIX_C_DEPRECATED_STARTING_198808L 36 | #endif 37 | 38 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199009L 39 | #define ___POSIX_C_DEPRECATED_STARTING_199009L __deprecated 40 | #else 41 | #define ___POSIX_C_DEPRECATED_STARTING_199009L 42 | #endif 43 | 44 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199209L 45 | #define ___POSIX_C_DEPRECATED_STARTING_199209L __deprecated 46 | #else 47 | #define ___POSIX_C_DEPRECATED_STARTING_199209L 48 | #endif 49 | 50 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199309L 51 | #define ___POSIX_C_DEPRECATED_STARTING_199309L __deprecated 52 | #else 53 | #define ___POSIX_C_DEPRECATED_STARTING_199309L 54 | #endif 55 | 56 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 199506L 57 | #define ___POSIX_C_DEPRECATED_STARTING_199506L __deprecated 58 | #else 59 | #define ___POSIX_C_DEPRECATED_STARTING_199506L 60 | #endif 61 | 62 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L 63 | #define ___POSIX_C_DEPRECATED_STARTING_200112L __deprecated 64 | #else 65 | #define ___POSIX_C_DEPRECATED_STARTING_200112L 66 | #endif 67 | 68 | #if !defined(_DARWIN_C_SOURCE) && defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L 69 | #define ___POSIX_C_DEPRECATED_STARTING_200809L __deprecated 70 | #else 71 | #define ___POSIX_C_DEPRECATED_STARTING_200809L 72 | #endif 73 | 74 | -------------------------------------------------------------------------------- /apple-include/sys/_pthread/_pthread_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2013 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _SYS__PTHREAD_TYPES_H_ 30 | #define _SYS__PTHREAD_TYPES_H_ 31 | 32 | #include 33 | 34 | // pthread opaque structures 35 | #if defined(__LP64__) 36 | #define __PTHREAD_SIZE__ 8176 37 | #define __PTHREAD_ATTR_SIZE__ 56 38 | #define __PTHREAD_MUTEXATTR_SIZE__ 8 39 | #define __PTHREAD_MUTEX_SIZE__ 56 40 | #define __PTHREAD_CONDATTR_SIZE__ 8 41 | #define __PTHREAD_COND_SIZE__ 40 42 | #define __PTHREAD_ONCE_SIZE__ 8 43 | #define __PTHREAD_RWLOCK_SIZE__ 192 44 | #define __PTHREAD_RWLOCKATTR_SIZE__ 16 45 | #else // !__LP64__ 46 | #define __PTHREAD_SIZE__ 4088 47 | #define __PTHREAD_ATTR_SIZE__ 36 48 | #define __PTHREAD_MUTEXATTR_SIZE__ 8 49 | #define __PTHREAD_MUTEX_SIZE__ 40 50 | #define __PTHREAD_CONDATTR_SIZE__ 4 51 | #define __PTHREAD_COND_SIZE__ 24 52 | #define __PTHREAD_ONCE_SIZE__ 4 53 | #define __PTHREAD_RWLOCK_SIZE__ 124 54 | #define __PTHREAD_RWLOCKATTR_SIZE__ 12 55 | #endif // !__LP64__ 56 | 57 | struct __darwin_pthread_handler_rec { 58 | void (*__routine)(void *); // Routine to call 59 | void *__arg; // Argument to pass 60 | struct __darwin_pthread_handler_rec *__next; 61 | }; 62 | 63 | struct _opaque_pthread_attr_t { 64 | long __sig; 65 | char __opaque[__PTHREAD_ATTR_SIZE__]; 66 | }; 67 | 68 | struct _opaque_pthread_cond_t { 69 | long __sig; 70 | char __opaque[__PTHREAD_COND_SIZE__]; 71 | }; 72 | 73 | struct _opaque_pthread_condattr_t { 74 | long __sig; 75 | char __opaque[__PTHREAD_CONDATTR_SIZE__]; 76 | }; 77 | 78 | struct _opaque_pthread_mutex_t { 79 | long __sig; 80 | char __opaque[__PTHREAD_MUTEX_SIZE__]; 81 | }; 82 | 83 | struct _opaque_pthread_mutexattr_t { 84 | long __sig; 85 | char __opaque[__PTHREAD_MUTEXATTR_SIZE__]; 86 | }; 87 | 88 | struct _opaque_pthread_once_t { 89 | long __sig; 90 | char __opaque[__PTHREAD_ONCE_SIZE__]; 91 | }; 92 | 93 | struct _opaque_pthread_rwlock_t { 94 | long __sig; 95 | char __opaque[__PTHREAD_RWLOCK_SIZE__]; 96 | }; 97 | 98 | struct _opaque_pthread_rwlockattr_t { 99 | long __sig; 100 | char __opaque[__PTHREAD_RWLOCKATTR_SIZE__]; 101 | }; 102 | 103 | struct _opaque_pthread_t { 104 | long __sig; 105 | struct __darwin_pthread_handler_rec *__cleanup_stack; 106 | char __opaque[__PTHREAD_SIZE__]; 107 | }; 108 | 109 | typedef struct _opaque_pthread_attr_t __darwin_pthread_attr_t; 110 | typedef struct _opaque_pthread_cond_t __darwin_pthread_cond_t; 111 | typedef struct _opaque_pthread_condattr_t __darwin_pthread_condattr_t; 112 | typedef unsigned long __darwin_pthread_key_t; 113 | typedef struct _opaque_pthread_mutex_t __darwin_pthread_mutex_t; 114 | typedef struct _opaque_pthread_mutexattr_t __darwin_pthread_mutexattr_t; 115 | typedef struct _opaque_pthread_once_t __darwin_pthread_once_t; 116 | typedef struct _opaque_pthread_rwlock_t __darwin_pthread_rwlock_t; 117 | typedef struct _opaque_pthread_rwlockattr_t __darwin_pthread_rwlockattr_t; 118 | typedef struct _opaque_pthread_t *__darwin_pthread_t; 119 | 120 | #endif // _SYS__PTHREAD_TYPES_H_ 121 | -------------------------------------------------------------------------------- /apple-include/sys/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2007 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef _SYS__TYPES_H_ 30 | #define _SYS__TYPES_H_ 31 | 32 | #include 33 | #include 34 | 35 | /* 36 | * Type definitions; takes common type definitions that must be used 37 | * in multiple header files due to [XSI], removes them from the system 38 | * space, and puts them in the implementation space. 39 | */ 40 | 41 | #ifdef __cplusplus 42 | #ifdef __GNUG__ 43 | #define __DARWIN_NULL __null 44 | #else /* ! __GNUG__ */ 45 | #ifdef __LP64__ 46 | #define __DARWIN_NULL (0L) 47 | #else /* !__LP64__ */ 48 | #define __DARWIN_NULL 0 49 | #endif /* __LP64__ */ 50 | #endif /* __GNUG__ */ 51 | #else /* ! __cplusplus */ 52 | #define __DARWIN_NULL ((void *)0) 53 | #endif /* __cplusplus */ 54 | 55 | typedef __int64_t __darwin_blkcnt_t; /* total blocks */ 56 | typedef __int32_t __darwin_blksize_t; /* preferred block size */ 57 | typedef __int32_t __darwin_dev_t; /* dev_t */ 58 | typedef unsigned int __darwin_fsblkcnt_t; /* Used by statvfs and fstatvfs */ 59 | typedef unsigned int __darwin_fsfilcnt_t; /* Used by statvfs and fstatvfs */ 60 | typedef __uint32_t __darwin_gid_t; /* [???] process and group IDs */ 61 | typedef __uint32_t __darwin_id_t; /* [XSI] pid_t, uid_t, or gid_t*/ 62 | typedef __uint64_t __darwin_ino64_t; /* [???] Used for 64 bit inodes */ 63 | #if __DARWIN_64_BIT_INO_T 64 | typedef __darwin_ino64_t __darwin_ino_t; /* [???] Used for inodes */ 65 | #else /* !__DARWIN_64_BIT_INO_T */ 66 | typedef __uint32_t __darwin_ino_t; /* [???] Used for inodes */ 67 | #endif /* __DARWIN_64_BIT_INO_T */ 68 | typedef __darwin_natural_t __darwin_mach_port_name_t; /* Used by mach */ 69 | typedef __darwin_mach_port_name_t __darwin_mach_port_t; /* Used by mach */ 70 | typedef __uint16_t __darwin_mode_t; /* [???] Some file attributes */ 71 | typedef __int64_t __darwin_off_t; /* [???] Used for file sizes */ 72 | typedef __int32_t __darwin_pid_t; /* [???] process and group IDs */ 73 | typedef __uint32_t __darwin_sigset_t; /* [???] signal set */ 74 | typedef __int32_t __darwin_suseconds_t; /* [???] microseconds */ 75 | typedef __uint32_t __darwin_uid_t; /* [???] user IDs */ 76 | typedef __uint32_t __darwin_useconds_t; /* [???] microseconds */ 77 | typedef unsigned char __darwin_uuid_t[16]; 78 | typedef char __darwin_uuid_string_t[37]; 79 | 80 | #include 81 | 82 | #endif /* _SYS__TYPES_H_ */ 83 | -------------------------------------------------------------------------------- /apple-include/sys/_types/_mach_port_t.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | /* 30 | * mach_port_t - a named port right 31 | * 32 | * In user-space, "rights" are represented by the name of the 33 | * right in the Mach port namespace. Even so, this type is 34 | * presented as a unique one to more clearly denote the presence 35 | * of a right coming along with the name. 36 | * 37 | * Often, various rights for a port held in a single name space 38 | * will coalesce and are, therefore, be identified by a single name 39 | * [this is the case for send and receive rights]. But not 40 | * always [send-once rights currently get a unique name for 41 | * each right]. 42 | * 43 | * This definition of mach_port_t is only for user-space. 44 | * 45 | */ 46 | 47 | #ifndef _MACH_PORT_T 48 | #define _MACH_PORT_T 49 | #include "../_types.h" /* __darwin_mach_port_t */ 50 | typedef __darwin_mach_port_t mach_port_t; 51 | #endif /* _MACH_PORT_T */ 52 | -------------------------------------------------------------------------------- /apple-include/sys/_types/_os_inline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2012 Apple Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | #if !defined(OS_INLINE) 29 | # if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 30 | # define OS_INLINE static inline 31 | # else 32 | # define OS_INLINE static __inline__ 33 | # endif 34 | #endif /* OS_INLINE */ 35 | -------------------------------------------------------------------------------- /apple-include/sys/appleapiopts.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 | * 6 | * This file contains Original Code and/or Modifications of Original Code 7 | * as defined in and that are subject to the Apple Public Source License 8 | * Version 2.0 (the 'License'). You may not use this file except in 9 | * compliance with the License. The rights granted to you under the License 10 | * may not be used to create, or enable the creation or redistribution of, 11 | * unlawful or unlicensed copies of an Apple operating system, or to 12 | * circumvent, violate, or enable the circumvention or violation of, any 13 | * terms of an Apple operating system software license agreement. 14 | * 15 | * Please obtain a copy of the License at 16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 | * 18 | * The Original Code and all software distributed under the License are 19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 | * Please see the License for the specific language governing rights and 24 | * limitations under the License. 25 | * 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 | */ 28 | 29 | #ifndef __SYS_APPLEAPIOPTS_H__ 30 | #define __SYS_APPLEAPIOPTS_H__ 31 | 32 | 33 | #ifndef __APPLE_API_STANDARD 34 | #define __APPLE_API_STANDARD 35 | #endif /* __APPLE_API_STANDARD */ 36 | 37 | #ifndef __APPLE_API_STABLE 38 | #define __APPLE_API_STABLE 39 | #endif /* __APPLE_API_STABLE */ 40 | 41 | #ifndef __APPLE_API_STRICT_CONFORMANCE 42 | 43 | #ifndef __APPLE_API_EVOLVING 44 | #define __APPLE_API_EVOLVING 45 | #endif /* __APPLE_API_EVOLVING */ 46 | 47 | #ifndef __APPLE_API_UNSTABLE 48 | #define __APPLE_API_UNSTABLE 49 | #endif /* __APPLE_API_UNSTABLE */ 50 | 51 | #ifndef __APPLE_API_PRIVATE 52 | #define __APPLE_API_PRIVATE 53 | #endif /* __APPLE_API_PRIVATE */ 54 | 55 | #ifndef __APPLE_API_OBSOLETE 56 | #define __APPLE_API_OBSOLETE 57 | #endif /* __APPLE_API_OBSOLETE */ 58 | 59 | #endif /* __APPLE_API_STRICT_CONFORMANCE */ 60 | 61 | #endif /* __SYS_APPLEAPIOPTS_H__ */ 62 | -------------------------------------------------------------------------------- /drivers/Makefile: -------------------------------------------------------------------------------- 1 | all: $(DRIVERS) 2 | 3 | $(DRIVERS): 4 | $(MAKE) -C "$@" 5 | 6 | .PHONY: all $(DRIVERS) 7 | -------------------------------------------------------------------------------- /drivers/dt/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | .PHONY: all 9 | -------------------------------------------------------------------------------- /drivers/dt/dtree.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | int dt_check(void* mem, uint32_t size, uint32_t* offp) 30 | { 31 | if (size < sizeof(dt_node_t)) 32 | return -1; 33 | dt_node_t* node = mem; 34 | uint32_t off = sizeof(dt_node_t); 35 | for (uint32_t i = 0, max = node->nprop; i < max; ++i) { 36 | if (size < off + sizeof(dt_prop_t)) 37 | return -1; 38 | dt_prop_t* prop = (dt_prop_t*)((uintptr_t)mem + off); 39 | uint32_t l = prop->len & 0xffffff; 40 | off += sizeof(dt_prop_t) + ((l + 0x3) & ~0x3); 41 | if (size < off) 42 | return -1; 43 | } 44 | for (uint32_t i = 0, max = node->nchld; i < max; ++i) { 45 | uint32_t add = 0; 46 | int r = dt_check((void*)((uintptr_t)mem + off), size - off, &add); 47 | if (r != 0) 48 | return r; 49 | off += add; 50 | } 51 | if (offp) 52 | *offp = off; 53 | return 0; 54 | } 55 | 56 | int dt_parse(dt_node_t* node, int depth, uint32_t* offp, int (*cb_node)(void*, dt_node_t*), void* cbn_arg, int (*cb_prop)(void*, dt_node_t*, int, const char*, void*, uint32_t), void* cbp_arg) 57 | { 58 | if (cb_node) { 59 | int r = cb_node(cbn_arg, node); 60 | if (r != 0) 61 | return r; 62 | } 63 | if (depth >= 0 || cb_prop) { 64 | uint32_t off = sizeof(dt_node_t); 65 | for (uint32_t i = 0, max = node->nprop; i < max; ++i) { 66 | dt_prop_t* prop = (dt_prop_t*)((uintptr_t)node + off); 67 | uint32_t l = prop->len & 0xffffff; 68 | off += sizeof(dt_prop_t) + ((l + 0x3) & ~0x3); 69 | if (cb_prop) { 70 | int r = cb_prop(cbp_arg, node, depth, prop->key, prop->val, l); 71 | if (r != 0) 72 | return r; 73 | } 74 | } 75 | if (depth >= 0) { 76 | for (uint32_t i = 0, max = node->nchld; i < max; ++i) { 77 | uint32_t add = 0; 78 | int r = dt_parse((dt_node_t*)((uintptr_t)node + off), depth + 1, &add, cb_node, cbn_arg, cb_prop, cbp_arg); 79 | if (r != 0) 80 | return r; 81 | off += add; 82 | } 83 | if (offp) 84 | *offp = off; 85 | } 86 | } 87 | return 0; 88 | } 89 | 90 | typedef struct 91 | { 92 | const char *name; 93 | dt_node_t *node; 94 | int matchdepth; 95 | } dt_find_cb_t; 96 | 97 | static int dt_find_cb(void *a, dt_node_t *node, int depth, const char *key, void *val, uint32_t len) 98 | { 99 | dt_find_cb_t *arg = a; 100 | if(strcmp(key, "name") != 0) 101 | { 102 | return 0; 103 | } 104 | const char *name = arg->name; 105 | if(name[0] == '/') // Absolute path 106 | { 107 | // If we ever get here, we traversed back out of an entry that 108 | // we matched against, without finding a matching child node. 109 | if(depth < arg->matchdepth) 110 | { 111 | return -1; 112 | } 113 | ++name; 114 | const char *end = strchr(name, '/'); 115 | if(end) // Handle non-leaf segment 116 | { 117 | my_size_t size = end - name; 118 | if(strncmp(name, val, size) == 0 && size + 1 == len && ((const char*)val)[size] == '\0') 119 | { 120 | arg->name = end; 121 | ++arg->matchdepth; 122 | } 123 | return 0; 124 | } 125 | // Leaf segment can fall through 126 | } 127 | // Simple name 128 | if(strncmp(name, val, len) == 0 && strlen(name) + 1 == len) 129 | { 130 | arg->node = node; 131 | return 1; 132 | } 133 | return 0; 134 | } 135 | 136 | dt_node_t* dt_find(dt_node_t *node, const char *name) 137 | { 138 | dt_find_cb_t arg = { name, NULL, 0 }; 139 | dt_parse(node, 0, NULL, NULL, NULL, &dt_find_cb, &arg); 140 | return arg.node; 141 | } 142 | 143 | typedef struct 144 | { 145 | const char *key; 146 | void *val; 147 | my_size_t len; 148 | } dt_prop_cb_t; 149 | 150 | static int dt_prop_cb(void *a, dt_node_t *node, int depth, const char *key, void *val, uint32_t len) 151 | { 152 | dt_prop_cb_t *arg = a; 153 | if(strcmp(arg->key, key) == 0) 154 | { 155 | arg->val = val; 156 | arg->len = len; 157 | return 1; 158 | } 159 | return 0; 160 | } 161 | 162 | void* dt_prop(dt_node_t *node, const char *key, uint32_t *lenp) 163 | { 164 | dt_prop_cb_t arg = { key, NULL, 0 }; 165 | dt_parse(node, -1, NULL, NULL, NULL, &dt_prop_cb, &arg); 166 | if(arg.val && lenp) *lenp = arg.len; 167 | return arg.val; 168 | } 169 | 170 | static int dt_find_memmap_cb(void* a, dt_node_t* node, int depth, const char* key, void* val, uint32_t len) 171 | { 172 | if ((key[0] == 'M' && key[1] == 'e' && key[9] == 'R' && key[10] == 'e') || (strcmp(*(void**)a, "RAMDisk") == 0)) { 173 | strcpy((char*)key, *(void**)a); 174 | *(void**)a = val; 175 | return 1; 176 | } 177 | return 0; 178 | } 179 | 180 | struct memmap* dt_alloc_memmap(dt_node_t* node, const char* name) 181 | { 182 | void* val = (void*)name; 183 | dt_parse(node, -1, NULL, NULL, NULL, &dt_find_memmap_cb, &val); 184 | if (val == name) 185 | return NULL; 186 | return val; 187 | } 188 | -------------------------------------------------------------------------------- /drivers/dt/dtree_getprop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | uint32_t dt_get_u32_prop(const char* device, const char* prop) { 30 | uint32_t rval = 0; 31 | uint32_t len = 0; 32 | dt_node_t* dev = dt_find(gDeviceTree, device); 33 | if (!dev) panic("invalid devicetree: no device!"); 34 | uint32_t* val = dt_prop(dev, prop, &len); 35 | if (!val) panic("invalid devicetree: no prop!"); 36 | memcpy(&rval, &val[0], 4); 37 | return rval; 38 | } 39 | uint64_t dt_get_u64_prop(const char* device, const char* prop) { 40 | uint64_t rval = 0; 41 | uint32_t len = 0; 42 | dt_node_t* dev = dt_find(gDeviceTree, device); 43 | if (!dev) panic("invalid devicetree: no device!"); 44 | uint64_t* val = dt_prop(dev, prop, &len); 45 | if (!val) panic("invalid devicetree: no prop!"); 46 | memcpy(&rval, &val[0], 8); 47 | return rval; 48 | } 49 | uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx) { 50 | uint64_t rval = 0; 51 | uint32_t len = 0; 52 | dt_node_t* dev = dt_find(gDeviceTree, device); 53 | if (!dev) panic("invalid devicetree: no device!"); 54 | uint64_t* val = dt_prop(dev, prop, &len); 55 | if (!val) panic("invalid devicetree: no prop!"); 56 | memcpy(&rval, &val[idx], 8); 57 | return rval; 58 | } 59 | void* dt_get_prop(const char* device, const char* prop, uint32_t* size) { 60 | uint32_t len = 0; 61 | dt_node_t* dev = dt_find(gDeviceTree, device); 62 | if (!dev) panic("invalid devicetree: no device!"); 63 | void* val = dt_prop(dev, prop, &len); 64 | if (!val) panic("invalid devicetree: no prop!"); 65 | if (size) *size = len; 66 | return val; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /drivers/framebuffer/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | .PHONY: all 9 | -------------------------------------------------------------------------------- /drivers/framebuffer/fb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2021 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | #define SCALE_FACTOR scale_factor 30 | #define LEFT_MARGIN 4 * scale_factor 31 | 32 | extern char overflow_mode; 33 | extern uint32_t* gFramebuffer; 34 | extern uint32_t gWidth; 35 | extern uint32_t gHeight; 36 | extern uint32_t gRowPixels; 37 | extern uint32_t y_cursor; 38 | extern uint32_t x_cursor; 39 | extern uint8_t scale_factor; 40 | 41 | void screen_init(); 42 | void screen_puts(const char* str); 43 | void screen_write(const char* str); 44 | void screen_putc(uint8_t c); 45 | void screen_clear_row(); 46 | void screen_mark_banner(); 47 | void screen_fill_basecolor(); 48 | void screen_fill(uint32_t color); 49 | void screen_invert(); 50 | -------------------------------------------------------------------------------- /drivers/plat/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | .PHONY: all 9 | -------------------------------------------------------------------------------- /drivers/plat/s8000.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int iboot_func_init(void) 5 | { 6 | // T8015 7 | if(*(uint32_t*)PAYLOAD_BASE_ADDRESS_S8000 == 0) 8 | { 9 | //memcpy(relocate_addr, load_addr, size) 10 | memcpy((void*)PAYLOAD_BASE_ADDRESS_S8000, (void*)0x800000000, 0x80000); 11 | 12 | uint64_t iboot_base = 0x870000000; 13 | 14 | void* idata = (void *)(0x870000000); 15 | size_t isize = *(uint64_t *)(idata + 0x308) - iboot_base; 16 | 17 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_S8000 + 0x40); 18 | 19 | // OF 20 | uint64_t _printf = find_printf(iboot_base, idata, isize); 21 | if(!_printf) 22 | return -1; 23 | _printf += iboot_base; 24 | 25 | uint64_t _mount_and_boot_system = find_mount_and_boot_system(iboot_base, idata, isize); 26 | if(!_mount_and_boot_system) 27 | return -1; 28 | _mount_and_boot_system += iboot_base; 29 | 30 | uint64_t _jumpto_func = find_jumpto_func(iboot_base, idata, isize); 31 | if(!_jumpto_func) 32 | return -1; 33 | _jumpto_func += iboot_base; 34 | 35 | uint64_t _panic = find_panic(iboot_base, idata, isize); 36 | if(!_panic) 37 | return -1; 38 | _panic += iboot_base; 39 | 40 | offsetBase[0] = _printf; 41 | offsetBase[1] = _mount_and_boot_system; 42 | offsetBase[2] = _jumpto_func; 43 | offsetBase[3] = _panic; 44 | } 45 | 46 | iboot_func_load(); 47 | 48 | return 0; 49 | } 50 | 51 | void iboot_func_load(void) 52 | { 53 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_S8000 + 0x40); 54 | iprintf = (printf_t)offsetBase[0]; 55 | fsboot = (fsboot_t)offsetBase[1]; 56 | jumpto = (jumpto_t)offsetBase[2]; 57 | ipanic = (panic_t)offsetBase[3]; 58 | } -------------------------------------------------------------------------------- /drivers/plat/t8010.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int iboot_func_init(void) 5 | { 6 | // T8010 7 | if(*(uint32_t*)PAYLOAD_BASE_ADDRESS_T8010 == 0) 8 | { 9 | //memcpy(relocate_addr, load_addr, size) 10 | memcpy((void*)PAYLOAD_BASE_ADDRESS_T8010, (void*)0x800800000, 0x80000); 11 | 12 | uint64_t iboot_base = 0x1800b0000; 13 | 14 | void* idata = (void *)(0x1800b0000); 15 | my_size_t isize = *(uint64_t *)(idata + 0x308) - iboot_base; 16 | 17 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_T8010 + 0x40); 18 | 19 | // OF 20 | uint64_t _printf = find_printf(iboot_base, idata, isize); 21 | if(!_printf) 22 | return -1; 23 | _printf += iboot_base; 24 | 25 | uint64_t _mount_and_boot_system = find_mount_and_boot_system(iboot_base, idata, isize); 26 | if(!_mount_and_boot_system) 27 | return -1; 28 | _mount_and_boot_system += iboot_base; 29 | 30 | uint64_t _jumpto_func = find_jumpto_func(iboot_base, idata, isize); 31 | if(!_jumpto_func) 32 | return -1; 33 | _jumpto_func += iboot_base; 34 | 35 | uint64_t _panic = find_panic(iboot_base, idata, isize); 36 | if(!_panic) 37 | return -1; 38 | _panic += iboot_base; 39 | 40 | offsetBase[0] = _printf; 41 | offsetBase[1] = _mount_and_boot_system; 42 | offsetBase[2] = _jumpto_func; 43 | offsetBase[3] = _panic; 44 | } 45 | 46 | iboot_func_load(); 47 | 48 | return 0; 49 | } 50 | 51 | void iboot_func_load(void) 52 | { 53 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_T8010 + 0x40); 54 | iprintf = (printf_t)offsetBase[0]; 55 | fsboot = (fsboot_t)offsetBase[1]; 56 | jumpto = (jumpto_t)offsetBase[2]; 57 | ipanic = (panic_t) offsetBase[3]; 58 | } -------------------------------------------------------------------------------- /drivers/plat/t8015.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int iboot_func_init(void) 5 | { 6 | // T8015 7 | if(*(uint32_t*)PAYLOAD_BASE_ADDRESS_T8015 == 0) 8 | { 9 | //memcpy(relocate_addr, load_addr, size) 10 | memcpy((void*)PAYLOAD_BASE_ADDRESS_T8015, (void*)0x801000000, 0x80000); 11 | 12 | uint64_t iboot_base = 0x18001c000; 13 | 14 | void* idata = (void *)(0x18001c000); 15 | size_t isize = *(uint64_t *)(idata + 0x308) - iboot_base; 16 | 17 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_T8015 + 0x40); 18 | 19 | // OF 20 | uint64_t _printf = find_printf(iboot_base, idata, isize); 21 | if(!_printf) 22 | return -1; 23 | _printf += iboot_base; 24 | 25 | uint64_t _mount_and_boot_system = find_mount_and_boot_system(iboot_base, idata, isize); 26 | if(!_mount_and_boot_system) 27 | return -1; 28 | _mount_and_boot_system += iboot_base; 29 | 30 | uint64_t _jumpto_func = find_jumpto_func(iboot_base, idata, isize); 31 | if(!_jumpto_func) 32 | return -1; 33 | _jumpto_func += iboot_base; 34 | 35 | uint64_t _panic = find_panic(iboot_base, idata, isize); 36 | if(!_panic) 37 | return -1; 38 | _panic += iboot_base; 39 | 40 | offsetBase[0] = _printf; 41 | offsetBase[1] = _mount_and_boot_system; 42 | offsetBase[2] = _jumpto_func; 43 | offsetBase[3] = _panic; 44 | } 45 | 46 | iboot_func_load(); 47 | 48 | return 0; 49 | } 50 | 51 | void iboot_func_load(void) 52 | { 53 | uint64_t* offsetBase = (uint64_t*)(PAYLOAD_BASE_ADDRESS_T8015 + 0x40); 54 | iprintf = (printf_t)offsetBase[0]; 55 | fsboot = (fsboot_t)offsetBase[1]; 56 | jumpto = (jumpto_t)offsetBase[2]; 57 | ipanic = (panic_t)offsetBase[3]; 58 | } 59 | -------------------------------------------------------------------------------- /drivers/tz/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | .PHONY: all 9 | -------------------------------------------------------------------------------- /drivers/tz/tz.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #include 28 | 29 | volatile uint32_t* gTZRegbase; 30 | #if DEV_BUILD 31 | void tz_command(void) { 32 | uint32_t raw[4]; 33 | uint32_t shift; 34 | 35 | raw[0] = gTZRegbase[0]; 36 | raw[1] = gTZRegbase[1]; 37 | raw[2] = gTZRegbase[2]; 38 | raw[3] = gTZRegbase[3]; 39 | shift = 12; 40 | uint64_t real[4]; 41 | real[0] = ( (uint64_t)raw[0] << shift) + 0x800000000ULL; 42 | real[1] = (((uint64_t)raw[1] + 1) << shift) + 0x800000000ULL; 43 | real[2] = ( (uint64_t)raw[2] << shift) + 0x800000000ULL; 44 | real[3] = (((uint64_t)raw[3] + 1) << shift) + 0x800000000ULL; 45 | printf("gTZRegBase = %p\n", gTZRegbase); 46 | printf("TZ0 (%s):\n" 47 | " base: %x (%llx)\n" 48 | " end: %x (%llx)\n" 49 | "\n" 50 | "TZ1 (%s):\n" 51 | " base: %x (%llx)\n" 52 | " end: %x (%llx)\n" 53 | "\n", 54 | gTZRegbase[4] ? "locked" : "unlocked", 55 | raw[0], real[0], 56 | raw[1], real[1], 57 | gTZRegbase[5] ? "locked" : "unlocked", 58 | raw[2], real[2], 59 | raw[3], real[3]); 60 | } 61 | 62 | void tz0_set(char* base_str, char *end_str) { 63 | 64 | uint64_t base = strtoull(base_str, NULL, 16); 65 | uint64_t end = strtoull(end_str, NULL, 16); 66 | if (gTZRegbase[4]) { 67 | printf("registers are locked\n"); 68 | return; 69 | } 70 | gTZRegbase[0] = base; 71 | gTZRegbase[1] = end; 72 | } 73 | 74 | void tz_lockdown(void) { 75 | bool have_tz0, have_tz1; 76 | have_tz0 = gTZRegbase[0] != 0; 77 | have_tz1 = gTZRegbase[2] != 0; 78 | if(have_tz0) gTZRegbase[4] = 1; 79 | if(have_tz1) gTZRegbase[5] = 1; 80 | } 81 | 82 | bool tz_blackbird(void) { 83 | if(gTZRegbase[4]) { 84 | printf("Registers are locked\n"); 85 | return false; 86 | } 87 | // XXX: This used to be XOR, but that doesn't work well with the expectations in sep.c. 88 | // This was probably here to allow toggling from the shell, but that could be done via tz0_set. 89 | gTZRegbase[0] |= 0x100000; 90 | return true; 91 | } 92 | 93 | void *tz0_calculate_encrypted_block_addr(uint64_t offset) { 94 | uint64_t offset_block = (offset & (~0x1f)); 95 | offset_block <<= 1; // * 2 96 | // TODO: get rid of this magic constant 97 | // Maybe change the API to just return an offset and let the caller add it to their memory base? 98 | return (void*)(0xc00000000ULL + offset_block); 99 | } 100 | 101 | bool tz0_is_locked(void) 102 | { 103 | return gTZRegbase[4] != 0; 104 | } 105 | 106 | uint64_t tz0_base(void) { 107 | return ((uint64_t)gTZRegbase[0] << 12) + 0x800000000ULL; 108 | } 109 | 110 | uint64_t tz0_size(void) 111 | { 112 | return (uint64_t)(gTZRegbase[1] - gTZRegbase[0] + 1) << 12; 113 | } 114 | 115 | #endif 116 | void tz_setup(void) { 117 | gTZRegbase = (volatile uint32_t*)(gIOBase + 0x480); 118 | } 119 | 120 | -------------------------------------------------------------------------------- /drivers/tz/tz.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | extern volatile uint32_t* gTZRegbase; 32 | void tz_setup(void); 33 | 34 | #if DEV_BUILD 35 | void tz_lockdown(void); 36 | bool tz_blackbird(void); 37 | void *tz0_calculate_encrypted_block_addr(uint64_t offset); 38 | bool tz0_is_locked(void); 39 | void tz0_set(char* base_str, char *end_str); 40 | uint64_t tz0_base(void); 41 | uint64_t tz0_size(void); 42 | void tz_setup(void); 43 | void tz_command(); 44 | #endif 45 | -------------------------------------------------------------------------------- /drivers/xnu/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = xnu.o xnu.S.o 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | xnu.S.o: xnu.S 9 | $(CC) -c $(CFLAGS) xnu.S -o xnu.S.o 10 | 11 | .PHONY: all 12 | -------------------------------------------------------------------------------- /drivers/xnu/xnu.S: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | .text 28 | .globl _pf_jit_iter_loop_head_start 29 | .globl _pf_jit_iter_loop_head_end 30 | .globl _pf_jit_iter_loop_head_load32_start 31 | .globl _pf_jit_iter_loop_head_load32_end 32 | .globl _pf_jit_iter_loop_iter_load32_start 33 | .globl _pf_jit_iter_loop_iter_load32_end 34 | .globl _pf_jit_iter_loop_head_load64_start 35 | .globl _pf_jit_iter_loop_head_load64_end 36 | .globl _pf_jit_iter_loop_iter_load64_start 37 | .globl _pf_jit_iter_loop_iter_load64_end 38 | .globl _pf_jit_iter_loop_end_start 39 | .globl _pf_jit_iter_loop_end_end 40 | 41 | .globl _pf_jit_absolute_branch_start 42 | .globl _pf_jit_absolute_branch_end 43 | 44 | .align 3 45 | _pf_jit_iter_loop_head_start: 46 | sub sp, sp, #0x60 47 | stp x20, x21, [sp] 48 | stp x22, x23, [sp,#0x10] 49 | stp x24, x25, [sp,#0x20] 50 | stp x26, x27, [sp,#0x30] 51 | stp x28, x29, [sp,#0x40] 52 | stp x30, x19, [sp,#0x50] 53 | mov x19, x0 54 | mov x28, x1 55 | .align 3 56 | _pf_jit_iter_loop_head_end: 57 | 58 | .align 3 59 | _pf_jit_absolute_branch_start: 60 | adr x1, _pf_jit_absolute_branch_end 61 | ldr x1, [x1] 62 | br x1 63 | .align 3 64 | _pf_jit_absolute_branch_end: 65 | 66 | .globl _pf_jit_iter_loop_iter_load8_start 67 | .globl _pf_jit_iter_loop_iter_load8_end 68 | .globl _pf_jit_iter_loop_head_load8_start 69 | .globl _pf_jit_iter_loop_head_load8_end 70 | 71 | .align 3 72 | _pf_jit_iter_loop_head_load8_start: 73 | mov x29, #0x8 // 8 bit 74 | ldrb w20, [x19], #1 75 | ldrb w21, [x19], #1 76 | ldrb w22, [x19], #1 77 | ldrb w23, [x19], #1 78 | ldrb w24, [x19], #1 79 | ldrb w25, [x19], #1 80 | ldrb w26, [x19], #1 81 | ldrb w27, [x19], #1 82 | cmp x19, x28 83 | b.lo Lnext81 84 | _pf_jit_iter_loop_head_load8_end: 85 | nop 86 | Lnext81: 87 | 88 | .align 3 89 | _pf_jit_iter_loop_iter_load8_start: 90 | mov w20, w21 91 | mov w21, w22 92 | mov w22, w23 93 | mov w23, w24 94 | mov w24, w25 95 | mov w25, w26 96 | mov w26, w27 97 | ldrb w27, [x19], #1 98 | cmp x19, x28 99 | b.hi Lnext82 100 | _pf_jit_iter_loop_iter_load8_end: 101 | nop 102 | Lnext82: 103 | 104 | .globl _pf_jit_iter_loop_iter_load16_start 105 | .globl _pf_jit_iter_loop_iter_load16_end 106 | .globl _pf_jit_iter_loop_head_load16_start 107 | .globl _pf_jit_iter_loop_head_load16_end 108 | 109 | .align 3 110 | _pf_jit_iter_loop_head_load16_start: 111 | mov x29, #0x10 // 16 bit 112 | ldrh w20, [x19], #2 113 | ldrh w21, [x19], #2 114 | ldrh w22, [x19], #2 115 | ldrh w23, [x19], #2 116 | ldrh w24, [x19], #2 117 | ldrh w25, [x19], #2 118 | ldrh w26, [x19], #2 119 | ldrh w27, [x19], #2 120 | cmp x19, x28 121 | b.lo Lnext161 122 | _pf_jit_iter_loop_head_load16_end: 123 | nop 124 | Lnext161: 125 | 126 | .align 3 127 | _pf_jit_iter_loop_iter_load16_start: 128 | mov w20, w21 129 | mov w21, w22 130 | mov w22, w23 131 | mov w23, w24 132 | mov w24, w25 133 | mov w25, w26 134 | mov w26, w27 135 | ldrh w27, [x19], #2 136 | cmp x19, x28 137 | b.hi Lnext162 138 | _pf_jit_iter_loop_iter_load16_end: 139 | nop 140 | Lnext162: 141 | 142 | .align 3 143 | _pf_jit_iter_loop_head_load32_start: 144 | mov x29, #0x20 // 32 bit 145 | ldr w20, [x19], #4 146 | ldr w21, [x19], #4 147 | ldr w22, [x19], #4 148 | ldr w23, [x19], #4 149 | ldr w24, [x19], #4 150 | ldr w25, [x19], #4 151 | ldr w26, [x19], #4 152 | ldr w27, [x19], #4 153 | cmp x19, x28 154 | b.lo Lnext1 155 | _pf_jit_iter_loop_head_load32_end: 156 | nop 157 | Lnext1: 158 | 159 | .align 3 160 | _pf_jit_iter_loop_iter_load32_start: 161 | mov w20, w21 162 | mov w21, w22 163 | mov w22, w23 164 | mov w23, w24 165 | mov w24, w25 166 | mov w25, w26 167 | mov w26, w27 168 | ldr w27, [x19], #4 169 | cmp x19, x28 170 | b.hi Lnext2 171 | _pf_jit_iter_loop_iter_load32_end: 172 | nop 173 | Lnext2: 174 | 175 | .align 3 176 | _pf_jit_iter_loop_head_load64_start: 177 | mov x29, #0x40 // 64 bit 178 | ldr x20, [x19], #8 179 | ldr x21, [x19], #8 180 | ldr x22, [x19], #8 181 | ldr x23, [x19], #8 182 | ldr x24, [x19], #8 183 | ldr x25, [x19], #8 184 | ldr x26, [x19], #8 185 | ldr x27, [x19], #8 186 | cmp x19, x28 187 | b.lo Lnext3 188 | _pf_jit_iter_loop_head_load64_end: 189 | nop 190 | Lnext3: 191 | 192 | .align 3 193 | _pf_jit_iter_loop_iter_load64_start: 194 | mov x20, x21 195 | mov x21, x22 196 | mov x22, x23 197 | mov x23, x24 198 | mov x24, x25 199 | mov x25, x26 200 | mov x26, x27 201 | ldr x27, [x19], #8 202 | cmp x19, x28 203 | b.hi Lnext4 204 | _pf_jit_iter_loop_iter_load64_end: 205 | nop 206 | Lnext4: 207 | 208 | .align 3 209 | _pf_jit_iter_loop_end_start: 210 | ldp x20, x21, [sp] 211 | ldp x22, x23, [sp,#0x10] 212 | ldp x24, x25, [sp,#0x20] 213 | ldp x26, x27, [sp,#0x30] 214 | ldp x28, x29, [sp,#0x40] 215 | ldp x30, x19, [sp,#0x50] 216 | add sp, sp, #0x60 217 | ret 218 | .align 3 219 | _pf_jit_iter_loop_end_end: 220 | 221 | 222 | .globl _pf_jit_ptr_comparison_start 223 | .globl _pf_jit_ptr_comparison_end 224 | 225 | .align 3 226 | _pf_jit_ptr_comparison_start: 227 | orr x8, x20, x2 228 | add x8, x8, x3 229 | cmp x8, x0 230 | b.lo _pf_jit_ptr_comparison_next 231 | cmp x8, x1 232 | b.hi _pf_jit_ptr_comparison_next 233 | ldr x0, _pf_jit_ptr_comparison_patch 234 | mov w1, w29 235 | sub x2, x19, #0x40 236 | mov x3, x2 237 | ldr x4, _pf_jit_ptr_comparison_slowpath 238 | blr x4 239 | b _pf_jit_ptr_comparison_next 240 | .align 3 241 | _pf_jit_ptr_comparison_end: 242 | 243 | _pf_jit_ptr_comparison_patch: 244 | .quad 0x4141414142424200 245 | _pf_jit_ptr_comparison_slowpath: 246 | .quad 0x4141414142424201 247 | _pf_jit_ptr_comparison_next: 248 | 249 | 250 | .globl _pf_jit_slowpath_start 251 | .globl _pf_jit_slowpath_end 252 | .globl _pf_jit_slowpath_next 253 | 254 | .align 3 255 | _pf_jit_slowpath_start: 256 | ldr x0, _pf_jit_slowpath_patch 257 | mov w1, w29 258 | sub x2, x19, x29 259 | mov x3, x2 260 | ldr x4, _pf_jit_slowpath_slowpath 261 | blr x4 262 | nop 263 | nop 264 | nop 265 | nop 266 | b _pf_jit_slowpath_next 267 | .align 3 268 | _pf_jit_slowpath_end: 269 | 270 | _pf_jit_slowpath_patch: 271 | .quad 0x4141414142424200 272 | _pf_jit_slowpath_slowpath: 273 | .quad 0x4141414142424201 274 | _pf_jit_slowpath_next: 275 | 276 | 277 | .globl _pf_jit_ptr_comparison_next 278 | -------------------------------------------------------------------------------- /drivers/xnu/xnu.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef XNU_H 28 | #define XNU_H 29 | #include 30 | #include 31 | #include 32 | 33 | #define XNU_PF_ACCESS_8BIT 0x8 34 | #define XNU_PF_ACCESS_16BIT 0x10 35 | #define XNU_PF_ACCESS_32BIT 0x20 36 | #define XNU_PF_ACCESS_64BIT 0x40 37 | #define kCacheableView 0x400000000ULL 38 | 39 | typedef struct xnu_pf_range { 40 | uint64_t va; 41 | uint64_t size; 42 | uint8_t* cacheable_base; 43 | uint8_t* device_base; 44 | } xnu_pf_range_t; 45 | 46 | struct xnu_pf_patchset; 47 | 48 | typedef struct xnu_pf_patch { 49 | bool (*pf_callback)(struct xnu_pf_patch* patch, void* cacheable_stream); 50 | bool is_required; 51 | bool has_fired; 52 | bool should_match; 53 | uint32_t pfjit_stolen_opcode; 54 | uint32_t pfjit_max_emit_size; 55 | uint32_t* (*pf_emit)(struct xnu_pf_patch* patch, struct xnu_pf_patchset *patchset,uint32_t* insn, uint32_t** insn_stream_end, uint8_t access_type); 56 | void (*pf_match)(struct xnu_pf_patch* patch, uint8_t access_type, void* preread, void* cacheable_stream); 57 | struct xnu_pf_patch* next_patch; 58 | uint32_t* pfjit_entry; 59 | uint32_t* pfjit_exit; 60 | uint8_t pf_data[0]; 61 | char * name; 62 | 63 | // patch->pf_match(XNU_PF_ACCESS_32BIT, reads, &stream[index], &dstream[index]); 64 | 65 | } xnu_pf_patch_t; 66 | 67 | typedef struct xnu_pf_patchset { 68 | xnu_pf_patch_t* patch_head; 69 | void* jit_matcher; 70 | uint64_t p0; 71 | uint8_t accesstype; 72 | bool is_required; 73 | } xnu_pf_patchset_t; 74 | 75 | #if DEV_BUILD 76 | extern void log_bootargs(); 77 | #endif 78 | extern uint64_t xnu_slide_hdr_va(struct mach_header_64* header, uint64_t hdr_va); 79 | extern uint64_t xnu_slide_value(struct mach_header_64* header); 80 | extern struct mach_header_64* xnu_header(void); 81 | extern uint32_t xnu_platform(void); 82 | extern xnu_pf_range_t* xnu_pf_range_from_va(uint64_t va, uint64_t size); 83 | extern xnu_pf_range_t* xnu_pf_segment(struct mach_header_64* header, char* segment_name); 84 | extern xnu_pf_range_t* xnu_pf_section(struct mach_header_64* header, void* segment, char* section_name); 85 | extern xnu_pf_range_t* xnu_pf_all(struct mach_header_64* header); 86 | extern xnu_pf_range_t* xnu_pf_all_x(struct mach_header_64* header); 87 | extern void xnu_pf_disable_patch(xnu_pf_patch_t* patch); 88 | extern void xnu_pf_enable_patch(xnu_pf_patch_t* patch); 89 | extern struct segment_command_64* macho_get_segment(struct mach_header_64* header, const char* segname); 90 | extern struct section_64 *macho_get_section(struct segment_command_64 *seg, const char *name); 91 | extern struct mach_header_64* xnu_pf_get_first_kext(struct mach_header_64* kheader); 92 | // extern void hexdump(void *mem, unsigned int len); 93 | extern void xnu_pf_emit(xnu_pf_patchset_t* patchset); // converts a patchset to JIT 94 | extern void xnu_pf_apply(xnu_pf_range_t* range, xnu_pf_patchset_t* patchset); 95 | extern xnu_pf_patchset_t* xnu_pf_patchset_create(uint8_t pf_accesstype); 96 | extern void xnu_pf_patchset_destroy(xnu_pf_patchset_t* patchset); 97 | extern void* xnu_va_to_ptr(uint64_t va); 98 | extern uint64_t xnu_ptr_to_va(void* ptr); 99 | extern uint64_t xnu_rebase_va(uint64_t va); 100 | extern uint64_t kext_rebase_va(uint64_t va); 101 | extern struct mach_header_64* xnu_pf_get_kext_header(struct mach_header_64* kheader, const char* kext_bundle_id); 102 | extern xnu_pf_patch_t* xnu_pf_maskmatch(xnu_pf_patchset_t* patchset, char * name, uint64_t* matches, uint64_t* masks, uint32_t entryc, bool required, bool (*callback)(struct xnu_pf_patch* patch, void* cacheable_stream)); 103 | extern void xnu_pf_apply_each_kext(struct mach_header_64* kheader, xnu_pf_patchset_t* patchset); 104 | xnu_pf_patch_t* xnu_pf_ptr_to_data(xnu_pf_patchset_t* patchset, uint64_t slide, xnu_pf_range_t* range, void* data, my_size_t datasz, bool required, bool (*callback)(struct xnu_pf_patch* patch, void* cacheable_stream)); 105 | 106 | extern void xnu_boot(void); 107 | extern void xnu_init(void); 108 | extern void xnu_loadrd(void); 109 | extern void xnu_hook(void); 110 | #endif 111 | -------------------------------------------------------------------------------- /include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H 2 | #define COMMON_H 3 | 4 | #include 5 | #include 6 | typedef uint64_t my_size_t; 7 | 8 | #include "drivers/framebuffer/fb.h" 9 | #include "drivers/xnu/xnu.h" 10 | #include "drivers/tz/tz.h" 11 | #include "../printf.h" 12 | 13 | extern uint32_t socnum; 14 | extern bool screen_is_initialized; 15 | extern bool serial_is_initialized; 16 | 17 | extern uint8_t* skip_md0_patch; 18 | 19 | #ifndef NULL 20 | #define NULL ((void*)0) 21 | #endif 22 | 23 | struct cmd_arg { 24 | bool b; 25 | my_size_t u; 26 | my_size_t h; 27 | char *str; 28 | }; 29 | 30 | #define ERANGE 34 31 | 32 | #define PAYLOAD_BASE_ADDRESS_T8015 (0x800F00000) // A11 33 | #define PAYLOAD_BASE_ADDRESS_T8010 (0x800700000) // A10 34 | #define PAYLOAD_BASE_ADDRESS_S8000 (0x800700000) // A9 35 | 36 | #if BUILDING_PAYLOAD 37 | #if defined(PAYLOAD_t8015) 38 | #define PAYLOAD_BASE_ADDRESS PAYLOAD_BASE_ADDRESS_T8015 39 | #elif defined(PAYLOAD_t8010) 40 | #define PAYLOAD_BASE_ADDRESS PAYLOAD_BASE_ADDRESS_T8010 41 | #elif defined(PAYLOAD_s8000) 42 | #define PAYLOAD_BASE_ADDRESS PAYLOAD_BASE_ADDRESS_S8000 43 | #else 44 | #error "unsupported platform" 45 | #endif 46 | #endif 47 | 48 | #define DT_KEY_LEN 0x20 49 | #define BOOT_LINE_LENGTH_iOS12 0x100 50 | #define BOOT_LINE_LENGTH_iOS13 0x260 51 | #define LAUNCHD_STRING "/sbin/launchd" 52 | 53 | bool is_16k(); 54 | 55 | struct Boot_Video { 56 | unsigned long v_baseAddr; /* Base address of video memory */ 57 | unsigned long v_display; /* Display Code (if Applicable) */ 58 | unsigned long v_rowBytes; /* Number of bytes per pixel row */ 59 | unsigned long v_width; /* Width */ 60 | unsigned long v_height; /* Height */ 61 | unsigned long v_depth; /* Pixel Depth and other parameters */ 62 | }; 63 | typedef struct boot_args { 64 | uint16_t Revision; /* Revision of boot_args structure */ 65 | uint16_t Version; /* Version of boot_args structure */ 66 | uint32_t __pad0; 67 | uint64_t virtBase; /* Virtual base of memory */ 68 | uint64_t physBase; /* Physical base of memory */ 69 | uint64_t memSize; /* Size of memory */ 70 | uint64_t topOfKernelData; /* Highest physical address used in kernel data area */ 71 | struct Boot_Video Video; /* Video Information */ 72 | uint32_t machineType; /* Machine Type */ 73 | uint32_t __pad1; 74 | void *deviceTreeP; /* Base of flattened device tree */ 75 | uint32_t deviceTreeLength; /* Length of flattened tree */ 76 | 77 | char CommandLine[BOOT_LINE_LENGTH_iOS13]; /* Passed in command line */ 78 | uint32_t __pad; 79 | uint64_t bootFlags; /* Additional flags specified by the bootloader */ 80 | uint64_t memSizeActual; /* Actual size of memory */ 81 | 82 | } __attribute__((packed)) boot_args; 83 | 84 | typedef struct 85 | { 86 | uint32_t nprop; 87 | uint32_t nchld; 88 | char prop[]; 89 | } dt_node_t; 90 | 91 | typedef struct 92 | { 93 | char key[DT_KEY_LEN]; 94 | uint32_t len; 95 | char val[]; 96 | } dt_prop_t; 97 | 98 | extern void* gEntryPoint; 99 | extern boot_args *gBootArgs; 100 | extern dt_node_t *gDeviceTree; 101 | extern uint32_t* gFramebuffer; 102 | uint64_t gIOBase; 103 | extern volatile uint32_t *gTZRegbase; 104 | extern uint64_t gInterruptBase; 105 | extern uint64_t gPMGRBase; 106 | extern uint64_t gWDTBase; 107 | 108 | extern int iboot_func_init(void); 109 | extern void iboot_func_load(void); 110 | 111 | extern int dt_check(void* mem, uint32_t size, uint32_t* offp); 112 | extern int dt_parse(dt_node_t* node, int depth, uint32_t* offp, int (*cb_node)(void*, dt_node_t*), void* cbn_arg, int (*cb_prop)(void*, dt_node_t*, int, const char*, void*, uint32_t), void* cbp_arg); 113 | extern dt_node_t* dt_find(dt_node_t* node, const char* name); 114 | extern void* dt_prop(dt_node_t* node, const char* key, uint32_t* lenp); 115 | extern void* dt_get_prop(const char* device, const char* prop, uint32_t* size); 116 | extern struct memmap* dt_alloc_memmap(dt_node_t* node, const char* name); 117 | extern uint64_t dt_get_u64_prop(const char* device, const char* prop); 118 | extern uint32_t dt_get_u32_prop(const char* device, const char* prop); 119 | extern uint64_t dt_get_u64_prop_i(const char* device, const char* prop, uint32_t idx); 120 | extern const char build_style[]; 121 | 122 | 123 | // iboot 124 | typedef int (*printf_t)(const char *format, ...); 125 | printf_t iprintf; 126 | typedef int (*jumpto_t)(void* arg0, void* arg1); 127 | jumpto_t jumpto; 128 | typedef void (*fsboot_t)(void); 129 | fsboot_t fsboot; 130 | typedef int (*panic_t)(const char *format, ...); 131 | panic_t ipanic; 132 | 133 | int panic(const char *format, ...); 134 | 135 | // main 136 | int iboot_func_init(void); 137 | void iboot_func_load(void); 138 | extern const uint64_t payload_baseaddr; 139 | void mem_stat(); 140 | extern char* gLaunchdString; 141 | extern char** gLaunchdString_p; 142 | 143 | #if DEV_BUILD 144 | #define dprintf(...) printf(__VA_ARGS__) 145 | #else 146 | #define dprintf(...) 147 | #endif 148 | 149 | // libc 150 | int errno; 151 | 152 | int strcmp(const char *s1, const char *s2); 153 | my_size_t strlen(const char * str); 154 | void *memset(void *s, int c, my_size_t n); 155 | int memcmp(const void *b1, const void *b2, size_t len); 156 | void *memmem(const void *haystack, my_size_t hlen, const void *needle, my_size_t nlen); 157 | void *memcpy(void *dst, const void *src, my_size_t len); 158 | void *memmove(void *dest, const void *src, my_size_t n); 159 | char *strcpy(char *to, const char *from); 160 | int strncmp(const char *s1, const char *s2, my_size_t n); 161 | char *strchr(const char *p, int ch); 162 | int isdigit(int c); 163 | int isalpha(int c); 164 | int isspace(int c); 165 | int isupper(int c); 166 | long atoi(const char* S); 167 | char* strcat (char* dest, char* src); 168 | unsigned long long strtoull(const char *str, char **endptr, int base); 169 | int puts(const char* str); 170 | char *strncpy(char *dest, const char *src, my_size_t n); 171 | void *malloc(my_size_t size); 172 | void bzero (void *s, my_size_t n); 173 | char *strstr(const char *string, char *substring); 174 | void free(void *ptr); 175 | unsigned long strtoul(const char* nptr, char ** endptr, register int base); 176 | intmax_t strtoimax(const char *nptr, char **endptr, int base); 177 | 178 | // pongo 179 | #if DEV_BUILD 180 | char* command_tokenize(char* str, unsigned int strbufsz); 181 | void bzero_command(char* addr_str, char* size_str); 182 | #endif 183 | void wdt_disable(); 184 | void wdt_enable(); 185 | void pmgr_init(); 186 | extern void *jit_alloc(my_size_t count, my_size_t size); 187 | extern void jit_free(void* ptr); 188 | 189 | // command 190 | #if DEV_BUILD 191 | void peek(char* addr_str, char* size_str); 192 | void poke(char* addr_str, char* u64_data); 193 | #endif 194 | 195 | #endif 196 | -------------------------------------------------------------------------------- /include/kerninfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * pongoOS - https://checkra.in 3 | * 4 | * Copyright (C) 2019-2022 checkra1n team 5 | * 6 | * This file is part of pongoOS. 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy 9 | * of this software and associated documentation files (the "Software"), to deal 10 | * in the Software without restriction, including without limitation the rights 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | * copies of the Software, and to permit persons to whom the Software is 13 | * furnished to do so, subject to the following conditions: 14 | * 15 | * The above copyright notice and this permission notice shall be included in all 16 | * copies or substantial portions of the Software. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | * SOFTWARE. 25 | * 26 | */ 27 | #ifndef _KERNINFO_H 28 | #define _KERNINFO_H 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #define MAX_BOOTARGS_LEN 256 35 | #define DEFAULT_BOOTARGS "rootdev=md0" 36 | #define DEFAULT_TVOS_BOOTARGS DEFAULT_BOOTARGS " AppleEmbeddedUSBArbitrator-force-usbdevice=1" 37 | 38 | #define checkrain_option_none 0x00000000 39 | #define checkrain_option_all 0x7fffffff 40 | #define checkrain_option_failure 0x80000000 41 | 42 | // Host options 43 | #define checkrain_option_verbose_logging (1 << 0) 44 | #define checkrain_option_demote (1 << 1) 45 | #define checkrain_option_early_exit (1 << 2) 46 | #define checkrain_option_quick_mode (1 << 3) 47 | #define checkrain_option_pongo_shell (1 << 4) 48 | 49 | // KPF options 50 | #define checkrain_option_verbose_boot (1 << 0) 51 | 52 | // Global options 53 | #define checkrain_option_safemode (1 << 0) 54 | #define checkrain_option_bind_mount (1 << 1) 55 | #define checkrain_option_force_revert (1 << 7) /* keep this at 7 */ 56 | 57 | typedef uint32_t checkrain_option_t, *checkrain_option_p; 58 | 59 | typedef enum { 60 | jailbreak_capability_tfp0 = 1 << 0, 61 | jailbreak_capability_userspace_reboot = 1 << 1, 62 | jailbreak_capability_dyld_ignore_os = 1 << 2, // TODO: This needs a better name 63 | } jailbreak_capability_t, *jailbreak_capability_p; 64 | 65 | #define DEFAULT_CAPABILITIES (jailbreak_capability_tfp0|jailbreak_capability_userspace_reboot) 66 | struct kerninfo { 67 | uint64_t size; 68 | uint64_t base; 69 | uint64_t slide; 70 | checkrain_option_t flags; 71 | }; 72 | struct kpfinfo { 73 | struct kerninfo k; 74 | checkrain_option_t kpf_flags; 75 | char bootargs[MAX_BOOTARGS_LEN]; 76 | }; 77 | 78 | #define checkrain_set_option(options, option, enabled) do { \ 79 | if (enabled) \ 80 | options = (checkrain_option_t)(options | option); \ 81 | else \ 82 | options = (checkrain_option_t)(options & ~option); \ 83 | } while (0); 84 | 85 | static inline bool checkrain_option_enabled(checkrain_option_t flags, checkrain_option_t opt) 86 | { 87 | if(flags == checkrain_option_failure) 88 | { 89 | switch(opt) 90 | { 91 | case checkrain_option_safemode: 92 | return true; 93 | default: 94 | return false; 95 | } 96 | } 97 | return (flags & opt) != 0; 98 | } 99 | 100 | #endif 101 | -------------------------------------------------------------------------------- /include/offsetfinder.h: -------------------------------------------------------------------------------- 1 | #ifndef OFFSETFINDER_H 2 | #define OFFSETFINDER_H 3 | 4 | #include 5 | #include 6 | 7 | uint64_t find_printf(uint64_t region, uint8_t* data, my_size_t size); 8 | uint64_t find_mount_and_boot_system(uint64_t region, uint8_t* data, my_size_t size); 9 | uint64_t find_jumpto_bl(uint64_t region, uint8_t* data, my_size_t size); 10 | uint64_t find_jumpto_func(uint64_t region, uint8_t* data, my_size_t size); 11 | uint64_t find_panic(uint64_t region, uint8_t* data, my_size_t size); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /kernel/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) entry.o 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | entry.o: entry.S 9 | $(CC) -c $(CFLAGS) entry.S 10 | 11 | .PHONY: all 12 | -------------------------------------------------------------------------------- /kernel/command.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if DEV_BUILD 4 | char* command_tokenize(char* str, unsigned int strbufsz) { 5 | char* bound = &str[strbufsz]; 6 | while (*str) { 7 | if (str > bound) return NULL; 8 | if (*str == ' ') { 9 | *str++ = 0; 10 | while (*str) { 11 | if (str > bound) return NULL; 12 | if (*str == ' ') { 13 | str++; 14 | } else 15 | break; 16 | } 17 | if (str > bound) return NULL; 18 | if (!*str) return ""; 19 | return str; 20 | } 21 | str++; 22 | } 23 | return ""; 24 | } 25 | 26 | /* ChatGPT FTW! */ 27 | void hexdump(void *addr, my_size_t len) { 28 | // The pointer to the memory location 29 | char *p = (char*)addr; 30 | 31 | // Loop through the memory, 16 bytes at a time 32 | for (my_size_t i = 0; i < len; i += 16) { 33 | // Print the address at the beginning of the line 34 | printf("%p: ", p + i); 35 | 36 | // Loop through the current 16 bytes and print their hexadecimal values 37 | for (my_size_t j = 0; j < 16; j++) { 38 | // If this is the first byte, print a leading space 39 | if (j == 0) { 40 | printf(" "); 41 | } 42 | 43 | // If we have reached the end of the memory, stop 44 | if (i + j >= len) { 45 | break; 46 | } 47 | 48 | // Print the hexadecimal value of the current byte, padded with zeros 49 | printf("%02X ", p[i + j]); 50 | } 51 | 52 | // Print some padding to align the ASCII representation 53 | printf("\n "); 54 | 55 | // Loop through the current 16 bytes and print their ASCII values 56 | for (my_size_t j = 0; j < 16; j++) { 57 | // If we have reached the end of the memory, stop 58 | if (i + j >= len) { 59 | break; 60 | } 61 | 62 | // Print the ASCII value of the current byte, or a dot if it's not printable 63 | char c = p[i + j]; 64 | if (c >= 32 && c <= 126) { 65 | printf("%c", c); 66 | } else { 67 | printf("."); 68 | } 69 | } 70 | 71 | // End the line 72 | printf("\n"); 73 | } 74 | } 75 | 76 | void peek(char* addr_str, char* size_str) { 77 | void* addr = (void*)strtoull(addr_str, NULL, 0); 78 | my_size_t size = (my_size_t)strtoull(size_str, NULL, 0); 79 | printf("addr = 0x%p, size = %llu\n", addr, size); 80 | hexdump(addr, size); 81 | return; 82 | } 83 | 84 | void poke(char* addr_str, char* u64_data) { 85 | uint64_t* addr = (uint64_t*)strtoull(addr_str, NULL, 0); 86 | uint64_t data = (uint64_t)strtoull(u64_data, NULL, 0); 87 | *addr = data; 88 | printf("*0x%p = %llu\n", addr, data); 89 | return; 90 | } 91 | 92 | void bzero_command(char* addr_str, char* size_str) { 93 | void* addr = (void*)strtoull(addr_str, NULL, 0); 94 | my_size_t size = (my_size_t)strtoull(size_str, NULL, 0); 95 | printf("addr = 0x%p, size = %llu\n", addr, size); 96 | bzero(addr, size); 97 | return; 98 | } 99 | #endif 100 | -------------------------------------------------------------------------------- /kernel/entry.S: -------------------------------------------------------------------------------- 1 | 2 | .globl _gprintf 3 | .align 2 4 | 5 | .globl start 6 | .align 4 7 | 8 | .globl _get_x18 9 | .align 4 10 | 11 | start: 12 | 13 | // 0x0000 14 | b _payload 15 | b _jump_hook 16 | b . 17 | nop 18 | 19 | // 0x0010 20 | nop 21 | nop 22 | nop 23 | nop 24 | nop 25 | nop 26 | nop 27 | nop 28 | nop 29 | nop 30 | nop 31 | nop 32 | 33 | // 0x0040 34 | gprintf: 35 | .quad 0x4040404040404040 36 | 37 | gfsboot: 38 | .quad 0x4141414141414141 39 | 40 | gjumpto: 41 | .quad 0x4242424242424242 42 | 43 | gpanic: 44 | .quad 0x4343434343434343 45 | 46 | // 0x0060 _rootdev 47 | .quad 0x4444444444444444 48 | .quad 0x4444444444444444 49 | 50 | // 0x0070 invert_fb 51 | .byte 0x45 52 | 53 | // 0x0071 xargs_set 54 | .byte 0x46 55 | 56 | // 0x0072 xfb_state 57 | .byte 0x47 58 | 59 | // 0x0073 skip_md0_patch 60 | .byte 0x49 61 | 62 | // 0x0074 launchd_string 63 | _gLaunchdString: 64 | .ascii "/sbin/launchd\0" 65 | 66 | // 0x0082 reserved 67 | // 0x0083 enable_kpf 68 | .byte 0x50 69 | .byte 0x51 70 | 71 | // 0x0084 CommandLine 72 | .quad 0x4848484848484848 73 | .quad 0x4848484848484848 74 | .quad 0x4848484848484848 75 | .quad 0x4848484848484848 76 | .quad 0x4848484848484848 77 | .quad 0x4848484848484848 78 | .quad 0x4848484848484848 79 | .quad 0x4848484848484848 80 | .quad 0x4848484848484848 81 | .quad 0x4848484848484848 82 | .quad 0x4848484848484848 83 | .quad 0x4848484848484848 84 | .quad 0x4848484848484848 85 | .quad 0x4848484848484848 86 | .quad 0x4848484848484848 87 | .quad 0x4848484848484848 88 | .quad 0x4848484848484848 89 | .quad 0x4848484848484848 90 | .quad 0x4848484848484848 91 | .quad 0x4848484848484848 92 | .quad 0x4848484848484848 93 | .quad 0x4848484848484848 94 | .quad 0x4848484848484848 95 | .quad 0x4848484848484848 96 | .quad 0x4848484848484848 97 | .quad 0x4848484848484848 98 | .quad 0x4848484848484848 99 | .quad 0x4848484848484848 100 | .quad 0x4848484848484848 101 | .quad 0x4848484848484848 102 | .quad 0x4848484848484848 103 | .quad 0x4848484848484848 104 | .quad 0x4848484848484848 105 | .quad 0x4848484848484848 106 | .quad 0x4848484848484848 107 | .quad 0x4848484848484848 108 | .quad 0x4848484848484848 109 | .quad 0x4848484848484848 110 | .quad 0x4848484848484848 111 | .quad 0x4848484848484848 112 | .quad 0x4848484848484848 113 | .quad 0x4848484848484848 114 | .quad 0x4848484848484848 115 | .quad 0x4848484848484848 116 | .quad 0x4848484848484848 117 | .quad 0x4848484848484848 118 | .quad 0x4848484848484848 119 | .quad 0x4848484848484848 120 | .quad 0x4848484848484848 121 | .quad 0x4848484848484848 122 | .quad 0x4848484848484848 123 | .quad 0x4848484848484848 124 | .quad 0x4848484848484848 125 | .quad 0x4848484848484848 126 | .quad 0x4848484848484848 127 | .quad 0x4848484848484848 128 | .quad 0x4848484848484848 129 | .quad 0x4848484848484848 130 | .quad 0x4848484848484848 131 | .quad 0x4848484848484848 132 | .quad 0x4848484848484848 133 | .quad 0x4848484848484848 134 | .quad 0x4848484848484848 135 | .quad 0x4848484848484848 136 | .quad 0x4848484848484848 137 | .quad 0x4848484848484848 138 | .quad 0x4848484848484848 139 | .quad 0x4848484848484848 140 | .quad 0x4848484848484848 141 | .quad 0x4848484848484848 142 | .quad 0x4848484848484848 143 | .quad 0x4848484848484848 144 | .quad 0x4848484848484848 145 | .quad 0x4848484848484848 146 | .quad 0x4848484848484848 147 | .quad 0x4848484848484848 148 | 149 | // 0x2e4 150 | 151 | #if DEV_BUILD 152 | .globl _crash 153 | .align 4 154 | 155 | _crash: 156 | mov x5, x30 157 | ldr x0, =0x800000000 158 | bl _cache_clean_and_invalidate_page 159 | mov x0, #0 160 | svc #0 161 | ic iallu 162 | nop 163 | nop 164 | b . 165 | ret 166 | 167 | _cache_clean_and_invalidate_page: 168 | mov x1, #0x80000 169 | mov x2, #0 170 | 171 | _one: 172 | cmp x1, x2 173 | b.eq _two 174 | dc civac, x0 175 | add x0, x0, #0x40 176 | add x2, x2, #0x40 177 | b _one 178 | 179 | _two: 180 | ret 181 | #endif 182 | 183 | _get_x18: 184 | mov x0, x18 185 | ret 186 | 187 | nop 188 | nop 189 | nop 190 | nop -------------------------------------------------------------------------------- /kernel/fakemm.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint64_t malloc_base = (uint64_t)NULL; 4 | uint64_t jit_alloc_base = (uint64_t)NULL; 5 | #define JIT_SIZE 32768 6 | #define JIT_BASE ((uint64_t)payload_baseaddr + 491520) 7 | 8 | void *malloc(my_size_t size) { 9 | void* mem = NULL; 10 | if ((void*)malloc_base == NULL) panic("mm is not initialized yet\n"); 11 | mem = (void*)malloc_base; 12 | malloc_base += size; 13 | if (malloc_base > (gBootArgs->physBase + gBootArgs->memSize)) { 14 | screen_puts("panic: out of memory"); 15 | panic("out of memory\n"); 16 | return NULL; 17 | } 18 | return mem; 19 | } 20 | 21 | void free(void *ptr) {} 22 | 23 | void *jit_alloc(my_size_t count, my_size_t size) { 24 | void* mem = NULL; 25 | if (jit_alloc_base == (uint64_t)NULL) panic("mm is not initialized yet\n"); 26 | mem = (void*)jit_alloc_base; 27 | jit_alloc_base += count * size; 28 | if (jit_alloc_base > (JIT_BASE + JIT_SIZE)) { 29 | screen_puts("panic: out of jit memory"); 30 | panic("out of jit memory\n"); 31 | return NULL; 32 | } 33 | return mem; 34 | } 35 | 36 | void jit_free(void* ptr) {} 37 | 38 | void mm_init() { 39 | malloc_base = gBootArgs->topOfKernelData; 40 | jit_alloc_base = JIT_BASE; 41 | } 42 | 43 | void mem_stat() { 44 | dprintf("Memory usage: %llu bytes\n", (malloc_base - (gBootArgs->topOfKernelData + 1))); 45 | dprintf("JIT memory usage: %llu bytes\n", jit_alloc_base - JIT_BASE); 46 | return; 47 | } 48 | -------------------------------------------------------------------------------- /kernel/lowlevel.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | uint64_t gInterruptBase; 4 | uint64_t gPMGRBase; 5 | uint64_t gWDTBase; 6 | 7 | bool panic_did_enter = false; 8 | 9 | typedef struct 10 | { 11 | uint64_t addr; 12 | uint64_t size; 13 | } pmgr_reg_t; 14 | 15 | typedef struct 16 | { 17 | uint32_t reg; 18 | uint32_t off; 19 | uint32_t idk; 20 | } pmgr_map_t; 21 | 22 | typedef struct 23 | { 24 | uint32_t flg : 8, 25 | a : 16, 26 | id : 8; 27 | uint32_t b; 28 | uint32_t c : 16, 29 | idx : 8, 30 | map : 8; 31 | uint32_t d; 32 | uint32_t e; 33 | uint32_t f; 34 | uint32_t g; 35 | uint32_t h; 36 | char name[0x10]; 37 | } pmgr_dev_t; 38 | 39 | static uint32_t gPMGRreglen = 0; 40 | static uint32_t gPMGRmaplen = 0; 41 | static uint32_t gPMGRdevlen = 0; 42 | static pmgr_reg_t *gPMGRreg = NULL; 43 | static pmgr_map_t *gPMGRmap = NULL; 44 | static pmgr_dev_t *gPMGRdev = NULL; 45 | 46 | #define WDT_CHIP_TMR (*(volatile uint32_t*)(gWDTBase + 0x0)) 47 | #define WDT_CHIP_RST (*(volatile uint32_t*)(gWDTBase + 0x4)) 48 | #define WDT_CHIP_INT (*(volatile uint32_t*)(gWDTBase + 0x8)) 49 | #define WDT_CHIP_CTL (*(volatile uint32_t*)(gWDTBase + 0xc)) 50 | 51 | #define WDT_SYS_TMR (*(volatile uint32_t*)(gWDTBase + 0x10)) 52 | #define WDT_SYS_RST (*(volatile uint32_t*)(gWDTBase + 0x14)) 53 | #define WDT_SYS_CTL (*(volatile uint32_t*)(gWDTBase + 0x1c)) 54 | 55 | void wdt_disable() 56 | { 57 | if (!gWDTBase) return; 58 | WDT_CHIP_CTL = 0x0; // Disable WDT 59 | WDT_SYS_CTL = 0x0; // Disable WDT 60 | } 61 | 62 | void wdt_enable() { 63 | return; 64 | } 65 | 66 | void wdt_reset() 67 | { 68 | if(!gWDTBase) 69 | { 70 | ipanic("wdt is not set up but was asked to reset, trying iBoot panic"); 71 | } 72 | else 73 | { 74 | WDT_CHIP_CTL = 0x0; // Disable WDT 75 | WDT_SYS_CTL = 0x0; // Disable WDT 76 | WDT_SYS_RST = 1; // Immediate reset 77 | WDT_SYS_CTL = 0x4; // Enable WDT 78 | WDT_SYS_TMR = 0; // Reset counter 79 | } 80 | panic("wdt reset"); 81 | } 82 | 83 | int panic(const char* format, ...) { 84 | va_list args; 85 | va_start(args, format); 86 | if (panic_did_enter == true) { 87 | printf("\ndouble panic: "); 88 | vprintf(format, args); 89 | va_end(args); 90 | puts(""); 91 | while(1) {}; 92 | } 93 | panic_did_enter = true; 94 | printf("\npanic: "); 95 | vprintf(format, args); 96 | va_end(args); 97 | puts(""); 98 | wdt_reset(); 99 | while(1) {}; 100 | } 101 | 102 | void pmgr_init() 103 | { 104 | dt_node_t *pmgr = dt_find(gDeviceTree, "pmgr"); 105 | gPMGRreg = dt_prop(pmgr, "reg", &gPMGRreglen); 106 | gPMGRmap = dt_prop(pmgr, "ps-regs", &gPMGRmaplen); 107 | gPMGRdev = dt_prop(pmgr, "devices", &gPMGRdevlen); 108 | gPMGRreglen /= sizeof(*gPMGRreg); 109 | gPMGRmaplen /= sizeof(*gPMGRmap); 110 | gPMGRdevlen /= sizeof(*gPMGRdev); 111 | gPMGRBase = gIOBase + gPMGRreg[0].addr; 112 | gWDTBase = gIOBase + dt_get_u64_prop("wdt", "reg"); 113 | } 114 | -------------------------------------------------------------------------------- /kpf/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = main.o shellcode.S.o 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | 8 | shellcode.S.o: shellcode.S 9 | $(CC) -c $(CFLAGS) shellcode.S -o shellcode.S.o 10 | 11 | .PHONY: all 12 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c)) 2 | 3 | all: $(OBJECTS) 4 | 5 | %.o: %.c 6 | $(CC) -c $(CFLAGS) $< 7 | -------------------------------------------------------------------------------- /lib/atoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | long atoi(const char* S) 4 | { 5 | long num = 0; 6 | 7 | int i = 0; 8 | 9 | // run till the end of the string is reached, or the 10 | // current character is non-numeric 11 | while (S[i] && (S[i] >= '0' && S[i] <= '9')) 12 | { 13 | num = num * 10 + (S[i] - '0'); 14 | i++; 15 | } 16 | 17 | return num; 18 | } -------------------------------------------------------------------------------- /lib/bzero.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bzero (void *s, my_size_t n) { 4 | for (my_size_t i = 0; i < n; i++) { 5 | *((char*)s + i) = '\0'; 6 | } 7 | } -------------------------------------------------------------------------------- /lib/errno.c: -------------------------------------------------------------------------------- 1 | int errno = 0; 2 | -------------------------------------------------------------------------------- /lib/isalpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int isalpha(c) 4 | int c; 5 | { 6 | return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ? 1 : 0); 7 | } 8 | -------------------------------------------------------------------------------- /lib/isdigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int isdigit(c) 4 | int c; 5 | { 6 | return (c >= '0' && c <= '9' ? 1 : 0); 7 | } 8 | -------------------------------------------------------------------------------- /lib/isspace.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int isspace(int c) { 4 | return (c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r' || c == ' ' ? 1 : 0); 5 | } -------------------------------------------------------------------------------- /lib/isupper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int isupper(int c) 4 | { 5 | return (c >= 'A' && c <= 'Z') || (c >= 0xC0 && c <= 0xDD); 6 | } 7 | -------------------------------------------------------------------------------- /lib/memcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * The contents of this file constitute Original Code as defined in and 7 | * are subject to the Apple Public Source License Version 1.1 (the 8 | * "License"). You may not use this file except in compliance with the 9 | * License. Please obtain a copy of the License at 10 | * http://www.apple.com/publicsource and read it before using this file. 11 | * 12 | * This Original Code and all software distributed under the License are 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 | * License for the specific language governing rights and limitations 18 | * under the License. 19 | * 20 | * @APPLE_LICENSE_HEADER_END@ 21 | */ 22 | /* 23 | * mem.c - Standard memory functions. 24 | * 25 | * Copyright (c) 1998-2002 Apple Computer, Inc. 26 | * 27 | * DRI: Josh de Cesare 28 | */ 29 | 30 | #include 31 | 32 | int 33 | memcmp(const void *b1, const void *b2, size_t len) 34 | { 35 | register long n = len; 36 | unsigned char *m1 = (unsigned char *)b1; 37 | unsigned char *m2 = (unsigned char *)b2; 38 | 39 | while (n-- && (*m1 == *m2)) { 40 | m1++; 41 | m2++; 42 | } 43 | 44 | return ((n < 0) ? 0 : (*m1 - *m2)); 45 | } 46 | -------------------------------------------------------------------------------- /lib/memmem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ibex - pseudo-library 3 | * 4 | * Copyright (c) 2015 xerub 5 | * Boyer-Moore-Horspool algorithm from Wikipedia 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | 22 | #include 23 | 24 | 25 | #define UCHAR_MAX 255 26 | 27 | unsigned char * 28 | boyermoore_horspool_memmem(const unsigned char* haystack, my_size_t hlen, 29 | const unsigned char* needle, my_size_t nlen) 30 | { 31 | my_size_t last, scan = 0; 32 | my_size_t bad_char_skip[UCHAR_MAX + 1]; /* Officially called: 33 | * bad character shift */ 34 | 35 | /* Sanity checks on the parameters */ 36 | if (nlen <= 0 || !haystack || !needle) 37 | return NULL; 38 | 39 | /* ---- Preprocess ---- */ 40 | /* Initialize the table to default value */ 41 | /* When a character is encountered that does not occur 42 | * in the needle, we can safely skip ahead for the whole 43 | * length of the needle. 44 | */ 45 | for (scan = 0; scan <= UCHAR_MAX; scan = scan + 1) 46 | bad_char_skip[scan] = nlen; 47 | 48 | /* C arrays have the first byte at [0], therefore: 49 | * [nlen - 1] is the last byte of the array. */ 50 | last = nlen - 1; 51 | 52 | /* Then populate it with the analysis of the needle */ 53 | for (scan = 0; scan < last; scan = scan + 1) 54 | bad_char_skip[needle[scan]] = last - scan; 55 | 56 | /* ---- Do the matching ---- */ 57 | 58 | /* Search the haystack, while the needle can still be within it. */ 59 | while (hlen >= nlen) 60 | { 61 | /* scan from the end of the needle */ 62 | for (scan = last; haystack[scan] == needle[scan]; scan = scan - 1) 63 | if (scan == 0) /* If the first byte matches, we've found it. */ 64 | return (void *)haystack; 65 | 66 | /* otherwise, we need to skip some bytes and start again. 67 | Note that here we are getting the skip value based on the last byte 68 | of needle, no matter where we didn't match. So if needle is: "abcd" 69 | then we are skipping based on 'd' and that value will be 4, and 70 | for "abcdd" we again skip on 'd' but the value will be only 1. 71 | The alternative of pretending that the mismatched character was 72 | the last character is slower in the normal case (E.g. finding 73 | "abcd" in "...azcd..." gives 4 by using 'd' but only 74 | 4-2==2 using 'z'. */ 75 | hlen -= bad_char_skip[haystack[last]]; 76 | haystack += bad_char_skip[haystack[last]]; 77 | } 78 | 79 | return NULL; 80 | } 81 | 82 | void * 83 | memmem(const void *haystack, my_size_t hlen, const void *needle, my_size_t nlen) 84 | { 85 | my_size_t i, j; 86 | if (!nlen) { 87 | return (void *)haystack; 88 | } 89 | if (nlen > hlen) { 90 | return NULL; 91 | } 92 | if (nlen >= 4 && hlen >= 256) { 93 | return boyermoore_horspool_memmem(haystack, hlen, needle, nlen); 94 | } 95 | for (j = 0, i = 0; i < hlen; i++) { 96 | if (((unsigned char *)haystack)[i] == ((unsigned char *)needle)[j]) { 97 | j++; 98 | if (j == nlen) { 99 | return (char *)haystack + i - nlen + 1; 100 | } 101 | } else { 102 | i -= j; 103 | j = 0; 104 | } 105 | } 106 | return NULL; 107 | } 108 | -------------------------------------------------------------------------------- /lib/memmove.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * The contents of this file constitute Original Code as defined in and 7 | * are subject to the Apple Public Source License Version 1.1 (the 8 | * "License"). You may not use this file except in compliance with the 9 | * License. Please obtain a copy of the License at 10 | * http://www.apple.com/publicsource and read it before using this file. 11 | * 12 | * This Original Code and all software distributed under the License are 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 | * License for the specific language governing rights and limitations 18 | * under the License. 19 | * 20 | * @APPLE_LICENSE_HEADER_END@ 21 | */ 22 | /* 23 | * mem.c - Standard memory functions. 24 | * 25 | * Copyright (c) 1998-2002 Apple Computer, Inc. 26 | * 27 | * DRI: Josh de Cesare 28 | */ 29 | 30 | #include 31 | 32 | void *memcpy(void *dst, const void *src, my_size_t len) 33 | { 34 | const char *s = src; 35 | char *d = dst; 36 | int pos = 0, dir = 1; 37 | 38 | if (d > s) { 39 | dir = -1; 40 | pos = len - 1; 41 | } 42 | 43 | while (len--) { 44 | d[pos] = s[pos]; 45 | pos += dir; 46 | } 47 | 48 | return dst; 49 | } 50 | 51 | void *memmove(void *dest, const void *src, my_size_t n) 52 | { 53 | return memcpy(dest, src, n); 54 | } 55 | -------------------------------------------------------------------------------- /lib/memset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 | * 4 | * @APPLE_LICENSE_HEADER_START@ 5 | * 6 | * The contents of this file constitute Original Code as defined in and 7 | * are subject to the Apple Public Source License Version 1.1 (the 8 | * "License"). You may not use this file except in compliance with the 9 | * License. Please obtain a copy of the License at 10 | * http://www.apple.com/publicsource and read it before using this file. 11 | * 12 | * This Original Code and all software distributed under the License are 13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER 14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the 17 | * License for the specific language governing rights and limitations 18 | * under the License. 19 | * 20 | * @APPLE_LICENSE_HEADER_END@ 21 | */ 22 | /* 23 | * mem.c - Standard memory functions. 24 | * 25 | * Copyright (c) 1998-2002 Apple Computer, Inc. 26 | * 27 | * DRI: Josh de Cesare 28 | */ 29 | 30 | #include 31 | 32 | void *memset(void *dst, int ch, my_size_t len) 33 | { 34 | long tmp = 0x0101010101010101 * (ch & 0x000000FF); 35 | char *dest = dst; 36 | 37 | if (len < 32) while (len--) *dest++ = ch; 38 | else { 39 | /* do the front chunk as chars */ 40 | while ((long)dest & 7) { 41 | len--; 42 | *dest++ = ch; 43 | } 44 | 45 | /* do the middle chunk as longs */ 46 | while (len > 7) { 47 | len -= 8; 48 | *(long *)dest = tmp; 49 | dest += 8; 50 | } 51 | 52 | /* do the last chunk as chars */ 53 | while (len--) *dest++ = ch; 54 | } 55 | 56 | return dst; 57 | } 58 | -------------------------------------------------------------------------------- /lib/puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int puts(const char* str) { 4 | return printf("%s\n", str); 5 | } -------------------------------------------------------------------------------- /lib/strcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char* strcat (char* dest, char* src) { 4 | char* dest_end = dest + strlen(dest); 5 | for (uint64_t i = 0; src[i] != '\0'; i++) { 6 | *dest_end = src[i]; 7 | dest_end++; 8 | } 9 | dest_end = NULL; 10 | return dest; 11 | } -------------------------------------------------------------------------------- /lib/strchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *strchr(const char *p, int ch) 4 | { 5 | char c; 6 | 7 | c = ch; 8 | for (;; ++p) { 9 | if (*p == c) 10 | return ((char *)p); 11 | if (*p == '\0') 12 | return (NULL); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /lib/strcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int strcmp(const char *s1, const char *s2) 4 | { 5 | while (*s1 == *s2 && *s1) { 6 | s1++; 7 | s2++; 8 | } 9 | 10 | return *s1 - *s2; 11 | } 12 | -------------------------------------------------------------------------------- /lib/strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *strcpy(char *to, const char *from) 4 | { 5 | if (to == NULL) { 6 | return NULL; 7 | } 8 | const char* ptr = from; 9 | uint64_t i = 0; 10 | for (; from[i] != '\0'; i++) { 11 | to[i] = *ptr; 12 | ptr++; 13 | } 14 | to[i] = '\0'; 15 | return to; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /lib/strlen.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | my_size_t strlen(const char * str) { 5 | my_size_t len = 0; 6 | while (*str++) { 7 | len++; 8 | } 9 | 10 | return len; 11 | } 12 | -------------------------------------------------------------------------------- /lib/strncmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int strncmp(const char *s1, const char *s2, my_size_t n) 4 | { 5 | 6 | if (n == 0) 7 | return (0); 8 | do { 9 | if (*s1 != *s2++) 10 | return (*(unsigned char *)s1 - *(unsigned char *)--s2); 11 | if (*s1++ == 0) 12 | break; 13 | } while (--n != 0); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /lib/strncpy.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | char *strncpy(char *dest, const char *src, my_size_t n) { 4 | my_size_t i; 5 | // copy src to dest 6 | for (i = 0; i < n && src[i] != '\0'; i++) 7 | dest[i] = src[i]; 8 | // fill the rest wiih NULL bytes 9 | for ( ; i < n; i++) 10 | dest[i] = '\0'; 11 | return dest; 12 | } -------------------------------------------------------------------------------- /lib/strstr.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | char *strstr(const char *string, char *substring) 5 | { 6 | register char *a, *b; 7 | 8 | /* First scan quickly through the two strings looking for a 9 | * single-character match. When it's found, then compare the 10 | * rest of the substring. 11 | */ 12 | 13 | b = substring; 14 | if (*b == 0) { 15 | return (char *)string; 16 | } 17 | for ( ; *string != 0; string += 1) { 18 | if (*string != *b) { 19 | continue; 20 | } 21 | a = (char *)string; 22 | while (1) { 23 | if (*b == 0) { 24 | return (char *)string; 25 | } 26 | if (*a++ != *b++) { 27 | break; 28 | } 29 | } 30 | b = substring; 31 | } 32 | return NULL; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /lib/strtoimax.c: -------------------------------------------------------------------------------- 1 | 2 | /* $OpenBSD: strtoimax.c,v 1.1 2006/01/13 17:58:09 millert Exp $ */ 3 | /*- 4 | * Copyright (c) 1992 The Regents of the University of California. 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | #include 32 | /* 33 | * Convert a string to an intmax_t 34 | * 35 | * Ignores `locale' stuff. Assumes that the upper and lower case 36 | * alphabets and digits are each contiguous. 37 | */ 38 | intmax_t 39 | strtoimax(const char *nptr, char **endptr, int base) 40 | { 41 | const char *s; 42 | intmax_t acc, cutoff; 43 | int c; 44 | int neg, any, cutlim; 45 | /* 46 | * Skip white space and pick up leading +/- sign if any. 47 | * If base is 0, allow 0x for hex and 0 for octal, else 48 | * assume decimal; if base is already 16, allow 0x. 49 | */ 50 | s = nptr; 51 | do { 52 | c = (unsigned char) *s++; 53 | } while (isspace(c)); 54 | if (c == '-') { 55 | neg = 1; 56 | c = *s++; 57 | } else { 58 | neg = 0; 59 | if (c == '+') 60 | c = *s++; 61 | } 62 | if ((base == 0 || base == 16) && 63 | c == '0' && (*s == 'x' || *s == 'X')) { 64 | c = s[1]; 65 | s += 2; 66 | base = 16; 67 | } 68 | if (base == 0) 69 | base = c == '0' ? 8 : 10; 70 | /* 71 | * Compute the cutoff value between legal numbers and illegal 72 | * numbers. That is the largest legal value, divided by the 73 | * base. An input number that is greater than this value, if 74 | * followed by a legal input character, is too big. One that 75 | * is equal to this value may be valid or not; the limit 76 | * between valid and invalid numbers is then based on the last 77 | * digit. For instance, if the range for intmax_t is 78 | * [-9223372036854775808..9223372036854775807] and the input base 79 | * is 10, cutoff will be set to 922337203685477580 and cutlim to 80 | * either 7 (neg==0) or 8 (neg==1), meaning that if we have 81 | * accumulated a value > 922337203685477580, or equal but the 82 | * next digit is > 7 (or 8), the number is too big, and we will 83 | * return a range error. 84 | * 85 | * Set any if any `digits' consumed; make it negative to indicate 86 | * overflow. 87 | */ 88 | /* BIONIC: avoid division and module for common cases */ 89 | #define CASE_BASE(x) \ 90 | case x: \ 91 | if (neg) { \ 92 | cutlim = INTMAX_MIN % x; \ 93 | cutoff = INTMAX_MIN / x; \ 94 | } else { \ 95 | cutlim = INTMAX_MAX % x; \ 96 | cutoff = INTMAX_MAX / x; \ 97 | }; \ 98 | break 99 | switch (base) { 100 | case 4: 101 | if (neg) { 102 | cutlim = (int)(INTMAX_MIN % 4); 103 | cutoff = INTMAX_MIN / 4; 104 | } else { 105 | cutlim = (int)(INTMAX_MAX % 4); 106 | cutoff = INTMAX_MAX / 4; 107 | } 108 | break; 109 | CASE_BASE(8); 110 | CASE_BASE(10); 111 | CASE_BASE(16); 112 | default: 113 | cutoff = neg ? INTMAX_MIN : INTMAX_MAX; 114 | cutlim = cutoff % base; 115 | cutoff /= base; 116 | } 117 | #undef CASE_BASE 118 | if (neg) { 119 | if (cutlim > 0) { 120 | cutlim -= base; 121 | cutoff += 1; 122 | } 123 | cutlim = -cutlim; 124 | } 125 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { 126 | if (isdigit(c)) 127 | c -= '0'; 128 | else if (isalpha(c)) 129 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 130 | else 131 | break; 132 | if (c >= base) 133 | break; 134 | if (any < 0) 135 | continue; 136 | if (neg) { 137 | if (acc < cutoff || (acc == cutoff && c > cutlim)) { 138 | any = -1; 139 | acc = INTMAX_MIN; 140 | errno = ERANGE; 141 | } else { 142 | any = 1; 143 | acc *= base; 144 | acc -= c; 145 | } 146 | } else { 147 | if (acc > cutoff || (acc == cutoff && c > cutlim)) { 148 | any = -1; 149 | acc = INTMAX_MAX; 150 | errno = ERANGE; 151 | } else { 152 | any = 1; 153 | acc *= base; 154 | acc += c; 155 | } 156 | } 157 | } 158 | if (endptr != 0) 159 | *endptr = (char *) (any ? s - 1 : nptr); 160 | return (acc); 161 | } -------------------------------------------------------------------------------- /lib/strtoul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define ULONG_MAX 0xFFFFFFFFUL 3 | 4 | unsigned long 5 | strtoul(const char* nptr, char ** endptr, register int base) { 6 | register const char *s = nptr; 7 | register unsigned long acc; 8 | register int c; 9 | register unsigned long cutoff; 10 | register int neg = 0, any, cutlim; 11 | 12 | /* 13 | * See strtol for comments as to the logic used. 14 | */ 15 | do { 16 | c = *s++; 17 | } while (isspace(c)); 18 | if (c == '-') { 19 | neg = 1; 20 | c = *s++; 21 | } else if (c == '+') 22 | c = *s++; 23 | if ((base == 0 || base == 16) && 24 | c == '0' && (*s == 'x' || *s == 'X')) { 25 | c = s[1]; 26 | s += 2; 27 | base = 16; 28 | } 29 | if (base == 0) 30 | base = c == '0' ? 8 : 10; 31 | cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; 32 | cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; 33 | for (acc = 0, any = 0;; c = *s++) { 34 | if (isdigit(c)) 35 | c -= '0'; 36 | else if (isalpha(c)) 37 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 38 | else 39 | break; 40 | if (c >= base) 41 | break; 42 | if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 43 | any = -1; 44 | else { 45 | any = 1; 46 | acc *= base; 47 | acc += c; 48 | } 49 | } 50 | if (any < 0) { 51 | acc = ULONG_MAX; 52 | errno = ERANGE; 53 | } else if (neg) 54 | acc = -acc; 55 | if (endptr != 0) 56 | *endptr = (char *)(any ? s - 1 : nptr); 57 | return (acc); 58 | } 59 | -------------------------------------------------------------------------------- /lib/strtoull.c: -------------------------------------------------------------------------------- 1 | #include 2 | #define ULLONG_MAX -1 3 | 4 | unsigned long long strtoull(const char *str, char **endptr, int base) 5 | { 6 | const char *s; 7 | unsigned long long acc, cutoff; 8 | int c; 9 | int neg, any, cutlim; 10 | 11 | /* 12 | * See strtoll for comments as to the logic used. 13 | */ 14 | if (base < 0 || base == 1 || base > 36) { 15 | if (endptr != 0) 16 | *endptr = (char *)str; 17 | return 0; 18 | } 19 | 20 | s = str; 21 | do { 22 | c = (unsigned char) *s++; 23 | } while (isspace(c)); 24 | if (c == '-') { 25 | neg = 1; 26 | c = *s++; 27 | } else { 28 | neg = 0; 29 | if (c == '+') 30 | c = *s++; 31 | } 32 | if ((base == 0 || base == 16) && 33 | c == '0' && (*s == 'x' || *s == 'X')) { 34 | c = s[1]; 35 | s += 2; 36 | base = 16; 37 | } 38 | if (base == 0) 39 | base = c == '0' ? 8 : 10; 40 | 41 | cutoff = ULLONG_MAX / (unsigned long long)base; 42 | cutlim = ULLONG_MAX % (unsigned long long)base; 43 | for (acc = 0, any = 0;; c = (unsigned char) *s++) { 44 | if (isdigit(c)) 45 | c -= '0'; 46 | else if (isalpha(c)) 47 | c -= isupper(c) ? 'A' - 10 : 'a' - 10; 48 | else 49 | break; 50 | if (c >= base) 51 | break; 52 | if (any < 0) 53 | continue; 54 | if (acc > cutoff || (acc == cutoff && c > cutlim)) { 55 | any = -1; 56 | acc = ULLONG_MAX; 57 | } else { 58 | any = 1; 59 | acc *= (unsigned long long)base; 60 | acc += c; 61 | } 62 | } 63 | if (neg && any > 0) 64 | acc = -acc; 65 | if (endptr != 0) 66 | *endptr = (char *) (any ? s - 1 : str); 67 | return (acc); 68 | } 69 | -------------------------------------------------------------------------------- /printf.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // \author (c) Marco Paland (info@paland.com) 3 | // 2014-2019, PALANDesign Hannover, Germany 4 | // 5 | // \license The MIT License (MIT) 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy 8 | // of this software and associated documentation files (the "Software"), to deal 9 | // in the Software without restriction, including without limitation the rights 10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | // copies of the Software, and to permit persons to whom the Software is 12 | // furnished to do so, subject to the following conditions: 13 | // 14 | // The above copyright notice and this permission notice shall be included in 15 | // all copies or substantial portions of the Software. 16 | // 17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | // THE SOFTWARE. 24 | // 25 | // \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on 26 | // embedded systems with a very limited resources. 27 | // Use this instead of bloated standard/newlib printf. 28 | // These routines are thread safe and reentrant. 29 | // 30 | /////////////////////////////////////////////////////////////////////////////// 31 | 32 | #ifndef _PRINTF_H_ 33 | #define _PRINTF_H_ 34 | 35 | #include 36 | #include 37 | #include "common.h" 38 | typedef unsigned long long my_size_t; 39 | 40 | #ifdef __cplusplus 41 | extern "C" { 42 | #endif 43 | 44 | 45 | /** 46 | * Output a character to a custom device like UART, used by the printf() function 47 | * This function is declared here only. You have to write your custom implementation somewhere 48 | * \param character Character to output 49 | */ 50 | void _putchar(char character); 51 | 52 | 53 | /** 54 | * Tiny printf implementation 55 | * You have to implement _putchar if you use printf() 56 | * To avoid conflicts with the regular printf() API it is overridden by macro defines 57 | * and internal underscore-appended functions like printf_() are used 58 | * \param format A string that specifies the format of the output 59 | * \return The number of characters that are written into the array, not counting the terminating null character 60 | */ 61 | #define printf printf_ 62 | int printf_(const char* format, ...); 63 | 64 | 65 | /** 66 | * Tiny sprintf implementation 67 | * Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD! 68 | * \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output! 69 | * \param format A string that specifies the format of the output 70 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 71 | */ 72 | #define sprintf sprintf_ 73 | int sprintf_(char* buffer, const char* format, ...); 74 | 75 | 76 | /** 77 | * Tiny snprintf/vsnprintf implementation 78 | * \param buffer A pointer to the buffer where to store the formatted string 79 | * \param count The maximum number of characters to store in the buffer, including a terminating null character 80 | * \param format A string that specifies the format of the output 81 | * \param va A value identifying a variable arguments list 82 | * \return The number of characters that COULD have been written into the buffer, not counting the terminating 83 | * null character. A value equal or larger than count indicates truncation. Only when the returned value 84 | * is non-negative and less than count, the string has been completely written. 85 | */ 86 | #define snprintf snprintf_ 87 | #define vsnprintf vsnprintf_ 88 | int snprintf_(char* buffer, my_size_t count, const char* format, ...); 89 | int vsnprintf_(char* buffer, my_size_t count, const char* format, va_list va); 90 | 91 | 92 | /** 93 | * Tiny vprintf implementation 94 | * \param format A string that specifies the format of the output 95 | * \param va A value identifying a variable arguments list 96 | * \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character 97 | */ 98 | #define vprintf vprintf_ 99 | int vprintf_(const char* format, va_list va); 100 | 101 | 102 | /** 103 | * printf with output function 104 | * You may use this as dynamic alternative to printf() with its fixed _putchar() output 105 | * \param out An output function which takes one character and an argument pointer 106 | * \param arg An argument pointer for user data passed to output function 107 | * \param format A string that specifies the format of the output 108 | * \return The number of characters that are sent to the output function, not counting the terminating null character 109 | */ 110 | int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); 111 | 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | 118 | #endif // _PRINTF_H_ 119 | -------------------------------------------------------------------------------- /sym_order.txt: -------------------------------------------------------------------------------- 1 | start 2 | --------------------------------------------------------------------------------