2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 #define __darwin_i386_exception_state i386_exception_state
24 #define __darwin_i386_float_state i386_float_state
25 #define __darwin_i386_thread_state i386_thread_state
27 #include <mach-o/loader.h>
28 #include <mach/m68k/thread_status.h>
29 #undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
30 #undef MACHINE_THREAD_STATE_COUNT
31 #undef THREAD_STATE_NONE
32 #undef VALID_THREAD_STATE_FLAVOR
33 #include <mach/ppc/thread_status.h>
34 #undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
35 #undef MACHINE_THREAD_STATE_COUNT
36 #undef THREAD_STATE_NONE
37 #undef VALID_THREAD_STATE_FLAVOR
38 #include <mach/m88k/thread_status.h>
39 #include <mach/i860/thread_status.h>
40 #include <mach/i386/thread_status.h>
41 #include <mach/hppa/thread_status.h>
42 #include <mach/sparc/thread_status.h>
43 #include <mach/arm/thread_status.h>
44 #include "stuff/bool.h"
45 #include "stuff/bytesex.h"
46 #include "stuff/errors.h"
49 * swap_object_headers() swaps the object file headers from the host byte sex
50 * into the non-host byte sex. It returns TRUE if it can and did swap the
51 * headers else returns FALSE and does not touch the headers and prints an error
52 * using the error() routine.
58 struct load_command
*load_commands
)
61 uint32_t magic
, ncmds
, sizeofcmds
, cmd_multiple
;
63 cpu_subtype_t cpusubtype
;
64 struct mach_header
*mh
;
65 struct mach_header_64
*mh64
;
66 enum byte_sex target_byte_sex
;
67 struct load_command
*lc
, l
;
68 struct segment_command
*sg
;
69 struct segment_command_64
*sg64
;
71 struct section_64
*s64
;
72 struct symtab_command
*st
;
73 struct dysymtab_command
*dyst
;
74 struct symseg_command
*ss
;
75 struct fvmlib_command
*fl
;
76 struct thread_command
*ut
;
77 struct ident_command
*id
;
78 struct entry_point_command
*ep
;
79 struct source_version_command
*sv
;
80 struct dylib_command
*dl
;
81 struct sub_framework_command
*sub
;
82 struct sub_umbrella_command
*usub
;
83 struct sub_library_command
*lsub
;
84 struct sub_client_command
*csub
;
85 struct prebound_dylib_command
*pbdylib
;
86 struct dylinker_command
*dyld
;
87 struct routines_command
*rc
;
88 struct routines_command_64
*rc64
;
89 struct twolevel_hints_command
*hints
;
90 struct prebind_cksum_command
*cs
;
91 struct uuid_command
*uuid
;
92 struct linkedit_data_command
*ld
;
93 struct rpath_command
*rpath
;
94 struct encryption_info_command
*ec
;
95 struct dyld_info_command
*dc
;
96 struct version_min_command
*vc
;
97 uint32_t flavor
, count
;
98 unsigned long nflavor
;
99 char *p
, *state
, *cmd_name
;
101 magic
= *((uint32_t *)mach_header
);
102 if(magic
== MH_MAGIC
){
103 mh
= (struct mach_header
*)mach_header
;
105 sizeofcmds
= mh
->sizeofcmds
;
106 cputype
= mh
->cputype
;
107 cpusubtype
= mh
->cpusubtype
;
112 mh64
= (struct mach_header_64
*)mach_header
;
114 sizeofcmds
= mh64
->sizeofcmds
;
115 cputype
= mh64
->cputype
;
116 cpusubtype
= mh64
->cpusubtype
;
121 * Make a pass through the load commands checking them to the level
122 * that they can be parsed and then swapped.
124 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
126 /* check load command size for a correct multiple size */
127 if(lc
->cmdsize
% cmd_multiple
!= 0){
128 error("in swap_object_headers(): malformed load command %lu "
129 "(cmdsize not a multiple of %u)", i
, cmd_multiple
);
132 /* check that load command does not extends past end of commands */
133 if((char *)lc
+ lc
->cmdsize
>
134 (char *)load_commands
+ sizeofcmds
){
135 error("in swap_object_headers(): truncated or malformed load "
136 "command %lu (extends past the end of the all load "
140 /* check that the load command size is not zero */
141 if(lc
->cmdsize
== 0){
142 error("in swap_object_headers(): malformed load command %lu "
143 "(cmdsize is zero)", i
);
148 sg
= (struct segment_command
*)lc
;
149 if(sg
->cmdsize
!= sizeof(struct segment_command
) +
150 sg
->nsects
* sizeof(struct section
)){
151 error("in swap_object_headers(): malformed load command "
152 "(inconsistent cmdsize in LC_SEGMENT command %lu for "
153 "the number of sections)", i
);
159 sg64
= (struct segment_command_64
*)lc
;
160 if(sg64
->cmdsize
!= sizeof(struct segment_command_64
) +
161 sg64
->nsects
* sizeof(struct section_64
)){
162 error("in swap_object_headers(): malformed load command "
163 "(inconsistent cmdsize in LC_SEGMENT_64 command %lu "
164 "for the number of sections)", i
);
170 st
= (struct symtab_command
*)lc
;
171 if(st
->cmdsize
!= sizeof(struct symtab_command
)){
172 error("in swap_object_headers(): malformed load commands "
173 "(LC_SYMTAB command %lu has incorrect cmdsize", i
);
179 dyst
= (struct dysymtab_command
*)lc
;
180 if(dyst
->cmdsize
!= sizeof(struct dysymtab_command
)){
181 error("in swap_object_headers(): malformed load commands "
182 "(LC_DYSYMTAB command %lu has incorrect cmdsize", i
);
188 ss
= (struct symseg_command
*)lc
;
189 if(ss
->cmdsize
!= sizeof(struct symseg_command
)){
190 error("in swap_object_headers(): malformed load command "
191 "(LC_SYMSEG command %lu has incorrect cmdsize", i
);
198 fl
= (struct fvmlib_command
*)lc
;
199 if(fl
->cmdsize
< sizeof(struct fvmlib_command
)){
200 error("in swap_object_headers(): malformed load commands "
201 "(%s command %lu has too small cmdsize field)",
202 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
206 if(fl
->fvmlib
.name
.offset
>= fl
->cmdsize
){
207 error("in swap_object_headers(): truncated or malformed "
208 "load commands (name.offset field of %s command %lu "
209 "extends past the end of all load commands)",
210 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
217 cmd_name
= "LC_ID_DYLIB";
218 goto check_dylib_command
;
220 cmd_name
= "LC_LOAD_DYLIB";
221 goto check_dylib_command
;
222 case LC_LOAD_WEAK_DYLIB
:
223 cmd_name
= "LC_LOAD_WEAK_DYLIB";
224 goto check_dylib_command
;
225 case LC_REEXPORT_DYLIB
:
226 cmd_name
= "LC_REEXPORT_DYLIB";
227 goto check_dylib_command
;
228 case LC_LOAD_UPWARD_DYLIB
:
229 cmd_name
= "LC_LOAD_UPWARD_DYLIB";
230 goto check_dylib_command
;
231 case LC_LAZY_LOAD_DYLIB
:
232 cmd_name
= "LC_LAZY_LOAD_DYLIB";
233 goto check_dylib_command
;
235 dl
= (struct dylib_command
*)lc
;
236 if(dl
->cmdsize
< sizeof(struct dylib_command
)){
237 error("in swap_object_headers(): malformed load commands "
238 "(%s command %lu has too small cmdsize field)",
242 if(dl
->dylib
.name
.offset
>= dl
->cmdsize
){
243 error("in swap_object_headers(): truncated or malformed "
244 "load commands (name.offset field of %s command %lu "
245 "extends past the end of all load commands)",
251 case LC_SUB_FRAMEWORK
:
252 sub
= (struct sub_framework_command
*)lc
;
253 if(sub
->cmdsize
< sizeof(struct sub_framework_command
)){
254 error("in swap_object_headers(): malformed load commands "
255 "(LC_SUB_FRAMEWORK command %lu has too small cmdsize "
259 if(sub
->umbrella
.offset
>= sub
->cmdsize
){
260 error("in swap_object_headers(): truncated or malformed "
261 "load commands (umbrella.offset field of "
262 "LC_SUB_FRAMEWORK command %lu extends past the end "
263 "of all load commands)", i
);
268 case LC_SUB_UMBRELLA
:
269 usub
= (struct sub_umbrella_command
*)lc
;
270 if(usub
->cmdsize
< sizeof(struct sub_umbrella_command
)){
271 error("in swap_object_headers(): malformed load commands "
272 "(LC_SUB_UMBRELLA command %lu has too small cmdsize "
276 if(usub
->sub_umbrella
.offset
>= usub
->cmdsize
){
277 error("in swap_object_headers(): truncated or malformed "
278 "load commands (sub_umbrella.offset field of "
279 "LC_SUB_UMBRELLA command %lu extends past the end "
280 "of all load commands)", i
);
286 lsub
= (struct sub_library_command
*)lc
;
287 if(lsub
->cmdsize
< sizeof(struct sub_library_command
)){
288 error("in swap_object_headers(): malformed load commands "
289 "(LC_SUB_LIBRARY command %lu has too small cmdsize "
293 if(lsub
->sub_library
.offset
>= lsub
->cmdsize
){
294 error("in swap_object_headers(): truncated or malformed "
295 "load commands (sub_library.offset field of "
296 "LC_SUB_LIBRARY command %lu extends past the end "
297 "of all load commands)", i
);
303 csub
= (struct sub_client_command
*)lc
;
304 if(csub
->cmdsize
< sizeof(struct sub_client_command
)){
305 error("in swap_object_headers(): malformed load commands "
306 "(LC_SUB_CLIENT command %lu has too small cmdsize "
310 if(csub
->client
.offset
>= csub
->cmdsize
){
311 error("in swap_object_headers(): truncated or malformed "
312 "load commands (client.offset field of "
313 "LC_SUB_CLIENT command %lu extends past the end "
314 "of all load commands)", i
);
319 case LC_PREBOUND_DYLIB
:
320 pbdylib
= (struct prebound_dylib_command
*)lc
;
321 if(pbdylib
->cmdsize
< sizeof(struct prebound_dylib_command
)){
322 error("in swap_object_headers(): malformed load commands "
323 "(LC_PREBOUND_DYLIB command %lu has too small "
324 "cmdsize field)", i
);
327 if(pbdylib
->name
.offset
>= pbdylib
->cmdsize
){
328 error("in swap_object_headers(): truncated or malformed "
329 "load commands (name.offset field of "
330 "LC_PREBOUND_DYLIB command %lu extends past the end "
331 "of all load commands)", i
);
334 if(pbdylib
->linked_modules
.offset
>= pbdylib
->cmdsize
){
335 error("in swap_object_headers(): truncated or malformed "
336 "load commands (linked_modules.offset field of "
337 "LC_PREBOUND_DYLIB command %lu extends past the end "
338 "of all load commands)", i
);
344 cmd_name
= "LC_ID_DYLINKER";
345 goto check_dylinker_command
;
346 case LC_LOAD_DYLINKER
:
347 cmd_name
= "LC_LOAD_DYLINKER";
348 goto check_dylinker_command
;
349 case LC_DYLD_ENVIRONMENT
:
350 cmd_name
= "LC_DYLD_ENVIRONMENT";
351 goto check_dylinker_command
;
352 check_dylinker_command
:
353 dyld
= (struct dylinker_command
*)lc
;
354 if(dyld
->cmdsize
< sizeof(struct dylinker_command
)){
355 error("in swap_object_headers(): malformed load commands "
356 "(%s command %lu has too small cmdsize field)",
360 if(dyld
->name
.offset
>= dyld
->cmdsize
){
361 error("in swap_object_headers(): truncated or malformed "
362 "load commands (name.offset field of %s command %lu "
363 "extends past the end of all load commands)",
371 ut
= (struct thread_command
*)lc
;
372 state
= (char *)ut
+ sizeof(struct thread_command
);
374 if(cputype
== CPU_TYPE_MC680x0
){
375 struct m68k_thread_state_regs
*cpu
;
376 struct m68k_thread_state_68882
*fpu
;
377 struct m68k_thread_state_user_reg
*user_reg
;
380 p
= (char *)ut
+ ut
->cmdsize
;
382 flavor
= *((uint32_t *)state
);
383 state
+= sizeof(uint32_t);
384 count
= *((uint32_t *)state
);
385 state
+= sizeof(uint32_t);
387 case M68K_THREAD_STATE_REGS
:
388 if(count
!= M68K_THREAD_STATE_REGS_COUNT
){
389 error("in swap_object_headers(): malformed "
390 "load commands (count "
391 "not M68K_THREAD_STATE_REGS_COUNT for "
392 "flavor number %lu which is a M68K_THREAD_"
393 "STATE_REGS flavor in %s command %lu)",
394 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
395 "LC_UNIXTHREAD" : "LC_THREAD", i
);
398 cpu
= (struct m68k_thread_state_regs
*)state
;
399 state
+= sizeof(struct m68k_thread_state_regs
);
401 case M68K_THREAD_STATE_68882
:
402 if(count
!= M68K_THREAD_STATE_68882_COUNT
){
403 error("in swap_object_headers(): malformed "
404 "load commands (count "
405 "not M68K_THREAD_STATE_68882_COUNT for "
406 "flavor number %lu which is a M68K_THREAD_"
407 "STATE_68882 flavor in %s command %lu)",
408 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
409 "LC_UNIXTHREAD" : "LC_THREAD", i
);
412 fpu
= (struct m68k_thread_state_68882
*)state
;
413 state
+= sizeof(struct m68k_thread_state_68882
);
415 case M68K_THREAD_STATE_USER_REG
:
416 if(count
!= M68K_THREAD_STATE_USER_REG_COUNT
){
417 error("in swap_object_headers(): malformed "
418 "load commands (count "
419 "not M68K_THREAD_STATE_USER_REG_COUNT for "
420 "flavor number %lu which is a M68K_THREAD_"
421 "STATE_USER_REG flavor in %s command %lu)",
422 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
423 "LC_UNIXTHREAD" : "LC_THREAD", i
);
427 (struct m68k_thread_state_user_reg
*)state
;
428 state
+= sizeof(struct m68k_thread_state_user_reg
);
431 error("in swap_object_headers(): malformed "
432 "load commands (unknown "
433 "flavor %u for flavor number %lu in %s command"
434 " %lu can't byte swap it)", flavor
, nflavor
,
435 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
443 if(cputype
== CPU_TYPE_POWERPC
||
444 cputype
== CPU_TYPE_VEO
||
445 cputype
== CPU_TYPE_POWERPC64
){
446 ppc_thread_state_t
*cpu
;
447 ppc_float_state_t
*fpu
;
448 ppc_exception_state_t
*except
;
449 ppc_thread_state64_t
*cpu64
;
452 p
= (char *)ut
+ ut
->cmdsize
;
454 flavor
= *((uint32_t *)state
);
455 state
+= sizeof(uint32_t);
456 count
= *((uint32_t *)state
);
457 state
+= sizeof(uint32_t);
459 case PPC_THREAD_STATE
:
460 if(count
!= PPC_THREAD_STATE_COUNT
){
461 error("in swap_object_headers(): malformed "
462 "load commands (count "
463 "not PPC_THREAD_STATE_COUNT for "
464 "flavor number %lu which is a PPC_THREAD_"
465 "STATE flavor in %s command %lu)",
466 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
467 "LC_UNIXTHREAD" : "LC_THREAD", i
);
470 cpu
= (ppc_thread_state_t
*)state
;
471 state
+= sizeof(ppc_thread_state_t
);
473 case PPC_FLOAT_STATE
:
474 if(count
!= PPC_FLOAT_STATE_COUNT
){
475 error("in swap_object_headers(): malformed "
476 "load commands (count "
477 "not PPC_FLOAT_STATE_COUNT for "
478 "flavor number %lu which is a PPC_FLOAT_"
479 "STATE flavor in %s command %lu)",
480 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
481 "LC_UNIXTHREAD" : "LC_THREAD", i
);
484 fpu
= (ppc_float_state_t
*)state
;
485 state
+= sizeof(ppc_float_state_t
);
487 case PPC_EXCEPTION_STATE
:
488 if(count
!= PPC_EXCEPTION_STATE_COUNT
){
489 error("in swap_object_headers(): malformed "
490 "load commands (count "
491 "not PPC_EXCEPTION_STATE_COUNT for "
492 "flavor number %lu which is a PPC_EXCEPT"
493 "ION_STATE flavor in %s command %lu)",
494 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
495 "LC_UNIXTHREAD" : "LC_THREAD", i
);
498 except
= (ppc_exception_state_t
*)state
;
499 state
+= sizeof(ppc_exception_state_t
);
501 case PPC_THREAD_STATE64
:
502 if(count
!= PPC_THREAD_STATE64_COUNT
){
503 error("in swap_object_headers(): malformed "
504 "load commands (count "
505 "not PPC_THREAD_STATE64_COUNT for "
506 "flavor number %lu which is a PPC_THREAD_"
507 "STATE64 flavor in %s command %lu)",
508 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
509 "LC_UNIXTHREAD" : "LC_THREAD", i
);
512 cpu64
= (ppc_thread_state64_t
*)state
;
513 state
+= sizeof(ppc_thread_state64_t
);
516 error("in swap_object_headers(): malformed "
517 "load commands (unknown "
518 "flavor %u for flavor number %lu in %s command"
519 " %lu can't byte swap it)", flavor
, nflavor
,
520 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
528 if(cputype
== CPU_TYPE_MC88000
){
529 m88k_thread_state_grf_t
*cpu
;
530 m88k_thread_state_xrf_t
*fpu
;
531 m88k_thread_state_user_t
*user
;
532 m88110_thread_state_impl_t
*spu
;
535 p
= (char *)ut
+ ut
->cmdsize
;
537 flavor
= *((uint32_t *)state
);
538 state
+= sizeof(uint32_t);
539 count
= *((uint32_t *)state
);
540 state
+= sizeof(uint32_t);
542 case M88K_THREAD_STATE_GRF
:
543 if(count
!= M88K_THREAD_STATE_GRF_COUNT
){
544 error("in swap_object_headers(): malformed "
545 "load commands (count "
546 "not M88K_THREAD_STATE_GRF_COUNT for "
547 "flavor number %lu which is a M88K_THREAD_"
548 "STATE_GRF flavor in %s command %lu)",
549 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
550 "LC_UNIXTHREAD" : "LC_THREAD", i
);
553 cpu
= (m88k_thread_state_grf_t
*)state
;
554 state
+= sizeof(m88k_thread_state_grf_t
);
556 case M88K_THREAD_STATE_XRF
:
557 if(count
!= M88K_THREAD_STATE_XRF_COUNT
){
558 error("in swap_object_headers(): malformed "
559 "load commands (count "
560 "not M88K_THREAD_STATE_XRF_COUNT for "
561 "flavor number %lu which is a M88K_THREAD_"
562 "STATE_XRF flavor in %s command %lu)",
563 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
564 "LC_UNIXTHREAD" : "LC_THREAD", i
);
567 fpu
= (m88k_thread_state_xrf_t
*)state
;
568 state
+= sizeof(m88k_thread_state_xrf_t
);
570 case M88K_THREAD_STATE_USER
:
571 if(count
!= M88K_THREAD_STATE_USER_COUNT
){
572 error("in swap_object_headers(): malformed "
573 "load commands (count "
574 "not M88K_THREAD_STATE_USER_COUNT for "
575 "flavor number %lu which is a M88K_THREAD_"
576 "STATE_USER flavor in %s command %lu)",
577 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
578 "LC_UNIXTHREAD" : "LC_THREAD", i
);
581 user
= (m88k_thread_state_user_t
*)state
;
582 state
+= sizeof(m88k_thread_state_user_t
);
584 case M88110_THREAD_STATE_IMPL
:
585 if(count
!= M88110_THREAD_STATE_IMPL_COUNT
){
586 error("in swap_object_headers(): malformed "
587 "load commands (count "
588 "not M88110_THREAD_STATE_IMPL_COUNT for "
589 "flavor number %lu which is a M88110_THREAD"
590 "_STATE_IMPL flavor in %s command %lu)",
591 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
592 "LC_UNIXTHREAD" : "LC_THREAD", i
);
595 spu
= (m88110_thread_state_impl_t
*)state
;
596 state
+= sizeof(m88110_thread_state_impl_t
);
599 error("in swap_object_headers(): malformed "
600 "load commands (unknown "
601 "flavor %u for flavor number %lu in %s command"
602 " %lu can't byte swap it)", flavor
, nflavor
,
603 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
611 if(cputype
== CPU_TYPE_I860
){
612 struct i860_thread_state_regs
*cpu
;
615 p
= (char *)ut
+ ut
->cmdsize
;
617 flavor
= *((uint32_t *)state
);
618 state
+= sizeof(uint32_t);
619 count
= *((uint32_t *)state
);
620 state
+= sizeof(uint32_t);
622 case I860_THREAD_STATE_REGS
:
623 if(count
!= I860_THREAD_STATE_REGS_COUNT
){
624 error("in swap_object_headers(): malformed "
625 "load commands (count "
626 "not I860_THREAD_STATE_REGS_COUNT for "
627 "flavor number %lu which is a I860_THREAD_"
628 "STATE_REGS flavor in %s command %lu)",
629 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
630 "LC_UNIXTHREAD" : "LC_THREAD", i
);
633 cpu
= (struct i860_thread_state_regs
*)state
;
634 state
+= sizeof(struct i860_thread_state_regs
);
637 error("in swap_object_headers(): malformed "
638 "load commands (unknown "
639 "flavor %u for flavor number %lu in %s command"
640 " %lu can't byte swap it)", flavor
, nflavor
,
641 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
649 if(cputype
== CPU_TYPE_I386
650 #ifdef x86_THREAD_STATE64
651 || cputype
== CPU_TYPE_X86_64
652 #endif /* x86_THREAD_STATE64 */
654 i386_thread_state_t
*cpu
;
655 #ifdef x86_THREAD_STATE64
656 x86_thread_state64_t
*cpu64
;
657 #endif /* x86_THREAD_STATE64 */
658 /* current i386 thread states */
659 #if i386_THREAD_STATE == 1
660 struct i386_float_state
*fpu
;
661 i386_exception_state_t
*exc
;
662 #endif /* i386_THREAD_STATE == 1 */
664 /* i386 thread states on older releases */
665 #if i386_THREAD_STATE == -1
666 i386_thread_fpstate_t
*fpu
;
667 i386_thread_exceptstate_t
*exc
;
668 i386_thread_cthreadstate_t
*user
;
669 #endif /* i386_THREAD_STATE == -1 */
672 p
= (char *)ut
+ ut
->cmdsize
;
674 flavor
= *((uint32_t *)state
);
675 state
+= sizeof(uint32_t);
676 count
= *((uint32_t *)state
);
677 state
+= sizeof(uint32_t);
679 case i386_THREAD_STATE
:
680 /* current i386 thread states */
681 #if i386_THREAD_STATE == 1
683 #endif /* i386_THREAD_STATE == 1 */
684 /* i386 thread states on older releases */
685 #if i386_THREAD_STATE == -1
687 #endif /* i386_THREAD_STATE == -1 */
688 if(count
!= i386_THREAD_STATE_COUNT
){
689 error("in swap_object_headers(): malformed "
690 "load commands (count "
691 "not i386_THREAD_STATE_COUNT for flavor "
692 "number %lu which is a i386_THREAD_STATE "
693 "flavor in %s command %lu)", nflavor
,
694 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
698 cpu
= (i386_thread_state_t
*)state
;
699 state
+= sizeof(i386_thread_state_t
);
701 /* current i386 thread states */
702 #if i386_THREAD_STATE == 1
703 case i386_FLOAT_STATE
:
704 if(count
!= i386_FLOAT_STATE_COUNT
){
705 error("in swap_object_headers(): malformed "
706 "load commands (count "
707 "not i386_FLOAT_STATE_COUNT for flavor "
708 "number %lu which is a i386_FLOAT_STATE "
709 "flavor in %s command %lu)", nflavor
,
710 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
714 fpu
= (struct i386_float_state
*)state
;
715 state
+= sizeof(struct i386_float_state
);
717 case i386_EXCEPTION_STATE
:
718 if(count
!= I386_EXCEPTION_STATE_COUNT
){
719 error("in swap_object_headers(): malformed "
720 "load commands (count "
721 "not I386_EXCEPTION_STATE_COUNT for "
722 "flavor number %lu which is a i386_"
723 "EXCEPTION_STATE flavor in %s command %lu)",
725 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
729 exc
= (i386_exception_state_t
*)state
;
730 state
+= sizeof(i386_exception_state_t
);
732 #endif /* i386_THREAD_STATE == 1 */
734 /* i386 thread states on older releases */
735 #if i386_THREAD_STATE == -1
736 case i386_THREAD_FPSTATE
:
737 if(count
!= i386_THREAD_FPSTATE_COUNT
){
738 error("in swap_object_headers(): malformed "
739 "load commands (count "
740 "not i386_THREAD_FPSTATE_COUNT for flavor "
741 "number %lu which is a i386_THREAD_FPSTATE "
742 "flavor in %s command %lu)", nflavor
,
743 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
747 fpu
= (i386_thread_fpstate_t
*)state
;
748 state
+= sizeof(i386_thread_fpstate_t
);
750 case i386_THREAD_EXCEPTSTATE
:
751 if(count
!= i386_THREAD_EXCEPTSTATE_COUNT
){
752 error("in swap_object_headers(): malformed "
753 "load commands (count "
754 "not i386_THREAD_EXCEPTSTATE_COUNT for "
755 "flavor number %lu which is a i386_THREAD_"
756 "EXCEPTSTATE flavor in %s command %lu)",
758 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
762 exc
= (i386_thread_exceptstate_t
*)state
;
763 state
+= sizeof(i386_thread_fpstate_t
);
765 case i386_THREAD_CTHREADSTATE
:
766 if(count
!= i386_THREAD_CTHREADSTATE_COUNT
){
767 error("in swap_object_headers(): malformed "
768 "load commands (count "
769 "not i386_THREAD_CTHREADSTATE_COUNT for "
770 "flavor number %lu which is a i386_THREAD_"
771 "CTHREADSTATE flavor in %s command %lu)",
773 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
777 user
= (i386_thread_cthreadstate_t
*)state
;
778 state
+= sizeof(i386_thread_fpstate_t
);
780 #endif /* i386_THREAD_STATE == -1 */
781 #ifdef x86_THREAD_STATE64
782 case x86_THREAD_STATE64
:
783 if(count
!= x86_THREAD_STATE64_COUNT
){
784 error("in swap_object_headers(): malformed "
785 "load commands (count "
786 "not x86_THREAD_STATE64_COUNT for "
787 "flavor number %lu which is an x86_THREAD_"
788 "STATE64 flavor in %s command %lu)",
790 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
794 cpu64
= (x86_thread_state64_t
*)state
;
795 state
+= sizeof(x86_thread_state64_t
);
797 #endif /* x86_THREAD_STATE64 */
799 error("in swap_object_headers(): malformed "
800 "load commands (unknown "
801 "flavor %u for flavor number %lu in %s command"
802 " %lu can't byte swap it)", flavor
, nflavor
,
803 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
811 if(cputype
== CPU_TYPE_HPPA
){
812 struct hp_pa_integer_thread_state
*cpu
;
813 struct hp_pa_frame_thread_state
*frame
;
814 struct hp_pa_fp_thread_state
*fpu
;
817 p
= (char *)ut
+ ut
->cmdsize
;
819 flavor
= *((uint32_t *)state
);
820 state
+= sizeof(uint32_t);
821 count
= *((uint32_t *)state
);
822 state
+= sizeof(uint32_t);
824 case HPPA_INTEGER_THREAD_STATE
:
825 if(count
!= HPPA_INTEGER_THREAD_STATE_COUNT
){
826 error("in swap_object_headers(): malformed "
827 "load commands (count "
828 "not HPPA_INTEGER_THREAD_STATE_COUNT for "
829 "flavor number %lu which is a HPPA_INTEGER"
830 "_THREAD_STATE flavor in %s command %lu)",
831 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
832 "LC_UNIXTHREAD" : "LC_THREAD", i
);
835 cpu
= (struct hp_pa_integer_thread_state
*)state
;
836 state
+= sizeof(struct hp_pa_integer_thread_state
);
838 case HPPA_FRAME_THREAD_STATE
:
839 if(count
!= HPPA_FRAME_THREAD_STATE_COUNT
){
840 error("in swap_object_headers(): malformed "
841 "load commands (count "
842 "not HPPA_FRAME_THREAD_STATE_COUNT for "
843 "flavor number %lu which is a HPPA_FRAME"
844 "_THREAD_STATE flavor in %s command %lu)",
845 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
846 "LC_UNIXTHREAD" : "LC_THREAD", i
);
849 frame
= (struct hp_pa_frame_thread_state
*)state
;
850 state
+= sizeof(struct hp_pa_frame_thread_state
);
852 case HPPA_FP_THREAD_STATE
:
853 if(count
!= HPPA_FP_THREAD_STATE_COUNT
){
854 error("in swap_object_headers(): malformed "
855 "load commands (count "
856 "not HPPA_FP_THREAD_STATE_COUNT for "
857 "flavor number %lu which is a HPPA_FP"
858 "_THREAD_STATE flavor in %s command %lu)",
859 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
860 "LC_UNIXTHREAD" : "LC_THREAD", i
);
863 fpu
= (struct hp_pa_fp_thread_state
*)state
;
864 state
+= sizeof(struct hp_pa_fp_thread_state
);
867 error("in swap_object_headers(): malformed "
868 "load commands (unknown "
869 "flavor %u for flavor number %lu in %s command"
870 " %lu can't byte swap it)", flavor
, nflavor
,
871 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
879 if(cputype
== CPU_TYPE_SPARC
) {
880 struct sparc_thread_state_regs
*cpu
;
881 struct sparc_thread_state_fpu
*fpu
;
884 p
= (char *)ut
+ ut
->cmdsize
;
886 flavor
= *((uint32_t *) state
);
887 state
+= sizeof(uint32_t);
888 count
= *((uint32_t *) state
);
889 state
+= sizeof(uint32_t);
891 case SPARC_THREAD_STATE_REGS
:
892 if (count
!= SPARC_THREAD_STATE_REGS_COUNT
) {
893 error("in swap_object_headers(): malformed "
894 "load commands (count "
895 "not SPARC_THREAD_STATE_REGS_COUNT for "
896 "flavor number %lu which is a SPARC_THREAD_"
897 "STATE_REGS flavor in %s command %lu)",
898 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
899 "LC_UNIXTHREAD" : "LC_THREAD", i
);
902 cpu
= (struct sparc_thread_state_regs
*) state
;
903 state
+= sizeof(struct sparc_thread_state_regs
);
905 case SPARC_THREAD_STATE_FPU
:
906 if (count
!= SPARC_THREAD_STATE_FPU_COUNT
) {
907 error("in swap_object_headers(): malformed "
908 "load commands (count "
909 "not SPARC_THREAD_STATE_FPU_COUNT for "
910 "flavor number %lu which is a SPARC_THREAD_"
911 "STATE_FPU flavor in %s command %lu)",
912 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
913 "LC_UNIXTHREAD" : "LC_THREAD", i
);
916 fpu
= (struct sparc_thread_state_fpu
*) state
;
917 state
+= sizeof(struct sparc_thread_state_fpu
);
923 if(cputype
== CPU_TYPE_ARM
){
924 arm_thread_state_t
*cpu
;
927 p
= (char *)ut
+ ut
->cmdsize
;
929 flavor
= *((uint32_t *)state
);
930 state
+= sizeof(uint32_t);
931 count
= *((uint32_t *)state
);
932 state
+= sizeof(uint32_t);
934 case ARM_THREAD_STATE
:
935 if(count
!= ARM_THREAD_STATE_COUNT
){
936 error("in swap_object_headers(): malformed "
937 "load commands (count "
938 "not ARM_THREAD_STATE_COUNT for "
939 "flavor number %lu which is a ARM_THREAD_"
940 "STATE flavor in %s command %lu)",
941 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
942 "LC_UNIXTHREAD" : "LC_THREAD", i
);
945 cpu
= (arm_thread_state_t
*)state
;
946 state
+= sizeof(arm_thread_state_t
);
949 error("in swap_object_headers(): malformed load "
950 "commands (unknown flavor for flavor number "
951 "%lu in %s command %lu can't byte swap it)",
952 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
953 "LC_UNIXTHREAD" : "LC_THREAD", i
);
960 error("in swap_object_headers(): malformed load commands "
961 "(unknown cputype (%d) and cpusubtype (%d) of object and "
962 "can't byte swap %s command %lu)", cputype
,
963 cpusubtype
, ut
->cmd
== LC_UNIXTHREAD
?
964 "LC_UNIXTHREAD" : "LC_THREAD", i
);
968 ep
= (struct entry_point_command
*)lc
;
969 if((char *)ep
+ ep
->cmdsize
>
970 (char *)load_commands
+ sizeofcmds
){
971 error("in swap_object_headers(): truncated or malformed "
972 "load commands (cmdsize field of LC_MAIN command %lu "
973 "extends past the end of the load commands)", i
);
978 case LC_SOURCE_VERSION
:
979 sv
= (struct source_version_command
*)lc
;
980 if((char *)sv
+ sv
->cmdsize
>
981 (char *)load_commands
+ sizeofcmds
){
982 error("in swap_object_headers(): truncated or malformed "
983 "load commands (cmdsize field of LC_SOURCE_VERSION "
984 "command %lu extends past the end of the load "
991 id
= (struct ident_command
*)lc
;
992 if((char *)id
+ id
->cmdsize
>
993 (char *)load_commands
+ sizeofcmds
){
994 error("in swap_object_headers(): truncated or malformed "
995 "load commands (cmdsize field of LC_IDENT command %lu "
996 "extends past the end of the load commands)", i
);
1002 rc
= (struct routines_command
*)lc
;
1003 if(rc
->cmdsize
!= sizeof(struct routines_command
)){
1004 error("in swap_object_headers(): malformed load commands ("
1005 "LC_ROUTINES command %lu has incorrect cmdsize",
1011 case LC_ROUTINES_64
:
1012 rc64
= (struct routines_command_64
*)lc
;
1013 if(rc64
->cmdsize
!= sizeof(struct routines_command_64
)){
1014 error("in swap_object_headers(): malformed load commands ("
1015 "LC_ROUTINES_64 command %lu has incorrect cmdsize",
1021 case LC_TWOLEVEL_HINTS
:
1022 hints
= (struct twolevel_hints_command
*)lc
;
1023 if(hints
->cmdsize
!= sizeof(struct twolevel_hints_command
)){
1024 error("in swap_object_headers(): malformed load commands "
1025 "(LC_TWOLEVEL_HINTS command %lu has incorrect "
1031 case LC_PREBIND_CKSUM
:
1032 cs
= (struct prebind_cksum_command
*)lc
;
1033 if(cs
->cmdsize
!= sizeof(struct prebind_cksum_command
)){
1034 error("in swap_object_headers(): malformed load commands "
1035 "(LC_PREBIND_CKSUM command %lu has incorrect cmdsize",
1042 uuid
= (struct uuid_command
*)lc
;
1043 if(uuid
->cmdsize
!= sizeof(struct uuid_command
)){
1044 error("in swap_object_headers(): malformed load commands "
1045 "(LC_UUID command %lu has incorrect cmdsize", i
);
1050 case LC_CODE_SIGNATURE
:
1051 ld
= (struct linkedit_data_command
*)lc
;
1052 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1053 error("in swap_object_headers(): malformed load commands "
1054 "(LC_CODE_SIGNATURE command %lu has incorrect "
1060 case LC_SEGMENT_SPLIT_INFO
:
1061 ld
= (struct linkedit_data_command
*)lc
;
1062 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1063 error("in swap_object_headers(): malformed load commands "
1064 "(LC_SEGMENT_SPLIT_INFO command %lu has incorrect "
1070 case LC_FUNCTION_STARTS
:
1071 ld
= (struct linkedit_data_command
*)lc
;
1072 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1073 error("in swap_object_headers(): malformed load commands "
1074 "(LC_FUNCTION_STARTS command %lu has incorrect "
1080 case LC_DATA_IN_CODE
:
1081 ld
= (struct linkedit_data_command
*)lc
;
1082 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1083 error("in swap_object_headers(): malformed load commands "
1084 "(LC_DATA_IN_CODE command %lu has incorrect "
1090 case LC_DYLIB_CODE_SIGN_DRS
:
1091 ld
= (struct linkedit_data_command
*)lc
;
1092 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1093 error("in swap_object_headers(): malformed load commands "
1094 "(LC_DYLIB_CODE_SIGN_DRS command %lu has incorrect "
1100 case LC_VERSION_MIN_MACOSX
:
1101 vc
= (struct version_min_command
*)lc
;
1102 if(vc
->cmdsize
!= sizeof(struct version_min_command
)){
1103 error("in swap_object_headers(): malformed load commands "
1104 "(LC_VERSION_MIN_MACOSX command %lu has incorrect "
1110 case LC_VERSION_MIN_IPHONEOS
:
1111 vc
= (struct version_min_command
*)lc
;
1112 if(vc
->cmdsize
!= sizeof(struct version_min_command
)){
1113 error("in swap_object_headers(): malformed load commands "
1114 "(LC_VERSION_MIN_IPHONEOS command %lu has incorrect "
1121 rpath
= (struct rpath_command
*)lc
;
1122 if(rpath
->cmdsize
< sizeof(struct rpath_command
)){
1123 error("in swap_object_headers(): malformed load commands "
1124 "(LC_RPATH command %lu has too small cmdsize field)",
1128 if(rpath
->path
.offset
>= rpath
->cmdsize
){
1129 error("in swap_object_headers(): truncated or malformed "
1130 "load commands (path.offset field of LC_RPATH "
1131 "command %lu extends past the end of all load "
1137 case LC_ENCRYPTION_INFO
:
1138 ec
= (struct encryption_info_command
*)lc
;
1139 if(ec
->cmdsize
!= sizeof(struct encryption_info_command
)){
1140 error("in swap_object_headers(): malformed load commands "
1141 "(LC_ENCRYPTION_INFO command %lu has incorrect "
1148 case LC_DYLD_INFO_ONLY
:
1149 dc
= (struct dyld_info_command
*)lc
;
1150 if(dc
->cmdsize
!= sizeof(struct dyld_info_command
)){
1151 error("in swap_object_headers(): malformed load commands "
1152 "(LC_DYLD_INFO command %lu has incorrect "
1159 error("in swap_object_headers(): malformed load commands "
1160 "(unknown load command %lu)", i
);
1164 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1165 /* check that next load command does not extends past the end */
1166 if((char *)lc
> (char *)load_commands
+ sizeofcmds
){
1167 error("in swap_object_headers(): truncated or malformed load "
1168 "commands (load command %lu extends past the end of all "
1169 "load commands)", i
+ 1);
1173 /* check for an inconsistent size of the load commands */
1174 if((char *)load_commands
+ sizeofcmds
!= (char *)lc
){
1175 error("in swap_object_headers(): malformed load commands "
1176 "(inconsistent sizeofcmds field in mach header)");
1182 * Now knowing the load commands can be parsed swap them.
1184 target_byte_sex
= get_host_byte_sex() == BIG_ENDIAN_BYTE_SEX
?
1185 LITTLE_ENDIAN_BYTE_SEX
: BIG_ENDIAN_BYTE_SEX
;
1186 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
1190 sg
= (struct segment_command
*)lc
;
1191 s
= (struct section
*)
1192 ((char *)sg
+ sizeof(struct segment_command
));
1193 swap_section(s
, sg
->nsects
, target_byte_sex
);
1194 swap_segment_command(sg
, target_byte_sex
);
1198 sg64
= (struct segment_command_64
*)lc
;
1199 s64
= (struct section_64
*)
1200 ((char *)sg64
+ sizeof(struct segment_command_64
));
1201 swap_section_64(s64
, sg64
->nsects
, target_byte_sex
);
1202 swap_segment_command_64(sg64
, target_byte_sex
);
1206 st
= (struct symtab_command
*)lc
;
1207 swap_symtab_command(st
, target_byte_sex
);
1211 dyst
= (struct dysymtab_command
*)lc
;
1212 swap_dysymtab_command(dyst
, target_byte_sex
);
1216 ss
= (struct symseg_command
*)lc
;
1217 swap_symseg_command(ss
, target_byte_sex
);
1222 fl
= (struct fvmlib_command
*)lc
;
1223 swap_fvmlib_command(fl
, target_byte_sex
);
1228 case LC_LOAD_WEAK_DYLIB
:
1229 case LC_REEXPORT_DYLIB
:
1230 case LC_LOAD_UPWARD_DYLIB
:
1231 case LC_LAZY_LOAD_DYLIB
:
1232 dl
= (struct dylib_command
*)lc
;
1233 swap_dylib_command(dl
, target_byte_sex
);
1236 case LC_SUB_FRAMEWORK
:
1237 sub
= (struct sub_framework_command
*)lc
;
1238 swap_sub_framework_command(sub
, target_byte_sex
);
1241 case LC_SUB_UMBRELLA
:
1242 usub
= (struct sub_umbrella_command
*)lc
;
1243 swap_sub_umbrella_command(usub
, target_byte_sex
);
1246 case LC_SUB_LIBRARY
:
1247 lsub
= (struct sub_library_command
*)lc
;
1248 swap_sub_library_command(lsub
, target_byte_sex
);
1252 csub
= (struct sub_client_command
*)lc
;
1253 swap_sub_client_command(csub
, target_byte_sex
);
1256 case LC_PREBOUND_DYLIB
:
1257 pbdylib
= (struct prebound_dylib_command
*)lc
;
1258 swap_prebound_dylib_command(pbdylib
, target_byte_sex
);
1261 case LC_ID_DYLINKER
:
1262 case LC_LOAD_DYLINKER
:
1263 case LC_DYLD_ENVIRONMENT
:
1264 dyld
= (struct dylinker_command
*)lc
;
1265 swap_dylinker_command(dyld
, target_byte_sex
);
1270 ut
= (struct thread_command
*)lc
;
1271 state
= (char *)ut
+ sizeof(struct thread_command
);
1272 p
= (char *)ut
+ ut
->cmdsize
;
1273 swap_thread_command(ut
, target_byte_sex
);
1275 if(cputype
== CPU_TYPE_MC680x0
){
1276 struct m68k_thread_state_regs
*cpu
;
1277 struct m68k_thread_state_68882
*fpu
;
1278 struct m68k_thread_state_user_reg
*user_reg
;
1281 flavor
= *((uint32_t *)state
);
1282 *((uint32_t *)state
) = SWAP_INT(flavor
);
1283 state
+= sizeof(uint32_t);
1284 count
= *((uint32_t *)state
);
1285 *((uint32_t *)state
) = SWAP_INT(count
);
1286 state
+= sizeof(uint32_t);
1288 case M68K_THREAD_STATE_REGS
:
1289 cpu
= (struct m68k_thread_state_regs
*)state
;
1290 swap_m68k_thread_state_regs(cpu
, target_byte_sex
);
1291 state
+= sizeof(struct m68k_thread_state_regs
);
1293 case M68K_THREAD_STATE_68882
:
1294 fpu
= (struct m68k_thread_state_68882
*)state
;
1295 swap_m68k_thread_state_68882(fpu
, target_byte_sex
);
1296 state
+= sizeof(struct m68k_thread_state_68882
);
1298 case M68K_THREAD_STATE_USER_REG
:
1300 (struct m68k_thread_state_user_reg
*)state
;
1301 swap_m68k_thread_state_user_reg(user_reg
,
1303 state
+= sizeof(struct m68k_thread_state_user_reg
);
1309 if(cputype
== CPU_TYPE_POWERPC
||
1310 cputype
== CPU_TYPE_VEO
||
1311 cputype
== CPU_TYPE_POWERPC64
){
1312 ppc_thread_state_t
*cpu
;
1313 ppc_thread_state64_t
*cpu64
;
1314 ppc_float_state_t
*fpu
;
1315 ppc_exception_state_t
*except
;
1318 flavor
= *((uint32_t *)state
);
1319 *((uint32_t *)state
) = SWAP_INT(flavor
);
1320 state
+= sizeof(uint32_t);
1321 count
= *((uint32_t *)state
);
1322 *((uint32_t *)state
) = SWAP_INT(count
);
1323 state
+= sizeof(uint32_t);
1325 case PPC_THREAD_STATE
:
1326 cpu
= (ppc_thread_state_t
*)state
;
1327 swap_ppc_thread_state_t(cpu
, target_byte_sex
);
1328 state
+= sizeof(ppc_thread_state_t
);
1330 case PPC_THREAD_STATE64
:
1331 cpu64
= (ppc_thread_state64_t
*)state
;
1332 swap_ppc_thread_state64_t(cpu64
, target_byte_sex
);
1333 state
+= sizeof(ppc_thread_state64_t
);
1335 case PPC_FLOAT_STATE
:
1336 fpu
= (ppc_float_state_t
*)state
;
1337 swap_ppc_float_state_t(fpu
, target_byte_sex
);
1338 state
+= sizeof(ppc_float_state_t
);
1339 case PPC_EXCEPTION_STATE
:
1340 except
= (ppc_exception_state_t
*)state
;
1341 swap_ppc_exception_state_t(except
, target_byte_sex
);
1342 state
+= sizeof(ppc_exception_state_t
);
1348 if(cputype
== CPU_TYPE_MC88000
){
1349 m88k_thread_state_grf_t
*cpu
;
1350 m88k_thread_state_xrf_t
*fpu
;
1351 m88k_thread_state_user_t
*user
;
1352 m88110_thread_state_impl_t
*spu
;
1355 flavor
= *((uint32_t *)state
);
1356 *((uint32_t *)state
) = SWAP_INT(flavor
);
1357 state
+= sizeof(uint32_t);
1358 count
= *((uint32_t *)state
);
1359 *((uint32_t *)state
) = SWAP_INT(count
);
1360 state
+= sizeof(uint32_t);
1362 case M88K_THREAD_STATE_GRF
:
1363 cpu
= (m88k_thread_state_grf_t
*)state
;
1364 swap_m88k_thread_state_grf_t(cpu
,
1366 state
+= sizeof(m88k_thread_state_grf_t
);
1368 case M88K_THREAD_STATE_XRF
:
1369 fpu
= (m88k_thread_state_xrf_t
*)state
;
1370 swap_m88k_thread_state_xrf_t(fpu
,
1372 state
+= sizeof(m88k_thread_state_xrf_t
);
1374 case M88K_THREAD_STATE_USER
:
1375 user
= (m88k_thread_state_user_t
*)state
;
1376 swap_m88k_thread_state_user_t(user
,
1378 state
+= sizeof(m88k_thread_state_user_t
);
1380 case M88110_THREAD_STATE_IMPL
:
1381 spu
= (m88110_thread_state_impl_t
*)state
;
1382 swap_m88110_thread_state_impl_t(spu
,
1384 state
+= sizeof(m88110_thread_state_impl_t
);
1390 if(cputype
== CPU_TYPE_I860
){
1391 struct i860_thread_state_regs
*cpu
;
1394 flavor
= *((uint32_t *)state
);
1395 *((uint32_t *)state
) = SWAP_INT(flavor
);
1396 state
+= sizeof(uint32_t);
1397 count
= *((uint32_t *)state
);
1398 *((uint32_t *)state
) = SWAP_INT(count
);
1399 state
+= sizeof(uint32_t);
1401 case I860_THREAD_STATE_REGS
:
1402 cpu
= (struct i860_thread_state_regs
*)state
;
1403 swap_i860_thread_state_regs(cpu
, target_byte_sex
);
1404 state
+= sizeof(struct i860_thread_state_regs
);
1410 if(cputype
== CPU_TYPE_I386
1411 #ifdef x86_THREAD_STATE64
1412 || cputype
== CPU_TYPE_X86_64
1413 #endif /* x86_THREAD_STATE64 */
1415 i386_thread_state_t
*cpu
;
1416 #ifdef x86_THREAD_STATE64
1417 x86_thread_state64_t
*cpu64
;
1418 #endif /* x86_THREAD_STATE64 */
1419 /* current i386 thread states */
1420 #if i386_THREAD_STATE == 1
1421 struct i386_float_state
*fpu
;
1422 i386_exception_state_t
*exc
;
1423 #endif /* i386_THREAD_STATE == 1 */
1425 /* i386 thread states on older releases */
1426 #if i386_THREAD_STATE == -1
1427 i386_thread_fpstate_t
*fpu
;
1428 i386_thread_exceptstate_t
*exc
;
1429 i386_thread_cthreadstate_t
*user
;
1430 #endif /* i386_THREAD_STATE == -1 */
1433 flavor
= *((uint32_t *)state
);
1434 *((uint32_t *)state
) = SWAP_INT(flavor
);
1435 state
+= sizeof(uint32_t);
1436 count
= *((uint32_t *)state
);
1437 *((uint32_t *)state
) = SWAP_INT(count
);
1438 state
+= sizeof(uint32_t);
1439 switch((int)flavor
){
1440 case i386_THREAD_STATE
:
1441 /* current i386 thread states */
1442 #if i386_THREAD_STATE == 1
1444 #endif /* i386_THREAD_STATE == 1 */
1445 /* i386 thread states on older releases */
1446 #if i386_THREAD_STATE == -1
1448 #endif /* i386_THREAD_STATE == -1 */
1449 cpu
= (i386_thread_state_t
*)state
;
1450 swap_i386_thread_state(cpu
, target_byte_sex
);
1451 state
+= sizeof(i386_thread_state_t
);
1453 /* current i386 thread states */
1454 #if i386_THREAD_STATE == 1
1455 case i386_FLOAT_STATE
:
1456 fpu
= (struct i386_float_state
*)state
;
1457 swap_i386_float_state(fpu
, target_byte_sex
);
1458 state
+= sizeof(struct i386_float_state
);
1460 case i386_EXCEPTION_STATE
:
1461 exc
= (i386_exception_state_t
*)state
;
1462 swap_i386_exception_state(exc
, target_byte_sex
);
1463 state
+= sizeof(i386_exception_state_t
);
1465 #endif /* i386_THREAD_STATE == 1 */
1467 /* i386 thread states on older releases */
1468 #if i386_THREAD_STATE == -1
1469 case i386_THREAD_FPSTATE
:
1470 fpu
= (i386_thread_fpstate_t
*)state
;
1471 swap_i386_thread_fpstate(fpu
, target_byte_sex
);
1472 state
+= sizeof(i386_thread_fpstate_t
);
1474 case i386_THREAD_EXCEPTSTATE
:
1475 exc
= (i386_thread_exceptstate_t
*)state
;
1476 swap_i386_thread_exceptstate(exc
, target_byte_sex
);
1477 state
+= sizeof(i386_thread_exceptstate_t
);
1479 case i386_THREAD_CTHREADSTATE
:
1480 user
= (i386_thread_cthreadstate_t
*)state
;
1481 swap_i386_thread_cthreadstate(user
,target_byte_sex
);
1482 state
+= sizeof(i386_thread_cthreadstate_t
);
1484 #endif /* i386_THREAD_STATE == -1 */
1485 #ifdef x86_THREAD_STATE64
1486 case x86_THREAD_STATE64
:
1487 cpu64
= (x86_thread_state64_t
*)state
;
1488 swap_x86_thread_state64(cpu64
, target_byte_sex
);
1489 state
+= sizeof(x86_thread_state64_t
);
1491 #endif /* x86_THREAD_STATE64 */
1496 if(cputype
== CPU_TYPE_HPPA
){
1497 struct hp_pa_integer_thread_state
*cpu
;
1498 struct hp_pa_frame_thread_state
*frame
;
1499 struct hp_pa_fp_thread_state
*fpu
;
1502 flavor
= *((uint32_t *)state
);
1503 *((uint32_t *)state
) = SWAP_INT(flavor
);
1504 state
+= sizeof(uint32_t);
1505 count
= *((uint32_t *)state
);
1506 *((uint32_t *)state
) = SWAP_INT(count
);
1507 state
+= sizeof(uint32_t);
1509 case HPPA_INTEGER_THREAD_STATE
:
1510 cpu
= (struct hp_pa_integer_thread_state
*)state
;
1511 swap_hppa_integer_thread_state(cpu
,
1513 state
+= sizeof(struct hp_pa_integer_thread_state
);
1515 case HPPA_FRAME_THREAD_STATE
:
1516 frame
= (struct hp_pa_frame_thread_state
*)state
;
1517 swap_hppa_frame_thread_state(frame
,
1519 state
+= sizeof(struct hp_pa_frame_thread_state
);
1521 case HPPA_FP_THREAD_STATE
:
1522 fpu
= (struct hp_pa_fp_thread_state
*)state
;
1523 swap_hppa_fp_thread_state(fpu
,
1525 state
+= sizeof(struct hp_pa_fp_thread_state
);
1532 if(cputype
== CPU_TYPE_SPARC
) {
1533 struct sparc_thread_state_regs
*cpu
;
1534 struct sparc_thread_state_fpu
*fpu
;
1537 flavor
= *((uint32_t *) state
);
1538 *((uint32_t *) state
) = SWAP_INT(flavor
);
1539 state
+= sizeof(uint32_t);
1540 count
= *((unsigned int *) state
);
1541 *((unsigned int *) state
) = SWAP_INT(count
);
1542 state
+= sizeof(uint32_t);
1544 case SPARC_THREAD_STATE_REGS
:
1545 cpu
= (struct sparc_thread_state_regs
*) state
;
1546 swap_sparc_thread_state_regs(cpu
, target_byte_sex
);
1547 state
+= sizeof(struct sparc_thread_state_regs
);
1549 case SPARC_THREAD_STATE_FPU
:
1550 fpu
= (struct sparc_thread_state_fpu
*) state
;
1551 swap_sparc_thread_state_fpu(fpu
, target_byte_sex
);
1552 state
+= sizeof(struct sparc_thread_state_fpu
);
1558 if(cputype
== CPU_TYPE_ARM
){
1559 arm_thread_state_t
*cpu
;
1562 flavor
= *((uint32_t *)state
);
1563 *((uint32_t *)state
) = SWAP_INT(flavor
);
1564 state
+= sizeof(uint32_t);
1565 count
= *((uint32_t *)state
);
1566 *((uint32_t *)state
) = SWAP_INT(count
);
1567 state
+= sizeof(uint32_t);
1569 case ARM_THREAD_STATE
:
1570 cpu
= (arm_thread_state_t
*)state
;
1571 swap_arm_thread_state_t(cpu
, target_byte_sex
);
1572 state
+= sizeof(arm_thread_state_t
);
1581 ep
= (struct entry_point_command
*)lc
;
1582 swap_entry_point_command(ep
, target_byte_sex
);
1585 case LC_SOURCE_VERSION
:
1586 sv
= (struct source_version_command
*)lc
;
1587 swap_source_version_command(sv
, target_byte_sex
);
1591 id
= (struct ident_command
*)lc
;
1592 swap_ident_command(id
, target_byte_sex
);
1596 rc
= (struct routines_command
*)lc
;
1597 swap_routines_command(rc
, target_byte_sex
);
1600 case LC_ROUTINES_64
:
1601 rc64
= (struct routines_command_64
*)lc
;
1602 swap_routines_command_64(rc64
, target_byte_sex
);
1605 case LC_TWOLEVEL_HINTS
:
1606 hints
= (struct twolevel_hints_command
*)lc
;
1607 swap_twolevel_hints_command(hints
, target_byte_sex
);
1610 case LC_PREBIND_CKSUM
:
1611 cs
= (struct prebind_cksum_command
*)lc
;
1612 swap_prebind_cksum_command(cs
, target_byte_sex
);
1616 uuid
= (struct uuid_command
*)lc
;
1617 swap_uuid_command(uuid
, target_byte_sex
);
1620 case LC_CODE_SIGNATURE
:
1621 case LC_SEGMENT_SPLIT_INFO
:
1622 case LC_FUNCTION_STARTS
:
1623 case LC_DATA_IN_CODE
:
1624 case LC_DYLIB_CODE_SIGN_DRS
:
1625 ld
= (struct linkedit_data_command
*)lc
;
1626 swap_linkedit_data_command(ld
, target_byte_sex
);
1630 rpath
= (struct rpath_command
*)lc
;
1631 swap_rpath_command(rpath
, target_byte_sex
);
1634 case LC_ENCRYPTION_INFO
:
1635 ec
= (struct encryption_info_command
*)lc
;
1636 swap_encryption_command(ec
, target_byte_sex
);
1640 case LC_DYLD_INFO_ONLY
:
1641 dc
= (struct dyld_info_command
*)lc
;
1642 swap_dyld_info_command(dc
, target_byte_sex
);
1645 case LC_VERSION_MIN_MACOSX
:
1646 case LC_VERSION_MIN_IPHONEOS
:
1647 vc
= (struct version_min_command
*)lc
;
1648 swap_version_min_command(vc
, target_byte_sex
);
1652 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1655 swap_mach_header(mh
, target_byte_sex
);
1657 swap_mach_header_64(mh64
, target_byte_sex
);