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 #undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
44 #undef MACHINE_THREAD_STATE_COUNT
45 #undef THREAD_STATE_NONE
46 #undef VALID_THREAD_STATE_FLAVOR
47 #include <mach/arm/thread_status.h>
48 #include "stuff/bool.h"
49 #include "stuff/bytesex.h"
50 #include "stuff/errors.h"
53 * swap_object_headers() swaps the object file headers from the host byte sex
54 * into the non-host byte sex. It returns TRUE if it can and did swap the
55 * headers else returns FALSE and does not touch the headers and prints an error
56 * using the error() routine.
62 struct load_command
*load_commands
)
65 uint32_t magic
, ncmds
, sizeofcmds
, cmd_multiple
;
67 cpu_subtype_t cpusubtype
;
68 struct mach_header
*mh
;
69 struct mach_header_64
*mh64
;
70 enum byte_sex target_byte_sex
;
71 struct load_command
*lc
, l
;
72 struct segment_command
*sg
;
73 struct segment_command_64
*sg64
;
75 struct section_64
*s64
;
76 struct symtab_command
*st
;
77 struct dysymtab_command
*dyst
;
78 struct symseg_command
*ss
;
79 struct fvmlib_command
*fl
;
80 struct thread_command
*ut
;
81 struct ident_command
*id
;
82 struct entry_point_command
*ep
;
83 struct source_version_command
*sv
;
84 struct dylib_command
*dl
;
85 struct sub_framework_command
*sub
;
86 struct sub_umbrella_command
*usub
;
87 struct sub_library_command
*lsub
;
88 struct sub_client_command
*csub
;
89 struct prebound_dylib_command
*pbdylib
;
90 struct dylinker_command
*dyld
;
91 struct routines_command
*rc
;
92 struct routines_command_64
*rc64
;
93 struct twolevel_hints_command
*hints
;
94 struct prebind_cksum_command
*cs
;
95 struct uuid_command
*uuid
;
96 struct linkedit_data_command
*ld
;
97 struct rpath_command
*rpath
;
98 struct encryption_info_command
*ec
;
99 struct dyld_info_command
*dc
;
100 struct version_min_command
*vc
;
101 uint32_t flavor
, count
;
102 unsigned long nflavor
;
103 char *p
, *state
, *cmd_name
;
105 magic
= *((uint32_t *)mach_header
);
106 if(magic
== MH_MAGIC
){
107 mh
= (struct mach_header
*)mach_header
;
109 sizeofcmds
= mh
->sizeofcmds
;
110 cputype
= mh
->cputype
;
111 cpusubtype
= mh
->cpusubtype
;
116 mh64
= (struct mach_header_64
*)mach_header
;
118 sizeofcmds
= mh64
->sizeofcmds
;
119 cputype
= mh64
->cputype
;
120 cpusubtype
= mh64
->cpusubtype
;
125 * Make a pass through the load commands checking them to the level
126 * that they can be parsed and then swapped.
128 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
130 /* check load command size for a correct multiple size */
131 if(lc
->cmdsize
% cmd_multiple
!= 0){
132 error("in swap_object_headers(): malformed load command %lu "
133 "(cmdsize not a multiple of %u)", i
, cmd_multiple
);
136 /* check that load command does not extends past end of commands */
137 if((char *)lc
+ lc
->cmdsize
>
138 (char *)load_commands
+ sizeofcmds
){
139 error("in swap_object_headers(): truncated or malformed load "
140 "command %lu (extends past the end of the all load "
144 /* check that the load command size is not zero */
145 if(lc
->cmdsize
== 0){
146 error("in swap_object_headers(): malformed load command %lu "
147 "(cmdsize is zero)", i
);
152 sg
= (struct segment_command
*)lc
;
153 if(sg
->cmdsize
!= sizeof(struct segment_command
) +
154 sg
->nsects
* sizeof(struct section
)){
155 error("in swap_object_headers(): malformed load command "
156 "(inconsistent cmdsize in LC_SEGMENT command %lu for "
157 "the number of sections)", i
);
163 sg64
= (struct segment_command_64
*)lc
;
164 if(sg64
->cmdsize
!= sizeof(struct segment_command_64
) +
165 sg64
->nsects
* sizeof(struct section_64
)){
166 error("in swap_object_headers(): malformed load command "
167 "(inconsistent cmdsize in LC_SEGMENT_64 command %lu "
168 "for the number of sections)", i
);
174 st
= (struct symtab_command
*)lc
;
175 if(st
->cmdsize
!= sizeof(struct symtab_command
)){
176 error("in swap_object_headers(): malformed load commands "
177 "(LC_SYMTAB command %lu has incorrect cmdsize", i
);
183 dyst
= (struct dysymtab_command
*)lc
;
184 if(dyst
->cmdsize
!= sizeof(struct dysymtab_command
)){
185 error("in swap_object_headers(): malformed load commands "
186 "(LC_DYSYMTAB command %lu has incorrect cmdsize", i
);
192 ss
= (struct symseg_command
*)lc
;
193 if(ss
->cmdsize
!= sizeof(struct symseg_command
)){
194 error("in swap_object_headers(): malformed load command "
195 "(LC_SYMSEG command %lu has incorrect cmdsize", i
);
202 fl
= (struct fvmlib_command
*)lc
;
203 if(fl
->cmdsize
< sizeof(struct fvmlib_command
)){
204 error("in swap_object_headers(): malformed load commands "
205 "(%s command %lu has too small cmdsize field)",
206 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
210 if(fl
->fvmlib
.name
.offset
>= fl
->cmdsize
){
211 error("in swap_object_headers(): truncated or malformed "
212 "load commands (name.offset field of %s command %lu "
213 "extends past the end of all load commands)",
214 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
221 cmd_name
= "LC_ID_DYLIB";
222 goto check_dylib_command
;
224 cmd_name
= "LC_LOAD_DYLIB";
225 goto check_dylib_command
;
226 case LC_LOAD_WEAK_DYLIB
:
227 cmd_name
= "LC_LOAD_WEAK_DYLIB";
228 goto check_dylib_command
;
229 case LC_REEXPORT_DYLIB
:
230 cmd_name
= "LC_REEXPORT_DYLIB";
231 goto check_dylib_command
;
232 case LC_LOAD_UPWARD_DYLIB
:
233 cmd_name
= "LC_LOAD_UPWARD_DYLIB";
234 goto check_dylib_command
;
235 case LC_LAZY_LOAD_DYLIB
:
236 cmd_name
= "LC_LAZY_LOAD_DYLIB";
237 goto check_dylib_command
;
239 dl
= (struct dylib_command
*)lc
;
240 if(dl
->cmdsize
< sizeof(struct dylib_command
)){
241 error("in swap_object_headers(): malformed load commands "
242 "(%s command %lu has too small cmdsize field)",
246 if(dl
->dylib
.name
.offset
>= dl
->cmdsize
){
247 error("in swap_object_headers(): truncated or malformed "
248 "load commands (name.offset field of %s command %lu "
249 "extends past the end of all load commands)",
255 case LC_SUB_FRAMEWORK
:
256 sub
= (struct sub_framework_command
*)lc
;
257 if(sub
->cmdsize
< sizeof(struct sub_framework_command
)){
258 error("in swap_object_headers(): malformed load commands "
259 "(LC_SUB_FRAMEWORK command %lu has too small cmdsize "
263 if(sub
->umbrella
.offset
>= sub
->cmdsize
){
264 error("in swap_object_headers(): truncated or malformed "
265 "load commands (umbrella.offset field of "
266 "LC_SUB_FRAMEWORK command %lu extends past the end "
267 "of all load commands)", i
);
272 case LC_SUB_UMBRELLA
:
273 usub
= (struct sub_umbrella_command
*)lc
;
274 if(usub
->cmdsize
< sizeof(struct sub_umbrella_command
)){
275 error("in swap_object_headers(): malformed load commands "
276 "(LC_SUB_UMBRELLA command %lu has too small cmdsize "
280 if(usub
->sub_umbrella
.offset
>= usub
->cmdsize
){
281 error("in swap_object_headers(): truncated or malformed "
282 "load commands (sub_umbrella.offset field of "
283 "LC_SUB_UMBRELLA command %lu extends past the end "
284 "of all load commands)", i
);
290 lsub
= (struct sub_library_command
*)lc
;
291 if(lsub
->cmdsize
< sizeof(struct sub_library_command
)){
292 error("in swap_object_headers(): malformed load commands "
293 "(LC_SUB_LIBRARY command %lu has too small cmdsize "
297 if(lsub
->sub_library
.offset
>= lsub
->cmdsize
){
298 error("in swap_object_headers(): truncated or malformed "
299 "load commands (sub_library.offset field of "
300 "LC_SUB_LIBRARY command %lu extends past the end "
301 "of all load commands)", i
);
307 csub
= (struct sub_client_command
*)lc
;
308 if(csub
->cmdsize
< sizeof(struct sub_client_command
)){
309 error("in swap_object_headers(): malformed load commands "
310 "(LC_SUB_CLIENT command %lu has too small cmdsize "
314 if(csub
->client
.offset
>= csub
->cmdsize
){
315 error("in swap_object_headers(): truncated or malformed "
316 "load commands (client.offset field of "
317 "LC_SUB_CLIENT command %lu extends past the end "
318 "of all load commands)", i
);
323 case LC_PREBOUND_DYLIB
:
324 pbdylib
= (struct prebound_dylib_command
*)lc
;
325 if(pbdylib
->cmdsize
< sizeof(struct prebound_dylib_command
)){
326 error("in swap_object_headers(): malformed load commands "
327 "(LC_PREBOUND_DYLIB command %lu has too small "
328 "cmdsize field)", i
);
331 if(pbdylib
->name
.offset
>= pbdylib
->cmdsize
){
332 error("in swap_object_headers(): truncated or malformed "
333 "load commands (name.offset field of "
334 "LC_PREBOUND_DYLIB command %lu extends past the end "
335 "of all load commands)", i
);
338 if(pbdylib
->linked_modules
.offset
>= pbdylib
->cmdsize
){
339 error("in swap_object_headers(): truncated or malformed "
340 "load commands (linked_modules.offset field of "
341 "LC_PREBOUND_DYLIB command %lu extends past the end "
342 "of all load commands)", i
);
348 cmd_name
= "LC_ID_DYLINKER";
349 goto check_dylinker_command
;
350 case LC_LOAD_DYLINKER
:
351 cmd_name
= "LC_LOAD_DYLINKER";
352 goto check_dylinker_command
;
353 case LC_DYLD_ENVIRONMENT
:
354 cmd_name
= "LC_DYLD_ENVIRONMENT";
355 goto check_dylinker_command
;
356 check_dylinker_command
:
357 dyld
= (struct dylinker_command
*)lc
;
358 if(dyld
->cmdsize
< sizeof(struct dylinker_command
)){
359 error("in swap_object_headers(): malformed load commands "
360 "(%s command %lu has too small cmdsize field)",
364 if(dyld
->name
.offset
>= dyld
->cmdsize
){
365 error("in swap_object_headers(): truncated or malformed "
366 "load commands (name.offset field of %s command %lu "
367 "extends past the end of all load commands)",
375 ut
= (struct thread_command
*)lc
;
376 state
= (char *)ut
+ sizeof(struct thread_command
);
378 if(cputype
== CPU_TYPE_MC680x0
){
379 struct m68k_thread_state_regs
*cpu
;
380 struct m68k_thread_state_68882
*fpu
;
381 struct m68k_thread_state_user_reg
*user_reg
;
384 p
= (char *)ut
+ ut
->cmdsize
;
386 flavor
= *((uint32_t *)state
);
387 state
+= sizeof(uint32_t);
388 count
= *((uint32_t *)state
);
389 state
+= sizeof(uint32_t);
391 case M68K_THREAD_STATE_REGS
:
392 if(count
!= M68K_THREAD_STATE_REGS_COUNT
){
393 error("in swap_object_headers(): malformed "
394 "load commands (count "
395 "not M68K_THREAD_STATE_REGS_COUNT for "
396 "flavor number %lu which is a M68K_THREAD_"
397 "STATE_REGS flavor in %s command %lu)",
398 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
399 "LC_UNIXTHREAD" : "LC_THREAD", i
);
402 cpu
= (struct m68k_thread_state_regs
*)state
;
403 state
+= sizeof(struct m68k_thread_state_regs
);
405 case M68K_THREAD_STATE_68882
:
406 if(count
!= M68K_THREAD_STATE_68882_COUNT
){
407 error("in swap_object_headers(): malformed "
408 "load commands (count "
409 "not M68K_THREAD_STATE_68882_COUNT for "
410 "flavor number %lu which is a M68K_THREAD_"
411 "STATE_68882 flavor in %s command %lu)",
412 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
413 "LC_UNIXTHREAD" : "LC_THREAD", i
);
416 fpu
= (struct m68k_thread_state_68882
*)state
;
417 state
+= sizeof(struct m68k_thread_state_68882
);
419 case M68K_THREAD_STATE_USER_REG
:
420 if(count
!= M68K_THREAD_STATE_USER_REG_COUNT
){
421 error("in swap_object_headers(): malformed "
422 "load commands (count "
423 "not M68K_THREAD_STATE_USER_REG_COUNT for "
424 "flavor number %lu which is a M68K_THREAD_"
425 "STATE_USER_REG flavor in %s command %lu)",
426 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
427 "LC_UNIXTHREAD" : "LC_THREAD", i
);
431 (struct m68k_thread_state_user_reg
*)state
;
432 state
+= sizeof(struct m68k_thread_state_user_reg
);
435 error("in swap_object_headers(): malformed "
436 "load commands (unknown "
437 "flavor %u for flavor number %lu in %s command"
438 " %lu can't byte swap it)", flavor
, nflavor
,
439 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
447 if(cputype
== CPU_TYPE_POWERPC
||
448 cputype
== CPU_TYPE_VEO
||
449 cputype
== CPU_TYPE_POWERPC64
){
450 ppc_thread_state_t
*cpu
;
451 ppc_float_state_t
*fpu
;
452 ppc_exception_state_t
*except
;
453 ppc_thread_state64_t
*cpu64
;
456 p
= (char *)ut
+ ut
->cmdsize
;
458 flavor
= *((uint32_t *)state
);
459 state
+= sizeof(uint32_t);
460 count
= *((uint32_t *)state
);
461 state
+= sizeof(uint32_t);
463 case PPC_THREAD_STATE
:
464 if(count
!= PPC_THREAD_STATE_COUNT
){
465 error("in swap_object_headers(): malformed "
466 "load commands (count "
467 "not PPC_THREAD_STATE_COUNT for "
468 "flavor number %lu which is a PPC_THREAD_"
469 "STATE flavor in %s command %lu)",
470 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
471 "LC_UNIXTHREAD" : "LC_THREAD", i
);
474 cpu
= (ppc_thread_state_t
*)state
;
475 state
+= sizeof(ppc_thread_state_t
);
477 case PPC_FLOAT_STATE
:
478 if(count
!= PPC_FLOAT_STATE_COUNT
){
479 error("in swap_object_headers(): malformed "
480 "load commands (count "
481 "not PPC_FLOAT_STATE_COUNT for "
482 "flavor number %lu which is a PPC_FLOAT_"
483 "STATE flavor in %s command %lu)",
484 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
485 "LC_UNIXTHREAD" : "LC_THREAD", i
);
488 fpu
= (ppc_float_state_t
*)state
;
489 state
+= sizeof(ppc_float_state_t
);
491 case PPC_EXCEPTION_STATE
:
492 if(count
!= PPC_EXCEPTION_STATE_COUNT
){
493 error("in swap_object_headers(): malformed "
494 "load commands (count "
495 "not PPC_EXCEPTION_STATE_COUNT for "
496 "flavor number %lu which is a PPC_EXCEPT"
497 "ION_STATE flavor in %s command %lu)",
498 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
499 "LC_UNIXTHREAD" : "LC_THREAD", i
);
502 except
= (ppc_exception_state_t
*)state
;
503 state
+= sizeof(ppc_exception_state_t
);
505 case PPC_THREAD_STATE64
:
506 if(count
!= PPC_THREAD_STATE64_COUNT
){
507 error("in swap_object_headers(): malformed "
508 "load commands (count "
509 "not PPC_THREAD_STATE64_COUNT for "
510 "flavor number %lu which is a PPC_THREAD_"
511 "STATE64 flavor in %s command %lu)",
512 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
513 "LC_UNIXTHREAD" : "LC_THREAD", i
);
516 cpu64
= (ppc_thread_state64_t
*)state
;
517 state
+= sizeof(ppc_thread_state64_t
);
520 error("in swap_object_headers(): malformed "
521 "load commands (unknown "
522 "flavor %u for flavor number %lu in %s command"
523 " %lu can't byte swap it)", flavor
, nflavor
,
524 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
532 if(cputype
== CPU_TYPE_MC88000
){
533 m88k_thread_state_grf_t
*cpu
;
534 m88k_thread_state_xrf_t
*fpu
;
535 m88k_thread_state_user_t
*user
;
536 m88110_thread_state_impl_t
*spu
;
539 p
= (char *)ut
+ ut
->cmdsize
;
541 flavor
= *((uint32_t *)state
);
542 state
+= sizeof(uint32_t);
543 count
= *((uint32_t *)state
);
544 state
+= sizeof(uint32_t);
546 case M88K_THREAD_STATE_GRF
:
547 if(count
!= M88K_THREAD_STATE_GRF_COUNT
){
548 error("in swap_object_headers(): malformed "
549 "load commands (count "
550 "not M88K_THREAD_STATE_GRF_COUNT for "
551 "flavor number %lu which is a M88K_THREAD_"
552 "STATE_GRF flavor in %s command %lu)",
553 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
554 "LC_UNIXTHREAD" : "LC_THREAD", i
);
557 cpu
= (m88k_thread_state_grf_t
*)state
;
558 state
+= sizeof(m88k_thread_state_grf_t
);
560 case M88K_THREAD_STATE_XRF
:
561 if(count
!= M88K_THREAD_STATE_XRF_COUNT
){
562 error("in swap_object_headers(): malformed "
563 "load commands (count "
564 "not M88K_THREAD_STATE_XRF_COUNT for "
565 "flavor number %lu which is a M88K_THREAD_"
566 "STATE_XRF flavor in %s command %lu)",
567 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
568 "LC_UNIXTHREAD" : "LC_THREAD", i
);
571 fpu
= (m88k_thread_state_xrf_t
*)state
;
572 state
+= sizeof(m88k_thread_state_xrf_t
);
574 case M88K_THREAD_STATE_USER
:
575 if(count
!= M88K_THREAD_STATE_USER_COUNT
){
576 error("in swap_object_headers(): malformed "
577 "load commands (count "
578 "not M88K_THREAD_STATE_USER_COUNT for "
579 "flavor number %lu which is a M88K_THREAD_"
580 "STATE_USER flavor in %s command %lu)",
581 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
582 "LC_UNIXTHREAD" : "LC_THREAD", i
);
585 user
= (m88k_thread_state_user_t
*)state
;
586 state
+= sizeof(m88k_thread_state_user_t
);
588 case M88110_THREAD_STATE_IMPL
:
589 if(count
!= M88110_THREAD_STATE_IMPL_COUNT
){
590 error("in swap_object_headers(): malformed "
591 "load commands (count "
592 "not M88110_THREAD_STATE_IMPL_COUNT for "
593 "flavor number %lu which is a M88110_THREAD"
594 "_STATE_IMPL flavor in %s command %lu)",
595 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
596 "LC_UNIXTHREAD" : "LC_THREAD", i
);
599 spu
= (m88110_thread_state_impl_t
*)state
;
600 state
+= sizeof(m88110_thread_state_impl_t
);
603 error("in swap_object_headers(): malformed "
604 "load commands (unknown "
605 "flavor %u for flavor number %lu in %s command"
606 " %lu can't byte swap it)", flavor
, nflavor
,
607 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
615 if(cputype
== CPU_TYPE_I860
){
616 struct i860_thread_state_regs
*cpu
;
619 p
= (char *)ut
+ ut
->cmdsize
;
621 flavor
= *((uint32_t *)state
);
622 state
+= sizeof(uint32_t);
623 count
= *((uint32_t *)state
);
624 state
+= sizeof(uint32_t);
626 case I860_THREAD_STATE_REGS
:
627 if(count
!= I860_THREAD_STATE_REGS_COUNT
){
628 error("in swap_object_headers(): malformed "
629 "load commands (count "
630 "not I860_THREAD_STATE_REGS_COUNT for "
631 "flavor number %lu which is a I860_THREAD_"
632 "STATE_REGS flavor in %s command %lu)",
633 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
634 "LC_UNIXTHREAD" : "LC_THREAD", i
);
637 cpu
= (struct i860_thread_state_regs
*)state
;
638 state
+= sizeof(struct i860_thread_state_regs
);
641 error("in swap_object_headers(): malformed "
642 "load commands (unknown "
643 "flavor %u for flavor number %lu in %s command"
644 " %lu can't byte swap it)", flavor
, nflavor
,
645 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
653 if(cputype
== CPU_TYPE_I386
654 #ifdef x86_THREAD_STATE64
655 || cputype
== CPU_TYPE_X86_64
656 #endif /* x86_THREAD_STATE64 */
658 i386_thread_state_t
*cpu
;
659 #ifdef x86_THREAD_STATE64
660 x86_thread_state64_t
*cpu64
;
661 #endif /* x86_THREAD_STATE64 */
662 /* current i386 thread states */
663 #if i386_THREAD_STATE == 1
664 struct i386_float_state
*fpu
;
665 i386_exception_state_t
*exc
;
666 #endif /* i386_THREAD_STATE == 1 */
668 /* i386 thread states on older releases */
669 #if i386_THREAD_STATE == -1
670 i386_thread_fpstate_t
*fpu
;
671 i386_thread_exceptstate_t
*exc
;
672 i386_thread_cthreadstate_t
*user
;
673 #endif /* i386_THREAD_STATE == -1 */
676 p
= (char *)ut
+ ut
->cmdsize
;
678 flavor
= *((uint32_t *)state
);
679 state
+= sizeof(uint32_t);
680 count
= *((uint32_t *)state
);
681 state
+= sizeof(uint32_t);
683 case i386_THREAD_STATE
:
684 /* current i386 thread states */
685 #if i386_THREAD_STATE == 1
687 #endif /* i386_THREAD_STATE == 1 */
688 /* i386 thread states on older releases */
689 #if i386_THREAD_STATE == -1
691 #endif /* i386_THREAD_STATE == -1 */
692 if(count
!= i386_THREAD_STATE_COUNT
){
693 error("in swap_object_headers(): malformed "
694 "load commands (count "
695 "not i386_THREAD_STATE_COUNT for flavor "
696 "number %lu which is a i386_THREAD_STATE "
697 "flavor in %s command %lu)", nflavor
,
698 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
702 cpu
= (i386_thread_state_t
*)state
;
703 state
+= sizeof(i386_thread_state_t
);
705 /* current i386 thread states */
706 #if i386_THREAD_STATE == 1
707 case i386_FLOAT_STATE
:
708 if(count
!= i386_FLOAT_STATE_COUNT
){
709 error("in swap_object_headers(): malformed "
710 "load commands (count "
711 "not i386_FLOAT_STATE_COUNT for flavor "
712 "number %lu which is a i386_FLOAT_STATE "
713 "flavor in %s command %lu)", nflavor
,
714 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
718 fpu
= (struct i386_float_state
*)state
;
719 state
+= sizeof(struct i386_float_state
);
721 case i386_EXCEPTION_STATE
:
722 if(count
!= I386_EXCEPTION_STATE_COUNT
){
723 error("in swap_object_headers(): malformed "
724 "load commands (count "
725 "not I386_EXCEPTION_STATE_COUNT for "
726 "flavor number %lu which is a i386_"
727 "EXCEPTION_STATE flavor in %s command %lu)",
729 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
733 exc
= (i386_exception_state_t
*)state
;
734 state
+= sizeof(i386_exception_state_t
);
736 #endif /* i386_THREAD_STATE == 1 */
738 /* i386 thread states on older releases */
739 #if i386_THREAD_STATE == -1
740 case i386_THREAD_FPSTATE
:
741 if(count
!= i386_THREAD_FPSTATE_COUNT
){
742 error("in swap_object_headers(): malformed "
743 "load commands (count "
744 "not i386_THREAD_FPSTATE_COUNT for flavor "
745 "number %lu which is a i386_THREAD_FPSTATE "
746 "flavor in %s command %lu)", nflavor
,
747 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
751 fpu
= (i386_thread_fpstate_t
*)state
;
752 state
+= sizeof(i386_thread_fpstate_t
);
754 case i386_THREAD_EXCEPTSTATE
:
755 if(count
!= i386_THREAD_EXCEPTSTATE_COUNT
){
756 error("in swap_object_headers(): malformed "
757 "load commands (count "
758 "not i386_THREAD_EXCEPTSTATE_COUNT for "
759 "flavor number %lu which is a i386_THREAD_"
760 "EXCEPTSTATE flavor in %s command %lu)",
762 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
766 exc
= (i386_thread_exceptstate_t
*)state
;
767 state
+= sizeof(i386_thread_fpstate_t
);
769 case i386_THREAD_CTHREADSTATE
:
770 if(count
!= i386_THREAD_CTHREADSTATE_COUNT
){
771 error("in swap_object_headers(): malformed "
772 "load commands (count "
773 "not i386_THREAD_CTHREADSTATE_COUNT for "
774 "flavor number %lu which is a i386_THREAD_"
775 "CTHREADSTATE flavor in %s command %lu)",
777 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
781 user
= (i386_thread_cthreadstate_t
*)state
;
782 state
+= sizeof(i386_thread_fpstate_t
);
784 #endif /* i386_THREAD_STATE == -1 */
785 #ifdef x86_THREAD_STATE64
786 case x86_THREAD_STATE64
:
787 if(count
!= x86_THREAD_STATE64_COUNT
){
788 error("in swap_object_headers(): malformed "
789 "load commands (count "
790 "not x86_THREAD_STATE64_COUNT for "
791 "flavor number %lu which is an x86_THREAD_"
792 "STATE64 flavor in %s command %lu)",
794 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
798 cpu64
= (x86_thread_state64_t
*)state
;
799 state
+= sizeof(x86_thread_state64_t
);
801 #endif /* x86_THREAD_STATE64 */
803 error("in swap_object_headers(): malformed "
804 "load commands (unknown "
805 "flavor %u for flavor number %lu in %s command"
806 " %lu can't byte swap it)", flavor
, nflavor
,
807 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
815 if(cputype
== CPU_TYPE_HPPA
){
816 struct hp_pa_integer_thread_state
*cpu
;
817 struct hp_pa_frame_thread_state
*frame
;
818 struct hp_pa_fp_thread_state
*fpu
;
821 p
= (char *)ut
+ ut
->cmdsize
;
823 flavor
= *((uint32_t *)state
);
824 state
+= sizeof(uint32_t);
825 count
= *((uint32_t *)state
);
826 state
+= sizeof(uint32_t);
828 case HPPA_INTEGER_THREAD_STATE
:
829 if(count
!= HPPA_INTEGER_THREAD_STATE_COUNT
){
830 error("in swap_object_headers(): malformed "
831 "load commands (count "
832 "not HPPA_INTEGER_THREAD_STATE_COUNT for "
833 "flavor number %lu which is a HPPA_INTEGER"
834 "_THREAD_STATE flavor in %s command %lu)",
835 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
836 "LC_UNIXTHREAD" : "LC_THREAD", i
);
839 cpu
= (struct hp_pa_integer_thread_state
*)state
;
840 state
+= sizeof(struct hp_pa_integer_thread_state
);
842 case HPPA_FRAME_THREAD_STATE
:
843 if(count
!= HPPA_FRAME_THREAD_STATE_COUNT
){
844 error("in swap_object_headers(): malformed "
845 "load commands (count "
846 "not HPPA_FRAME_THREAD_STATE_COUNT for "
847 "flavor number %lu which is a HPPA_FRAME"
848 "_THREAD_STATE flavor in %s command %lu)",
849 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
850 "LC_UNIXTHREAD" : "LC_THREAD", i
);
853 frame
= (struct hp_pa_frame_thread_state
*)state
;
854 state
+= sizeof(struct hp_pa_frame_thread_state
);
856 case HPPA_FP_THREAD_STATE
:
857 if(count
!= HPPA_FP_THREAD_STATE_COUNT
){
858 error("in swap_object_headers(): malformed "
859 "load commands (count "
860 "not HPPA_FP_THREAD_STATE_COUNT for "
861 "flavor number %lu which is a HPPA_FP"
862 "_THREAD_STATE flavor in %s command %lu)",
863 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
864 "LC_UNIXTHREAD" : "LC_THREAD", i
);
867 fpu
= (struct hp_pa_fp_thread_state
*)state
;
868 state
+= sizeof(struct hp_pa_fp_thread_state
);
871 error("in swap_object_headers(): malformed "
872 "load commands (unknown "
873 "flavor %u for flavor number %lu in %s command"
874 " %lu can't byte swap it)", flavor
, nflavor
,
875 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
883 if(cputype
== CPU_TYPE_SPARC
) {
884 struct sparc_thread_state_regs
*cpu
;
885 struct sparc_thread_state_fpu
*fpu
;
888 p
= (char *)ut
+ ut
->cmdsize
;
890 flavor
= *((uint32_t *) state
);
891 state
+= sizeof(uint32_t);
892 count
= *((uint32_t *) state
);
893 state
+= sizeof(uint32_t);
895 case SPARC_THREAD_STATE_REGS
:
896 if (count
!= SPARC_THREAD_STATE_REGS_COUNT
) {
897 error("in swap_object_headers(): malformed "
898 "load commands (count "
899 "not SPARC_THREAD_STATE_REGS_COUNT for "
900 "flavor number %lu which is a SPARC_THREAD_"
901 "STATE_REGS flavor in %s command %lu)",
902 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
903 "LC_UNIXTHREAD" : "LC_THREAD", i
);
906 cpu
= (struct sparc_thread_state_regs
*) state
;
907 state
+= sizeof(struct sparc_thread_state_regs
);
909 case SPARC_THREAD_STATE_FPU
:
910 if (count
!= SPARC_THREAD_STATE_FPU_COUNT
) {
911 error("in swap_object_headers(): malformed "
912 "load commands (count "
913 "not SPARC_THREAD_STATE_FPU_COUNT for "
914 "flavor number %lu which is a SPARC_THREAD_"
915 "STATE_FPU flavor in %s command %lu)",
916 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
917 "LC_UNIXTHREAD" : "LC_THREAD", i
);
920 fpu
= (struct sparc_thread_state_fpu
*) state
;
921 state
+= sizeof(struct sparc_thread_state_fpu
);
927 if(cputype
== CPU_TYPE_ARM
){
928 arm_thread_state_t
*cpu
;
931 p
= (char *)ut
+ ut
->cmdsize
;
933 flavor
= *((uint32_t *)state
);
934 state
+= sizeof(uint32_t);
935 count
= *((uint32_t *)state
);
936 state
+= sizeof(uint32_t);
938 case ARM_THREAD_STATE
:
939 if(count
!= ARM_THREAD_STATE_COUNT
){
940 error("in swap_object_headers(): malformed "
941 "load commands (count "
942 "not ARM_THREAD_STATE_COUNT for "
943 "flavor number %lu which is a ARM_THREAD_"
944 "STATE flavor in %s command %lu)",
945 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
946 "LC_UNIXTHREAD" : "LC_THREAD", i
);
949 cpu
= (arm_thread_state_t
*)state
;
950 state
+= sizeof(arm_thread_state_t
);
953 error("in swap_object_headers(): malformed load "
954 "commands (unknown flavor for flavor number "
955 "%lu in %s command %lu can't byte swap it)",
956 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
957 "LC_UNIXTHREAD" : "LC_THREAD", i
);
964 error("in swap_object_headers(): malformed load commands "
965 "(unknown cputype (%d) and cpusubtype (%d) of object and "
966 "can't byte swap %s command %lu)", cputype
,
967 cpusubtype
, ut
->cmd
== LC_UNIXTHREAD
?
968 "LC_UNIXTHREAD" : "LC_THREAD", i
);
972 ep
= (struct entry_point_command
*)lc
;
973 if((char *)ep
+ ep
->cmdsize
>
974 (char *)load_commands
+ sizeofcmds
){
975 error("in swap_object_headers(): truncated or malformed "
976 "load commands (cmdsize field of LC_MAIN command %lu "
977 "extends past the end of the load commands)", i
);
982 case LC_SOURCE_VERSION
:
983 sv
= (struct source_version_command
*)lc
;
984 if((char *)sv
+ sv
->cmdsize
>
985 (char *)load_commands
+ sizeofcmds
){
986 error("in swap_object_headers(): truncated or malformed "
987 "load commands (cmdsize field of LC_SOURCE_VERSION "
988 "command %lu extends past the end of the load "
995 id
= (struct ident_command
*)lc
;
996 if((char *)id
+ id
->cmdsize
>
997 (char *)load_commands
+ sizeofcmds
){
998 error("in swap_object_headers(): truncated or malformed "
999 "load commands (cmdsize field of LC_IDENT command %lu "
1000 "extends past the end of the load commands)", i
);
1006 rc
= (struct routines_command
*)lc
;
1007 if(rc
->cmdsize
!= sizeof(struct routines_command
)){
1008 error("in swap_object_headers(): malformed load commands ("
1009 "LC_ROUTINES command %lu has incorrect cmdsize",
1015 case LC_ROUTINES_64
:
1016 rc64
= (struct routines_command_64
*)lc
;
1017 if(rc64
->cmdsize
!= sizeof(struct routines_command_64
)){
1018 error("in swap_object_headers(): malformed load commands ("
1019 "LC_ROUTINES_64 command %lu has incorrect cmdsize",
1025 case LC_TWOLEVEL_HINTS
:
1026 hints
= (struct twolevel_hints_command
*)lc
;
1027 if(hints
->cmdsize
!= sizeof(struct twolevel_hints_command
)){
1028 error("in swap_object_headers(): malformed load commands "
1029 "(LC_TWOLEVEL_HINTS command %lu has incorrect "
1035 case LC_PREBIND_CKSUM
:
1036 cs
= (struct prebind_cksum_command
*)lc
;
1037 if(cs
->cmdsize
!= sizeof(struct prebind_cksum_command
)){
1038 error("in swap_object_headers(): malformed load commands "
1039 "(LC_PREBIND_CKSUM command %lu has incorrect cmdsize",
1046 uuid
= (struct uuid_command
*)lc
;
1047 if(uuid
->cmdsize
!= sizeof(struct uuid_command
)){
1048 error("in swap_object_headers(): malformed load commands "
1049 "(LC_UUID command %lu has incorrect cmdsize", i
);
1054 case LC_CODE_SIGNATURE
:
1055 ld
= (struct linkedit_data_command
*)lc
;
1056 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1057 error("in swap_object_headers(): malformed load commands "
1058 "(LC_CODE_SIGNATURE command %lu has incorrect "
1064 case LC_SEGMENT_SPLIT_INFO
:
1065 ld
= (struct linkedit_data_command
*)lc
;
1066 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1067 error("in swap_object_headers(): malformed load commands "
1068 "(LC_SEGMENT_SPLIT_INFO command %lu has incorrect "
1074 case LC_FUNCTION_STARTS
:
1075 ld
= (struct linkedit_data_command
*)lc
;
1076 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1077 error("in swap_object_headers(): malformed load commands "
1078 "(LC_FUNCTION_STARTS command %lu has incorrect "
1084 case LC_DATA_IN_CODE
:
1085 ld
= (struct linkedit_data_command
*)lc
;
1086 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1087 error("in swap_object_headers(): malformed load commands "
1088 "(LC_DATA_IN_CODE command %lu has incorrect "
1094 case LC_DYLIB_CODE_SIGN_DRS
:
1095 ld
= (struct linkedit_data_command
*)lc
;
1096 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1097 error("in swap_object_headers(): malformed load commands "
1098 "(LC_DYLIB_CODE_SIGN_DRS command %lu has incorrect "
1104 case LC_VERSION_MIN_MACOSX
:
1105 vc
= (struct version_min_command
*)lc
;
1106 if(vc
->cmdsize
!= sizeof(struct version_min_command
)){
1107 error("in swap_object_headers(): malformed load commands "
1108 "(LC_VERSION_MIN_MACOSX command %lu has incorrect "
1114 case LC_VERSION_MIN_IPHONEOS
:
1115 vc
= (struct version_min_command
*)lc
;
1116 if(vc
->cmdsize
!= sizeof(struct version_min_command
)){
1117 error("in swap_object_headers(): malformed load commands "
1118 "(LC_VERSION_MIN_IPHONEOS command %lu has incorrect "
1125 rpath
= (struct rpath_command
*)lc
;
1126 if(rpath
->cmdsize
< sizeof(struct rpath_command
)){
1127 error("in swap_object_headers(): malformed load commands "
1128 "(LC_RPATH command %lu has too small cmdsize field)",
1132 if(rpath
->path
.offset
>= rpath
->cmdsize
){
1133 error("in swap_object_headers(): truncated or malformed "
1134 "load commands (path.offset field of LC_RPATH "
1135 "command %lu extends past the end of all load "
1141 case LC_ENCRYPTION_INFO
:
1142 ec
= (struct encryption_info_command
*)lc
;
1143 if(ec
->cmdsize
!= sizeof(struct encryption_info_command
)){
1144 error("in swap_object_headers(): malformed load commands "
1145 "(LC_ENCRYPTION_INFO command %lu has incorrect "
1152 case LC_DYLD_INFO_ONLY
:
1153 dc
= (struct dyld_info_command
*)lc
;
1154 if(dc
->cmdsize
!= sizeof(struct dyld_info_command
)){
1155 error("in swap_object_headers(): malformed load commands "
1156 "(LC_DYLD_INFO command %lu has incorrect "
1163 error("in swap_object_headers(): malformed load commands "
1164 "(unknown load command %lu)", i
);
1168 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1169 /* check that next load command does not extends past the end */
1170 if((char *)lc
> (char *)load_commands
+ sizeofcmds
){
1171 error("in swap_object_headers(): truncated or malformed load "
1172 "commands (load command %lu extends past the end of all "
1173 "load commands)", i
+ 1);
1177 /* check for an inconsistent size of the load commands */
1178 if((char *)load_commands
+ sizeofcmds
!= (char *)lc
){
1179 error("in swap_object_headers(): malformed load commands "
1180 "(inconsistent sizeofcmds field in mach header)");
1186 * Now knowing the load commands can be parsed swap them.
1188 target_byte_sex
= get_host_byte_sex() == BIG_ENDIAN_BYTE_SEX
?
1189 LITTLE_ENDIAN_BYTE_SEX
: BIG_ENDIAN_BYTE_SEX
;
1190 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
1194 sg
= (struct segment_command
*)lc
;
1195 s
= (struct section
*)
1196 ((char *)sg
+ sizeof(struct segment_command
));
1197 swap_section(s
, sg
->nsects
, target_byte_sex
);
1198 swap_segment_command(sg
, target_byte_sex
);
1202 sg64
= (struct segment_command_64
*)lc
;
1203 s64
= (struct section_64
*)
1204 ((char *)sg64
+ sizeof(struct segment_command_64
));
1205 swap_section_64(s64
, sg64
->nsects
, target_byte_sex
);
1206 swap_segment_command_64(sg64
, target_byte_sex
);
1210 st
= (struct symtab_command
*)lc
;
1211 swap_symtab_command(st
, target_byte_sex
);
1215 dyst
= (struct dysymtab_command
*)lc
;
1216 swap_dysymtab_command(dyst
, target_byte_sex
);
1220 ss
= (struct symseg_command
*)lc
;
1221 swap_symseg_command(ss
, target_byte_sex
);
1226 fl
= (struct fvmlib_command
*)lc
;
1227 swap_fvmlib_command(fl
, target_byte_sex
);
1232 case LC_LOAD_WEAK_DYLIB
:
1233 case LC_REEXPORT_DYLIB
:
1234 case LC_LOAD_UPWARD_DYLIB
:
1235 case LC_LAZY_LOAD_DYLIB
:
1236 dl
= (struct dylib_command
*)lc
;
1237 swap_dylib_command(dl
, target_byte_sex
);
1240 case LC_SUB_FRAMEWORK
:
1241 sub
= (struct sub_framework_command
*)lc
;
1242 swap_sub_framework_command(sub
, target_byte_sex
);
1245 case LC_SUB_UMBRELLA
:
1246 usub
= (struct sub_umbrella_command
*)lc
;
1247 swap_sub_umbrella_command(usub
, target_byte_sex
);
1250 case LC_SUB_LIBRARY
:
1251 lsub
= (struct sub_library_command
*)lc
;
1252 swap_sub_library_command(lsub
, target_byte_sex
);
1256 csub
= (struct sub_client_command
*)lc
;
1257 swap_sub_client_command(csub
, target_byte_sex
);
1260 case LC_PREBOUND_DYLIB
:
1261 pbdylib
= (struct prebound_dylib_command
*)lc
;
1262 swap_prebound_dylib_command(pbdylib
, target_byte_sex
);
1265 case LC_ID_DYLINKER
:
1266 case LC_LOAD_DYLINKER
:
1267 case LC_DYLD_ENVIRONMENT
:
1268 dyld
= (struct dylinker_command
*)lc
;
1269 swap_dylinker_command(dyld
, target_byte_sex
);
1274 ut
= (struct thread_command
*)lc
;
1275 state
= (char *)ut
+ sizeof(struct thread_command
);
1276 p
= (char *)ut
+ ut
->cmdsize
;
1277 swap_thread_command(ut
, target_byte_sex
);
1279 if(cputype
== CPU_TYPE_MC680x0
){
1280 struct m68k_thread_state_regs
*cpu
;
1281 struct m68k_thread_state_68882
*fpu
;
1282 struct m68k_thread_state_user_reg
*user_reg
;
1285 flavor
= *((uint32_t *)state
);
1286 *((uint32_t *)state
) = SWAP_INT(flavor
);
1287 state
+= sizeof(uint32_t);
1288 count
= *((uint32_t *)state
);
1289 *((uint32_t *)state
) = SWAP_INT(count
);
1290 state
+= sizeof(uint32_t);
1292 case M68K_THREAD_STATE_REGS
:
1293 cpu
= (struct m68k_thread_state_regs
*)state
;
1294 swap_m68k_thread_state_regs(cpu
, target_byte_sex
);
1295 state
+= sizeof(struct m68k_thread_state_regs
);
1297 case M68K_THREAD_STATE_68882
:
1298 fpu
= (struct m68k_thread_state_68882
*)state
;
1299 swap_m68k_thread_state_68882(fpu
, target_byte_sex
);
1300 state
+= sizeof(struct m68k_thread_state_68882
);
1302 case M68K_THREAD_STATE_USER_REG
:
1304 (struct m68k_thread_state_user_reg
*)state
;
1305 swap_m68k_thread_state_user_reg(user_reg
,
1307 state
+= sizeof(struct m68k_thread_state_user_reg
);
1313 if(cputype
== CPU_TYPE_POWERPC
||
1314 cputype
== CPU_TYPE_VEO
||
1315 cputype
== CPU_TYPE_POWERPC64
){
1316 ppc_thread_state_t
*cpu
;
1317 ppc_thread_state64_t
*cpu64
;
1318 ppc_float_state_t
*fpu
;
1319 ppc_exception_state_t
*except
;
1322 flavor
= *((uint32_t *)state
);
1323 *((uint32_t *)state
) = SWAP_INT(flavor
);
1324 state
+= sizeof(uint32_t);
1325 count
= *((uint32_t *)state
);
1326 *((uint32_t *)state
) = SWAP_INT(count
);
1327 state
+= sizeof(uint32_t);
1329 case PPC_THREAD_STATE
:
1330 cpu
= (ppc_thread_state_t
*)state
;
1331 swap_ppc_thread_state_t(cpu
, target_byte_sex
);
1332 state
+= sizeof(ppc_thread_state_t
);
1334 case PPC_THREAD_STATE64
:
1335 cpu64
= (ppc_thread_state64_t
*)state
;
1336 swap_ppc_thread_state64_t(cpu64
, target_byte_sex
);
1337 state
+= sizeof(ppc_thread_state64_t
);
1339 case PPC_FLOAT_STATE
:
1340 fpu
= (ppc_float_state_t
*)state
;
1341 swap_ppc_float_state_t(fpu
, target_byte_sex
);
1342 state
+= sizeof(ppc_float_state_t
);
1343 case PPC_EXCEPTION_STATE
:
1344 except
= (ppc_exception_state_t
*)state
;
1345 swap_ppc_exception_state_t(except
, target_byte_sex
);
1346 state
+= sizeof(ppc_exception_state_t
);
1352 if(cputype
== CPU_TYPE_MC88000
){
1353 m88k_thread_state_grf_t
*cpu
;
1354 m88k_thread_state_xrf_t
*fpu
;
1355 m88k_thread_state_user_t
*user
;
1356 m88110_thread_state_impl_t
*spu
;
1359 flavor
= *((uint32_t *)state
);
1360 *((uint32_t *)state
) = SWAP_INT(flavor
);
1361 state
+= sizeof(uint32_t);
1362 count
= *((uint32_t *)state
);
1363 *((uint32_t *)state
) = SWAP_INT(count
);
1364 state
+= sizeof(uint32_t);
1366 case M88K_THREAD_STATE_GRF
:
1367 cpu
= (m88k_thread_state_grf_t
*)state
;
1368 swap_m88k_thread_state_grf_t(cpu
,
1370 state
+= sizeof(m88k_thread_state_grf_t
);
1372 case M88K_THREAD_STATE_XRF
:
1373 fpu
= (m88k_thread_state_xrf_t
*)state
;
1374 swap_m88k_thread_state_xrf_t(fpu
,
1376 state
+= sizeof(m88k_thread_state_xrf_t
);
1378 case M88K_THREAD_STATE_USER
:
1379 user
= (m88k_thread_state_user_t
*)state
;
1380 swap_m88k_thread_state_user_t(user
,
1382 state
+= sizeof(m88k_thread_state_user_t
);
1384 case M88110_THREAD_STATE_IMPL
:
1385 spu
= (m88110_thread_state_impl_t
*)state
;
1386 swap_m88110_thread_state_impl_t(spu
,
1388 state
+= sizeof(m88110_thread_state_impl_t
);
1394 if(cputype
== CPU_TYPE_I860
){
1395 struct i860_thread_state_regs
*cpu
;
1398 flavor
= *((uint32_t *)state
);
1399 *((uint32_t *)state
) = SWAP_INT(flavor
);
1400 state
+= sizeof(uint32_t);
1401 count
= *((uint32_t *)state
);
1402 *((uint32_t *)state
) = SWAP_INT(count
);
1403 state
+= sizeof(uint32_t);
1405 case I860_THREAD_STATE_REGS
:
1406 cpu
= (struct i860_thread_state_regs
*)state
;
1407 swap_i860_thread_state_regs(cpu
, target_byte_sex
);
1408 state
+= sizeof(struct i860_thread_state_regs
);
1414 if(cputype
== CPU_TYPE_I386
1415 #ifdef x86_THREAD_STATE64
1416 || cputype
== CPU_TYPE_X86_64
1417 #endif /* x86_THREAD_STATE64 */
1419 i386_thread_state_t
*cpu
;
1420 #ifdef x86_THREAD_STATE64
1421 x86_thread_state64_t
*cpu64
;
1422 #endif /* x86_THREAD_STATE64 */
1423 /* current i386 thread states */
1424 #if i386_THREAD_STATE == 1
1425 struct i386_float_state
*fpu
;
1426 i386_exception_state_t
*exc
;
1427 #endif /* i386_THREAD_STATE == 1 */
1429 /* i386 thread states on older releases */
1430 #if i386_THREAD_STATE == -1
1431 i386_thread_fpstate_t
*fpu
;
1432 i386_thread_exceptstate_t
*exc
;
1433 i386_thread_cthreadstate_t
*user
;
1434 #endif /* i386_THREAD_STATE == -1 */
1437 flavor
= *((uint32_t *)state
);
1438 *((uint32_t *)state
) = SWAP_INT(flavor
);
1439 state
+= sizeof(uint32_t);
1440 count
= *((uint32_t *)state
);
1441 *((uint32_t *)state
) = SWAP_INT(count
);
1442 state
+= sizeof(uint32_t);
1443 switch((int)flavor
){
1444 case i386_THREAD_STATE
:
1445 /* current i386 thread states */
1446 #if i386_THREAD_STATE == 1
1448 #endif /* i386_THREAD_STATE == 1 */
1449 /* i386 thread states on older releases */
1450 #if i386_THREAD_STATE == -1
1452 #endif /* i386_THREAD_STATE == -1 */
1453 cpu
= (i386_thread_state_t
*)state
;
1454 swap_i386_thread_state(cpu
, target_byte_sex
);
1455 state
+= sizeof(i386_thread_state_t
);
1457 /* current i386 thread states */
1458 #if i386_THREAD_STATE == 1
1459 case i386_FLOAT_STATE
:
1460 fpu
= (struct i386_float_state
*)state
;
1461 swap_i386_float_state(fpu
, target_byte_sex
);
1462 state
+= sizeof(struct i386_float_state
);
1464 case i386_EXCEPTION_STATE
:
1465 exc
= (i386_exception_state_t
*)state
;
1466 swap_i386_exception_state(exc
, target_byte_sex
);
1467 state
+= sizeof(i386_exception_state_t
);
1469 #endif /* i386_THREAD_STATE == 1 */
1471 /* i386 thread states on older releases */
1472 #if i386_THREAD_STATE == -1
1473 case i386_THREAD_FPSTATE
:
1474 fpu
= (i386_thread_fpstate_t
*)state
;
1475 swap_i386_thread_fpstate(fpu
, target_byte_sex
);
1476 state
+= sizeof(i386_thread_fpstate_t
);
1478 case i386_THREAD_EXCEPTSTATE
:
1479 exc
= (i386_thread_exceptstate_t
*)state
;
1480 swap_i386_thread_exceptstate(exc
, target_byte_sex
);
1481 state
+= sizeof(i386_thread_exceptstate_t
);
1483 case i386_THREAD_CTHREADSTATE
:
1484 user
= (i386_thread_cthreadstate_t
*)state
;
1485 swap_i386_thread_cthreadstate(user
,target_byte_sex
);
1486 state
+= sizeof(i386_thread_cthreadstate_t
);
1488 #endif /* i386_THREAD_STATE == -1 */
1489 #ifdef x86_THREAD_STATE64
1490 case x86_THREAD_STATE64
:
1491 cpu64
= (x86_thread_state64_t
*)state
;
1492 swap_x86_thread_state64(cpu64
, target_byte_sex
);
1493 state
+= sizeof(x86_thread_state64_t
);
1495 #endif /* x86_THREAD_STATE64 */
1500 if(cputype
== CPU_TYPE_HPPA
){
1501 struct hp_pa_integer_thread_state
*cpu
;
1502 struct hp_pa_frame_thread_state
*frame
;
1503 struct hp_pa_fp_thread_state
*fpu
;
1506 flavor
= *((uint32_t *)state
);
1507 *((uint32_t *)state
) = SWAP_INT(flavor
);
1508 state
+= sizeof(uint32_t);
1509 count
= *((uint32_t *)state
);
1510 *((uint32_t *)state
) = SWAP_INT(count
);
1511 state
+= sizeof(uint32_t);
1513 case HPPA_INTEGER_THREAD_STATE
:
1514 cpu
= (struct hp_pa_integer_thread_state
*)state
;
1515 swap_hppa_integer_thread_state(cpu
,
1517 state
+= sizeof(struct hp_pa_integer_thread_state
);
1519 case HPPA_FRAME_THREAD_STATE
:
1520 frame
= (struct hp_pa_frame_thread_state
*)state
;
1521 swap_hppa_frame_thread_state(frame
,
1523 state
+= sizeof(struct hp_pa_frame_thread_state
);
1525 case HPPA_FP_THREAD_STATE
:
1526 fpu
= (struct hp_pa_fp_thread_state
*)state
;
1527 swap_hppa_fp_thread_state(fpu
,
1529 state
+= sizeof(struct hp_pa_fp_thread_state
);
1536 if(cputype
== CPU_TYPE_SPARC
) {
1537 struct sparc_thread_state_regs
*cpu
;
1538 struct sparc_thread_state_fpu
*fpu
;
1541 flavor
= *((uint32_t *) state
);
1542 *((uint32_t *) state
) = SWAP_INT(flavor
);
1543 state
+= sizeof(uint32_t);
1544 count
= *((unsigned int *) state
);
1545 *((unsigned int *) state
) = SWAP_INT(count
);
1546 state
+= sizeof(uint32_t);
1548 case SPARC_THREAD_STATE_REGS
:
1549 cpu
= (struct sparc_thread_state_regs
*) state
;
1550 swap_sparc_thread_state_regs(cpu
, target_byte_sex
);
1551 state
+= sizeof(struct sparc_thread_state_regs
);
1553 case SPARC_THREAD_STATE_FPU
:
1554 fpu
= (struct sparc_thread_state_fpu
*) state
;
1555 swap_sparc_thread_state_fpu(fpu
, target_byte_sex
);
1556 state
+= sizeof(struct sparc_thread_state_fpu
);
1562 if(cputype
== CPU_TYPE_ARM
){
1563 arm_thread_state_t
*cpu
;
1566 flavor
= *((uint32_t *)state
);
1567 *((uint32_t *)state
) = SWAP_INT(flavor
);
1568 state
+= sizeof(uint32_t);
1569 count
= *((uint32_t *)state
);
1570 *((uint32_t *)state
) = SWAP_INT(count
);
1571 state
+= sizeof(uint32_t);
1573 case ARM_THREAD_STATE
:
1574 cpu
= (arm_thread_state_t
*)state
;
1575 swap_arm_thread_state_t(cpu
, target_byte_sex
);
1576 state
+= sizeof(arm_thread_state_t
);
1585 ep
= (struct entry_point_command
*)lc
;
1586 swap_entry_point_command(ep
, target_byte_sex
);
1589 case LC_SOURCE_VERSION
:
1590 sv
= (struct source_version_command
*)lc
;
1591 swap_source_version_command(sv
, target_byte_sex
);
1595 id
= (struct ident_command
*)lc
;
1596 swap_ident_command(id
, target_byte_sex
);
1600 rc
= (struct routines_command
*)lc
;
1601 swap_routines_command(rc
, target_byte_sex
);
1604 case LC_ROUTINES_64
:
1605 rc64
= (struct routines_command_64
*)lc
;
1606 swap_routines_command_64(rc64
, target_byte_sex
);
1609 case LC_TWOLEVEL_HINTS
:
1610 hints
= (struct twolevel_hints_command
*)lc
;
1611 swap_twolevel_hints_command(hints
, target_byte_sex
);
1614 case LC_PREBIND_CKSUM
:
1615 cs
= (struct prebind_cksum_command
*)lc
;
1616 swap_prebind_cksum_command(cs
, target_byte_sex
);
1620 uuid
= (struct uuid_command
*)lc
;
1621 swap_uuid_command(uuid
, target_byte_sex
);
1624 case LC_CODE_SIGNATURE
:
1625 case LC_SEGMENT_SPLIT_INFO
:
1626 case LC_FUNCTION_STARTS
:
1627 case LC_DATA_IN_CODE
:
1628 case LC_DYLIB_CODE_SIGN_DRS
:
1629 ld
= (struct linkedit_data_command
*)lc
;
1630 swap_linkedit_data_command(ld
, target_byte_sex
);
1634 rpath
= (struct rpath_command
*)lc
;
1635 swap_rpath_command(rpath
, target_byte_sex
);
1638 case LC_ENCRYPTION_INFO
:
1639 ec
= (struct encryption_info_command
*)lc
;
1640 swap_encryption_command(ec
, target_byte_sex
);
1644 case LC_DYLD_INFO_ONLY
:
1645 dc
= (struct dyld_info_command
*)lc
;
1646 swap_dyld_info_command(dc
, target_byte_sex
);
1649 case LC_VERSION_MIN_MACOSX
:
1650 case LC_VERSION_MIN_IPHONEOS
:
1651 vc
= (struct version_min_command
*)lc
;
1652 swap_version_min_command(vc
, target_byte_sex
);
1656 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1659 swap_mach_header(mh
, target_byte_sex
);
1661 swap_mach_header_64(mh64
, target_byte_sex
);