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 dylib_command
*dl
;
79 struct sub_framework_command
*sub
;
80 struct sub_umbrella_command
*usub
;
81 struct sub_library_command
*lsub
;
82 struct sub_client_command
*csub
;
83 struct prebound_dylib_command
*pbdylib
;
84 struct dylinker_command
*dyld
;
85 struct routines_command
*rc
;
86 struct routines_command_64
*rc64
;
87 struct twolevel_hints_command
*hints
;
88 struct prebind_cksum_command
*cs
;
89 struct uuid_command
*uuid
;
90 struct linkedit_data_command
*ld
;
91 struct rpath_command
*rpath
;
92 struct encryption_info_command
*ec
;
93 struct dyld_info_command
*dc
;
94 uint32_t flavor
, count
;
95 unsigned long nflavor
;
96 char *p
, *state
, *cmd_name
;
98 magic
= *((uint32_t *)mach_header
);
99 if(magic
== MH_MAGIC
){
100 mh
= (struct mach_header
*)mach_header
;
102 sizeofcmds
= mh
->sizeofcmds
;
103 cputype
= mh
->cputype
;
104 cpusubtype
= mh
->cpusubtype
;
109 mh64
= (struct mach_header_64
*)mach_header
;
111 sizeofcmds
= mh64
->sizeofcmds
;
112 cputype
= mh64
->cputype
;
113 cpusubtype
= mh64
->cpusubtype
;
118 * Make a pass through the load commands checking them to the level
119 * that they can be parsed and then swapped.
121 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
123 /* check load command size for a correct multiple size */
124 if(lc
->cmdsize
% cmd_multiple
!= 0){
125 error("in swap_object_headers(): malformed load command %lu "
126 "(cmdsize not a multiple of %u)", i
, cmd_multiple
);
129 /* check that load command does not extends past end of commands */
130 if((char *)lc
+ lc
->cmdsize
>
131 (char *)load_commands
+ sizeofcmds
){
132 error("in swap_object_headers(): truncated or malformed load "
133 "command %lu (extends past the end of the all load "
137 /* check that the load command size is not zero */
138 if(lc
->cmdsize
== 0){
139 error("in swap_object_headers(): malformed load command %lu "
140 "(cmdsize is zero)", i
);
145 sg
= (struct segment_command
*)lc
;
146 if(sg
->cmdsize
!= sizeof(struct segment_command
) +
147 sg
->nsects
* sizeof(struct section
)){
148 error("in swap_object_headers(): malformed load command "
149 "(inconsistent cmdsize in LC_SEGMENT command %lu for "
150 "the number of sections)", i
);
156 sg64
= (struct segment_command_64
*)lc
;
157 if(sg64
->cmdsize
!= sizeof(struct segment_command_64
) +
158 sg64
->nsects
* sizeof(struct section_64
)){
159 error("in swap_object_headers(): malformed load command "
160 "(inconsistent cmdsize in LC_SEGMENT_64 command %lu "
161 "for the number of sections)", i
);
167 st
= (struct symtab_command
*)lc
;
168 if(st
->cmdsize
!= sizeof(struct symtab_command
)){
169 error("in swap_object_headers(): malformed load commands "
170 "(LC_SYMTAB command %lu has incorrect cmdsize", i
);
176 dyst
= (struct dysymtab_command
*)lc
;
177 if(dyst
->cmdsize
!= sizeof(struct dysymtab_command
)){
178 error("in swap_object_headers(): malformed load commands "
179 "(LC_DYSYMTAB command %lu has incorrect cmdsize", i
);
185 ss
= (struct symseg_command
*)lc
;
186 if(ss
->cmdsize
!= sizeof(struct symseg_command
)){
187 error("in swap_object_headers(): malformed load command "
188 "(LC_SYMSEG command %lu has incorrect cmdsize", i
);
195 fl
= (struct fvmlib_command
*)lc
;
196 if(fl
->cmdsize
< sizeof(struct fvmlib_command
)){
197 error("in swap_object_headers(): malformed load commands "
198 "(%s command %lu has too small cmdsize field)",
199 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
203 if(fl
->fvmlib
.name
.offset
>= fl
->cmdsize
){
204 error("in swap_object_headers(): truncated or malformed "
205 "load commands (name.offset field of %s command %lu "
206 "extends past the end of all load commands)",
207 fl
->cmd
== LC_IDFVMLIB
? "LC_IDFVMLIB" :
214 cmd_name
= "LC_ID_DYLIB";
215 goto check_dylib_command
;
217 cmd_name
= "LC_LOAD_DYLIB";
218 goto check_dylib_command
;
219 case LC_LOAD_WEAK_DYLIB
:
220 cmd_name
= "LC_LOAD_WEAK_DYLIB";
221 goto check_dylib_command
;
222 case LC_REEXPORT_DYLIB
:
223 cmd_name
= "LC_REEXPORT_DYLIB";
224 goto check_dylib_command
;
225 case LC_LAZY_LOAD_DYLIB
:
226 cmd_name
= "LC_LAZY_LOAD_DYLIB";
227 goto check_dylib_command
;
229 dl
= (struct dylib_command
*)lc
;
230 if(dl
->cmdsize
< sizeof(struct dylib_command
)){
231 error("in swap_object_headers(): malformed load commands "
232 "(%s command %lu has too small cmdsize field)",
236 if(dl
->dylib
.name
.offset
>= dl
->cmdsize
){
237 error("in swap_object_headers(): truncated or malformed "
238 "load commands (name.offset field of %s command %lu "
239 "extends past the end of all load commands)",
245 case LC_SUB_FRAMEWORK
:
246 sub
= (struct sub_framework_command
*)lc
;
247 if(sub
->cmdsize
< sizeof(struct sub_framework_command
)){
248 error("in swap_object_headers(): malformed load commands "
249 "(LC_SUB_FRAMEWORK command %lu has too small cmdsize "
253 if(sub
->umbrella
.offset
>= sub
->cmdsize
){
254 error("in swap_object_headers(): truncated or malformed "
255 "load commands (umbrella.offset field of "
256 "LC_SUB_FRAMEWORK command %lu extends past the end "
257 "of all load commands)", i
);
262 case LC_SUB_UMBRELLA
:
263 usub
= (struct sub_umbrella_command
*)lc
;
264 if(usub
->cmdsize
< sizeof(struct sub_umbrella_command
)){
265 error("in swap_object_headers(): malformed load commands "
266 "(LC_SUB_UMBRELLA command %lu has too small cmdsize "
270 if(usub
->sub_umbrella
.offset
>= usub
->cmdsize
){
271 error("in swap_object_headers(): truncated or malformed "
272 "load commands (sub_umbrella.offset field of "
273 "LC_SUB_UMBRELLA command %lu extends past the end "
274 "of all load commands)", i
);
280 lsub
= (struct sub_library_command
*)lc
;
281 if(lsub
->cmdsize
< sizeof(struct sub_library_command
)){
282 error("in swap_object_headers(): malformed load commands "
283 "(LC_SUB_LIBRARY command %lu has too small cmdsize "
287 if(lsub
->sub_library
.offset
>= lsub
->cmdsize
){
288 error("in swap_object_headers(): truncated or malformed "
289 "load commands (sub_library.offset field of "
290 "LC_SUB_LIBRARY command %lu extends past the end "
291 "of all load commands)", i
);
297 csub
= (struct sub_client_command
*)lc
;
298 if(csub
->cmdsize
< sizeof(struct sub_client_command
)){
299 error("in swap_object_headers(): malformed load commands "
300 "(LC_SUB_CLIENT command %lu has too small cmdsize "
304 if(csub
->client
.offset
>= csub
->cmdsize
){
305 error("in swap_object_headers(): truncated or malformed "
306 "load commands (client.offset field of "
307 "LC_SUB_CLIENT command %lu extends past the end "
308 "of all load commands)", i
);
313 case LC_PREBOUND_DYLIB
:
314 pbdylib
= (struct prebound_dylib_command
*)lc
;
315 if(pbdylib
->cmdsize
< sizeof(struct prebound_dylib_command
)){
316 error("in swap_object_headers(): malformed load commands "
317 "(LC_PREBOUND_DYLIB command %lu has too small "
318 "cmdsize field)", i
);
321 if(pbdylib
->name
.offset
>= pbdylib
->cmdsize
){
322 error("in swap_object_headers(): truncated or malformed "
323 "load commands (name.offset field of "
324 "LC_PREBOUND_DYLIB command %lu extends past the end "
325 "of all load commands)", i
);
328 if(pbdylib
->linked_modules
.offset
>= pbdylib
->cmdsize
){
329 error("in swap_object_headers(): truncated or malformed "
330 "load commands (linked_modules.offset field of "
331 "LC_PREBOUND_DYLIB command %lu extends past the end "
332 "of all load commands)", i
);
338 case LC_LOAD_DYLINKER
:
339 dyld
= (struct dylinker_command
*)lc
;
340 if(dyld
->cmdsize
< sizeof(struct dylinker_command
)){
341 error("in swap_object_headers(): malformed load commands "
342 "(%s command %lu has too small cmdsize field)",
343 dyld
->cmd
== LC_ID_DYLINKER
? "LC_ID_DYLINKER" :
344 "LC_LOAD_DYLINKER", i
);
347 if(dyld
->name
.offset
>= dyld
->cmdsize
){
348 error("in swap_object_headers(): truncated or malformed "
349 "load commands (name.offset field of %s command %lu "
350 "extends past the end of all load commands)",
351 dyld
->cmd
== LC_ID_DYLINKER
? "LC_ID_DYLINKER" :
352 "LC_LOAD_DYLINKER", i
);
359 ut
= (struct thread_command
*)lc
;
360 state
= (char *)ut
+ sizeof(struct thread_command
);
362 if(cputype
== CPU_TYPE_MC680x0
){
363 struct m68k_thread_state_regs
*cpu
;
364 struct m68k_thread_state_68882
*fpu
;
365 struct m68k_thread_state_user_reg
*user_reg
;
368 p
= (char *)ut
+ ut
->cmdsize
;
370 flavor
= *((uint32_t *)state
);
371 state
+= sizeof(uint32_t);
372 count
= *((uint32_t *)state
);
373 state
+= sizeof(uint32_t);
375 case M68K_THREAD_STATE_REGS
:
376 if(count
!= M68K_THREAD_STATE_REGS_COUNT
){
377 error("in swap_object_headers(): malformed "
378 "load commands (count "
379 "not M68K_THREAD_STATE_REGS_COUNT for "
380 "flavor number %lu which is a M68K_THREAD_"
381 "STATE_REGS flavor in %s command %lu)",
382 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
383 "LC_UNIXTHREAD" : "LC_THREAD", i
);
386 cpu
= (struct m68k_thread_state_regs
*)state
;
387 state
+= sizeof(struct m68k_thread_state_regs
);
389 case M68K_THREAD_STATE_68882
:
390 if(count
!= M68K_THREAD_STATE_68882_COUNT
){
391 error("in swap_object_headers(): malformed "
392 "load commands (count "
393 "not M68K_THREAD_STATE_68882_COUNT for "
394 "flavor number %lu which is a M68K_THREAD_"
395 "STATE_68882 flavor in %s command %lu)",
396 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
397 "LC_UNIXTHREAD" : "LC_THREAD", i
);
400 fpu
= (struct m68k_thread_state_68882
*)state
;
401 state
+= sizeof(struct m68k_thread_state_68882
);
403 case M68K_THREAD_STATE_USER_REG
:
404 if(count
!= M68K_THREAD_STATE_USER_REG_COUNT
){
405 error("in swap_object_headers(): malformed "
406 "load commands (count "
407 "not M68K_THREAD_STATE_USER_REG_COUNT for "
408 "flavor number %lu which is a M68K_THREAD_"
409 "STATE_USER_REG flavor in %s command %lu)",
410 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
411 "LC_UNIXTHREAD" : "LC_THREAD", i
);
415 (struct m68k_thread_state_user_reg
*)state
;
416 state
+= sizeof(struct m68k_thread_state_user_reg
);
419 error("in swap_object_headers(): malformed "
420 "load commands (unknown "
421 "flavor %u for flavor number %lu in %s command"
422 " %lu can't byte swap it)", flavor
, nflavor
,
423 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
431 if(cputype
== CPU_TYPE_POWERPC
||
432 cputype
== CPU_TYPE_VEO
||
433 cputype
== CPU_TYPE_POWERPC64
){
434 ppc_thread_state_t
*cpu
;
435 ppc_float_state_t
*fpu
;
436 ppc_exception_state_t
*except
;
437 ppc_thread_state64_t
*cpu64
;
440 p
= (char *)ut
+ ut
->cmdsize
;
442 flavor
= *((uint32_t *)state
);
443 state
+= sizeof(uint32_t);
444 count
= *((uint32_t *)state
);
445 state
+= sizeof(uint32_t);
447 case PPC_THREAD_STATE
:
448 if(count
!= PPC_THREAD_STATE_COUNT
){
449 error("in swap_object_headers(): malformed "
450 "load commands (count "
451 "not PPC_THREAD_STATE_COUNT for "
452 "flavor number %lu which is a PPC_THREAD_"
453 "STATE flavor in %s command %lu)",
454 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
455 "LC_UNIXTHREAD" : "LC_THREAD", i
);
458 cpu
= (ppc_thread_state_t
*)state
;
459 state
+= sizeof(ppc_thread_state_t
);
461 case PPC_FLOAT_STATE
:
462 if(count
!= PPC_FLOAT_STATE_COUNT
){
463 error("in swap_object_headers(): malformed "
464 "load commands (count "
465 "not PPC_FLOAT_STATE_COUNT for "
466 "flavor number %lu which is a PPC_FLOAT_"
467 "STATE flavor in %s command %lu)",
468 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
469 "LC_UNIXTHREAD" : "LC_THREAD", i
);
472 fpu
= (ppc_float_state_t
*)state
;
473 state
+= sizeof(ppc_float_state_t
);
475 case PPC_EXCEPTION_STATE
:
476 if(count
!= PPC_EXCEPTION_STATE_COUNT
){
477 error("in swap_object_headers(): malformed "
478 "load commands (count "
479 "not PPC_EXCEPTION_STATE_COUNT for "
480 "flavor number %lu which is a PPC_EXCEPT"
481 "ION_STATE flavor in %s command %lu)",
482 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
483 "LC_UNIXTHREAD" : "LC_THREAD", i
);
486 except
= (ppc_exception_state_t
*)state
;
487 state
+= sizeof(ppc_exception_state_t
);
489 case PPC_THREAD_STATE64
:
490 if(count
!= PPC_THREAD_STATE64_COUNT
){
491 error("in swap_object_headers(): malformed "
492 "load commands (count "
493 "not PPC_THREAD_STATE64_COUNT for "
494 "flavor number %lu which is a PPC_THREAD_"
495 "STATE64 flavor in %s command %lu)",
496 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
497 "LC_UNIXTHREAD" : "LC_THREAD", i
);
500 cpu64
= (ppc_thread_state64_t
*)state
;
501 state
+= sizeof(ppc_thread_state64_t
);
504 error("in swap_object_headers(): malformed "
505 "load commands (unknown "
506 "flavor %u for flavor number %lu in %s command"
507 " %lu can't byte swap it)", flavor
, nflavor
,
508 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
516 if(cputype
== CPU_TYPE_MC88000
){
517 m88k_thread_state_grf_t
*cpu
;
518 m88k_thread_state_xrf_t
*fpu
;
519 m88k_thread_state_user_t
*user
;
520 m88110_thread_state_impl_t
*spu
;
523 p
= (char *)ut
+ ut
->cmdsize
;
525 flavor
= *((uint32_t *)state
);
526 state
+= sizeof(uint32_t);
527 count
= *((uint32_t *)state
);
528 state
+= sizeof(uint32_t);
530 case M88K_THREAD_STATE_GRF
:
531 if(count
!= M88K_THREAD_STATE_GRF_COUNT
){
532 error("in swap_object_headers(): malformed "
533 "load commands (count "
534 "not M88K_THREAD_STATE_GRF_COUNT for "
535 "flavor number %lu which is a M88K_THREAD_"
536 "STATE_GRF flavor in %s command %lu)",
537 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
538 "LC_UNIXTHREAD" : "LC_THREAD", i
);
541 cpu
= (m88k_thread_state_grf_t
*)state
;
542 state
+= sizeof(m88k_thread_state_grf_t
);
544 case M88K_THREAD_STATE_XRF
:
545 if(count
!= M88K_THREAD_STATE_XRF_COUNT
){
546 error("in swap_object_headers(): malformed "
547 "load commands (count "
548 "not M88K_THREAD_STATE_XRF_COUNT for "
549 "flavor number %lu which is a M88K_THREAD_"
550 "STATE_XRF flavor in %s command %lu)",
551 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
552 "LC_UNIXTHREAD" : "LC_THREAD", i
);
555 fpu
= (m88k_thread_state_xrf_t
*)state
;
556 state
+= sizeof(m88k_thread_state_xrf_t
);
558 case M88K_THREAD_STATE_USER
:
559 if(count
!= M88K_THREAD_STATE_USER_COUNT
){
560 error("in swap_object_headers(): malformed "
561 "load commands (count "
562 "not M88K_THREAD_STATE_USER_COUNT for "
563 "flavor number %lu which is a M88K_THREAD_"
564 "STATE_USER flavor in %s command %lu)",
565 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
566 "LC_UNIXTHREAD" : "LC_THREAD", i
);
569 user
= (m88k_thread_state_user_t
*)state
;
570 state
+= sizeof(m88k_thread_state_user_t
);
572 case M88110_THREAD_STATE_IMPL
:
573 if(count
!= M88110_THREAD_STATE_IMPL_COUNT
){
574 error("in swap_object_headers(): malformed "
575 "load commands (count "
576 "not M88110_THREAD_STATE_IMPL_COUNT for "
577 "flavor number %lu which is a M88110_THREAD"
578 "_STATE_IMPL flavor in %s command %lu)",
579 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
580 "LC_UNIXTHREAD" : "LC_THREAD", i
);
583 spu
= (m88110_thread_state_impl_t
*)state
;
584 state
+= sizeof(m88110_thread_state_impl_t
);
587 error("in swap_object_headers(): malformed "
588 "load commands (unknown "
589 "flavor %u for flavor number %lu in %s command"
590 " %lu can't byte swap it)", flavor
, nflavor
,
591 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
599 if(cputype
== CPU_TYPE_I860
){
600 struct i860_thread_state_regs
*cpu
;
603 p
= (char *)ut
+ ut
->cmdsize
;
605 flavor
= *((uint32_t *)state
);
606 state
+= sizeof(uint32_t);
607 count
= *((uint32_t *)state
);
608 state
+= sizeof(uint32_t);
610 case I860_THREAD_STATE_REGS
:
611 if(count
!= I860_THREAD_STATE_REGS_COUNT
){
612 error("in swap_object_headers(): malformed "
613 "load commands (count "
614 "not I860_THREAD_STATE_REGS_COUNT for "
615 "flavor number %lu which is a I860_THREAD_"
616 "STATE_REGS flavor in %s command %lu)",
617 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
618 "LC_UNIXTHREAD" : "LC_THREAD", i
);
621 cpu
= (struct i860_thread_state_regs
*)state
;
622 state
+= sizeof(struct i860_thread_state_regs
);
625 error("in swap_object_headers(): malformed "
626 "load commands (unknown "
627 "flavor %u for flavor number %lu in %s command"
628 " %lu can't byte swap it)", flavor
, nflavor
,
629 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
637 if(cputype
== CPU_TYPE_I386
638 #ifdef x86_THREAD_STATE64
639 || cputype
== CPU_TYPE_X86_64
640 #endif /* x86_THREAD_STATE64 */
642 i386_thread_state_t
*cpu
;
643 #ifdef x86_THREAD_STATE64
644 x86_thread_state64_t
*cpu64
;
645 #endif /* x86_THREAD_STATE64 */
646 /* current i386 thread states */
647 #if i386_THREAD_STATE == 1
648 struct i386_float_state
*fpu
;
649 i386_exception_state_t
*exc
;
650 #endif /* i386_THREAD_STATE == 1 */
652 /* i386 thread states on older releases */
653 #if i386_THREAD_STATE == -1
654 i386_thread_fpstate_t
*fpu
;
655 i386_thread_exceptstate_t
*exc
;
656 i386_thread_cthreadstate_t
*user
;
657 #endif /* i386_THREAD_STATE == -1 */
660 p
= (char *)ut
+ ut
->cmdsize
;
662 flavor
= *((uint32_t *)state
);
663 state
+= sizeof(uint32_t);
664 count
= *((uint32_t *)state
);
665 state
+= sizeof(uint32_t);
667 case i386_THREAD_STATE
:
668 /* current i386 thread states */
669 #if i386_THREAD_STATE == 1
671 #endif /* i386_THREAD_STATE == 1 */
672 /* i386 thread states on older releases */
673 #if i386_THREAD_STATE == -1
675 #endif /* i386_THREAD_STATE == -1 */
676 if(count
!= i386_THREAD_STATE_COUNT
){
677 error("in swap_object_headers(): malformed "
678 "load commands (count "
679 "not i386_THREAD_STATE_COUNT for flavor "
680 "number %lu which is a i386_THREAD_STATE "
681 "flavor in %s command %lu)", nflavor
,
682 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
686 cpu
= (i386_thread_state_t
*)state
;
687 state
+= sizeof(i386_thread_state_t
);
689 /* current i386 thread states */
690 #if i386_THREAD_STATE == 1
691 case i386_FLOAT_STATE
:
692 if(count
!= i386_FLOAT_STATE_COUNT
){
693 error("in swap_object_headers(): malformed "
694 "load commands (count "
695 "not i386_FLOAT_STATE_COUNT for flavor "
696 "number %lu which is a i386_FLOAT_STATE "
697 "flavor in %s command %lu)", nflavor
,
698 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
702 fpu
= (struct i386_float_state
*)state
;
703 state
+= sizeof(struct i386_float_state
);
705 case i386_EXCEPTION_STATE
:
706 if(count
!= I386_EXCEPTION_STATE_COUNT
){
707 error("in swap_object_headers(): malformed "
708 "load commands (count "
709 "not I386_EXCEPTION_STATE_COUNT for "
710 "flavor number %lu which is a i386_"
711 "EXCEPTION_STATE flavor in %s command %lu)",
713 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
717 exc
= (i386_exception_state_t
*)state
;
718 state
+= sizeof(i386_exception_state_t
);
720 #endif /* i386_THREAD_STATE == 1 */
722 /* i386 thread states on older releases */
723 #if i386_THREAD_STATE == -1
724 case i386_THREAD_FPSTATE
:
725 if(count
!= i386_THREAD_FPSTATE_COUNT
){
726 error("in swap_object_headers(): malformed "
727 "load commands (count "
728 "not i386_THREAD_FPSTATE_COUNT for flavor "
729 "number %lu which is a i386_THREAD_FPSTATE "
730 "flavor in %s command %lu)", nflavor
,
731 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
735 fpu
= (i386_thread_fpstate_t
*)state
;
736 state
+= sizeof(i386_thread_fpstate_t
);
738 case i386_THREAD_EXCEPTSTATE
:
739 if(count
!= i386_THREAD_EXCEPTSTATE_COUNT
){
740 error("in swap_object_headers(): malformed "
741 "load commands (count "
742 "not i386_THREAD_EXCEPTSTATE_COUNT for "
743 "flavor number %lu which is a i386_THREAD_"
744 "EXCEPTSTATE flavor in %s command %lu)",
746 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
750 exc
= (i386_thread_exceptstate_t
*)state
;
751 state
+= sizeof(i386_thread_fpstate_t
);
753 case i386_THREAD_CTHREADSTATE
:
754 if(count
!= i386_THREAD_CTHREADSTATE_COUNT
){
755 error("in swap_object_headers(): malformed "
756 "load commands (count "
757 "not i386_THREAD_CTHREADSTATE_COUNT for "
758 "flavor number %lu which is a i386_THREAD_"
759 "CTHREADSTATE flavor in %s command %lu)",
761 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
765 user
= (i386_thread_cthreadstate_t
*)state
;
766 state
+= sizeof(i386_thread_fpstate_t
);
768 #endif /* i386_THREAD_STATE == -1 */
769 #ifdef x86_THREAD_STATE64
770 case x86_THREAD_STATE64
:
771 if(count
!= x86_THREAD_STATE64_COUNT
){
772 error("in swap_object_headers(): malformed "
773 "load commands (count "
774 "not x86_THREAD_STATE64_COUNT for "
775 "flavor number %lu which is an x86_THREAD_"
776 "STATE64 flavor in %s command %lu)",
778 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
782 cpu64
= (x86_thread_state64_t
*)state
;
783 state
+= sizeof(x86_thread_state64_t
);
785 #endif /* x86_THREAD_STATE64 */
787 error("in swap_object_headers(): malformed "
788 "load commands (unknown "
789 "flavor %u for flavor number %lu in %s command"
790 " %lu can't byte swap it)", flavor
, nflavor
,
791 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
799 if(cputype
== CPU_TYPE_HPPA
){
800 struct hp_pa_integer_thread_state
*cpu
;
801 struct hp_pa_frame_thread_state
*frame
;
802 struct hp_pa_fp_thread_state
*fpu
;
805 p
= (char *)ut
+ ut
->cmdsize
;
807 flavor
= *((uint32_t *)state
);
808 state
+= sizeof(uint32_t);
809 count
= *((uint32_t *)state
);
810 state
+= sizeof(uint32_t);
812 case HPPA_INTEGER_THREAD_STATE
:
813 if(count
!= HPPA_INTEGER_THREAD_STATE_COUNT
){
814 error("in swap_object_headers(): malformed "
815 "load commands (count "
816 "not HPPA_INTEGER_THREAD_STATE_COUNT for "
817 "flavor number %lu which is a HPPA_INTEGER"
818 "_THREAD_STATE flavor in %s command %lu)",
819 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
820 "LC_UNIXTHREAD" : "LC_THREAD", i
);
823 cpu
= (struct hp_pa_integer_thread_state
*)state
;
824 state
+= sizeof(struct hp_pa_integer_thread_state
);
826 case HPPA_FRAME_THREAD_STATE
:
827 if(count
!= HPPA_FRAME_THREAD_STATE_COUNT
){
828 error("in swap_object_headers(): malformed "
829 "load commands (count "
830 "not HPPA_FRAME_THREAD_STATE_COUNT for "
831 "flavor number %lu which is a HPPA_FRAME"
832 "_THREAD_STATE flavor in %s command %lu)",
833 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
834 "LC_UNIXTHREAD" : "LC_THREAD", i
);
837 frame
= (struct hp_pa_frame_thread_state
*)state
;
838 state
+= sizeof(struct hp_pa_frame_thread_state
);
840 case HPPA_FP_THREAD_STATE
:
841 if(count
!= HPPA_FP_THREAD_STATE_COUNT
){
842 error("in swap_object_headers(): malformed "
843 "load commands (count "
844 "not HPPA_FP_THREAD_STATE_COUNT for "
845 "flavor number %lu which is a HPPA_FP"
846 "_THREAD_STATE flavor in %s command %lu)",
847 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
848 "LC_UNIXTHREAD" : "LC_THREAD", i
);
851 fpu
= (struct hp_pa_fp_thread_state
*)state
;
852 state
+= sizeof(struct hp_pa_fp_thread_state
);
855 error("in swap_object_headers(): malformed "
856 "load commands (unknown "
857 "flavor %u for flavor number %lu in %s command"
858 " %lu can't byte swap it)", flavor
, nflavor
,
859 ut
->cmd
== LC_UNIXTHREAD
? "LC_UNIXTHREAD" :
867 if(cputype
== CPU_TYPE_SPARC
) {
868 struct sparc_thread_state_regs
*cpu
;
869 struct sparc_thread_state_fpu
*fpu
;
872 p
= (char *)ut
+ ut
->cmdsize
;
874 flavor
= *((uint32_t *) state
);
875 state
+= sizeof(uint32_t);
876 count
= *((uint32_t *) state
);
877 state
+= sizeof(uint32_t);
879 case SPARC_THREAD_STATE_REGS
:
880 if (count
!= SPARC_THREAD_STATE_REGS_COUNT
) {
881 error("in swap_object_headers(): malformed "
882 "load commands (count "
883 "not SPARC_THREAD_STATE_REGS_COUNT for "
884 "flavor number %lu which is a SPARC_THREAD_"
885 "STATE_REGS flavor in %s command %lu)",
886 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
887 "LC_UNIXTHREAD" : "LC_THREAD", i
);
890 cpu
= (struct sparc_thread_state_regs
*) state
;
891 state
+= sizeof(struct sparc_thread_state_regs
);
893 case SPARC_THREAD_STATE_FPU
:
894 if (count
!= SPARC_THREAD_STATE_FPU_COUNT
) {
895 error("in swap_object_headers(): malformed "
896 "load commands (count "
897 "not SPARC_THREAD_STATE_FPU_COUNT for "
898 "flavor number %lu which is a SPARC_THREAD_"
899 "STATE_FPU flavor in %s command %lu)",
900 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
901 "LC_UNIXTHREAD" : "LC_THREAD", i
);
904 fpu
= (struct sparc_thread_state_fpu
*) state
;
905 state
+= sizeof(struct sparc_thread_state_fpu
);
911 if(cputype
== CPU_TYPE_ARM
){
912 arm_thread_state_t
*cpu
;
915 p
= (char *)ut
+ ut
->cmdsize
;
917 flavor
= *((uint32_t *)state
);
918 state
+= sizeof(uint32_t);
919 count
= *((uint32_t *)state
);
920 state
+= sizeof(uint32_t);
922 case ARM_THREAD_STATE
:
923 if(count
!= ARM_THREAD_STATE_COUNT
){
924 error("in swap_object_headers(): malformed "
925 "load commands (count "
926 "not ARM_THREAD_STATE_COUNT for "
927 "flavor number %lu which is a ARM_THREAD_"
928 "STATE flavor in %s command %lu)",
929 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
930 "LC_UNIXTHREAD" : "LC_THREAD", i
);
933 cpu
= (arm_thread_state_t
*)state
;
934 state
+= sizeof(arm_thread_state_t
);
937 error("in swap_object_headers(): malformed load "
938 "commands (unknown flavor for flavor number "
939 "%lu in %s command %lu can't byte swap it)",
940 nflavor
, ut
->cmd
== LC_UNIXTHREAD
?
941 "LC_UNIXTHREAD" : "LC_THREAD", i
);
948 error("in swap_object_headers(): malformed load commands "
949 "(unknown cputype (%d) and cpusubtype (%d) of object and "
950 "can't byte swap %s command %lu)", cputype
,
951 cpusubtype
, ut
->cmd
== LC_UNIXTHREAD
?
952 "LC_UNIXTHREAD" : "LC_THREAD", i
);
955 id
= (struct ident_command
*)lc
;
956 if((char *)id
+ id
->cmdsize
>
957 (char *)load_commands
+ sizeofcmds
){
958 error("in swap_object_headers(): truncated or malformed "
959 "load commands (cmdsize field of LC_IDENT command %lu "
960 "extends past the end of the load commands)", i
);
966 rc
= (struct routines_command
*)lc
;
967 if(rc
->cmdsize
!= sizeof(struct routines_command
)){
968 error("in swap_object_headers(): malformed load commands ("
969 "LC_ROUTINES command %lu has incorrect cmdsize",
976 rc64
= (struct routines_command_64
*)lc
;
977 if(rc64
->cmdsize
!= sizeof(struct routines_command_64
)){
978 error("in swap_object_headers(): malformed load commands ("
979 "LC_ROUTINES_64 command %lu has incorrect cmdsize",
985 case LC_TWOLEVEL_HINTS
:
986 hints
= (struct twolevel_hints_command
*)lc
;
987 if(hints
->cmdsize
!= sizeof(struct twolevel_hints_command
)){
988 error("in swap_object_headers(): malformed load commands "
989 "(LC_TWOLEVEL_HINTS command %lu has incorrect "
995 case LC_PREBIND_CKSUM
:
996 cs
= (struct prebind_cksum_command
*)lc
;
997 if(cs
->cmdsize
!= sizeof(struct prebind_cksum_command
)){
998 error("in swap_object_headers(): malformed load commands "
999 "(LC_PREBIND_CKSUM command %lu has incorrect cmdsize",
1006 uuid
= (struct uuid_command
*)lc
;
1007 if(uuid
->cmdsize
!= sizeof(struct uuid_command
)){
1008 error("in swap_object_headers(): malformed load commands "
1009 "(LC_UUID command %lu has incorrect cmdsize", i
);
1014 case LC_CODE_SIGNATURE
:
1015 ld
= (struct linkedit_data_command
*)lc
;
1016 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1017 error("in swap_object_headers(): malformed load commands "
1018 "(LC_CODE_SIGNATURE command %lu has incorrect "
1024 case LC_SEGMENT_SPLIT_INFO
:
1025 ld
= (struct linkedit_data_command
*)lc
;
1026 if(ld
->cmdsize
!= sizeof(struct linkedit_data_command
)){
1027 error("in swap_object_headers(): malformed load commands "
1028 "(LC_SEGMENT_SPLIT_INFO command %lu has incorrect "
1035 rpath
= (struct rpath_command
*)lc
;
1036 if(rpath
->cmdsize
< sizeof(struct rpath_command
)){
1037 error("in swap_object_headers(): malformed load commands "
1038 "(LC_RPATH command %lu has too small cmdsize field)",
1042 if(rpath
->path
.offset
>= rpath
->cmdsize
){
1043 error("in swap_object_headers(): truncated or malformed "
1044 "load commands (path.offset field of LC_RPATH "
1045 "command %lu extends past the end of all load "
1051 case LC_ENCRYPTION_INFO
:
1052 ec
= (struct encryption_info_command
*)lc
;
1053 if(ec
->cmdsize
!= sizeof(struct encryption_info_command
)){
1054 error("in swap_object_headers(): malformed load commands "
1055 "(LC_ENCRYPTION_INFO command %lu has incorrect "
1062 case LC_DYLD_INFO_ONLY
:
1063 dc
= (struct dyld_info_command
*)lc
;
1064 if(dc
->cmdsize
!= sizeof(struct dyld_info_command
)){
1065 error("in swap_object_headers(): malformed load commands "
1066 "(LC_DYLD_INFO command %lu has incorrect "
1073 error("in swap_object_headers(): malformed load commands "
1074 "(unknown load command %lu)", i
);
1078 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1079 /* check that next load command does not extends past the end */
1080 if((char *)lc
> (char *)load_commands
+ sizeofcmds
){
1081 error("in swap_object_headers(): truncated or malformed load "
1082 "commands (load command %lu extends past the end of all "
1083 "load commands)", i
+ 1);
1087 /* check for an inconsistent size of the load commands */
1088 if((char *)load_commands
+ sizeofcmds
!= (char *)lc
){
1089 error("in swap_object_headers(): malformed load commands "
1090 "(inconsistent sizeofcmds field in mach header)");
1096 * Now knowing the load commands can be parsed swap them.
1098 target_byte_sex
= get_host_byte_sex() == BIG_ENDIAN_BYTE_SEX
?
1099 LITTLE_ENDIAN_BYTE_SEX
: BIG_ENDIAN_BYTE_SEX
;
1100 for(i
= 0, lc
= load_commands
; i
< ncmds
; i
++){
1104 sg
= (struct segment_command
*)lc
;
1105 s
= (struct section
*)
1106 ((char *)sg
+ sizeof(struct segment_command
));
1107 swap_section(s
, sg
->nsects
, target_byte_sex
);
1108 swap_segment_command(sg
, target_byte_sex
);
1112 sg64
= (struct segment_command_64
*)lc
;
1113 s64
= (struct section_64
*)
1114 ((char *)sg64
+ sizeof(struct segment_command_64
));
1115 swap_section_64(s64
, sg64
->nsects
, target_byte_sex
);
1116 swap_segment_command_64(sg64
, target_byte_sex
);
1120 st
= (struct symtab_command
*)lc
;
1121 swap_symtab_command(st
, target_byte_sex
);
1125 dyst
= (struct dysymtab_command
*)lc
;
1126 swap_dysymtab_command(dyst
, target_byte_sex
);
1130 ss
= (struct symseg_command
*)lc
;
1131 swap_symseg_command(ss
, target_byte_sex
);
1136 fl
= (struct fvmlib_command
*)lc
;
1137 swap_fvmlib_command(fl
, target_byte_sex
);
1142 case LC_LOAD_WEAK_DYLIB
:
1143 case LC_REEXPORT_DYLIB
:
1144 case LC_LAZY_LOAD_DYLIB
:
1145 dl
= (struct dylib_command
*)lc
;
1146 swap_dylib_command(dl
, target_byte_sex
);
1149 case LC_SUB_FRAMEWORK
:
1150 sub
= (struct sub_framework_command
*)lc
;
1151 swap_sub_framework_command(sub
, target_byte_sex
);
1154 case LC_SUB_UMBRELLA
:
1155 usub
= (struct sub_umbrella_command
*)lc
;
1156 swap_sub_umbrella_command(usub
, target_byte_sex
);
1159 case LC_SUB_LIBRARY
:
1160 lsub
= (struct sub_library_command
*)lc
;
1161 swap_sub_library_command(lsub
, target_byte_sex
);
1165 csub
= (struct sub_client_command
*)lc
;
1166 swap_sub_client_command(csub
, target_byte_sex
);
1169 case LC_PREBOUND_DYLIB
:
1170 pbdylib
= (struct prebound_dylib_command
*)lc
;
1171 swap_prebound_dylib_command(pbdylib
, target_byte_sex
);
1174 case LC_ID_DYLINKER
:
1175 case LC_LOAD_DYLINKER
:
1176 dyld
= (struct dylinker_command
*)lc
;
1177 swap_dylinker_command(dyld
, target_byte_sex
);
1182 ut
= (struct thread_command
*)lc
;
1183 state
= (char *)ut
+ sizeof(struct thread_command
);
1184 p
= (char *)ut
+ ut
->cmdsize
;
1185 swap_thread_command(ut
, target_byte_sex
);
1187 if(cputype
== CPU_TYPE_MC680x0
){
1188 struct m68k_thread_state_regs
*cpu
;
1189 struct m68k_thread_state_68882
*fpu
;
1190 struct m68k_thread_state_user_reg
*user_reg
;
1193 flavor
= *((uint32_t *)state
);
1194 *((uint32_t *)state
) = SWAP_INT(flavor
);
1195 state
+= sizeof(uint32_t);
1196 count
= *((uint32_t *)state
);
1197 *((uint32_t *)state
) = SWAP_INT(count
);
1198 state
+= sizeof(uint32_t);
1200 case M68K_THREAD_STATE_REGS
:
1201 cpu
= (struct m68k_thread_state_regs
*)state
;
1202 swap_m68k_thread_state_regs(cpu
, target_byte_sex
);
1203 state
+= sizeof(struct m68k_thread_state_regs
);
1205 case M68K_THREAD_STATE_68882
:
1206 fpu
= (struct m68k_thread_state_68882
*)state
;
1207 swap_m68k_thread_state_68882(fpu
, target_byte_sex
);
1208 state
+= sizeof(struct m68k_thread_state_68882
);
1210 case M68K_THREAD_STATE_USER_REG
:
1212 (struct m68k_thread_state_user_reg
*)state
;
1213 swap_m68k_thread_state_user_reg(user_reg
,
1215 state
+= sizeof(struct m68k_thread_state_user_reg
);
1221 if(cputype
== CPU_TYPE_POWERPC
||
1222 cputype
== CPU_TYPE_VEO
||
1223 cputype
== CPU_TYPE_POWERPC64
){
1224 ppc_thread_state_t
*cpu
;
1225 ppc_thread_state64_t
*cpu64
;
1226 ppc_float_state_t
*fpu
;
1227 ppc_exception_state_t
*except
;
1230 flavor
= *((uint32_t *)state
);
1231 *((uint32_t *)state
) = SWAP_INT(flavor
);
1232 state
+= sizeof(uint32_t);
1233 count
= *((uint32_t *)state
);
1234 *((uint32_t *)state
) = SWAP_INT(count
);
1235 state
+= sizeof(uint32_t);
1237 case PPC_THREAD_STATE
:
1238 cpu
= (ppc_thread_state_t
*)state
;
1239 swap_ppc_thread_state_t(cpu
, target_byte_sex
);
1240 state
+= sizeof(ppc_thread_state_t
);
1242 case PPC_THREAD_STATE64
:
1243 cpu64
= (ppc_thread_state64_t
*)state
;
1244 swap_ppc_thread_state64_t(cpu64
, target_byte_sex
);
1245 state
+= sizeof(ppc_thread_state64_t
);
1247 case PPC_FLOAT_STATE
:
1248 fpu
= (ppc_float_state_t
*)state
;
1249 swap_ppc_float_state_t(fpu
, target_byte_sex
);
1250 state
+= sizeof(ppc_float_state_t
);
1251 case PPC_EXCEPTION_STATE
:
1252 except
= (ppc_exception_state_t
*)state
;
1253 swap_ppc_exception_state_t(except
, target_byte_sex
);
1254 state
+= sizeof(ppc_exception_state_t
);
1260 if(cputype
== CPU_TYPE_MC88000
){
1261 m88k_thread_state_grf_t
*cpu
;
1262 m88k_thread_state_xrf_t
*fpu
;
1263 m88k_thread_state_user_t
*user
;
1264 m88110_thread_state_impl_t
*spu
;
1267 flavor
= *((uint32_t *)state
);
1268 *((uint32_t *)state
) = SWAP_INT(flavor
);
1269 state
+= sizeof(uint32_t);
1270 count
= *((uint32_t *)state
);
1271 *((uint32_t *)state
) = SWAP_INT(count
);
1272 state
+= sizeof(uint32_t);
1274 case M88K_THREAD_STATE_GRF
:
1275 cpu
= (m88k_thread_state_grf_t
*)state
;
1276 swap_m88k_thread_state_grf_t(cpu
,
1278 state
+= sizeof(m88k_thread_state_grf_t
);
1280 case M88K_THREAD_STATE_XRF
:
1281 fpu
= (m88k_thread_state_xrf_t
*)state
;
1282 swap_m88k_thread_state_xrf_t(fpu
,
1284 state
+= sizeof(m88k_thread_state_xrf_t
);
1286 case M88K_THREAD_STATE_USER
:
1287 user
= (m88k_thread_state_user_t
*)state
;
1288 swap_m88k_thread_state_user_t(user
,
1290 state
+= sizeof(m88k_thread_state_user_t
);
1292 case M88110_THREAD_STATE_IMPL
:
1293 spu
= (m88110_thread_state_impl_t
*)state
;
1294 swap_m88110_thread_state_impl_t(spu
,
1296 state
+= sizeof(m88110_thread_state_impl_t
);
1302 if(cputype
== CPU_TYPE_I860
){
1303 struct i860_thread_state_regs
*cpu
;
1306 flavor
= *((uint32_t *)state
);
1307 *((uint32_t *)state
) = SWAP_INT(flavor
);
1308 state
+= sizeof(uint32_t);
1309 count
= *((uint32_t *)state
);
1310 *((uint32_t *)state
) = SWAP_INT(count
);
1311 state
+= sizeof(uint32_t);
1313 case I860_THREAD_STATE_REGS
:
1314 cpu
= (struct i860_thread_state_regs
*)state
;
1315 swap_i860_thread_state_regs(cpu
, target_byte_sex
);
1316 state
+= sizeof(struct i860_thread_state_regs
);
1322 if(cputype
== CPU_TYPE_I386
1323 #ifdef x86_THREAD_STATE64
1324 || cputype
== CPU_TYPE_X86_64
1325 #endif /* x86_THREAD_STATE64 */
1327 i386_thread_state_t
*cpu
;
1328 #ifdef x86_THREAD_STATE64
1329 x86_thread_state64_t
*cpu64
;
1330 #endif /* x86_THREAD_STATE64 */
1331 /* current i386 thread states */
1332 #if i386_THREAD_STATE == 1
1333 struct i386_float_state
*fpu
;
1334 i386_exception_state_t
*exc
;
1335 #endif /* i386_THREAD_STATE == 1 */
1337 /* i386 thread states on older releases */
1338 #if i386_THREAD_STATE == -1
1339 i386_thread_fpstate_t
*fpu
;
1340 i386_thread_exceptstate_t
*exc
;
1341 i386_thread_cthreadstate_t
*user
;
1342 #endif /* i386_THREAD_STATE == -1 */
1345 flavor
= *((uint32_t *)state
);
1346 *((uint32_t *)state
) = SWAP_INT(flavor
);
1347 state
+= sizeof(uint32_t);
1348 count
= *((uint32_t *)state
);
1349 *((uint32_t *)state
) = SWAP_INT(count
);
1350 state
+= sizeof(uint32_t);
1352 case i386_THREAD_STATE
:
1353 /* current i386 thread states */
1354 #if i386_THREAD_STATE == 1
1356 #endif /* i386_THREAD_STATE == 1 */
1357 /* i386 thread states on older releases */
1358 #if i386_THREAD_STATE == -1
1360 #endif /* i386_THREAD_STATE == -1 */
1361 cpu
= (i386_thread_state_t
*)state
;
1362 swap_i386_thread_state(cpu
, target_byte_sex
);
1363 state
+= sizeof(i386_thread_state_t
);
1365 /* current i386 thread states */
1366 #if i386_THREAD_STATE == 1
1367 case i386_FLOAT_STATE
:
1368 fpu
= (struct i386_float_state
*)state
;
1369 swap_i386_float_state(fpu
, target_byte_sex
);
1370 state
+= sizeof(struct i386_float_state
);
1372 case i386_EXCEPTION_STATE
:
1373 exc
= (i386_exception_state_t
*)state
;
1374 swap_i386_exception_state(exc
, target_byte_sex
);
1375 state
+= sizeof(i386_exception_state_t
);
1377 #endif /* i386_THREAD_STATE == 1 */
1379 /* i386 thread states on older releases */
1380 #if i386_THREAD_STATE == -1
1381 case i386_THREAD_FPSTATE
:
1382 fpu
= (i386_thread_fpstate_t
*)state
;
1383 swap_i386_thread_fpstate(fpu
, target_byte_sex
);
1384 state
+= sizeof(i386_thread_fpstate_t
);
1386 case i386_THREAD_EXCEPTSTATE
:
1387 exc
= (i386_thread_exceptstate_t
*)state
;
1388 swap_i386_thread_exceptstate(exc
, target_byte_sex
);
1389 state
+= sizeof(i386_thread_exceptstate_t
);
1391 case i386_THREAD_CTHREADSTATE
:
1392 user
= (i386_thread_cthreadstate_t
*)state
;
1393 swap_i386_thread_cthreadstate(user
,target_byte_sex
);
1394 state
+= sizeof(i386_thread_cthreadstate_t
);
1396 #endif /* i386_THREAD_STATE == -1 */
1397 #ifdef x86_THREAD_STATE64
1398 case x86_THREAD_STATE64
:
1399 cpu64
= (x86_thread_state64_t
*)state
;
1400 swap_x86_thread_state64(cpu64
, target_byte_sex
);
1401 state
+= sizeof(x86_thread_state64_t
);
1403 #endif /* x86_THREAD_STATE64 */
1408 if(cputype
== CPU_TYPE_HPPA
){
1409 struct hp_pa_integer_thread_state
*cpu
;
1410 struct hp_pa_frame_thread_state
*frame
;
1411 struct hp_pa_fp_thread_state
*fpu
;
1414 flavor
= *((uint32_t *)state
);
1415 *((uint32_t *)state
) = SWAP_INT(flavor
);
1416 state
+= sizeof(uint32_t);
1417 count
= *((uint32_t *)state
);
1418 *((uint32_t *)state
) = SWAP_INT(count
);
1419 state
+= sizeof(uint32_t);
1421 case HPPA_INTEGER_THREAD_STATE
:
1422 cpu
= (struct hp_pa_integer_thread_state
*)state
;
1423 swap_hppa_integer_thread_state(cpu
,
1425 state
+= sizeof(struct hp_pa_integer_thread_state
);
1427 case HPPA_FRAME_THREAD_STATE
:
1428 frame
= (struct hp_pa_frame_thread_state
*)state
;
1429 swap_hppa_frame_thread_state(frame
,
1431 state
+= sizeof(struct hp_pa_frame_thread_state
);
1433 case HPPA_FP_THREAD_STATE
:
1434 fpu
= (struct hp_pa_fp_thread_state
*)state
;
1435 swap_hppa_fp_thread_state(fpu
,
1437 state
+= sizeof(struct hp_pa_fp_thread_state
);
1444 if(cputype
== CPU_TYPE_SPARC
) {
1445 struct sparc_thread_state_regs
*cpu
;
1446 struct sparc_thread_state_fpu
*fpu
;
1449 flavor
= *((uint32_t *) state
);
1450 *((uint32_t *) state
) = SWAP_INT(flavor
);
1451 state
+= sizeof(uint32_t);
1452 count
= *((unsigned int *) state
);
1453 *((unsigned int *) state
) = SWAP_INT(count
);
1454 state
+= sizeof(uint32_t);
1456 case SPARC_THREAD_STATE_REGS
:
1457 cpu
= (struct sparc_thread_state_regs
*) state
;
1458 swap_sparc_thread_state_regs(cpu
, target_byte_sex
);
1459 state
+= sizeof(struct sparc_thread_state_regs
);
1461 case SPARC_THREAD_STATE_FPU
:
1462 fpu
= (struct sparc_thread_state_fpu
*) state
;
1463 swap_sparc_thread_state_fpu(fpu
, target_byte_sex
);
1464 state
+= sizeof(struct sparc_thread_state_fpu
);
1470 if(cputype
== CPU_TYPE_ARM
){
1471 arm_thread_state_t
*cpu
;
1474 flavor
= *((uint32_t *)state
);
1475 *((uint32_t *)state
) = SWAP_INT(flavor
);
1476 state
+= sizeof(uint32_t);
1477 count
= *((uint32_t *)state
);
1478 *((uint32_t *)state
) = SWAP_INT(count
);
1479 state
+= sizeof(uint32_t);
1481 case ARM_THREAD_STATE
:
1482 cpu
= (arm_thread_state_t
*)state
;
1483 swap_arm_thread_state_t(cpu
, target_byte_sex
);
1484 state
+= sizeof(arm_thread_state_t
);
1493 id
= (struct ident_command
*)lc
;
1494 swap_ident_command(id
, target_byte_sex
);
1498 rc
= (struct routines_command
*)lc
;
1499 swap_routines_command(rc
, target_byte_sex
);
1502 case LC_ROUTINES_64
:
1503 rc64
= (struct routines_command_64
*)lc
;
1504 swap_routines_command_64(rc64
, target_byte_sex
);
1507 case LC_TWOLEVEL_HINTS
:
1508 hints
= (struct twolevel_hints_command
*)lc
;
1509 swap_twolevel_hints_command(hints
, target_byte_sex
);
1512 case LC_PREBIND_CKSUM
:
1513 cs
= (struct prebind_cksum_command
*)lc
;
1514 swap_prebind_cksum_command(cs
, target_byte_sex
);
1518 uuid
= (struct uuid_command
*)lc
;
1519 swap_uuid_command(uuid
, target_byte_sex
);
1522 case LC_CODE_SIGNATURE
:
1523 case LC_SEGMENT_SPLIT_INFO
:
1524 ld
= (struct linkedit_data_command
*)lc
;
1525 swap_linkedit_data_command(ld
, target_byte_sex
);
1529 rpath
= (struct rpath_command
*)lc
;
1530 swap_rpath_command(rpath
, target_byte_sex
);
1533 case LC_ENCRYPTION_INFO
:
1534 ec
= (struct encryption_info_command
*)lc
;
1535 swap_encryption_command(ec
, target_byte_sex
);
1539 case LC_DYLD_INFO_ONLY
:
1540 dc
= (struct dyld_info_command
*)lc
;
1541 swap_dyld_info_command(dc
, target_byte_sex
);
1545 lc
= (struct load_command
*)((char *)lc
+ l
.cmdsize
);
1548 swap_mach_header(mh
, target_byte_sex
);
1550 swap_mach_header_64(mh64
, target_byte_sex
);