411954 I know how to strip a binary's symbol table of all non-global symbols except for text symbols. I also know how to strip LC_CODE_SIGNATURE load commands once they've been added. Introducing striptease. r=smorgan r=ardissone

This commit is contained in:
mark%moxienet.com 2008-01-22 20:17:59 +00:00
Родитель 65194957b3
Коммит 789d7b60fc
59 изменённых файлов: 19547 добавлений и 48 удалений

Просмотреть файл

@ -0,0 +1,86 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
*
* File: architecture/m88k/reg_help.h
* Author: Mike DeMoney, NeXT Computer, Inc.
*
* This header file defines cpp macros useful for defining
* machine register and doing machine-level operations.
*
* HISTORY
* 23-Jan-91 Mike DeMoney (mike@next.com)
* Created.
*/
#ifndef _ARCH_M88K_REG_HELP_H_
#define _ARCH_M88K_REG_HELP_H_
#import <architecture/nrw/reg_help.h>
/* Stack pointer must always be a multiple of 16 */
#define STACK_INCR 16
#define ROUND_FRAME(x) ((((unsigned)(x)) + STACK_INCR - 1) & ~(STACK_INCR-1))
/*
* REG_PAIR_DEF -- define a register pair
* Register pairs are appropriately aligned to allow access via
* ld.d and st.d.
*
* Usage:
* struct foo {
* REG_PAIR_DEF(
* bar_t *, barp,
* afu_t, afu
* );
* };
*
* Access to individual entries of the pair is via the REG_PAIR
* macro (below).
*/
#define REG_PAIR_DEF(type0, name0, type1, name1) \
struct { \
type0 name0 __attribute__(( aligned(8) )); \
type1 name1; \
} name0##_##name1
/*
* REG_PAIR -- Macro to define names for accessing individual registers
* of register pairs.
*
* Usage:
* arg0 is first element of pair
* arg1 is second element of pair
* arg2 is desired element of pair
* eg:
* #define foo_barp REG_PAIR(barp, afu, afu)
*/
#define REG_PAIR(name0, name1, the_name) \
name0##_##name1.the_name
#endif /* _ARCH_M88K_REG_HELP_H_ */

Просмотреть файл

@ -0,0 +1,68 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
*
* File: architecture/nrw/reg_help.h
* Author: Mike DeMoney, NeXT Computer, Inc.
*
* This header file defines cpp macros useful for defining
* machine register and doing machine-level operations.
*
* HISTORY
* 23-Jan-91 Mike DeMoney (mike@next.com)
* Created.
*/
#ifndef _NRW_REG_HELP_H_
#define _NRW_REG_HELP_H_
/* Bitfield definition aid */
#define BITS_WIDTH(msb, lsb) ((msb)-(lsb)+1)
#define BIT_WIDTH(pos) (1) /* mostly to record the position */
/* Mask creation */
#define MKMASK(width, offset) (((unsigned)-1)>>(32-(width))<<(offset))
#define BITSMASK(msb, lsb) MKMASK(BITS_WIDTH(msb, lsb), lsb & 0x1f)
#define BITMASK(pos) MKMASK(BIT_WIDTH(pos), pos & 0x1f)
/* Register addresses */
#if __ASSEMBLER__
# define REG_ADDR(type, addr) (addr)
#else /* __ASSEMBLER__ */
# define REG_ADDR(type, addr) (*(volatile type *)(addr))
#endif /* __ASSEMBLER__ */
/* Cast a register to be an unsigned */
#define CONTENTS(foo) (*(unsigned *) &(foo))
/* STRINGIFY -- perform all possible substitutions, then stringify */
#define __STR(x) #x /* just a helper macro */
#define STRINGIFY(x) __STR(x)
#endif /* _NRW_REG_HELP_H_ */

Просмотреть файл

@ -0,0 +1,327 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* @(#)reg.h 1.16 92/04/28 SMI */
/*
* Copyright (c) 1985 by Sun Microsystems, Inc.
*/
#ifndef _sparc_reg_h
#define _sparc_reg_h
/*
* Location of the users' stored
* registers relative to R0.
* Usage is u.u_ar0[XX].
*/
#define PSR (0)
#define PC (1)
#define nPC (2)
#define SPARC_Y (3)
#define G1 (4)
#define G2 (5)
#define G3 (6)
#define G4 (7)
#define G5 (8)
#define G6 (9)
#define G7 (10)
#define O0 (11)
#define O1 (12)
#define O2 (13)
#define O3 (14)
#define O4 (15)
#define O5 (16)
#define O6 (17)
#define O7 (18)
/* the following defines are for portability */
#define PS PSR
#define SP O6
#define R0 O0
#define R1 O1
/*
* And now for something completely the same...
*/
#ifndef __ASSEMBLER__
struct regs {
int r_psr; /* processor status register */
int r_pc; /* program counter */
int r_npc; /* next program counter */
int r_y; /* the y register */
int r_g1; /* user global regs */
int r_g2;
int r_g3;
int r_g4;
int r_g5;
int r_g6;
int r_g7;
int r_o0;
int r_o1;
int r_o2;
int r_o3;
int r_o4;
int r_o5;
int r_o6;
int r_o7;
};
#define r_ps r_psr /* for portablility */
#define r_r0 r_o0
#define r_sp r_o6
#endif /* !__ASSEMBLER__ */
/*
* Floating point definitions.
*/
#define FPU /* we have an external float unit */
#ifndef __ASSEMBLER__
#define FQ_DEPTH 16 /* maximum instuctions in FQ */
/*
* struct fpu_status is the floating point processor state
* struct fpu is the sum total of all possible floating point state
* which includes the state of external floating point hardware,
* fpa registers, etc..., if it exists.
*/
struct fpq {
unsigned long *addr; /* address */
unsigned long instr; /* instruction */
};
struct fq {
union { /* FPU inst/addr queue */
double whole;
struct fpq fpq;
} FQu;
};
#define FPU_REGS_TYPE unsigned
#define FPU_FSR_TYPE unsigned
struct fpu {
union { /* FPU floating point regs */
FPU_REGS_TYPE Fpu_regs[32]; /* 32 singles */
double Fpu_dregs[16]; /* 16 doubles */
} fpu_fr;
FPU_FSR_TYPE Fpu_fsr; /* FPU status register */
unsigned Fpu_flags; /* control flags */
unsigned Fpu_extra; /* extra word */
unsigned Fpu_qcnt; /* count of valid entries in fps_q */
struct fq Fpu_q[FQ_DEPTH]; /* FPU instruction address queue */
};
#define fpu_regs fpu_fr.Fpu_regs
#define fpu_dregs fpu_fr.Fpu_dregs
#define fpu_fsr Fpu_fsr
#define fpu_flags Fpu_flags
#define fpu_extra Fpu_extra
#define fpu_q Fpu_q
#define fpu_qcnt Fpu_qcnt
#endif /* !__ASSEMBLER__ */
/*
* Definition of bits in the Sun-4 FSR (Floating-point Status Register)
* ________________________________________________________________________
* | RD | RP | TEM | NS | res | vers | FTT | QNE | PR | FCC | AEXC | CEXC |
* |-----|---- |-----|----|-----|------|-----|-----|----|-----|------|------|
* 31 30 29 28 27 23 22 21 20 19 17 16 14 13 12 11 10 9 5 4 0
*/
#define FSR_CEXC 0x0000001f /* Current Exception */
#define FSR_AEXC 0x000003e0 /* ieee accrued exceptions */
#define FSR_FCC 0x00000c00 /* Floating-point Condition Codes */
#define FSR_PR 0x00001000 /* Partial Remainder */
#define FSR_QNE 0x00002000 /* Queue not empty */
#define FSR_FTT 0x0001c000 /* Floating-point Trap Type */
#define FSR_VERS 0x000e0000 /* version field */
#define FSR_RESV 0x00300000 /* reserved */
#define FSR_NS 0x00400000 /* non-standard fp */
#define FSR_TEM 0x0f800000 /* ieee Trap Enable Mask */
#define FSR_RP 0x30000000 /* Rounding Precision */
#define FSR_RD 0xc0000000 /* Rounding Direction */
#define FSR_VERS_SHIFT (17) /* amount to shift version field */
/*
* Definition of CEXC (Current EXCeption) bit field of fsr
*/
#define FSR_CEXC_NX 0x00000001 /* inexact */
#define FSR_CEXC_DZ 0x00000002 /* divide-by-zero */
#define FSR_CEXC_UF 0x00000004 /* underflow */.
#define FSR_CEXC_OF 0x00000008 /* overflow */
#define FSR_CEXC_NV 0x00000010 /* invalid */
/*
* Definition of AEXC (Accrued EXCeption) bit field of fsr
*/
#define FSR_AEXC_NX (0x1 << 5) /* inexact */
#define FSR_AEXC_DZ (0x2 << 5) /* divide-by-zero */
#define FSR_AEXC_UF (0x4 << 5) /* underflow */.
#define FSR_AEXC_OF (0x8 << 5) /* overflow */
#define FSR_AEXC_NV (0x10 << 5) /* invalid */
/*
* Defintion of FTT (Floating-point Trap Type) field within the FSR
*/
#define FTT_NONE 0 /* no excepitons */
#define FTT_IEEE 1 /* IEEE exception */
#define FTT_UNFIN 2 /* unfinished fpop */
#define FTT_UNIMP 3 /* unimplemented fpop */
#define FTT_SEQ 4 /* sequence error */
#define FTT_ALIGN 5 /* alignment, by software convention */
#define FTT_DFAULT 6 /* data fault, by software convention */
#define FSR_FTT_SHIFT 14 /* shift needed to justfy ftt field */
#define FSR_FTT_IEEE (FTT_IEEE << FSR_FTT_SHIFT)
#define FSR_FTT_UNFIN (FTT_UNFIN << FSR_FTT_SHIFT)
#define FSR_FTT_UNIMP (FTT_UNIMP << FSR_FTT_SHIFT)
#define FSR_FTT_SEQ (FTT_SEQ << FSR_FTT_SHIFT)
#define FSR_FTT_ALIGN (FTT_ALIGN << FSR_FTT_SHIFT)
#define FSR_FTT_DFAULT (FTT_DFAULT << FSR_FTT_SHIFT)
/*
* Values of VERS (version) field within the FSR
* NOTE: these values are overloaded; the cpu type must be used to
* further discriminate amongst these. For that reason, no #defines are
* provided.
*
* Version cpu = 21-22, 51-54 cpu = 23-24, 55-57
* 0 Weitek 1164/5 (FAB 1-4) TI 8847
* 1 Weitek 1164/5 (FAB 5-6) LSI L64814
* 2 TI 8847 TI TMS390C602A
* 3 Weitek 3170 Weitek 3171
* 4 Meiko ?
* 5 ? ?
* 6 ? ?
* 7 No FP Hardware No FP Hardware
*/
/*
* Definition of TEM (Trap Enable Mask) bit field of fsr
*/
#define FSR_TEM_NX (0x1 << 23) /* inexact */
#define FSR_TEM_DZ (0x2 << 23) /* divide-by-zero */
#define FSR_TEM_UF (0x4 << 23) /* underflow */.
#define FSR_TEM_OF (0x8 << 23) /* overflow */
#define FSR_TEM_NV (0x10 << 23) /* invalid */
/*
* Definition of RP (Rounding Precision) field of fsr
*/
#define RP_DBLEXT 0 /* double-extended */
#define RP_SINGLE 1 /* single */
#define RP_DOUBLE 2 /* double */
#define RP_RESERVED 3 /* unused and reserved */
/*
* Defintion of RD (Rounding Direction) field of fsr
*/
#define RD_NEAR 0 /* nearest or even if tie */
#define RD_ZER0 1 /* to zero */
#define RD_POSINF 2 /* positive infinity */
#define RD_NEGINF 3 /* negative infinity */
/*
* Definition of the FP enable flags of the pcb struct
* Normal operation, all flags are zero
*/
#define FP_UNINITIALIZED 1
#define FP_STARTSIG 2
#define FP_DISABLE 4
#define FP_ENABLE 8
#ifndef __ASSEMBLER__
/*
* How a register window looks on the stack.
*/
struct rwindow {
int rw_local[8]; /* locals */
int rw_in[8]; /* ins */
};
#define rw_fp rw_in[6] /* frame pointer */
#define rw_rtn rw_in[7] /* return address */
#endif /* !__ASSEMBLER__ */
/*
* Definition of bits in the Sun-4 PSR (Processor Status Register)
* ____________________________________________________________________
* | IMPL | VER | ICC | res | EC | EF | PIL | S | PS | ET | CWP |
* |-----------|-----|------|-----|----|----|-------|---|----|----|-----|
* 31 28 27 24 23 20 19 14 13 12 11 8 7 6 5 4 0
*/
struct p_status {
union {
unsigned int psr;
struct {
unsigned int
impl:4,
ver:4,
icc:4,
reserved:6,
ec:1,
ef:1,
pil:4,
s:1,
ps:1,
et:1,
cwp:5;
} psr_bits;
} PSRREG;
};
struct f_status {
union {
FPU_FSR_TYPE Fpu_fsr; /* FPU status register */
struct {
unsigned int
rd:2,
rp:2,
tem:5,
res:6,
ftt:3,
qne:1,
pr:1,
fcc:2,
aexc:5,
cexc:5;
} Fpu_fsr_bits;
} FPUREG;
};
#endif /*!_sparc_reg_h*/

Просмотреть файл

@ -0,0 +1,327 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACH_O_DYLD_H_
#define _MACH_O_DYLD_H_
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#include <mach-o/loader.h>
#include <AvailabilityMacros.h>
#ifndef AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
#define AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER
#endif
#ifndef ENUM_DYLD_BOOL
#define ENUM_DYLD_BOOL
#undef FALSE
#undef TRUE
enum DYLD_BOOL {
FALSE,
TRUE
};
#endif /* ENUM_DYLD_BOOL */
/*
* The high level NS... API.
*/
/* Object file image API */
typedef enum {
NSObjectFileImageFailure, /* for this a message is printed on stderr */
NSObjectFileImageSuccess,
NSObjectFileImageInappropriateFile,
NSObjectFileImageArch,
NSObjectFileImageFormat, /* for this a message is printed on stderr */
NSObjectFileImageAccess
} NSObjectFileImageReturnCode;
typedef void * NSObjectFileImage;
/* limited implementation, only MH_BUNDLE files can be used */
extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromFile(
const char *pathName,
NSObjectFileImage *objectFileImage);
extern NSObjectFileImageReturnCode NSCreateCoreFileImageFromFile(
const char *pathName,
NSObjectFileImage *objectFileImage);
/* not yet implemented */
extern NSObjectFileImageReturnCode NSCreateObjectFileImageFromMemory(
void *address,
unsigned long size,
NSObjectFileImage *objectFileImage);
extern enum DYLD_BOOL NSDestroyObjectFileImage(
NSObjectFileImage objectFileImage);
/*
* API on NSObjectFileImage's for:
* "for Each Symbol Definition In Object File Image" (for Dynamic Bundles)
* and the same thing for references
*/
extern unsigned long NSSymbolDefinitionCountInObjectFileImage(
NSObjectFileImage objectFileImage);
extern const char * NSSymbolDefinitionNameInObjectFileImage(
NSObjectFileImage objectFileImage,
unsigned long ordinal);
extern unsigned long NSSymbolReferenceCountInObjectFileImage(
NSObjectFileImage objectFileImage);
extern const char * NSSymbolReferenceNameInObjectFileImage(
NSObjectFileImage objectFileImage,
unsigned long ordinal,
enum DYLD_BOOL *tentative_definition); /* can be NULL */
/*
* API on NSObjectFileImage:
* "does Object File Image define symbol name X" (using sorted symbol table)
* and a way to get the named objective-C section
*/
extern enum DYLD_BOOL NSIsSymbolDefinedInObjectFileImage(
NSObjectFileImage objectFileImage,
const char *symbolName);
extern void * NSGetSectionDataInObjectFileImage(
NSObjectFileImage objectFileImage,
const char *segmentName,
const char *sectionName,
unsigned long *size); /* can be NULL */
/* SPI first appeared in Mac OS X 10.3 */
extern enum DYLD_BOOL NSHasModInitObjectFileImage(
NSObjectFileImage objectFileImage)
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
/* module API */
typedef void * NSModule;
extern const char * NSNameOfModule(
NSModule m);
extern const char * NSLibraryNameForModule(
NSModule m);
/* limited implementation, only MH_BUNDLE files can be linked */
extern NSModule NSLinkModule(
NSObjectFileImage objectFileImage,
const char *moduleName,
unsigned long options);
#define NSLINKMODULE_OPTION_NONE 0x0
#define NSLINKMODULE_OPTION_BINDNOW 0x1
#define NSLINKMODULE_OPTION_PRIVATE 0x2
#define NSLINKMODULE_OPTION_RETURN_ON_ERROR 0x4
#define NSLINKMODULE_OPTION_DONT_CALL_MOD_INIT_ROUTINES 0x8
#define NSLINKMODULE_OPTION_TRAILING_PHYS_NAME 0x10
/* limited implementation, only modules loaded with NSLinkModule() can be
unlinked */
extern enum DYLD_BOOL NSUnLinkModule(
NSModule module,
unsigned long options);
#define NSUNLINKMODULE_OPTION_NONE 0x0
#define NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED 0x1
#define NSUNLINKMODULE_OPTION_RESET_LAZY_REFERENCES 0x2
/* not yet implemented */
extern NSModule NSReplaceModule(
NSModule moduleToReplace,
NSObjectFileImage newObjectFileImage,
unsigned long options);
/* symbol API */
typedef void * NSSymbol;
extern enum DYLD_BOOL NSIsSymbolNameDefined(
const char *symbolName);
extern enum DYLD_BOOL NSIsSymbolNameDefinedWithHint(
const char *symbolName,
const char *libraryNameHint);
extern enum DYLD_BOOL NSIsSymbolNameDefinedInImage(
const struct mach_header *image,
const char *symbolName);
extern NSSymbol NSLookupAndBindSymbol(
const char *symbolName);
extern NSSymbol NSLookupAndBindSymbolWithHint(
const char *symbolName,
const char *libraryNameHint);
extern NSSymbol NSLookupSymbolInModule(
NSModule module,
const char *symbolName);
extern NSSymbol NSLookupSymbolInImage(
const struct mach_header *image,
const char *symbolName,
unsigned long options);
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND 0x0
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_NOW 0x1
#define NSLOOKUPSYMBOLINIMAGE_OPTION_BIND_FULLY 0x2
#define NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR 0x4
extern const char * NSNameOfSymbol(
NSSymbol symbol);
extern void * NSAddressOfSymbol(
NSSymbol symbol);
extern NSModule NSModuleForSymbol(
NSSymbol symbol);
/* error handling API */
typedef enum {
NSLinkEditFileAccessError,
NSLinkEditFileFormatError,
NSLinkEditMachResourceError,
NSLinkEditUnixResourceError,
NSLinkEditOtherError,
NSLinkEditWarningError,
NSLinkEditMultiplyDefinedError,
NSLinkEditUndefinedError
} NSLinkEditErrors;
/*
* For the NSLinkEditErrors value NSLinkEditOtherError these are the values
* passed to the link edit error handler as the errorNumber (what would be an
* errno value for NSLinkEditUnixResourceError or a kern_return_t value for
* NSLinkEditMachResourceError).
*/
typedef enum {
NSOtherErrorRelocation,
NSOtherErrorLazyBind,
NSOtherErrorIndrLoop,
NSOtherErrorLazyInit,
NSOtherErrorInvalidArgs
} NSOtherErrorNumbers;
extern void NSLinkEditError(
NSLinkEditErrors *c,
int *errorNumber,
const char **fileName,
const char **errorString);
typedef struct {
void (*undefined)(const char *symbolName);
NSModule (*multiple)(NSSymbol s, NSModule oldModule, NSModule newModule);
void (*linkEdit)(NSLinkEditErrors errorClass, int errorNumber,
const char *fileName, const char *errorString);
} NSLinkEditErrorHandlers;
extern void NSInstallLinkEditErrorHandlers(
NSLinkEditErrorHandlers *handlers);
/* other API */
extern enum DYLD_BOOL NSAddLibrary(
const char *pathName);
extern enum DYLD_BOOL NSAddLibraryWithSearching(
const char *pathName);
extern const struct mach_header * NSAddImage(
const char *image_name,
unsigned long options);
#define NSADDIMAGE_OPTION_NONE 0x0
#define NSADDIMAGE_OPTION_RETURN_ON_ERROR 0x1
#define NSADDIMAGE_OPTION_WITH_SEARCHING 0x2
#define NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED 0x4
#define NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME 0x8
extern long NSVersionOfRunTimeLibrary(
const char *libraryName);
extern long NSVersionOfLinkTimeLibrary(
const char *libraryName);
extern int _NSGetExecutablePath( /* SPI first appeared in Mac OS X 10.2 */
char *buf,
unsigned long *bufsize);
/*
* The low level _dyld_... API.
* (used by the objective-C runtime primarily)
*/
extern unsigned long _dyld_present(
void);
extern unsigned long _dyld_image_count(
void);
#ifdef __LP64__
extern struct mach_header_64 * _dyld_get_image_header(
uint32_t image_index);
#else /* !defined(__LP64__) */
extern struct mach_header * _dyld_get_image_header(
unsigned long image_index);
#endif /* !defined(__LP64__) */
extern unsigned long _dyld_get_image_vmaddr_slide(
unsigned long image_index);
extern char * _dyld_get_image_name(
unsigned long image_index);
extern void _dyld_register_func_for_add_image(
void (*func)(struct mach_header *mh, unsigned long vmaddr_slide));
extern void _dyld_register_func_for_remove_image(
void (*func)(struct mach_header *mh, unsigned long vmaddr_slide));
extern void _dyld_register_func_for_link_module(
void (*func)(NSModule module));
/* not yet implemented */
extern void _dyld_register_func_for_unlink_module(
void (*func)(NSModule module));
/* not yet implemented */
extern void _dyld_register_func_for_replace_module(
void (*func)(NSModule oldmodule, NSModule newmodule));
extern void _dyld_get_objc_module_sect_for_module(
NSModule module,
void **objc_module,
unsigned long *size);
extern void _dyld_bind_objc_module(
void *objc_module);
extern enum DYLD_BOOL _dyld_bind_fully_image_containing_address(
unsigned long *address);
extern enum DYLD_BOOL _dyld_image_containing_address(
unsigned long address);
/* SPI first appeared in Mac OS X 10.3 */
extern struct mach_header * _dyld_get_image_header_containing_address(
unsigned long address)
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
extern void _dyld_moninit(
void (*monaddition)(char *lowpc, char *highpc));
extern enum DYLD_BOOL _dyld_launched_prebound(
void);
/* SPI first appeared in Mac OS X 10.3 */
extern enum DYLD_BOOL _dyld_all_twolevel_modules_prebound(
void)
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
extern void _dyld_lookup_and_bind(
const char *symbol_name,
unsigned long *address,
void **module);
extern void _dyld_lookup_and_bind_with_hint(
const char *symbol_name,
const char *library_name_hint,
unsigned long *address,
void **module);
extern void _dyld_lookup_and_bind_objc(
const char *symbol_name,
unsigned long *address,
void **module);
extern void _dyld_lookup_and_bind_fully(
const char *symbol_name,
unsigned long *address,
void **module);
__private_extern__ int _dyld_func_lookup(
const char *dyld_func_name,
unsigned long *address);
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* _MACH_O_DYLD_H_ */

Просмотреть файл

@ -0,0 +1,64 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACH_O_FAT_H_
#define _MACH_O_FAT_H_
/*
* This header file describes the structures of the file format for "fat"
* architecture specific file (wrapper design). At the begining of the file
* there is one fat_header structure followed by a number of fat_arch
* structures. For each architecture in the file, specified by a pair of
* cputype and cpusubtype, the fat_header describes the file offset, file
* size and alignment in the file of the architecture specific member.
* The padded bytes in the file to place each member on it's specific alignment
* are defined to be read as zeros and can be left as "holes" if the file system
* can support them as long as they read as zeros.
*
* All structures defined here are always written and read to/from disk
* in big-endian order.
*/
/*
* <mach/machine.h> is needed here for the cpu_type_t and cpu_subtype_t types
* and contains the constants for the possible values of these types.
*/
#include <stdint.h>
#include <mach/machine.h>
#include <architecture/byte_order.h>
#define FAT_MAGIC 0xcafebabe
#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
struct fat_header {
uint32_t magic; /* FAT_MAGIC */
uint32_t nfat_arch; /* number of structs that follow */
};
struct fat_arch {
cpu_type_t cputype; /* cpu specifier (int) */
cpu_subtype_t cpusubtype; /* machine specifier (int) */
uint32_t offset; /* file offset to this object file */
uint32_t size; /* size of this object file */
uint32_t align; /* alignment as a power of 2 */
};
#endif /* _MACH_O_FAT_H_ */

Просмотреть файл

@ -0,0 +1,107 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* reloc.h - assemble for HP-PA */
/* Defines machine specific relocation entries */
#ifndef HPPA_RELOC_INCLUDED
#define HPPA_RELOC_INCLUDED
/*
* Relocation types used in the hppa implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* in <mach-o/reloc.h> and their r_type is HPPA_RELOC_VANILLA. The rest of the
* relocation types are for instructions. Since they are for instructions the
* r_address field indicates the 32 bit instruction that the relocation is to
* be preformed on. The field r_pcrel is set only for the HPPA_RELOC_BR17.
* And r_length is set to long for all non-RELOC_VANILLA r_types.
*/
enum reloc_type_hppa
{
HPPA_RELOC_VANILLA, /* generic relocation as discribed in <mach-o/reloc.h>*/
HPPA_RELOC_PAIR, /* the second relocation entry of a pair */
HPPA_RELOC_HI21, /* a PAIR follows with the low part */
HPPA_RELOC_LO14, /* a PAIR follows with the high part */
HPPA_RELOC_BR17, /* 17 bit branch displacement (to a word address)
a PAIR follows with the high part */
HPPA_RELOC_BL17, /* a bl instruction (overlow causes an error) */
HPPA_RELOC_JBSR, /* a bl instruction that is targeted at a long branch
stub, a PAIR follows with the high part */
HPPA_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_HI21_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_LO14_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_PB_LA_PTR /* prebound lazy pointer */
};
/*
* For the HI and LO relocation types the two parts of the relocated expression
* (symbol + offset) are calculated as follows:
*
* rounded = round(offset, 0x2000);
* left21 = (symbol + rounded) & 0xfffff800;
* right14 = ((symbol + rounded) & 0x000007ff) + (offset - rounded);
*
* This allows the left part to be shared between references with different
* offsets as long as the rounded offsets are the same.
*
* The HPPA_RELOC_BR17 r_type also uses the above calculation and the right14
* bits, sign extened to fill the displacement, and converted to a word
* displacement by droping the low bits (after checking they are zero).
*/
/*
* For relocation types that use pairs the part of the relocated expression that
* is not stored in the instruction is stored in the r_address feild of the
* PAIR's entry.
*
* All low parts are stored as sign extened byte addressed values in the PAIR's
* r_address field as 32 bit values. This allows the HI21 not to have to know
* which type of low it is used with.
*
* The high parts are left justified 21 bit values zero filled to 32 bits and
* stored in the PAIR's r_address field.
*/
/*
* The instructions that use the non-RELOC_VANILLA r_types are and the r_types
* they use are as follows:
* instructions r_type
*
* LDIL,ADDIL HPPA_RELOC_HI21
* LDx, STx, LDO HPPA_RELOC_LO14
* BE, BLE HPPA_RELOC_BR17
* BL HPPA_RELOC_BL17
*
* For the HPPA_RELOC_JBSR the BL instruction must be targeted at a long branch
* stub that can be reached with 17 bits of signed word displacement. Also the
* stub must be in the same block as the BL instruction so that scattered
* loading done by the link editor will not move them apart. For example in
* assembly code:
* jbsr foo,%r2,L1 ; creates a bl inst with a HPPA_RELOC_JBSR
* ; relocation entry for the symbol foo and the
* ; instruction is targeted to L1
* ...
* L1: ldil L'foo,%r1 ; a HPPA_RELOC_HI21 entry for symbol foo
* ble,n R'foo(%sr4,%r1) ; a HPPA_RELOC_BR17 entry for symbol foo
*/
#endif /* HPPA_RELOC_INCLUDED */

Просмотреть файл

@ -0,0 +1,78 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Relocation types used in the I860 implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* above and their r_type is RELOC_VANILLA. The rest of the relocation types
* are for instructions. Since they are for instructions the r_address field
* indicates the 32 bit instruction that the relocation is to be preformed on.
* The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types
* except RELOC_SPLIT0 as discribed below.
*/
enum reloc_type_i860
{
I860_RELOC_VANILLA, /* generic relocation as discribed above */
I860_RELOC_PAIR, /* Only follows a I860_RELOC_HIGH or a
* I860_RELOC_HIGHADJ and only the r_address has any
* meaning.
*/
I860_RELOC_HIGH, /* The low 16 bits of the instruction contains the high
* 16 bits of the item being refered to. This
* relocation type must be followed by a I860_RELOC_PAIR
* relocation type. The low 16 bits of the item being
* refered to is stored in the r_address of the
* I860_RELOC_PAIR entry.
*/
I860_RELOC_LOW0, /* For all of these the low 16 bits of the instruction*/
I860_RELOC_LOW1, /* (minus the low 0, 1, 2, 3, or 4 bits) contain the */
I860_RELOC_LOW2, /* low 16 bits of the item being refered to. The bits*/
I860_RELOC_LOW3, /* of the reference that are missing are 0 and the */
I860_RELOC_LOW4, /* bits in the instruction are part of the encoding of*/
/* instruction. The resulting low 16 bits of the item*/
/* being refered to is sign extended to 32 bits. */
I860_RELOC_SPLIT0, /* For all of these the bits 20-14 and bits 10-0 of */
I860_RELOC_SPLIT1, /* the instruction (minus the low 0, 1 or 2 bits) */
I860_RELOC_SPLIT2, /* contain the low 16 bits of the item to being */
/* refered to. The bits of the reference that are */
/* missing are 0 and the bits of the instruction are */
/* part of the encoding of the instruction. The */
/* resulting low 16 bits of the item being relocated */
/* is sign extened to 32 bits. A special case of the */
/* I860_RELOC_SPLIT0 is when r_pcrel is non-zero (for */
/* branch displacements). In this case the 16 bits */
/* from the instruction is a 32 bit word displacement.*/
I860_RELOC_HIGHADJ, /* Same as the RELOC_HIGH except the low 16 bits and the
* high 16 bits are added together with the low 16 bits
* sign extened first. This means if bit 15 of the low
* 16 bits is set the high 16 bits stored in the
* instruction will be adjusted.
*/
I860_RELOC_BRADDR, /* The low 26 bits of the instruction is a 32 bit
* word displacement from the pc to the item to being
* refered to.
*/
I860_RELOC_SECTDIFF /* a PAIR follows with subtract symbol value */
};

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,107 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* reloc.h - assemble for HP-PA */
/* Defines machine specific relocation entries */
#ifndef HPPA_RELOC_INCLUDED
#define HPPA_RELOC_INCLUDED
/*
* Relocation types used in the hppa implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* in <mach-o/reloc.h> and their r_type is HPPA_RELOC_VANILLA. The rest of the
* relocation types are for instructions. Since they are for instructions the
* r_address field indicates the 32 bit instruction that the relocation is to
* be preformed on. The field r_pcrel is set only for the HPPA_RELOC_BR17.
* And r_length is set to long for all non-RELOC_VANILLA r_types.
*/
enum reloc_type_hppa
{
HPPA_RELOC_VANILLA, /* generic relocation as discribed in <mach-o/reloc.h>*/
HPPA_RELOC_PAIR, /* the second relocation entry of a pair */
HPPA_RELOC_HI21, /* a PAIR follows with the low part */
HPPA_RELOC_LO14, /* a PAIR follows with the high part */
HPPA_RELOC_BR17, /* 17 bit branch displacement (to a word address)
a PAIR follows with the high part */
HPPA_RELOC_BL17, /* a bl instruction (overlow causes an error) */
HPPA_RELOC_JBSR, /* a bl instruction that is targeted at a long branch
stub, a PAIR follows with the high part */
HPPA_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_HI21_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_LO14_SECTDIFF, /* a PAIR follows with subtract symbol value */
HPPA_RELOC_PB_LA_PTR /* prebound lazy pointer */
};
/*
* For the HI and LO relocation types the two parts of the relocated expression
* (symbol + offset) are calculated as follows:
*
* rounded = round(offset, 0x2000);
* left21 = (symbol + rounded) & 0xfffff800;
* right14 = ((symbol + rounded) & 0x000007ff) + (offset - rounded);
*
* This allows the left part to be shared between references with different
* offsets as long as the rounded offsets are the same.
*
* The HPPA_RELOC_BR17 r_type also uses the above calculation and the right14
* bits, sign extened to fill the displacement, and converted to a word
* displacement by droping the low bits (after checking they are zero).
*/
/*
* For relocation types that use pairs the part of the relocated expression that
* is not stored in the instruction is stored in the r_address feild of the
* PAIR's entry.
*
* All low parts are stored as sign extened byte addressed values in the PAIR's
* r_address field as 32 bit values. This allows the HI21 not to have to know
* which type of low it is used with.
*
* The high parts are left justified 21 bit values zero filled to 32 bits and
* stored in the PAIR's r_address field.
*/
/*
* The instructions that use the non-RELOC_VANILLA r_types are and the r_types
* they use are as follows:
* instructions r_type
*
* LDIL,ADDIL HPPA_RELOC_HI21
* LDx, STx, LDO HPPA_RELOC_LO14
* BE, BLE HPPA_RELOC_BR17
* BL HPPA_RELOC_BL17
*
* For the HPPA_RELOC_JBSR the BL instruction must be targeted at a long branch
* stub that can be reached with 17 bits of signed word displacement. Also the
* stub must be in the same block as the BL instruction so that scattered
* loading done by the link editor will not move them apart. For example in
* assembly code:
* jbsr foo,%r2,L1 ; creates a bl inst with a HPPA_RELOC_JBSR
* ; relocation entry for the symbol foo and the
* ; instruction is targeted to L1
* ...
* L1: ldil L'foo,%r1 ; a HPPA_RELOC_HI21 entry for symbol foo
* ble,n R'foo(%sr4,%r1) ; a HPPA_RELOC_BR17 entry for symbol foo
*/
#endif /* HPPA_RELOC_INCLUDED */

Просмотреть файл

@ -0,0 +1,41 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Relocation types used in the m88k implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* above and their r_type is RELOC_VANILLA. The rest of the relocation types
* are for instructions. Since they are for instructions the r_address field
* indicates the 32 bit instruction that the relocation is to be preformed on.
* The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types.
*/
enum reloc_type_m88k
{
M88K_RELOC_VANILLA, /* generic relocation as discribed above */
M88K_RELOC_PAIR, /* the second relocation entry of a pair */
M88K_RELOC_PC16,
M88K_RELOC_PC26,
M88K_RELOC_HI16, /* a PAIR follows with the low half */
M88K_RELOC_LO16, /* a PAIR follows with the high half */
M88K_RELOC_SECTDIFF,/* a PAIR follows with subtract symbol value */
M88K_RELOC_PB_LA_PTR/* prebound lazy pointer */
};

Просмотреть файл

@ -0,0 +1,290 @@
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACHO_NLIST_H_
#define _MACHO_NLIST_H_
/* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nlist.h 8.2 (Berkeley) 1/21/94
*/
#include <stdint.h>
/*
* Format of a symbol table entry of a Mach-O file for 32-bit architectures.
* Modified from the BSD format. The modifications from the original format
* were changing n_other (an unused field) to n_sect and the addition of the
* N_SECT type. These modifications are required to support symbols in a larger
* number of sections not just the three sections (text, data and bss) in a BSD
* file.
*/
struct nlist {
union {
#ifndef __LP64__
char *n_name; /* for use when in-core */
#endif
int32_t n_strx; /* index into the string table */
} n_un;
uint8_t n_type; /* type flag, see below */
uint8_t n_sect; /* section number or NO_SECT */
int16_t n_desc; /* see <mach-o/stab.h> */
uint32_t n_value; /* value of this symbol (or stab offset) */
};
/*
* This is the symbol table entry structure for 64-bit architectures.
*/
struct nlist_64 {
union {
uint32_t n_strx; /* index into the string table */
} n_un;
uint8_t n_type; /* type flag, see below */
uint8_t n_sect; /* section number or NO_SECT */
uint16_t n_desc; /* see <mach-o/stab.h> */
uint64_t n_value; /* value of this symbol (or stab offset) */
};
/*
* Symbols with a index into the string table of zero (n_un.n_strx == 0) are
* defined to have a null, "", name. Therefore all string indexes to non null
* names must not have a zero string index. This is bit historical information
* that has never been well documented.
*/
/*
* The n_type field really contains four fields:
* unsigned char N_STAB:3,
* N_PEXT:1,
* N_TYPE:3,
* N_EXT:1;
* which are used via the following masks.
*/
#define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
#define N_PEXT 0x10 /* private external symbol bit */
#define N_TYPE 0x0e /* mask for the type bits */
#define N_EXT 0x01 /* external symbol bit, set for external symbols */
/*
* Only symbolic debugging entries have some of the N_STAB bits set and if any
* of these bits are set then it is a symbolic debugging entry (a stab). In
* which case then the values of the n_type field (the entire field) are given
* in <mach-o/stab.h>
*/
/*
* Values for N_TYPE bits of the n_type field.
*/
#define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
#define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
#define N_SECT 0xe /* defined in section number n_sect */
#define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
#define N_INDR 0xa /* indirect */
/*
* If the type is N_INDR then the symbol is defined to be the same as another
* symbol. In this case the n_value field is an index into the string table
* of the other symbol's name. When the other symbol is defined then they both
* take on the defined type and value.
*/
/*
* If the type is N_SECT then the n_sect field contains an ordinal of the
* section the symbol is defined in. The sections are numbered from 1 and
* refer to sections in order they appear in the load commands for the file
* they are in. This means the same ordinal may very well refer to different
* sections in different files.
*
* The n_value field for all symbol table entries (including N_STAB's) gets
* updated by the link editor based on the value of it's n_sect field and where
* the section n_sect references gets relocated. If the value of the n_sect
* field is NO_SECT then it's n_value field is not changed by the link editor.
*/
#define NO_SECT 0 /* symbol is not in any section */
#define MAX_SECT 255 /* 1 thru 255 inclusive */
/*
* Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
* who's values (n_value) are non-zero. In which case the value of the n_value
* field is the size (in bytes) of the common symbol. The n_sect field is set
* to NO_SECT. The alignment of a common symbol may be set as a power of 2
* between 2^1 and 2^15 as part of the n_desc field using the macros below. If
* the alignment is not set (a value of zero) then natural alignment based on
* the size is used.
*/
#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f)
#define SET_COMM_ALIGN(n_desc,align) \
(n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
/*
* To support the lazy binding of undefined symbols in the dynamic link-editor,
* the undefined symbols in the symbol table (the nlist structures) are marked
* with the indication if the undefined reference is a lazy reference or
* non-lazy reference. If both a non-lazy reference and a lazy reference is
* made to the same symbol the non-lazy reference takes precedence. A reference
* is lazy only when all references to that symbol are made through a symbol
* pointer in a lazy symbol pointer section.
*
* The implementation of marking nlist structures in the symbol table for
* undefined symbols will be to use some of the bits of the n_desc field as a
* reference type. The mask REFERENCE_TYPE will be applied to the n_desc field
* of an nlist structure for an undefined symbol to determine the type of
* undefined reference (lazy or non-lazy).
*
* The constants for the REFERENCE FLAGS are propagated to the reference table
* in a shared library file. In that case the constant for a defined symbol,
* REFERENCE_FLAG_DEFINED, is also used.
*/
/* Reference type bits of the n_desc field of undefined symbols */
#define REFERENCE_TYPE 0xf
/* types of references */
#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
#define REFERENCE_FLAG_UNDEFINED_LAZY 1
#define REFERENCE_FLAG_DEFINED 2
#define REFERENCE_FLAG_PRIVATE_DEFINED 3
#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
/*
* To simplify stripping of objects that use are used with the dynamic link
* editor, the static link editor marks the symbols defined an object that are
* referenced by a dynamicly bound object (dynamic shared libraries, bundles).
* With this marking strip knows not to strip these symbols.
*/
#define REFERENCED_DYNAMICALLY 0x0010
/*
* For images created by the static link editor with the -twolevel_namespace
* option in effect the flags field of the mach header is marked with
* MH_TWOLEVEL. And the binding of the undefined references of the image are
* determined by the static link editor. Which library an undefined symbol is
* bound to is recorded by the static linker in the high 8 bits of the n_desc
* field using the SET_LIBRARY_ORDINAL macro below. The ordinal recorded
* references the libraries listed in the Mach-O's LC_LOAD_DYLIB load commands
* in the order they appear in the headers. The library ordinals start from 1.
* For a dynamic library that is built as a two-level namespace image the
* undefined references from module defined in another use the same nlist struct
* an in that case SELF_LIBRARY_ORDINAL is used as the library ordinal. For
* defined symbols in all images they also must have the library ordinal set to
* SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable
* image for references from plugins that refer to the executable that loads
* them.
*
* The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace
* image that are looked up by the dynamic linker with flat namespace semantics.
* This ordinal was added as a feature in Mac OS X 10.3 by reducing the
* value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries
* or binaries built with older tools to have 0xfe (254) dynamic libraries. In
* this case the ordinal value 0xfe (254) must be treated as a library ordinal
* for compatibility.
*/
#define GET_LIBRARY_ORDINAL(n_desc) (((n_desc) >> 8) & 0xff)
#define SET_LIBRARY_ORDINAL(n_desc,ordinal) \
(n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
#define SELF_LIBRARY_ORDINAL 0x0
#define MAX_LIBRARY_ORDINAL 0xfd
#define DYNAMIC_LOOKUP_ORDINAL 0xfe
#define EXECUTABLE_ORDINAL 0xff
/*
* The bit 0x0020 of the n_desc field is used for two non-overlapping purposes
* and has two different symbolic names, N_NO_DEAD_STRIP and N_DESC_DISCARDED.
*/
/*
* The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
* relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
* static link editor it is never to dead strip the symbol.
*/
#define N_NO_DEAD_STRIP 0x0020 /* symbol is not to be dead stripped */
/*
* The N_DESC_DISCARDED bit of the n_desc field never appears in linked image.
* But is used in very rare cases by the dynamic link editor to mark an in
* memory symbol as discared and longer used for linking.
*/
#define N_DESC_DISCARDED 0x0020 /* symbol is discarded */
/*
* The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
* the undefined symbol is allowed to be missing and is to have the address of
* zero when missing.
*/
#define N_WEAK_REF 0x0040 /* symbol is weak referenced */
/*
* The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
* linkers that the symbol definition is weak, allowing a non-weak symbol to
* also be used which causes the weak definition to be discared. Currently this
* is only supported for symbols in coalesed sections.
*/
#define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */
/*
* The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
* that the undefined symbol should be resolved using flat namespace searching.
*/
#define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */
#ifndef __STRICT_BSD__
/*
* The function nlist(3) from the C library.
*/
extern int nlist (const char *filename, struct nlist *list);
#endif /* __STRICT_BSD__ */
#endif /* _MACHO_LIST_H_ */

Просмотреть файл

@ -0,0 +1,65 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Relocation types used in the ppc implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* above and their r_type is RELOC_VANILLA. The rest of the relocation types
* are for instructions. Since they are for instructions the r_address field
* indicates the 32 bit instruction that the relocation is to be preformed on.
* The fields r_pcrel and r_length are ignored for non-RELOC_VANILLA r_types
* except for PPC_RELOC_BR14.
*
* For PPC_RELOC_BR14 if the r_length is the unused value 3, then the branch was
* statically predicted setting or clearing the Y-bit based on the sign of the
* displacement or the opcode. If this is the case the static linker must flip
* the value of the Y-bit if the sign of the displacement changes for non-branch
* always conditions.
*/
enum reloc_type_ppc
{
PPC_RELOC_VANILLA, /* generic relocation as discribed above */
PPC_RELOC_PAIR, /* the second relocation entry of a pair */
PPC_RELOC_BR14, /* 14 bit branch displacement (to a word address) */
PPC_RELOC_BR24, /* 24 bit branch displacement (to a word address) */
PPC_RELOC_HI16, /* a PAIR follows with the low half */
PPC_RELOC_LO16, /* a PAIR follows with the high half */
PPC_RELOC_HA16, /* Same as the RELOC_HI16 except the low 16 bits and the
* high 16 bits are added together with the low 16 bits
* sign extened first. This means if bit 15 of the low
* 16 bits is set the high 16 bits stored in the
* instruction will be adjusted.
*/
PPC_RELOC_LO14, /* Same as the LO16 except that the low 2 bits are not
* stored in the instruction and are always zero. This
* is used in double word load/store instructions.
*/
PPC_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
PPC_RELOC_PB_LA_PTR,/* prebound lazy pointer */
PPC_RELOC_HI16_SECTDIFF, /* section difference forms of above. a PAIR */
PPC_RELOC_LO16_SECTDIFF, /* follows these with subtract symbol value */
PPC_RELOC_HA16_SECTDIFF,
PPC_RELOC_JBSR,
PPC_RELOC_LO14_SECTDIFF,
PPC_RELOC_LOCAL_SECTDIFF /* like PPC_RELOC_SECTDIFF, but the symbol
referenced was local. */
};

Просмотреть файл

@ -0,0 +1,67 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ranlib.h 4.1 83/05/03 */
#ifndef _MACH_O_RANLIB_H_
#define _MACH_O_RANLIB_H_
#include <stdint.h>
#include <sys/types.h> /* off_t */
/*
* There are two known orders of table of contents for archives. The first is
* the order ranlib(1) originally produced and still produces without any
* options. This table of contents has the archive member name "__.SYMDEF"
* This order has the ranlib structures in the order the objects appear in the
* archive and the symbol names of those objects in the order of symbol table.
* The second know order is sorted by symbol name and is produced with the -s
* option to ranlib(1). This table of contents has the archive member name
* "__.SYMDEF SORTED" and many programs (notably the 1.0 version of ld(1) can't
* tell the difference between names because of the imbedded blank in the name
* and works with either table of contents). This second order is used by the
* post 1.0 link editor to produce faster linking. The original 1.0 version of
* ranlib(1) gets confused when it is run on a archive with the second type of
* table of contents because it and ar(1) which it uses use different ways to
* determined the member name (ar(1) treats all blanks in the name as
* significant and ranlib(1) only checks for the first one).
*/
#define SYMDEF "__.SYMDEF"
#define SYMDEF_SORTED "__.SYMDEF SORTED"
/*
* Structure of the __.SYMDEF table of contents for an archive.
* __.SYMDEF begins with a long giving the size in bytes of the ranlib
* structures which immediately follow, and then continues with a string
* table consisting of a long giving the number of bytes of strings which
* follow and then the strings themselves. The ran_strx fields index the
* string table whose first byte is numbered 0.
*/
struct ranlib {
union {
uint32_t ran_strx; /* string table index of */
#ifndef __LP64__
char *ran_name; /* symbol defined by */
#endif
} ran_un;
uint32_t ran_off; /* library member at this offset */
};
#endif /* _MACH_O_RANLIB_H_ */

Просмотреть файл

@ -0,0 +1,202 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */
/*
* Copyright (c) 1993 Christopher G. Demetriou
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _MACHO_RELOC_H_
#define _MACHO_RELOC_H_
#include <stdint.h>
/*
* Format of a relocation entry of a Mach-O file. Modified from the 4.3BSD
* format. The modifications from the original format were changing the value
* of the r_symbolnum field for "local" (r_extern == 0) relocation entries.
* This modification is required to support symbols in an arbitrary number of
* sections not just the three sections (text, data and bss) in a 4.3BSD file.
* Also the last 4 bits have had the r_type tag added to them.
*/
struct relocation_info {
int32_t r_address; /* offset in the section to what is being
relocated */
uint32_t r_symbolnum:24, /* symbol index if r_extern == 1 or section
ordinal if r_extern == 0 */
r_pcrel:1, /* was relocated pc relative already */
r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
r_extern:1, /* does not include value of sym referenced */
r_type:4; /* if not 0, machine specific relocation type */
};
#define R_ABS 0 /* absolute relocation type for Mach-O files */
/*
* The r_address is not really the address as it's name indicates but an offset.
* In 4.3BSD a.out objects this offset is from the start of the "segment" for
* which relocation entry is for (text or data). For Mach-O object files it is
* also an offset but from the start of the "section" for which the relocation
* entry is for. See comments in <mach-o/loader.h> about the r_address feild
* in images for used with the dynamic linker.
*
* In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal
* for the segment the symbol being relocated is in. These ordinals are the
* symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these
* ordinals refer to the sections in the object file in the order their section
* structures appear in the headers of the object file they are in. The first
* section has the ordinal 1, the second 2, and so on. This means that the
* same ordinal in two different object files could refer to two different
* sections. And further could have still different ordinals when combined
* by the link-editor. The value R_ABS is used for relocation entries for
* absolute symbols which need no further relocation.
*/
/*
* For RISC machines some of the references are split across two instructions
* and the instruction does not contain the complete value of the reference.
* In these cases a second, or paired relocation entry, follows each of these
* relocation entries, using a PAIR r_type, which contains the other part of the
* reference not contained in the instruction. This other part is stored in the
* pair's r_address field. The exact number of bits of the other part of the
* reference store in the r_address field is dependent on the particular
* relocation type for the particular architecture.
*/
/*
* To make scattered loading by the link editor work correctly "local"
* relocation entries can't be used when the item to be relocated is the value
* of a symbol plus an offset (where the resulting expresion is outside the
* block the link editor is moving, a blocks are divided at symbol addresses).
* In this case. where the item is a symbol value plus offset, the link editor
* needs to know more than just the section the symbol was defined. What is
* needed is the actual value of the symbol without the offset so it can do the
* relocation correctly based on where the value of the symbol got relocated to
* not the value of the expression (with the offset added to the symbol value).
* So for the NeXT 2.0 release no "local" relocation entries are ever used when
* there is a non-zero offset added to a symbol. The "external" and "local"
* relocation entries remain unchanged.
*
* The implemention is quite messy given the compatibility with the existing
* relocation entry format. The ASSUMPTION is that a section will never be
* bigger than 2**24 - 1 (0x00ffffff or 16,777,215) bytes. This assumption
* allows the r_address (which is really an offset) to fit in 24 bits and high
* bit of the r_address field in the relocation_info structure to indicate
* it is really a scattered_relocation_info structure. Since these are only
* used in places where "local" relocation entries are used and not where
* "external" relocation entries are used the r_extern field has been removed.
*
* For scattered loading to work on a RISC machine where some of the references
* are split across two instructions the link editor needs to be assured that
* each reference has a unique 32 bit reference (that more than one reference is
* NOT sharing the same high 16 bits for example) so it move each referenced
* item independent of each other. Some compilers guarantees this but the
* compilers don't so scattered loading can be done on those that do guarantee
* this.
*/
#if defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__)
/*
* The reason for the ifdef's of __BIG_ENDIAN__ and __LITTLE_ENDIAN__ are that
* when stattered relocation entries were added the mistake of using a mask
* against a structure that is made up of bit fields was used. To make this
* design work this structure must be laid out in memory the same way so the
* mask can be applied can check the same bit each time (r_scattered).
*/
#endif /* defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) */
#define R_SCATTERED 0x80000000 /* mask to be applied to the r_address field
of a relocation_info structure to tell that
is is really a scattered_relocation_info
stucture */
struct scattered_relocation_info {
#ifdef __BIG_ENDIAN__
uint32_t r_scattered:1, /* 1=scattered, 0=non-scattered (see above) */
r_pcrel:1, /* was relocated pc relative already */
r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
r_type:4, /* if not 0, machine specific relocation type */
r_address:24; /* offset in the section to what is being
relocated */
int32_t r_value; /* the value the item to be relocated is
refering to (without any offset added) */
#endif /* __BIG_ENDIAN__ */
#ifdef __LITTLE_ENDIAN__
uint32_t
r_address:24, /* offset in the section to what is being
relocated */
r_type:4, /* if not 0, machine specific relocation type */
r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
r_pcrel:1, /* was relocated pc relative already */
r_scattered:1; /* 1=scattered, 0=non-scattered (see above) */
int32_t r_value; /* the value the item to be relocated is
refering to (without any offset added) */
#endif /* __LITTLE_ENDIAN__ */
};
/*
* Relocation types used in a generic implementation. Relocation entries for
* normal things use the generic relocation as discribed above and their r_type
* is GENERIC_RELOC_VANILLA (a value of zero).
*
* Another type of generic relocation, GENERIC_RELOC_SECTDIFF, is to support
* the difference of two symbols defined in different sections. That is the
* expression "symbol1 - symbol2 + constant" is a relocatable expression when
* both symbols are defined in some section. For this type of relocation the
* both relocations entries are scattered relocation entries. The value of
* symbol1 is stored in the first relocation entry's r_value field and the
* value of symbol2 is stored in the pair's r_value field.
*
* A special case for a prebound lazy pointer is needed to beable to set the
* value of the lazy pointer back to its non-prebound state. This is done
* using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation
* entry where the r_value feild is the value of the lazy pointer not prebound.
*/
enum reloc_type_generic
{
GENERIC_RELOC_VANILLA, /* generic relocation as discribed above */
GENERIC_RELOC_PAIR, /* Only follows a GENERIC_RELOC_SECTDIFF */
GENERIC_RELOC_SECTDIFF,
GENERIC_RELOC_PB_LA_PTR, /* prebound lazy pointer */
GENERIC_RELOC_LOCAL_SECTDIFF
};
#endif /* _MACHO_RELOC_H_ */

Просмотреть файл

@ -0,0 +1,52 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* reloc.h - assemble for Sparc */
/* Defines machine specific relocation entries */
#ifndef SPARC_RELOC_INCLUDED
#define SPARC_RELOC_INCLUDED
/*
* Relocation types used in the sparc implementation. Relocation entries for
* things other than instructions use the same generic relocation as discribed
* in <mach-o/reloc.h> and their r_type is SPARC_RELOC_VANILLA. The rest of the
* relocation types are for instructions. Since they are for instructions the
* r_address field indicates the 32 bit instruction that the relocation is to
* be preformed on. The field r_pcrel is set only for the SPARC_RELOC_WDISP22
* and SPARC_RELOC_WDISP30. And r_length is set to long for all
* non-RELOC_VANILLA r_types.
*/
enum reloc_type_sparc
{
SPARC_RELOC_VANILLA, /* vanilla relocation */
SPARC_RELOC_PAIR, /* the second relocation entry of a pair */
SPARC_RELOC_HI22, /* 22 high bits (sethi) (has pair) */
SPARC_RELOC_LO10, /* 10 low bits (has pair) */
SPARC_RELOC_WDISP22, /* 22 bit PC relative displacement */
SPARC_RELOC_WDISP30, /* 30 bit PC relative displacement */
SPARC_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
SPARC_RELOC_HI22_SECTDIFF,
SPARC_RELOC_LO10_SECTDIFF,
SPARC_RELOC_PB_LA_PTR /* prebound lazy pointer */
};
#endif /* SPARC_RELOC_INCLUDED */

Просмотреть файл

@ -0,0 +1,122 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACHO_STAB_H_
#define _MACHO_STAB_H_
/* $NetBSD: stab.h,v 1.4 1994/10/26 00:56:25 cgd Exp $ */
/*-
* Copyright (c) 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)stab.h 5.2 (Berkeley) 4/4/91
*/
/*
* This file gives definitions supplementing <nlist.h> for permanent symbol
* table entries of Mach-O files. Modified from the BSD definitions. The
* modifications from the original definitions were changing what the values of
* what was the n_other field (an unused field) which is now the n_sect field.
* These modifications are required to support symbols in an arbitrary number of
* sections not just the three sections (text, data and bss) in a BSD file.
* The values of the defined constants have NOT been changed.
*
* These must have one of the N_STAB bits on. The n_value fields are subject
* to relocation according to the value of their n_sect field. So for types
* that refer to things in sections the n_sect field must be filled in with the
* proper section ordinal. For types that are not to have their n_value field
* relocatated the n_sect field must be NO_SECT.
*/
/*
* Symbolic debugger symbols. The comments give the conventional use for
*
* .stabs "n_name", n_type, n_sect, n_desc, n_value
*
* where n_type is the defined constant and not listed in the comment. Other
* fields not listed are zero. n_sect is the section ordinal the entry is
* refering to.
*/
#define N_GSYM 0x20 /* global symbol: name,,NO_SECT,type,0 */
#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,NO_SECT,0,0 */
#define N_FUN 0x24 /* procedure: name,,n_sect,linenumber,address */
#define N_STSYM 0x26 /* static symbol: name,,n_sect,type,address */
#define N_LCSYM 0x28 /* .lcomm symbol: name,,n_sect,type,address */
#define N_BNSYM 0x2e /* begin nsect sym: 0,,n_sect,0,address */
#define N_OPT 0x3c /* emitted with gcc2_compiled and in gcc source */
#define N_RSYM 0x40 /* register sym: name,,NO_SECT,type,register */
#define N_SLINE 0x44 /* src line: 0,,n_sect,linenumber,address */
#define N_ENSYM 0x4e /* end nsect sym: 0,,n_sect,0,address */
#define N_SSYM 0x60 /* structure elt: name,,NO_SECT,type,struct_offset */
#define N_SO 0x64 /* source file name: name,,n_sect,0,address */
#define N_OSO 0x66 /* object file name: name,,0,0,st_mtime */
#define N_LSYM 0x80 /* local sym: name,,NO_SECT,type,offset */
#define N_BINCL 0x82 /* include file beginning: name,,NO_SECT,0,sum */
#define N_SOL 0x84 /* #included file name: name,,n_sect,0,address */
#define N_PARAMS 0x86 /* compiler parameters: name,,NO_SECT,0,0 */
#define N_VERSION 0x88 /* compiler version: name,,NO_SECT,0,0 */
#define N_OLEVEL 0x8A /* compiler -O level: name,,NO_SECT,0,0 */
#define N_PSYM 0xa0 /* parameter: name,,NO_SECT,type,offset */
#define N_EINCL 0xa2 /* include file end: name,,NO_SECT,0,0 */
#define N_ENTRY 0xa4 /* alternate entry: name,,n_sect,linenumber,address */
#define N_LBRAC 0xc0 /* left bracket: 0,,NO_SECT,nesting level,address */
#define N_EXCL 0xc2 /* deleted include file: name,,NO_SECT,0,sum */
#define N_RBRAC 0xe0 /* right bracket: 0,,NO_SECT,nesting level,address */
#define N_BCOMM 0xe2 /* begin common: name,,NO_SECT,0,0 */
#define N_ECOMM 0xe4 /* end common: name,,n_sect,0,0 */
#define N_ECOML 0xe8 /* end common (local name): 0,,n_sect,0,address */
#define N_LENG 0xfe /* second stab entry with length information */
/*
* for the berkeley pascal compiler, pc(1):
*/
#define N_PC 0x30 /* global pascal symbol: name,,NO_SECT,subtype,line */
#endif /* _MACHO_STAB_H_ */

Просмотреть файл

@ -0,0 +1,174 @@
/*
* Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Relocations for x86_64 are a bit different than for other architectures in
* Mach-O: Scattered relocations are not used. Almost all relocations produced
* by the compiler are external relocations. An external relocation has the
* r_extern bit set to 1 and the r_symbolnum field contains the symbol table
* index of the target label.
*
* When the assembler is generating relocations, if the target label is a local
* label (begins with 'L'), then the previous non-local label in the same
* section is used as the target of the external relocation. An addend is used
* with the distance from that non-local label to the target label. Only when
* there is no previous non-local label in the section is an internal
* relocation used.
*
* The addend (i.e. the 4 in _foo+4) is encoded in the instruction (Mach-O does
* not have RELA relocations). For PC-relative relocations, the addend is
* stored directly in the instruction. This is different from other Mach-O
* architectures, which encode the addend minus the current section offset.
*
* The relocation types are:
*
* X86_64_RELOC_UNSIGNED // for absolute addresses
* X86_64_RELOC_SIGNED // for signed 32-bit displacement
* X86_64_RELOC_BRANCH // a CALL/JMP instruction with 32-bit displacement
* X86_64_RELOC_GOT_LOAD // a MOVQ load of a GOT entry
* X86_64_RELOC_GOT // other GOT references
* X86_64_RELOC_SUBTRACTOR // must be followed by a X86_64_RELOC_UNSIGNED
*
* The following are sample assembly instructions, followed by the relocation
* and section content they generate in an object file:
*
* call _foo
* r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* E8 00 00 00 00
*
* call _foo+4
* r_type=X86_64_RELOC_BRANCH, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* E8 04 00 00 00
*
* movq _foo@GOTPCREL(%rip), %rax
* r_type=X86_64_RELOC_GOT_LOAD, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* 48 8B 05 00 00 00 00
*
* pushq _foo@GOTPCREL(%rip)
* r_type=X86_64_RELOC_GOT, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* FF 35 00 00 00 00
*
* movl _foo(%rip), %eax
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* 8B 05 00 00 00 00
*
* movl _foo+4(%rip), %eax
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* 8B 05 04 00 00 00
*
* movb $0x12, _foo(%rip)
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* C6 05 FF FF FF FF 12
*
* movl $0x12345678, _foo(%rip)
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_foo
* C7 05 FC FF FF FF 78 56 34 12
*
* .quad _foo
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* 00 00 00 00 00 00 00 00
*
* .quad _foo+4
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* 04 00 00 00 00 00 00 00
*
* .quad _foo - _bar
* r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* 00 00 00 00 00 00 00 00
*
* .quad _foo - _bar + 4
* r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_bar
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* 04 00 00 00 00 00 00 00
*
* .long _foo - _bar
* r_type=X86_64_RELOC_SUBTRACTOR, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_bar
* r_type=X86_64_RELOC_UNSIGNED, r_length=2, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* 00 00 00 00
*
* lea L1(%rip), %rax
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=1, r_pcrel=1, r_symbolnum=_prev
* 48 8d 05 12 00 00 00
* // assumes _prev is the first non-local label 0x12 bytes before L1
*
* lea L0(%rip), %rax
* r_type=X86_64_RELOC_SIGNED, r_length=2, r_extern=0, r_pcrel=1, r_symbolnum=3
* 48 8d 05 56 00 00 00
* // assumes L0 is in third section, has an address of 0x00000056 in .o
* // file, and there is no previous non-local label
*
* .quad L1
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
* 12 00 00 00 00 00 00 00
* // assumes _prev is the first non-local label 0x12 bytes before L1
*
* .quad L0
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=0, r_pcrel=0, r_symbolnum=3
* 56 00 00 00 00 00 00 00
* // assumes L0 is in third section, has an address of 0x00000056 in .o
* // file, and there is no previous non-local label
*
* .quad _foo - .
* r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* EE FF FF FF FF FF FF FF
* // assumes _prev is the first non-local label 0x12 bytes before this
* // .quad
*
* .quad _foo - L1
* r_type=X86_64_RELOC_SUBTRACTOR, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_prev
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_extern=1, r_pcrel=0, r_symbolnum=_foo
* EE FF FF FF FF FF FF FF
* // assumes _prev is the first non-local label 0x12 bytes before L1
*
* .quad L1 - _prev
* // No relocations. This is an assembly time constant.
* 12 00 00 00 00 00 00 00
* // assumes _prev is the first non-local label 0x12 bytes before L1
*
*
*
* In final linked images, there are only two valid relocation kinds:
*
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=1, r_symbolnum=sym_index
* This tells dyld to add the address of a symbol to a pointer sized (8-byte)
* piece of data (i.e on disk the 8-byte piece of data contains the addend). The
* r_symbolnum contains the index into the symbol table of the target symbol.
*
* r_type=X86_64_RELOC_UNSIGNED, r_length=3, r_pcrel=0, r_extern=0, r_symbolnum=0
* This tells dyld to adjust the pointer sized (8-byte) piece of data by the amount
* the containing image was loaded from its base address (e.g. slide).
*
*/
enum reloc_type_x86_64
{
X86_64_RELOC_UNSIGNED, // for absolute addresses
X86_64_RELOC_SIGNED, // for signed 32-bit displacement
X86_64_RELOC_BRANCH, // a CALL/JMP instruction with 32-bit displacement
X86_64_RELOC_GOT_LOAD, // a MOVQ load of a GOT entry
X86_64_RELOC_GOT, // other GOT references
X86_64_RELOC_SUBTRACTOR, // must be followed by a X86_64_RELOC_UNSIGNED
X86_64_RELOC_SIGNED_1, // for signed 32-bit displacement with a -1 addend
X86_64_RELOC_SIGNED_2, // for signed 32-bit displacement with a -2 addend
X86_64_RELOC_SIGNED_4, // for signed 32-bit displacement with a -4 addend
};

Просмотреть файл

@ -0,0 +1,207 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* @HP_COPYRIGHT@
*/
/*
* HISTORY
* Revision 1.1.1.1 1997/09/03 20:53:39 roland
* Initial checkin of SGS release 244
*
* Revision 1.4.3.2 1992/01/09 20:05:31 sharpe
* initial 1.1 vers from 1.0
* [1992/01/09 19:29:20 sharpe]
*
* Revision 1.4 1991/07/03 17:25:42 osfrcs
* 06/19/90 rand Add THREAD_STATE_FLAVOR_LIST to getstatus
* [91/06/21 17:29:52 brezak]
*
* Revision 1.3.2.2 91/06/21 18:05:17 brezak
* 06/19/90 rand Add THREAD_STATE_FLAVOR_LIST to getstatus
* [91/06/21 17:29:52 brezak]
*
* Revision 1.2.2.2 91/04/30 09:48:00 brezak
* rand 04/19/91 Add options to control reflection of assist/unalign exceptions
* [91/04/29 11:46:12 brezak]
*
* Revision 1.2 91/04/14 20:47:10 osfrcs
* Initial version.
* [91/03/30 09:32:42 brezak]
*
*/
#ifndef _HPPA_THREAD_STATE_
#define _HPPA_THREAD_STATE_
#include <mach/machine/boolean.h>
#define HPPA_INTEGER_THREAD_STATE 1
#define HPPA_FRAME_THREAD_STATE 2
#define HPPA_FP_THREAD_STATE 3
/*
* Flow control information that can
* be changed from user state (with
* some restrictions on psw).
*/
struct hp_pa_frame_thread_state {
unsigned long ts_pcsq_front; /* instruction address space front */
unsigned long ts_pcsq_back; /* instruction address space back */
unsigned long ts_pcoq_front; /* instruction offset space front */
unsigned long ts_pcoq_back; /* instruction offset space back */
unsigned long ts_psw; /* process status word */
unsigned long ts_unaligned_faults; /* number of unaligned data references READ-ONLY */
unsigned long ts_fault_address; /* address of failing page fault READ-ONLY */
/*
* A step range is a range of address that
* will be executed with out generating a single
* step event. If both values are 0 no stepping
* will occur. Otherwise the program will run while:
*
* if (step_range_start <= step_range_stop)
* pcoq0 >= step_range_start && pcoq0 < step_range_stop
* if (step_range_start > step_range_stop)
* pcoq0 < step_range_stop && pcoq0 >= step_range_start
*
* notice that setting step_range_start and step_range_stop to the
* same non-zero value will execute only one instruction due to action
* of the pc queue. (Yes, nullified instructions count)
*/
unsigned long ts_step_range_start;
unsigned long ts_step_range_stop;
/* Generate an exception when OS assists with an alignment fault */
boolean_t ts_alignment_trap_reflect;
/* Generate an exception when OS assists with an FP fault */
boolean_t ts_execution_trap_reflect;
};
/*
* Get rid of as soon as all users of frame_thread_state
* have been recompiled. XXX
*/
struct hp_pa_old_frame_thread_state {
unsigned long ts_pcsq_front; /* instruction address space front */
unsigned long ts_pcsq_back; /* instruction address space back */
unsigned long ts_pcoq_front; /* instruction offset space front */
unsigned long ts_pcoq_back; /* instruction offset space back */
unsigned long ts_psw; /* process status word */
};
/*
* The unsigned longeger state that may be changed by any
* process in user space.
*/
typedef struct hp_pa_integer_thread_state {
unsigned long ts_gr1; /* the user's general registers */
unsigned long ts_gr2;
unsigned long ts_gr3;
unsigned long ts_gr4;
unsigned long ts_gr5;
unsigned long ts_gr6;
unsigned long ts_gr7;
unsigned long ts_gr8;
unsigned long ts_gr9;
unsigned long ts_gr10;
unsigned long ts_gr11;
unsigned long ts_gr12;
unsigned long ts_gr13;
unsigned long ts_gr14;
unsigned long ts_gr15;
unsigned long ts_gr16;
unsigned long ts_gr17;
unsigned long ts_gr18;
unsigned long ts_gr19;
unsigned long ts_gr20;
unsigned long ts_gr21;
unsigned long ts_gr22;
unsigned long ts_gr23;
unsigned long ts_gr24;
unsigned long ts_gr25;
unsigned long ts_gr26;
unsigned long ts_gr27;
unsigned long ts_gr28;
unsigned long ts_gr29;
unsigned long ts_gr30;
unsigned long ts_gr31;
unsigned long ts_sr0; /* the user's space registgers */
unsigned long ts_sr1;
unsigned long ts_sr2;
unsigned long ts_sr3;
unsigned long ts_sar; /* the user's shift amount register */
} hp_pa_integer_thread_state_t;
/*
* The floating point state that may be changed by any
* process in user space.
*/
typedef struct hp_pa_fp_thread_state {
double ts_fp0; /* all of the execution unit registers */
double ts_fp1;
double ts_fp2;
double ts_fp3;
double ts_fp4;
double ts_fp5;
double ts_fp6;
double ts_fp7;
double ts_fp8;
double ts_fp9;
double ts_fp10;
double ts_fp11;
double ts_fp12;
double ts_fp13;
double ts_fp14;
double ts_fp15;
double ts_fp16;
double ts_fp17;
double ts_fp18;
double ts_fp19;
double ts_fp20;
double ts_fp21;
double ts_fp22;
double ts_fp23;
double ts_fp24;
double ts_fp25;
double ts_fp26;
double ts_fp27;
double ts_fp28;
double ts_fp29;
double ts_fp30;
double ts_fp31;
} hp_pa_fp_thread_state_t;
#define HPPA_INTEGER_THREAD_STATE_COUNT (sizeof(struct hp_pa_integer_thread_state) / sizeof(unsigned long))
#define HPPA_FRAME_THREAD_STATE_COUNT (sizeof(struct hp_pa_frame_thread_state) / sizeof(unsigned long))
#define HPPA_FP_THREAD_STATE_COUNT (sizeof(struct hp_pa_fp_thread_state) / sizeof(unsigned long))
/* Get rid of as soon as all users of thread_frame_state have been recompiled XXX */
#define HPPA_OLD_FRAME_THREAD_STATE_COUNT (sizeof(struct hp_pa_old_frame_thread_state) / sizeof(unsigned long))
#endif /* _HPPA_THREAD_STATE_ */

Просмотреть файл

@ -0,0 +1,76 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1987, 1988 NeXT, Inc.
*/
#ifndef _I860_THREAD_STATE_
#define _I860_THREAD_STATE_
/*
* I860_thread_state_regs this is the structure that is exported
* to user threads for use in set/get
* status calls. This structure should
* never change.
*/
#define I860_THREAD_STATE_REGS (4) /* normal registers */
struct i860_thread_state_regs {
int ireg[31]; /* core registers (incl stack pointer, but not r0) */
int freg[30]; /* FPU registers, except f0 and f1 */
int psr; /* user's processor status register */
int epsr; /* user's extended processor status register */
int db; /* user's data breakpoint register */
int pc; /* user's program counter */
int _padding_; /* not used */
/* Pipeline state for FPU */
double Mres3;
double Ares3;
double Mres2;
double Ares2;
double Mres1;
double Ares1;
double Ires1;
double Lres3m;
double Lres2m;
double Lres1m;
double KR;
double KI;
double T;
int Fsr3;
int Fsr2;
int Fsr1;
int Mergelo32;
int Mergehi32;
};
#define I860_THREAD_STATE_REGS_COUNT \
(sizeof (struct i860_thread_state_regs) / sizeof (int))
#endif /* _I860_THREAD_STATE_ */

Просмотреть файл

@ -0,0 +1,99 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1987, 1988 NeXT, Inc.
*
* HISTORY
* 15-May-91 Gregg Kellogg (gk) at NeXT
* Use m68k_saved_state instead of NeXT_saved_state.
* Use m68k_thread_state_regs NeXT_regs.
* Use m68k_thread_state_68882 NeXT_thread_state_68882.
* Use m68k_thread_state_user_reg NeXT_thread_state_user_reg.
* Moved m68k_saved_state and USER_REGS to pcb.h.
*
*/
#ifndef _MACH_M68K_THREAD_STATUS_
#define _MACH_M68K_THREAD_STATUS_
/*
* m68k_thread_state_regs this is the structure that is exported
* to user threads for use in set/get status
* calls. This structure should never
* change.
*
* m68k_thread_state_68882 this structure is exported to user threads
* to allow the to set/get 68882 floating
* pointer register state.
*
* m68k_saved_state this structure corresponds to the state
* of the user registers as saved on the
* stack upon kernel entry. This structure
* is used internally only. Since this
* structure may change from version to
* version, it is hidden from the user.
*/
#define M68K_THREAD_STATE_REGS (1) /* normal registers */
#define M68K_THREAD_STATE_68882 (2) /* 68882 registers */
#define M68K_THREAD_STATE_USER_REG (3) /* additional user register */
#define M68K_THREAD_STATE_MAXFLAVOR (3)
struct m68k_thread_state_regs {
int dreg[8]; /* data registers */
int areg[8]; /* address registers (incl stack pointer) */
short pad0; /* not used */
short sr; /* user's status register */
int pc; /* user's program counter */
};
#define M68K_THREAD_STATE_REGS_COUNT \
(sizeof (struct m68k_thread_state_regs) / sizeof (int))
struct m68k_thread_state_68882 {
struct {
int fp[3]; /* 96-bit extended format */
} regs[8];
int cr; /* control */
int sr; /* status */
int iar; /* instruction address */
int state; /* execution state */
};
#define M68K_THREAD_STATE_68882_COUNT \
(sizeof (struct m68k_thread_state_68882) / sizeof (int))
struct m68k_thread_state_user_reg {
int user_reg; /* user register (used by cthreads) */
};
#define M68K_THREAD_STATE_USER_REG_COUNT \
(sizeof (struct m68k_thread_state_user_reg) / sizeof (int))
#endif /* _MACH_M68K_THREAD_STATUS_ */

Просмотреть файл

@ -0,0 +1,284 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
*
* File: mach/m88k/thread_status.h
* Author: Mike DeMoney, NeXT Computer, Inc.
*
* This include file defines the per-thread state
* for NeXT 88K-based products.
*
* HISTORY
* 23-Jan-91 Mike DeMoney (mike@next.com)
* Created.
*
* FIXME:
* All of these types should be pulled from architecture.
* Solve possible conflicting types problem for implementations
* by making user define an implementation (e.g. #define __M88110__)
* to get a implementation specific features.
*
* Put fp envelope stuff in mach/m88k/m88110_fpee.h.
*/
#ifndef _MACH_M88K_THREAD_STATE_
#define _MACH_M88K_THREAD_STATE_
#import <architecture/m88k/fp_regs.h>
#import <architecture/m88k/reg_help.h>
/**************************************************************************
* Data Typedefs used by thread_getstatus() and thread_setstatus() *
* NOTE: FP control and status regs described in <mach/m88k/fp_regs.h> *
**************************************************************************/
#define M88K_THREAD_STATE_GRF (1) // general registers
#define M88K_THREAD_STATE_XRF (2) // extended and fp registers
#define M88K_THREAD_STATE_USER (3) // non-architectural user state
#define M88110_THREAD_STATE_IMPL (4) // 88110 impl specific
#define M88K_THREAD_STATE_MAXFLAVOR (M88110_THREAD_STATE_IMPL)
/*
* m88k_thread_state_grf -- basic thread state for NeXT 88K-based products
*/
typedef struct _m88k_thread_state_grf {
unsigned r1; // rpc: return pc, caller-saved
unsigned r2; // a0: argument 0, caller-saved
unsigned r3; // a1
unsigned r4; // a2
unsigned r5; // a3
unsigned r6; // a4
unsigned r7; // a5
unsigned r8; // a6
unsigned r9; // a7
unsigned r10; // t0: temporary, caller-saved
unsigned r11; // t1
unsigned r12; // t2: struct return ptr,
unsigned r13; // t3
unsigned r14; // s0: saved, callee-saved
unsigned r15; // s1
unsigned r16; // s2
unsigned r17; // s3
unsigned r18; // s4
unsigned r19; // s5
unsigned r20; // s6
unsigned r21; // s7
unsigned r22; // s8
unsigned r23; // s9
unsigned r24; // s10
unsigned r25; // s11
unsigned r26; // t4
unsigned r27; // at: temp, used by asm macros
unsigned r28; // lk0: reserved for link editor
unsigned r29; // lk1
unsigned r30; // fp: frame ptr, callee-saved
unsigned r31; // sp: stack ptr, callee-saved
unsigned xip; // executing instruction pointer
unsigned xip_in_bd; // non-zero => xip in branch delay slot
/*
* nip is only valid if xip_in_bd is TRUE
*/
unsigned nip; // next instruction pointer
} m88k_thread_state_grf_t;
#define M88K_THREAD_STATE_GRF_COUNT \
(sizeof(m88k_thread_state_grf_t)/sizeof(int))
/*
* m88k_thread_state_xrf -- extended register file contents and floating point
* control registers for NeXT 88K-based products.
*/
typedef struct _m88k_thread_state_xrf {
m88k_xrf_t x1; // caller-saved
m88k_xrf_t x2;
m88k_xrf_t x3;
m88k_xrf_t x4;
m88k_xrf_t x5;
m88k_xrf_t x6;
m88k_xrf_t x7;
m88k_xrf_t x8;
m88k_xrf_t x9;
m88k_xrf_t x10;
m88k_xrf_t x11;
m88k_xrf_t x12;
m88k_xrf_t x13;
m88k_xrf_t x14;
m88k_xrf_t x15;
m88k_xrf_t x16;
m88k_xrf_t x17;
m88k_xrf_t x18;
m88k_xrf_t x19;
m88k_xrf_t x20;
m88k_xrf_t x21;
m88k_xrf_t x22; // callee-saved
m88k_xrf_t x23;
m88k_xrf_t x24;
m88k_xrf_t x25;
m88k_xrf_t x26;
m88k_xrf_t x27;
m88k_xrf_t x28;
m88k_xrf_t x29;
m88k_xrf_t x30; // reserved
m88k_xrf_t x31;
m88k_fpsr_t fpsr; // fp status, fcr62
m88k_fpcr_t fpcr; // fp control, fcr63
} m88k_thread_state_xrf_t;
#define M88K_THREAD_STATE_XRF_COUNT \
(sizeof(m88k_thread_state_xrf_t)/sizeof(int))
typedef struct _m88k_thread_state_user {
int user; // user register (for cthreads)
} m88k_thread_state_user_t;
#define M88K_THREAD_STATE_USER_COUNT \
(sizeof(m88k_thread_state_user_t)/sizeof(int))
/*
* Motorola 88110 specific state
* (Can't count on this being in all m88k implementations.)
*/
#define M88110_N_DATA_BP 2 // 88110 supports 2 data bp's
/*
* Data Breakpoint Address Match Mask -- actually indicates don't
* care bits in addr
*/
typedef enum {
M88110_MATCH_BYTE = 0,
M88110_MATCH_SHORT = 0x1,
M88110_MATCH_WORD = 0x3,
M88110_MATCH_DOUBLE = 0x7,
M88110_MATCH_QUAD = 0xf,
M88110_MATCH_32 = 0x1f,
M88110_MATCH_64 = 0x3f,
M88110_MATCH_128 = 0x7f,
M88110_MATCH_256 = 0xff,
M88110_MATCH_512 = 0x1ff,
M88110_MATCH_1024 = 0x3ff,
M88110_MATCH_2048 = 0x7ff,
M88110_MATCH_4096 = 0xfff
} m88110_match_t;
/*
* Data Breakpoint Control Word
*/
typedef struct {
unsigned :BITS_WIDTH(31,29);
unsigned rw:BIT_WIDTH(28); // 1 => read access
unsigned rwm:BIT_WIDTH(27); // 0 => rw is don't care
unsigned :BITS_WIDTH(26,13);
m88110_match_t addr_match:BITS_WIDTH(12,1); // addr(12,1) don't cares
unsigned v:BIT_WIDTH(0);
} m88110_bp_ctrl_t;
/*
* A complete Data Breakpoint spec
*/
typedef struct {
unsigned addr; // data address
m88110_bp_ctrl_t ctrl;
} m88110_data_bp_t;
/*
* m88110_psr_t -- 88110 Processor Status Register
* System prohibits modification of supr, le, se, sgn_imd, sm and mxm_dis
* bits for user threads.
*/
typedef struct {
unsigned supr:BIT_WIDTH(31);
unsigned le:BIT_WIDTH(30); // little endian mode
unsigned se:BIT_WIDTH(29); // serial exec mode
unsigned c:BIT_WIDTH(28); // carry
unsigned :BIT_WIDTH(27);
unsigned sgn_imd:BIT_WIDTH(26); // signed immediates
unsigned sm:BIT_WIDTH(25); // serialize mem refs
unsigned :BIT_WIDTH(24);
unsigned trace:BIT_WIDTH(23);
unsigned :BITS_WIDTH(22,5);
unsigned sfu2dis:BIT_WIDTH(4); // gpu (sfu2) disable
unsigned sfu1dis:BIT_WIDTH(3); // fpu (sfu1) disable
unsigned mxm_dis:BIT_WIDTH(2); // misaligned dis
unsigned :BITS_WIDTH(1,0);
} m88110_psr_t;
/*
* Information for IEEE floating point user trap handlers
*/
typedef enum {
M88110_IRESULT_SIZE_NONE = 0, // no intermediate result
M88110_IRESULT_SIZE_SINGLE = 1, // single precision result
M88110_IRESULT_SIZE_DOUBLE = 2, // double precision result
M88110_IRESULT_SIZE_EXTENDED = 3 // double extended result
} m88110_iresult_size_t;
typedef struct {
unsigned :BITS_WIDTH(31,16); // unused
m88110_iresult_size_t iresult_size:BITS_WIDTH(15,14);
// size of iresult
unsigned :BITS_WIDTH(13,9); // unused
unsigned sfu1_disabled:BIT_WIDTH(8); // sfu disabled
unsigned int:BIT_WIDTH(7); // invalid int conv
unsigned unimp:BIT_WIDTH(6); // unimp ctrl reg
unsigned priv:BIT_WIDTH(5); // priv violation
unsigned efinv:BIT_WIDTH(4); // IEEE EFINV
unsigned efdvz:BIT_WIDTH(3); // IEEE EFDVZ
unsigned efunf:BIT_WIDTH(2); // IEEE EFUNF
unsigned efovf:BIT_WIDTH(1); // IEEE EFOVF
unsigned efinx:BIT_WIDTH(0); // IEEE EFINX
} m88110_fp_trap_status_t;
/*
* m88110_thread_state_impl -- 88110 implementation-specific
* control registers for NeXT 88K-based products.
*/
typedef struct _m88110_thread_state_impl {
m88110_data_bp_t data_bp[M88110_N_DATA_BP];
/*
* Certain of the 88110 psr bits may be modified
*/
m88110_psr_t psr; // processor status
/*
* IEEE floating point user trap information. Read only.
* (Only valid immediately after an EXC_ARITHMETIC
* exception with code EXC_M88K_SFU1_EXCP. Trap
* handlers must determine operation, source and
* destination registers by fetching instruction at
* exip.)
*/
m88k_xrf_t intermediate_result;
m88110_fp_trap_status_t fp_trap_status;
} m88110_thread_state_impl_t;
#define M88110_THREAD_STATE_IMPL_COUNT \
(sizeof(m88110_thread_state_impl_t)/sizeof(int))
#endif /* _MACH_M88K_THREAD_STATE_ */

Просмотреть файл

@ -0,0 +1,383 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Mach Operating System
* Copyright (c) 1989 Carnegie-Mellon University
* Copyright (c) 1988 Carnegie-Mellon University
* Copyright (c) 1987 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* HISTORY
* Revision 1.1.1.1 1997/09/03 20:53:37 roland
* Initial checkin of SGS release 244
*
* 2 July 1992 Mac Gillon at NeXT
* Changed HPPA subtypes to follow our practice.
*
* 11 September 1992 David E. Bohman at NeXT
* Added CPU_SUBTYPE_486SX to the i386 family.
*
* 16 July 1992 David E. Bohman at NeXT
* Added CPU_SUBTYPE_586 to the i386 family.
*
* 17-Dec-91 Peter King (king) at NeXT
* Added support for the XXX_ALL subtypes. These are used to
* tag object files that can run on any implementation of a
* particular family.
*
* 1-Mar-90 John Seamons (jks) at NeXT
* Redefined cpu_type and cpu_subtype definitions to indicate processor
* architecture instead of product types for the MC680x0.
*
* Revision 2.15 89/10/11 14:39:56 dlb
* Removed should_exit - replaced by action thread.
* [89/01/25 dlb]
*
* Revision 2.14 89/07/14 17:21:39 rvb
* Added CPU types and subtypes for MC68030, MC68040, MC88000,
* HPPA, ARM and Sun4-SPARC.
* [89/07/13 mrt]
*
* Revision 2.12 89/05/30 10:38:58 rvb
* Add R2000 machine types.
* [89/05/30 08:28:53 rvb]
*
* Revision 2.11 89/04/18 16:43:32 mwyoung
* Use <machine/vm_types.h> rather than <vm/vm_param.h> to get
* VM types. Remove old history... none of it was insightful.
*
* The variable declarations should be moved elsewhere.
* [89/01/24 mwyoung]
*
*/
/*
* Machine independent machine abstraction.
* Copyright (C) 1986, Avadis Tevanian, Jr.
*/
#ifndef _MACH_MACHINE_H_
#define _MACH_MACHINE_H_
#import <mach/machine/vm_types.h>
#import <mach/boolean.h>
/*
* For each host, there is a maximum possible number of
* cpus that may be available in the system. This is the
* compile-time constant NCPUS, which is defined in cpus.h.
*
* In addition, there is a machine_slot specifier for each
* possible cpu in the system.
*/
struct machine_info {
int major_version; /* kernel major version id */
int minor_version; /* kernel minor version id */
int max_cpus; /* max number of cpus compiled */
int avail_cpus; /* number actually available */
vm_size_t memory_size; /* size of memory in bytes */
};
typedef struct machine_info *machine_info_t;
typedef struct machine_info machine_info_data_t; /* bogus */
typedef int cpu_type_t;
typedef int cpu_subtype_t;
typedef integer_t cpu_threadtype_t;
#define CPU_STATE_MAX 3
#define CPU_STATE_USER 0
#define CPU_STATE_SYSTEM 1
#define CPU_STATE_IDLE 2
struct machine_slot {
boolean_t is_cpu; /* is there a cpu in this slot? */
cpu_type_t cpu_type; /* type of cpu */
cpu_subtype_t cpu_subtype; /* subtype of cpu */
volatile boolean_t running; /* is cpu running */
long cpu_ticks[CPU_STATE_MAX];
int clock_freq; /* clock interrupt frequency */
};
typedef struct machine_slot *machine_slot_t;
typedef struct machine_slot machine_slot_data_t; /* bogus */
#ifdef KERNEL
extern struct machine_info machine_info;
extern struct machine_slot machine_slot[];
extern vm_offset_t interrupt_stack[];
#endif /* KERNEL */
/*
* Machine types known by all.
*/
#define CPU_TYPE_ANY ((cpu_type_t) -1)
#define CPU_TYPE_VAX ((cpu_type_t) 1)
#define CPU_TYPE_ROMP ((cpu_type_t) 2)
#define CPU_TYPE_NS32032 ((cpu_type_t) 4)
#define CPU_TYPE_NS32332 ((cpu_type_t) 5)
#define CPU_TYPE_MC680x0 ((cpu_type_t) 6)
#define CPU_TYPE_I386 ((cpu_type_t) 7)
#define CPU_TYPE_X86_64 ((cpu_type_t) (CPU_TYPE_I386 | CPU_ARCH_ABI64))
#define CPU_TYPE_MIPS ((cpu_type_t) 8)
#define CPU_TYPE_NS32532 ((cpu_type_t) 9)
#define CPU_TYPE_HPPA ((cpu_type_t) 11)
#define CPU_TYPE_ARM ((cpu_type_t) 12)
#define CPU_TYPE_MC88000 ((cpu_type_t) 13)
#define CPU_TYPE_SPARC ((cpu_type_t) 14)
#define CPU_TYPE_I860 ((cpu_type_t) 15) // big-endian
#define CPU_TYPE_I860_LITTLE ((cpu_type_t) 16) // little-endian
#define CPU_TYPE_RS6000 ((cpu_type_t) 17)
#define CPU_TYPE_MC98000 ((cpu_type_t) 18)
#define CPU_TYPE_POWERPC ((cpu_type_t) 18)
#define CPU_ARCH_ABI64 0x1000000
#define CPU_TYPE_POWERPC64 ((cpu_type_t)(CPU_TYPE_POWERPC | CPU_ARCH_ABI64))
#define CPU_TYPE_VEO ((cpu_type_t) 255)
/*
* Machine subtypes (these are defined here, instead of in a machine
* dependent directory, so that any program can get all definitions
* regardless of where is it compiled).
*/
/*
* Capability bits used in the definition of cpu_subtype.
*/
#define CPU_SUBTYPE_MASK 0xff000000 /* mask for feature flags */
#define CPU_SUBTYPE_LIB64 0x80000000 /* 64 bit libraries */
/*
* Object files that are hand-crafted to run on any
* implementation of an architecture are tagged with
* CPU_SUBTYPE_MULTIPLE. This functions essentially the same as
* the "ALL" subtype of an architecture except that it allows us
* to easily find object files that may need to be modified
* whenever a new implementation of an architecture comes out.
*
* It is the responsibility of the implementor to make sure the
* software handles unsupported implementations elegantly.
*/
#define CPU_SUBTYPE_MULTIPLE ((cpu_subtype_t) -1)
/*
* VAX subtypes (these do *not* necessary conform to the actual cpu
* ID assigned by DEC available via the SID register).
*/
#define CPU_SUBTYPE_VAX_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_VAX780 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_VAX785 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_VAX750 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_VAX730 ((cpu_subtype_t) 4)
#define CPU_SUBTYPE_UVAXI ((cpu_subtype_t) 5)
#define CPU_SUBTYPE_UVAXII ((cpu_subtype_t) 6)
#define CPU_SUBTYPE_VAX8200 ((cpu_subtype_t) 7)
#define CPU_SUBTYPE_VAX8500 ((cpu_subtype_t) 8)
#define CPU_SUBTYPE_VAX8600 ((cpu_subtype_t) 9)
#define CPU_SUBTYPE_VAX8650 ((cpu_subtype_t) 10)
#define CPU_SUBTYPE_VAX8800 ((cpu_subtype_t) 11)
#define CPU_SUBTYPE_UVAXIII ((cpu_subtype_t) 12)
/*
* ROMP subtypes.
*/
#define CPU_SUBTYPE_RT_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_RT_PC ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_RT_APC ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_RT_135 ((cpu_subtype_t) 3)
/*
* 32032/32332/32532 subtypes.
*/
#define CPU_SUBTYPE_MMAX_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_MMAX_DPC ((cpu_subtype_t) 1) /* 032 CPU */
#define CPU_SUBTYPE_SQT ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_MMAX_APC_FPU ((cpu_subtype_t) 3) /* 32081 FPU */
#define CPU_SUBTYPE_MMAX_APC_FPA ((cpu_subtype_t) 4) /* Weitek FPA */
#define CPU_SUBTYPE_MMAX_XPC ((cpu_subtype_t) 5) /* 532 CPU */
/*
* I386 subtypes.
*/
#define CPU_SUBTYPE_I386_ALL ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_X86_64_ALL CPU_SUBTYPE_I386_ALL
#define CPU_SUBTYPE_386 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_486 ((cpu_subtype_t) 4)
#define CPU_SUBTYPE_486SX ((cpu_subtype_t) 4 + 128)
#define CPU_SUBTYPE_586 ((cpu_subtype_t) 5)
#define CPU_SUBTYPE_INTEL(f, m) ((cpu_subtype_t) (f) + ((m) << 4))
#define CPU_SUBTYPE_PENT CPU_SUBTYPE_INTEL(5, 0)
#define CPU_SUBTYPE_PENTPRO CPU_SUBTYPE_INTEL(6, 1)
#define CPU_SUBTYPE_PENTII_M3 CPU_SUBTYPE_INTEL(6, 3)
#define CPU_SUBTYPE_PENTII_M5 CPU_SUBTYPE_INTEL(6, 5)
#define CPU_SUBTYPE_PENTIUM_4 CPU_SUBTYPE_INTEL(10, 0)
#define CPU_SUBTYPE_INTEL_FAMILY(x) ((x) & 15)
#define CPU_SUBTYPE_INTEL_FAMILY_MAX 15
#define CPU_SUBTYPE_INTEL_MODEL(x) ((x) >> 4)
#define CPU_SUBTYPE_INTEL_MODEL_ALL 0
/*
* Mips subtypes.
*/
#define CPU_SUBTYPE_MIPS_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_MIPS_R2300 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_MIPS_R2600 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_MIPS_R2800 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_MIPS_R2000a ((cpu_subtype_t) 4)
/*
* 680x0 subtypes
*
* The subtype definitions here are unusual for historical reasons.
* NeXT used to consider 68030 code as generic 68000 code. For
* backwards compatability:
*
* CPU_SUBTYPE_MC68030 symbol has been preserved for source code
* compatability.
*
* CPU_SUBTYPE_MC680x0_ALL has been defined to be the same
* subtype as CPU_SUBTYPE_MC68030 for binary comatability.
*
* CPU_SUBTYPE_MC68030_ONLY has been added to allow new object
* files to be tagged as containing 68030-specific instructions.
*/
#define CPU_SUBTYPE_MC680x0_ALL ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_MC68030 ((cpu_subtype_t) 1) /* compat */
#define CPU_SUBTYPE_MC68040 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_MC68030_ONLY ((cpu_subtype_t) 3)
/*
* HPPA subtypes for Hewlett-Packard HP-PA family of
* risc processors. Port by NeXT to 700 series.
*/
#define CPU_SUBTYPE_HPPA_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_HPPA_7100 ((cpu_subtype_t) 0) /* compat */
#define CPU_SUBTYPE_HPPA_7100LC ((cpu_subtype_t) 1)
/*
* Acorn subtypes - Acorn Risc Machine port done by
* Olivetti System Software Laboratory
*/
#define CPU_SUBTYPE_ARM_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_ARM_A500_ARCH ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_ARM_A500 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_ARM_A440 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_ARM_M4 ((cpu_subtype_t) 4)
#define CPU_SUBTYPE_ARM_A680 ((cpu_subtype_t) 5)
/*
* MC88000 subtypes
*/
#define CPU_SUBTYPE_MC88000_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_MMAX_JPC ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_MC88100 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_MC88110 ((cpu_subtype_t) 2)
/*
* MC98000 (PowerPC) subtypes
*/
#define CPU_SUBTYPE_MC98000_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_MC98601 ((cpu_subtype_t) 1)
/*
* I860 subtypes
*/
#define CPU_SUBTYPE_I860_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_I860_860 ((cpu_subtype_t) 1)
/*
* I860 subtypes for NeXT-internal backwards compatability.
* These constants will be going away. DO NOT USE THEM!!!
*/
#define CPU_SUBTYPE_LITTLE_ENDIAN ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_BIG_ENDIAN ((cpu_subtype_t) 1)
/*
* I860_LITTLE subtypes
*/
#define CPU_SUBTYPE_I860_LITTLE_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_I860_LITTLE ((cpu_subtype_t) 1)
/*
* RS6000 subtypes
*/
#define CPU_SUBTYPE_RS6000_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_RS6000 ((cpu_subtype_t) 1)
/*
* Sun4 subtypes - port done at CMU
*/
#define CPU_SUBTYPE_SUN4_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_SUN4_260 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_SUN4_110 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_SPARC_ALL ((cpu_subtype_t) 0)
/*
* PowerPC subtypes
*/
#define CPU_SUBTYPE_POWERPC_ALL ((cpu_subtype_t) 0)
#define CPU_SUBTYPE_POWERPC_601 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_POWERPC_602 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_POWERPC_603 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_POWERPC_603e ((cpu_subtype_t) 4)
#define CPU_SUBTYPE_POWERPC_603ev ((cpu_subtype_t) 5)
#define CPU_SUBTYPE_POWERPC_604 ((cpu_subtype_t) 6)
#define CPU_SUBTYPE_POWERPC_604e ((cpu_subtype_t) 7)
#define CPU_SUBTYPE_POWERPC_620 ((cpu_subtype_t) 8)
#define CPU_SUBTYPE_POWERPC_750 ((cpu_subtype_t) 9)
#define CPU_SUBTYPE_POWERPC_7400 ((cpu_subtype_t) 10)
#define CPU_SUBTYPE_POWERPC_7450 ((cpu_subtype_t) 11)
#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
/*
* VEO subtypes
* Note: the CPU_SUBTYPE_VEO_ALL will likely change over time to be defined as
* one of the specific subtypes.
*/
#define CPU_SUBTYPE_VEO_1 ((cpu_subtype_t) 1)
#define CPU_SUBTYPE_VEO_2 ((cpu_subtype_t) 2)
#define CPU_SUBTYPE_VEO_3 ((cpu_subtype_t) 3)
#define CPU_SUBTYPE_VEO_4 ((cpu_subtype_t) 4)
#define CPU_SUBTYPE_VEO_ALL CPU_SUBTYPE_VEO_2
#endif /* _MACH_MACHINE_H_ */

Просмотреть файл

@ -0,0 +1,82 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Copyright (c) 1994 by Sun Microsystems, Inc
*/
#ifndef _MACH_SPARC_THREAD_STATUS_H_
#define _MACH_SPARC_THREAD_STATUS_H_
#include <architecture/sparc/reg.h>
/*
* sparc_thread_state_regs
* This is the structure that is exported
* to user threads for use in set/get status
* calls. This structure should never change.
* The "local" and "in" registers of the corresponding
* register window are saved in the stack frame pointed
* to by sp -> %o6.
*
* sparc_thread_state_fpu
* This is the structure that is exported
* to user threads for use in set/get FPU register
* status calls.
*
*/
#define SPARC_THREAD_STATE_REGS 1
struct sparc_thread_state_regs {
struct regs regs;
};
#define SPARC_THREAD_STATE_REGS_COUNT \
(sizeof(struct sparc_thread_state_regs) / sizeof(int))
/*
* Floating point unit registers
*/
#define SPARC_THREAD_STATE_FPU 2
struct sparc_thread_state_fpu {
struct fpu fpu; /* floating point registers/status */
};
#define SPARC_THREAD_STATE_FPU_COUNT \
(sizeof(struct sparc_thread_state_fpu) / sizeof(int))
#define SPARC_THREAD_STATE_FLAVOR_COUNT 2
#define SPARC_THREAD_STATE_FLAVOR_LIST_COUNT \
( SPARC_THREAD_STATE_FLAVOR_COUNT * \
(sizeof (struct thread_state_flavor) / sizeof(int)))
#endif /* _MACH_SPARC_THREAD_STATUS_H_ */

Просмотреть файл

@ -0,0 +1,40 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
/* defined in allocate.c */
__private_extern__ void *allocate(
unsigned long size);
__private_extern__ void *reallocate(
void *,
unsigned long size);
__private_extern__ char *savestr(
const char *s);
__private_extern__ char *makestr(
const char *args, ...);

Просмотреть файл

@ -0,0 +1,157 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _STUFF_ARCH_H_
#define _STUFF_ARCH_H_
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
/*
* This file contains the current known set of flags and constants for the
* known architectures.
*/
#include <mach/machine.h>
#include <stuff/bytesex.h>
/*
* The structure describing an architecture flag with the string of the flag
* name, and the cputype and cpusubtype.
*/
struct arch_flag {
char *name;
cpu_type_t cputype;
cpu_subtype_t cpusubtype;
};
/*
* get_arch_from_flag() is passed a name of an architecture flag and returns
* zero if that flag is not known and non-zero if the flag is known.
* If the pointer to the arch_flag is not NULL it is filled in with the
* arch_flag struct that matches the name.
*/
__private_extern__ int get_arch_from_flag(
char *name,
struct arch_flag *arch_flag);
/*
* get_arch_from_host() gets the architecture from the host this is running on
* and returns zero if the architecture is not known and zero if the
* architecture is known. If the parameters family_arch_flag and
* specific_arch_flag are not NULL they get fill in with the family
* architecture and specific architecure for the host. If the architecture
* is unknown and the parameters are not NULL then all fields are set to zero.
*/
__private_extern__ int get_arch_from_host(
struct arch_flag *family_arch_flag,
struct arch_flag *specific_arch_flag);
/*
* get_arch_flags() returns a pointer to an array of all currently know
* architecture flags (terminated with an entry with all zeros).
*/
__private_extern__ const struct arch_flag *get_arch_flags(
void);
/*
* arch_usage() is called when an unknown architecture flag is encountered.
* It prints the currently know architecture flags on stderr.
*/
__private_extern__ void arch_usage(
void);
/*
* set_arch_flag_name() sets the name field of the specified arch_flag to
* match it's cputype and cpusubtype. The string is allocated via malloc by
* the routines in "allocate.h" and errors are handled by the routines in
* "error.h".
*/
__private_extern__ void set_arch_flag_name(
struct arch_flag *p);
/*
* get_arch_name_from_types() returns the name of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns a pointer
* to the string "unknown".
*/
__private_extern__ const char *get_arch_name_from_types(
cpu_type_t cputype,
cpu_subtype_t cpusubtype);
/*
* get_arch_family_from_cputype() returns the family architecture for the
* specified cputype if known. If unknown it returns NULL.
*/
__private_extern__ const struct arch_flag *get_arch_family_from_cputype(
cpu_type_t cputype);
/*
* get_byte_sex_from_flag() returns the byte sex of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns
* UNKNOWN_BYTE_SEX. If the bytesex can be determined directly as in the case
* of reading a magic number from a file that should be done and this routine
* should not be used as it could be out of date.
*/
__private_extern__ enum byte_sex get_byte_sex_from_flag(
const struct arch_flag *flag);
/*
* get_stack_direction_from_flag() returns the direction the stack grows as
* either positive (+1) or negative (-1) of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns 0.
*/
__private_extern__ long get_stack_direction_from_flag(
const struct arch_flag *flag);
/*
* get_stack_addr_from_flag() returns the default starting address of the user
* stack.
*/
__private_extern__ uint64_t get_stack_addr_from_flag(
const struct arch_flag *flag);
/*
* get_stack_size_from_flag() returns the default size of the userstack.
*/
__private_extern__ unsigned long get_stack_size_from_flag(
const struct arch_flag *flag);
/*
* get_segalign_from_flag() returns the default segment alignment (page size).
*/
__private_extern__ unsigned long get_segalign_from_flag(
const struct arch_flag *flag);
/*
* get_segprot_from_flag() returns the default segment protection.
*/
__private_extern__ vm_prot_t get_segprot_from_flag(
const struct arch_flag *flag);
/*
* force_cpusubtype_ALL_for_cputype() takes a cputype and returns TRUE if for
* that cputype the cpusubtype should always be forced to the ALL cpusubtype,
* otherwise it returns FALSE.
*/
__private_extern__ enum bool force_cpusubtype_ALL_for_cputype(
cpu_type_t cputype);
#endif /* _STUFF_ARCH_H_ */

Просмотреть файл

@ -0,0 +1,44 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* bool.h */
#ifndef ENUM_DYLD_BOOL
#define ENUM_DYLD_BOOL
#define _STDBOOL_H
#undef bool
#define DYLD_BOOL bool
#undef FALSE
#undef TRUE
enum bool {
FALSE,
TRUE
};
#endif /* ENUM_DYLD_BOOL */

Просмотреть файл

@ -0,0 +1,271 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#import "stuff/ofile.h"
/*
* This is used to build the table of contents of an archive. Each toc_entry
* Contains a pointer to a symbol name that is defined by a member of the
* archive. The member that defines this symbol is referenced by its index in
* the archive plus one. This is done so the negative value if the index can
* be used for marking then later to generate the ran_off field with the byte
* offset.
*/
struct toc_entry {
char *symbol_name;
long member_index;
};
/*
* The input files are broken out in to their object files and then placed in
* these structures. These structures are then used to edit the object files'
* symbol table. And then finally used to reassemble the object file for
* output.
*/
struct arch {
char *file_name; /* name of file this arch came from */
enum ofile_type type; /* The type of file for this architecture */
/* can be OFILE_ARCHIVE, OFILE_Mach_O or */
/* OFILE_UNKNOWN. */
struct fat_arch *fat_arch; /* If this came from fat file this is valid */
/* and not NULL (needed for the align value */
/* and to output a fat file if only one arch)*/
char *fat_arch_name; /* If this came from fat file this is valid */
/* and is tthe name of this architecture */
/* (used for error messages). */
/* if this is an archive: the members of this archive */
struct member *members; /* the members of the library for this arch */
unsigned long nmembers; /* the number of the above members */
/*
* The output table of contents (toc) for this arch in the library (this
* must be recreated, or at least the time of the toc member set, when
* the output is modified because modifiy time is shared by all libraries
* in the file).
*/
unsigned long toc_size; /* total size of the toc including ar_hdr */
struct ar_hdr toc_ar_hdr; /* the archive header for this member */
enum bool toc_long_name;/* use the long name in the output */
char *toc_name; /* name of toc member */
unsigned long toc_name_size;/* size of name of toc member */
unsigned long ntocs; /* number of table of contents entries */
struct toc_entry
*toc_entries; /* the table of contents entries */
struct ranlib *toc_ranlibs; /* the ranlib structs */
char *toc_strings; /* strings of symbol names for toc entries */
unsigned long toc_strsize; /* number of bytes for the strings above */
unsigned long library_size; /* current working size and final output size */
/* for this arch when it's a library (used */
/* for creating the toc entries). */
/* if this is an object file: the object file */
struct object *object; /* the object file */
/* if this is an unknown file: the addr and size of the file */
char *unknown_addr;
unsigned long unknown_size;
/* don't update LC_ID_DYLIB timestamp */
enum bool dont_update_LC_ID_DYLIB_timestamp;
};
struct member {
enum ofile_type type; /* the type of this member can be OFILE_Mach_O*/
/* or OFILE_UNKNOWN */
struct ar_hdr *ar_hdr; /* the archive header for this member */
unsigned long offset; /* current working offset and final offset */
/* use in creating the table of contents */
/* the name of the member in the output */
char *member_name; /* the member name */
unsigned long member_name_size; /* the size of the member name */
enum bool member_long_name; /* use the extended format #1 for the
member name in the output */
/* if this member is an object file: the object file */
struct object *object; /* the object file */
/* if this member is an unknown file: the addr and size of the member */
char *unknown_addr;
unsigned long unknown_size;
/*
* If this member was created from a file then input_file_name is set else
* it is NULL and input_ar_hdr is set (these are recorded to allow
* warn_member() messages to be printed)
*/
char *input_file_name;
struct ar_hdr *input_ar_hdr;
};
struct object {
char *object_addr; /* the address of the object file */
unsigned long object_size; /* the size of the object file on input */
enum byte_sex object_byte_sex; /* the byte sex of the object file */
struct mach_header *mh; /* the mach_header of 32-bit object file */
struct mach_header_64 *mh64; /* the mach_header of 64-bit object file */
/* these copied from the mach header above */
cpu_type_t mh_cputype; /* cpu specifier */
cpu_subtype_t mh_cpusubtype; /* machine specifier */
uint32_t mh_filetype; /* type of file */
struct load_command /* the start of the load commands */
*load_commands;
struct symtab_command *st; /* the symbol table command */
struct dysymtab_command *dyst; /* the dynamic symbol table command */
struct twolevel_hints_command /* the two-level namespace hints command */
*hints_cmd;
struct prebind_cksum_command *cs;/* the prebind check sum command */
struct segment_command
*seg_linkedit; /* the 32-bit link edit segment command */
struct segment_command_64
*seg_linkedit64; /* the 64-bit link edit segment command */
struct linkedit_data_command
*code_sig_cmd; /* the code signature load command, if any*/
struct linkedit_data_command
*split_info_cmd; /* the split info load command, if any*/
struct section **sections; /* array of 32-bit section structs */
struct section_64 **sections64; /* array of 64-bit section structs */
/*
* This is only used for redo_prebinding and is calculated by breakout()
* if the calculate_input_prebind_cksum parameter is TRUE and there is an
* LC_PREBIND_CKSUM load command that has a zero value for the cksum field
* (if so this will be value of the cksum field on output).
*/
unsigned long calculated_input_prebind_cksum;
unsigned long input_sym_info_size;
unsigned long output_sym_info_size;
/*
* For 64-bit Mach-O files they may have an odd number of indirect symbol
* table entries so the next offset MAYBE or MAY NOT be rounded to a
* multiple of 8. input_indirectsym_pad contains the amount of padding in
* that was in the input.
*/
unsigned long input_indirectsym_pad;
struct nlist *output_symbols;
struct nlist_64 *output_symbols64;
unsigned long output_nsymbols;
char *output_strings;
unsigned long output_strings_size;
char *output_code_sig_data;
unsigned long output_code_sig_data_size;
char *output_split_info_data;
unsigned long output_split_info_data_size;
unsigned long output_ilocalsym;
unsigned long output_nlocalsym;
unsigned long output_iextdefsym;
unsigned long output_nextdefsym;
unsigned long output_iundefsym;
unsigned long output_nundefsym;
struct twolevel_hint *output_hints;
struct relocation_info *output_loc_relocs;
struct relocation_info *output_ext_relocs;
uint32_t *output_indirect_symtab;
struct dylib_table_of_contents *output_tocs;
unsigned long output_ntoc;
struct dylib_module *output_mods;
struct dylib_module_64 *output_mods64;
unsigned long output_nmodtab;
struct dylib_reference *output_refs;
unsigned long output_nextrefsyms;
};
__private_extern__ struct ofile * breakout(
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum);
__private_extern__ struct ofile * breakout_mem(
void *membuf,
unsigned long length,
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum);
__private_extern__ void free_archs(
struct arch *archs,
unsigned long narchs);
__private_extern__ void writeout(
struct arch *archs,
unsigned long narchs,
char *output,
unsigned short mode,
enum bool sort_toc,
enum bool commons_in_toc,
enum bool library_warnings,
unsigned long *throttle);
__private_extern__ void writeout_to_mem(
struct arch *archs,
unsigned long narchs,
char *filename,
void **outputbuf,
unsigned long *length,
enum bool sort_toc,
enum bool commons_in_toc,
enum bool library_warning,
enum bool *seen_archive);
__private_extern__ void checkout(
struct arch *archs,
unsigned long narchs);
void warning_arch(
struct arch *arch,
struct member *member,
char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
#endif
;
void error_arch(
struct arch *arch,
struct member *member,
char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
#endif
;
void fatal_arch(
struct arch *arch,
struct member *member,
char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 3, 4)))
#endif
;

Просмотреть файл

@ -0,0 +1,407 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* bytesex.h */
#ifndef _STUFF_BYTESEX_H_
#define _STUFF_BYTESEX_H_
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#include <mach/m68k/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/ppc/thread_status.h>
#undef MACHINE_THREAD_STATE /* need to undef these to avoid warnings */
#undef MACHINE_THREAD_STATE_COUNT
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#include <mach/m88k/thread_status.h>
#include <mach/i860/thread_status.h>
#include <mach/i386/thread_status.h>
#include <mach/hppa/thread_status.h>
#include <mach/sparc/thread_status.h>
#include <mach-o/nlist.h>
#include <mach-o/reloc.h>
#include <mach-o/ranlib.h>
#include "stuff/bool.h"
enum byte_sex {
UNKNOWN_BYTE_SEX,
BIG_ENDIAN_BYTE_SEX,
LITTLE_ENDIAN_BYTE_SEX
};
#define SWAP_SHORT(a) ( ((a & 0xff) << 8) | ((unsigned short)(a) >> 8) )
#define SWAP_INT(a) ( ((a) << 24) | \
(((a) << 8) & 0x00ff0000) | \
(((a) >> 8) & 0x0000ff00) | \
((unsigned int)(a) >> 24) )
#ifndef __LP64__
#define SWAP_LONG(a) ( ((a) << 24) | \
(((a) << 8) & 0x00ff0000) | \
(((a) >> 8) & 0x0000ff00) | \
((unsigned long)(a) >> 24) )
#endif
__private_extern__ long long SWAP_LONG_LONG(
long long ll);
__private_extern__ float SWAP_FLOAT(
float f);
__private_extern__ double SWAP_DOUBLE(
double d);
__private_extern__ enum byte_sex get_host_byte_sex(
void);
__private_extern__ void swap_fat_header(
struct fat_header *fat_header,
enum byte_sex target_byte_sex);
__private_extern__ void swap_fat_arch(
struct fat_arch *fat_archs,
unsigned long nfat_arch,
enum byte_sex target_byte_sex);
__private_extern__ void swap_mach_header(
struct mach_header *mh,
enum byte_sex target_byte_sex);
__private_extern__ void swap_mach_header_64(
struct mach_header_64 *mh,
enum byte_sex target_byte_sex);
__private_extern__ void swap_load_command(
struct load_command *lc,
enum byte_sex target_byte_sex);
__private_extern__ void swap_segment_command(
struct segment_command *sg,
enum byte_sex target_byte_sex);
__private_extern__ void swap_segment_command_64(
struct segment_command_64 *sg,
enum byte_sex target_byte_sex);
__private_extern__ void swap_section(
struct section *s,
unsigned long nsects,
enum byte_sex target_byte_sex);
__private_extern__ void swap_section_64(
struct section_64 *s,
unsigned long nsects,
enum byte_sex target_byte_sex);
__private_extern__ void swap_symtab_command(
struct symtab_command *st,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dysymtab_command(
struct dysymtab_command *dyst,
enum byte_sex target_byte_sex);
__private_extern__ void swap_symseg_command(
struct symseg_command *ss,
enum byte_sex target_byte_sex);
__private_extern__ void swap_fvmlib_command(
struct fvmlib_command *fl,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylib_command(
struct dylib_command *dl,
enum byte_sex target_byte_sex);
__private_extern__ void swap_sub_framework_command(
struct sub_framework_command *sub,
enum byte_sex target_byte_sex);
__private_extern__ void swap_sub_umbrella_command(
struct sub_umbrella_command *usub,
enum byte_sex target_byte_sex);
__private_extern__ void swap_sub_library_command(
struct sub_library_command *lsub,
enum byte_sex target_byte_sex);
__private_extern__ void swap_sub_client_command(
struct sub_client_command *csub,
enum byte_sex target_byte_sex);
__private_extern__ void swap_prebound_dylib_command(
struct prebound_dylib_command *pbdylib,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylinker_command(
struct dylinker_command *dyld,
enum byte_sex target_byte_sex);
__private_extern__ void swap_fvmfile_command(
struct fvmfile_command *ff,
enum byte_sex target_byte_sex);
__private_extern__ void swap_thread_command(
struct thread_command *ut,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m68k_thread_state_regs(
struct m68k_thread_state_regs *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m68k_thread_state_68882(
struct m68k_thread_state_68882 *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m68k_thread_state_user_reg(
struct m68k_thread_state_user_reg *user_reg,
enum byte_sex target_byte_sex);
__private_extern__ void swap_ppc_thread_state_t(
ppc_thread_state_t *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_ppc_thread_state64_t(
ppc_thread_state64_t *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_ppc_float_state_t(
ppc_float_state_t *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_ppc_exception_state_t(
ppc_exception_state_t *state,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m88k_thread_state_grf_t(
m88k_thread_state_grf_t *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m88k_thread_state_xrf_t(
m88k_thread_state_xrf_t *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m88k_thread_state_user_t(
m88k_thread_state_user_t *user,
enum byte_sex target_byte_sex);
__private_extern__ void swap_m88110_thread_state_impl_t(
m88110_thread_state_impl_t *spu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_i860_thread_state_regs(
struct i860_thread_state_regs *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_i386_thread_state(
i386_thread_state_t *cpu,
enum byte_sex target_byte_sex);
/* current i386 thread states */
#if i386_THREAD_STATE == 1
__private_extern__ void swap_i386_float_state(
struct __darwin_i386_float_state *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_i386_exception_state(
i386_exception_state_t *exc,
enum byte_sex target_byte_sex);
#endif /* i386_THREAD_STATE == 1 */
/* i386 thread states on older releases */
#if i386_THREAD_STATE == -1
__private_extern__ void swap_i386_thread_fpstate(
i386_thread_fpstate_t *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_i386_thread_exceptstate(
i386_thread_exceptstate_t *exc,
enum byte_sex target_byte_sex);
__private_extern__ void swap_i386_thread_cthreadstate(
i386_thread_cthreadstate_t *user,
enum byte_sex target_byte_sex);
#endif /* i386_THREAD_STATE == -1 */
#ifdef x86_THREAD_STATE64
__private_extern__ void swap_x86_thread_state64(
x86_thread_state64_t *cpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_x86_float_state64(
x86_float_state64_t *fpu,
enum byte_sex target_byte_sex);
__private_extern__ void swap_x86_state_hdr(
struct x86_state_hdr *hdr,
enum byte_sex target_byte_sex);
__private_extern__ void swap_x86_exception_state64(
x86_exception_state64_t *exc,
enum byte_sex target_byte_sex);
__private_extern__ void swap_x86_debug_state32(
x86_debug_state32_t *debug,
enum byte_sex target_byte_sex);
__private_extern__ void swap_x86_debug_state64(
x86_debug_state64_t *debug,
enum byte_sex target_byte_sex);
#endif /* x86_THREAD_STATE64 */
__private_extern__ void swap_hppa_integer_thread_state(
struct hp_pa_integer_thread_state *regs,
enum byte_sex target_byte_order);
__private_extern__ void swap_hppa_frame_thread_state(
struct hp_pa_frame_thread_state *frame,
enum byte_sex target_byte_order);
__private_extern__ void swap_hppa_fp_thread_state(
struct hp_pa_fp_thread_state *fp,
enum byte_sex target_byte_order);
__private_extern__ void swap_sparc_thread_state_regs(
struct sparc_thread_state_regs *cpu,
enum byte_sex target_byte_order);
__private_extern__ void swap_sparc_thread_state_fpu(
struct sparc_thread_state_fpu *fpu,
enum byte_sex target_byte_order);
__private_extern__ void swap_ident_command(
struct ident_command *id_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_routines_command(
struct routines_command *r_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_routines_command_64(
struct routines_command_64 *r_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_twolevel_hints_command(
struct twolevel_hints_command *hints_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_prebind_cksum_command(
struct prebind_cksum_command *cksum_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_uuid_command(
struct uuid_command *uuid_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_linkedit_data_command(
struct linkedit_data_command *ld,
enum byte_sex target_byte_sex);
__private_extern__ void swap_rpath_command(
struct rpath_command *rpath_cmd,
enum byte_sex target_byte_sex);
__private_extern__ void swap_nlist(
struct nlist *symbols,
unsigned long nsymbols,
enum byte_sex target_byte_sex);
__private_extern__ void swap_nlist_64(
struct nlist_64 *symbols,
unsigned long nsymbols,
enum byte_sex target_byte_sex);
__private_extern__ void swap_ranlib(
struct ranlib *ranlibs,
unsigned long nranlibs,
enum byte_sex target_byte_sex);
__private_extern__ void swap_relocation_info(
struct relocation_info *relocs,
unsigned long nrelocs,
enum byte_sex target_byte_sex);
__private_extern__ void swap_indirect_symbols(
uint32_t *indirect_symbols,
uint32_t nindirect_symbols,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylib_reference(
struct dylib_reference *refs,
unsigned long nrefs,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylib_module(
struct dylib_module *mods,
unsigned long nmods,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylib_module_64(
struct dylib_module_64 *mods,
unsigned long nmods,
enum byte_sex target_byte_sex);
__private_extern__ void swap_dylib_table_of_contents(
struct dylib_table_of_contents *tocs,
unsigned long ntocs,
enum byte_sex target_byte_sex);
__private_extern__ void swap_twolevel_hint(
struct twolevel_hint *hints,
unsigned long nhints,
enum byte_sex target_byte_sex);
/*
* swap_object_headers() swaps the object file headers from the host byte sex
* into the non-host byte sex. It returns TRUE if it can and did swap the
* headers else returns FALSE and does not touch the headers and prints an error
* using the error() routine.
*/
__private_extern__ enum bool swap_object_headers(
void *mach_header, /* either a mach_header or a mach_header_64 */
struct load_command *load_commands);
/*
* get_toc_byte_sex() guesses the byte sex of the table of contents of the
* library mapped in at the address, addr, of size, size based on the first
* object file's bytesex. If it can't figure it out, because the library has
* no object file members or is malformed it will return UNKNOWN_BYTE_SEX.
*/
__private_extern__ enum byte_sex get_toc_byte_sex(
char *addr,
unsigned long size);
#endif /* _STUFF_BYTESEX_H_ */

Просмотреть файл

@ -0,0 +1,25 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
__private_extern__ unsigned long crc32(
const void *buf,
unsigned int len);

Просмотреть файл

@ -0,0 +1,91 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#import "mach/mach.h"
/* user defined (imported) */
__private_extern__ char *progname;
/* defined in errors.c */
/* number of detected calls to error() */
__private_extern__ unsigned long errors;
__private_extern__ void warning(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void error(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void error_with_arch(
const char *arch_name,
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
;
__private_extern__ void system_error(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void fatal(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void system_fatal(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void my_mach_error(
kern_return_t r,
char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
;
__private_extern__ void mach_fatal(
kern_return_t r,
char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
#endif
;

Просмотреть файл

@ -0,0 +1,193 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/* ofile.h */
#ifndef _STUFF_OFILE_H_
#define _STUFF_OFILE_H_
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#import <ar.h>
#ifndef AR_EFMT1
#define AR_EFMT1 "#1/" /* extended format #1 */
#endif
#import <mach-o/loader.h>
#ifdef OFI
#import <mach-o/dyld.h>
#endif
#import "stuff/bytesex.h"
#import "stuff/bool.h"
#import "stuff/arch.h"
enum ofile_type {
OFILE_UNKNOWN,
OFILE_FAT,
OFILE_ARCHIVE,
OFILE_Mach_O
};
/*
* The structure used by ofile_*() routines for object files.
*/
struct ofile {
char *file_name; /* pointer to name malloc'ed by ofile_map */
char *file_addr; /* pointer to vm_allocate'ed memory */
unsigned long file_size; /* size of vm_allocate'ed memory */
enum ofile_type file_type; /* type of the file */
struct fat_header *fat_header; /* If a fat file these are filled in and */
struct fat_arch *fat_archs; /* if needed converted to host byte sex */
/* If this is a fat file then these are valid and filled in */
unsigned long narch; /* the current architecture */
enum ofile_type arch_type; /* the type of file for this arch. */
struct arch_flag arch_flag; /* the arch_flag for this arch, the name */
/* field is pointing at space malloc'ed */
/* by ofile_map. */
/* If this structure is currently referencing an archive member or an object
file that is an archive member these are valid and filled in. */
unsigned long member_offset; /* logical offset to the member starting */
char *member_addr; /* pointer to the member contents */
unsigned long member_size; /* actual size of the member (not rounded)*/
struct ar_hdr *member_ar_hdr; /* pointer to the ar_hdr for this member */
char *member_name; /* name of this member */
unsigned long member_name_size; /* size of the member name */
enum ofile_type member_type; /* the type of file for this member */
cpu_type_t archive_cputype; /* if the archive contains objects then */
cpu_subtype_t /* these two fields reflect the object */
archive_cpusubtype; /* at are in the archive. */
/* If this structure is currently referencing a dynamic library module
these are valid and filled in. */
struct dylib_module *modtab; /* the 32-bit module table */
struct dylib_module_64 *modtab64;/* the 64-bit module table */
unsigned long nmodtab; /* the number of module table entries */
struct dylib_module /* pointer to the 32-bit dylib_module for */
*dylib_module; /* this module. */
struct dylib_module_64 /* pointer to the 64-bit dylib_module for */
*dylib_module64; /* this module. */
char *dylib_module_name; /* the name of the module */
/* If this structure is currently referencing an object file these are
valid and filled in. The mach_header and load commands have been
converted to the host byte sex if needed */
enum bool headers_swapped; /* true if the headers have already been
swapped to host byte sex */
char *object_addr; /* the address of the object file */
unsigned long object_size; /* the size of the object file */
enum byte_sex object_byte_sex; /* the byte sex of the object file */
struct mach_header *mh; /* the mach_header of 32-bit object file */
struct mach_header_64 *mh64; /* the mach_header of 64-bit object file */
struct load_command /* the start of the load commands */
*load_commands;
/* these copied from the mach header above */
cpu_type_t mh_cputype; /* cpu specifier */
cpu_subtype_t mh_cpusubtype; /* machine specifier */
uint32_t mh_filetype; /* type of file */
};
__private_extern__ void ofile_process(
char *name,
struct arch_flag *arch_flags,
unsigned long narch_flags,
enum bool all_archs,
enum bool process_non_objects,
enum bool dylib_flat,
enum bool use_member_syntax,
void (*processor)(struct ofile *ofile, char *arch_name, void *cookie),
void *cookie);
#ifdef OFI
__private_extern__ NSObjectFileImageReturnCode ofile_map(
#else
__private_extern__ enum bool ofile_map(
#endif
const char *file_name,
const struct arch_flag *arch_flag, /* can be NULL */
const char *object_name, /* can be NULL */
struct ofile *ofile,
enum bool archives_with_fat_objects);
#ifdef OFI
__private_extern__ NSObjectFileImageReturnCode ofile_map_from_memory(
#else
__private_extern__ enum bool ofile_map_from_memory(
#endif
char *addr,
unsigned long size,
const char *file_name,
const struct arch_flag *arch_flag, /* can be NULL */
const char *object_name, /* can be NULL */
struct ofile *ofile,
enum bool archives_with_fat_objects);
__private_extern__ void ofile_unmap(
struct ofile *ofile);
__private_extern__ enum bool ofile_first_arch(
struct ofile *ofile);
__private_extern__ enum bool ofile_next_arch(
struct ofile *ofile);
__private_extern__ enum bool ofile_first_member(
struct ofile *ofile);
__private_extern__ enum bool ofile_next_member(
struct ofile *ofile);
__private_extern__ enum bool ofile_specific_member(
const char *object_name,
struct ofile *ofile);
__private_extern__ enum bool ofile_first_module(
struct ofile *ofile);
__private_extern__ enum bool ofile_next_module(
struct ofile *ofile);
__private_extern__ enum bool ofile_specific_module(
const char *module_name,
struct ofile *ofile);
__private_extern__ void ofile_print(
struct ofile *ofile);
__private_extern__ unsigned long size_ar_name(
const struct ar_hdr *ar_hdr);
__private_extern__ long ofile_get_word(
uint64_t addr,
uint32_t *word,
void *get_word_data /* struct ofile *ofile */);
__private_extern__ void archive_error(
struct ofile *ofile,
const char *format, ...)
#ifndef __MWERKS__
__attribute__ ((format (printf, 2, 3)))
#endif
;
__private_extern__ void archive_member_error(
struct ofile *ofile,
const char *format, ...)
#ifndef __MWERKS__
__attribute__ ((format (printf, 2, 3)))
#endif
;
__private_extern__ void Mach_O_error(
struct ofile *ofile,
const char *format, ...)
#ifndef __MWERKS__
__attribute__ ((format (printf, 2, 3)))
#endif
;
#endif /* _STUFF_OFILE_H_ */

Просмотреть файл

@ -0,0 +1,41 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __OPENSTEP__
/*
* This file is used to allow cctools to be compiled for Openstep now that
* the code has been changed to use Mach 3.0 names (which work for MacOS X and
* Rhapsody but not for Openstep).
*/
#define mach_task_self task_self
#define mach_task_self_ task_self_
#define mach_host_self host_self
#define mach_thread_self thread_self
#define mach_port_allocate port_allocate
#define mach_port_deallocate port_deallocate
#define mach_port_names port_names
#endif /* __OPENSTEP__ */

Просмотреть файл

@ -0,0 +1,36 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#import <stdarg.h>
__private_extern__ void print(
const char *format, ...)
#ifdef __GNUC__
__attribute__ ((format (printf, 1, 2)))
#endif
;
__private_extern__ void vprint(
const char *format, va_list ap);

Просмотреть файл

@ -0,0 +1,37 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
#import <mach/machine.h>
#import "stuff/bool.h"
__private_extern__ unsigned long reloc_pair_r_type(
cpu_type_t cputype);
__private_extern__ enum bool reloc_has_pair(
cpu_type_t cputype,
unsigned long r_type);
__private_extern__ enum bool reloc_is_sectdiff(
cpu_type_t cputype,
unsigned long r_type);

Просмотреть файл

@ -0,0 +1,37 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(__MWERKS__) && !defined(__private_extern__)
#define __private_extern__ __declspec(private_extern)
#endif
/*
* round() rounds v to a multiple of r.
*/
__private_extern__ unsigned long round(
unsigned long v,
unsigned long r);

Просмотреть файл

@ -0,0 +1,42 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <mach-o/nlist.h>
#include <stuff/bool.h>
/*
* Data structures to perform selective stripping of symbol table entries.
*/
struct symbol_list {
char *name; /* name of the global symbol */
void *sym; /* pointer to the nlist structure for this symbol */
enum bool seen; /* set if the symbol is seen in the input file */
};
__private_extern__ void setup_symbol_list(
char *file,
struct symbol_list **list,
unsigned long *size);
__private_extern__ int symbol_list_bsearch(
const char *name,
const struct symbol_list *sym);

Просмотреть файл

@ -0,0 +1,26 @@
/*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include "stuff/bool.h"
__private_extern__ enum bool get_unix_standard_mode(
void);

Просмотреть файл

@ -0,0 +1,123 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <mach/mach.h>
#include "stuff/allocate.h"
#include "stuff/errors.h"
/*
* allocate() is just a wrapper around malloc that prints an error message and
* exits if the malloc fails.
*/
__private_extern__
void *
allocate(
unsigned long size)
{
void *p;
if(size == 0)
return(NULL);
if((p = malloc(size)) == NULL)
system_fatal("virtual memory exhausted (malloc failed)");
return(p);
}
/*
* reallocate() is just a wrapper around realloc that prints and error message
* and exits if the realloc fails.
*/
__private_extern__
void *
reallocate(
void *p,
unsigned long size)
{
if(p == NULL)
return(allocate(size));
if((p = realloc(p, size)) == NULL)
system_fatal("virtual memory exhausted (realloc failed)");
return(p);
}
/*
* savestr() malloc's space for the string passed to it, copys the string into
* the space and returns a pointer to that space.
*/
__private_extern__
char *
savestr(
const char *s)
{
long len;
char *r;
len = strlen(s) + 1;
r = (char *)allocate(len);
strcpy(r, s);
return(r);
}
/*
* Makestr() creates a string that is the concatenation of a variable number of
* strings. It is pass a variable number of pointers to strings and the last
* pointer is NULL. It returns the pointer to the string it created. The
* storage for the string is malloc()'ed can be free()'ed when nolonger needed.
*/
__private_extern__
char *
makestr(
const char *args,
...)
{
va_list ap;
char *s, *p;
long size;
size = 0;
if(args != NULL){
size += strlen(args);
va_start(ap, args);
p = (char *)va_arg(ap, char *);
while(p != NULL){
size += strlen(p);
p = (char *)va_arg(ap, char *);
}
}
s = allocate(size + 1);
*s = '\0';
if(args != NULL){
(void)strcat(s, args);
va_start(ap, args);
p = (char *)va_arg(ap, char *);
while(p != NULL){
(void)strcat(s, p);
p = (char *)va_arg(ap, char *);
}
va_end(ap);
}
return(s);
}

Просмотреть файл

@ -0,0 +1,342 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include "stdio.h"
#endif /* !defined(RLD) */
#include "stdlib.h"
#include "string.h"
#include <mach/mach.h>
#include "stuff/openstep_mach.h"
#include "stuff/arch.h"
#include "stuff/allocate.h"
/*
* The array of all currently know architecture flags (terminated with an entry
* with all zeros). Pointer to this returned with get_arch_flags().
*/
#ifdef __DYNAMIC__
static struct arch_flag arch_flags[] = {
#else
static const struct arch_flag arch_flags[] = {
#endif
{ "any", CPU_TYPE_ANY, CPU_SUBTYPE_MULTIPLE },
{ "little", CPU_TYPE_ANY, CPU_SUBTYPE_LITTLE_ENDIAN },
{ "big", CPU_TYPE_ANY, CPU_SUBTYPE_BIG_ENDIAN },
/* 64-bit Mach-O architectures */
/* architecture families */
{ "ppc64", CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_ALL },
{ "x86_64", CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL },
/* specific architecture implementations */
{ "ppc970-64", CPU_TYPE_POWERPC64, CPU_SUBTYPE_POWERPC_970 },
/* 32-bit Mach-O architectures */
/* architecture families */
{ "ppc", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_ALL },
{ "i386", CPU_TYPE_I386, CPU_SUBTYPE_I386_ALL },
{ "m68k", CPU_TYPE_MC680x0, CPU_SUBTYPE_MC680x0_ALL },
{ "hppa", CPU_TYPE_HPPA, CPU_SUBTYPE_HPPA_ALL },
{ "sparc", CPU_TYPE_SPARC, CPU_SUBTYPE_SPARC_ALL },
{ "m88k", CPU_TYPE_MC88000, CPU_SUBTYPE_MC88000_ALL },
{ "i860", CPU_TYPE_I860, CPU_SUBTYPE_I860_ALL },
{ "veo", CPU_TYPE_VEO, CPU_SUBTYPE_VEO_ALL },
/* specific architecture implementations */
{ "ppc601", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_601 },
{ "ppc603", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_603 },
{ "ppc603e",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_603e },
{ "ppc603ev",CPU_TYPE_POWERPC,CPU_SUBTYPE_POWERPC_603ev },
{ "ppc604", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_604 },
{ "ppc604e",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_604e },
{ "ppc750", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_750 },
{ "ppc7400",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7400 },
{ "ppc7450",CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_7450 },
{ "ppc970", CPU_TYPE_POWERPC, CPU_SUBTYPE_POWERPC_970 },
{ "i486", CPU_TYPE_I386, CPU_SUBTYPE_486 },
{ "i486SX", CPU_TYPE_I386, CPU_SUBTYPE_486SX },
{ "pentium",CPU_TYPE_I386, CPU_SUBTYPE_PENT }, /* same as i586 */
{ "i586", CPU_TYPE_I386, CPU_SUBTYPE_586 },
{ "pentpro", CPU_TYPE_I386, CPU_SUBTYPE_PENTPRO }, /* same as i686 */
{ "i686", CPU_TYPE_I386, CPU_SUBTYPE_PENTPRO },
{ "pentIIm3",CPU_TYPE_I386, CPU_SUBTYPE_PENTII_M3 },
{ "pentIIm5",CPU_TYPE_I386, CPU_SUBTYPE_PENTII_M5 },
{ "pentium4",CPU_TYPE_I386, CPU_SUBTYPE_PENTIUM_4 },
{ "m68030", CPU_TYPE_MC680x0, CPU_SUBTYPE_MC68030_ONLY },
{ "m68040", CPU_TYPE_MC680x0, CPU_SUBTYPE_MC68040 },
{ "hppa7100LC", CPU_TYPE_HPPA, CPU_SUBTYPE_HPPA_7100LC },
{ "veo1", CPU_TYPE_VEO, CPU_SUBTYPE_VEO_1 },
{ "veo2", CPU_TYPE_VEO, CPU_SUBTYPE_VEO_2 },
{ "veo3", CPU_TYPE_VEO, CPU_SUBTYPE_VEO_3 },
{ "veo4", CPU_TYPE_VEO, CPU_SUBTYPE_VEO_4 },
{ NULL, 0, 0 }
};
#ifndef RLD
/*
* get_arch_from_flag() is passed a name of an architecture flag and returns
* zero if that flag is not known and non-zero if the flag is known.
* If the pointer to the arch_flag is not NULL it is filled in with the
* arch_flag struct that matches the name.
*/
__private_extern__
int
get_arch_from_flag(
char *name,
struct arch_flag *arch_flag)
{
unsigned long i;
for(i = 0; arch_flags[i].name != NULL; i++){
if(strcmp(arch_flags[i].name, name) == 0){
if(arch_flag != NULL)
*arch_flag = arch_flags[i];
return(1);
}
}
if(arch_flag != NULL)
memset(arch_flag, '\0', sizeof(struct arch_flag));
return(0);
}
/*
* get_arch_flags() returns a pointer to an array of all currently know
* architecture flags (terminated with an entry with all zeros).
*/
__private_extern__
const struct arch_flag *
get_arch_flags(
void)
{
return(arch_flags);
}
#endif /* !defined(RLD) */
/*
* get_arch_name_from_types() returns the name of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns a pointer
* to the an allocated string "cputype X cpusubtype Y" where X and Y are decimal
* values.
*/
__private_extern__
const char *
get_arch_name_from_types(
cpu_type_t cputype,
cpu_subtype_t cpusubtype)
{
unsigned long i;
char *p;
for(i = 0; arch_flags[i].name != NULL; i++){
if(arch_flags[i].cputype == cputype &&
(arch_flags[i].cpusubtype & ~CPU_SUBTYPE_MASK) ==
(cpusubtype & ~CPU_SUBTYPE_MASK))
return(arch_flags[i].name);
}
#ifndef RLD
p = savestr("cputype 1234567890 cpusubtype 1234567890");
if(p != NULL)
sprintf(p, "cputype %u cpusubtype %u", cputype,
cpusubtype & ~CPU_SUBTYPE_MASK);
#else
/* there is no sprintf() in the rld kernel API's */
p = savestr("cputype ?? cpusubtype ??");
#endif
return(p);
}
/*
* get_arch_family_from_cputype() returns the family architecture for the
* specified cputype if known. If unknown it returns NULL.
*/
__private_extern__
const struct arch_flag *
get_arch_family_from_cputype(
cpu_type_t cputype)
{
unsigned long i;
for(i = 0; arch_flags[i].name != NULL; i++){
if(arch_flags[i].cputype == cputype)
return(arch_flags + i);
}
return(NULL);
}
/*
* get_byte_sex_from_flag() returns the byte sex of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns
* UNKNOWN_BYTE_SEX. If the bytesex can be determined directly as in the case
* of reading a magic number from a file that should be done and this routine
* should not be used as it could be out of date.
*/
__private_extern__
enum byte_sex
get_byte_sex_from_flag(
const struct arch_flag *flag)
{
if(flag->cputype == CPU_TYPE_MC680x0 ||
flag->cputype == CPU_TYPE_MC88000 ||
flag->cputype == CPU_TYPE_POWERPC ||
flag->cputype == CPU_TYPE_POWERPC64 ||
flag->cputype == CPU_TYPE_HPPA ||
flag->cputype == CPU_TYPE_SPARC ||
flag->cputype == CPU_TYPE_I860 ||
flag->cputype == CPU_TYPE_VEO)
return BIG_ENDIAN_BYTE_SEX;
else if(flag->cputype == CPU_TYPE_I386)
return LITTLE_ENDIAN_BYTE_SEX;
else
return UNKNOWN_BYTE_SEX;
}
#ifndef RLD
/*
* get_stack_direction_from_flag() returns the direction the stack grows as
* either positive (+1) or negative (-1) of the architecture for the
* specified cputype and cpusubtype if known. If unknown it returns 0.
*/
__private_extern__
long
get_stack_direction_from_flag(
const struct arch_flag *flag)
{
if(flag->cputype == CPU_TYPE_MC680x0 ||
flag->cputype == CPU_TYPE_MC88000 ||
flag->cputype == CPU_TYPE_POWERPC ||
flag->cputype == CPU_TYPE_I386 ||
flag->cputype == CPU_TYPE_SPARC ||
flag->cputype == CPU_TYPE_I860 ||
flag->cputype == CPU_TYPE_VEO)
return(-1);
else if(flag->cputype == CPU_TYPE_HPPA)
return(+1);
else
return(0);
}
/*
* get_stack_addr_from_flag() returns the default starting address of the user
* stack. This should be in the header file <bsd/XXX/vmparam.h> as USRSTACK.
* Since some architectures have come and gone and come back and because you
* can't include all of these headers in one source the constants have been
* copied here.
*/
__private_extern__
uint64_t
get_stack_addr_from_flag(
const struct arch_flag *flag)
{
switch(flag->cputype){
case CPU_TYPE_MC680x0:
return(0x04000000);
case CPU_TYPE_MC88000:
return(0xffffe000);
case CPU_TYPE_POWERPC:
case CPU_TYPE_VEO:
return(0xc0000000);
case CPU_TYPE_I386:
return(0xc0000000);
case CPU_TYPE_SPARC:
return(0xf0000000);
case CPU_TYPE_I860:
return(0);
case CPU_TYPE_HPPA:
return(0xc0000000-0x04000000);
case CPU_TYPE_POWERPC64:
return(0x7ffff00000000LL);
case CPU_TYPE_X86_64:
return(0x7fff5fc00000LL);
default:
return(0);
}
}
/*
* get_stack_size_from_flag() returns the default size of the userstack. This
* should be in the header file <bsd/XXX/vmparam.h> as MAXSSIZ. Since some
* architectures have come and gone and come back, you can't include all of
* these headers in one source and some of the constants covered the whole
* address space the common value of 64meg was chosen.
*/
__private_extern__
unsigned long
get_stack_size_from_flag(
const struct arch_flag *flag)
{
#ifdef __MWERKS__
const struct arch_flag *dummy;
dummy = flag;
#endif
return(64*1024*1024);
}
#endif /* !defined(RLD) */
/*
* get_segalign_from_flag() returns the default segment alignment (page size).
*/
__private_extern__
unsigned long
get_segalign_from_flag(
const struct arch_flag *flag)
{
if(flag->cputype == CPU_TYPE_POWERPC ||
flag->cputype == CPU_TYPE_POWERPC64 ||
flag->cputype == CPU_TYPE_VEO ||
flag->cputype == CPU_TYPE_I386 ||
flag->cputype == CPU_TYPE_X86_64)
return(0x1000); /* 4K */
else
return(0x2000); /* 8K */
}
/*
* get_segprot_from_flag() returns the default segment protection.
*/
__private_extern__
vm_prot_t
get_segprot_from_flag(
const struct arch_flag *flag)
{
if(flag->cputype == CPU_TYPE_I386)
return(VM_PROT_READ | VM_PROT_WRITE);
else
return(VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
}
/*
* force_cpusubtype_ALL_for_cputype() takes a cputype and returns TRUE if for
* that cputype the cpusubtype should always be forced to the ALL cpusubtype,
* otherwise it returns FALSE.
*/
__private_extern__
enum bool
force_cpusubtype_ALL_for_cputype(
cpu_type_t cputype)
{
if(cputype == CPU_TYPE_I386)
return(TRUE);
else
return(FALSE);
}

Просмотреть файл

@ -0,0 +1,47 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <mach/mach.h> /* first to get rid of pre-comp warning */
#include <stdio.h>
#include "stuff/arch.h"
#include "stuff/errors.h"
/*
* arch_usage() is called when an unknown architecture flag is encountered.
* It prints the currently know architecture flags on stderr.
*/
__private_extern__
void
arch_usage(void)
{
unsigned long i;
const struct arch_flag *arch_flags;
arch_flags = get_arch_flags();
fprintf(stderr, "%s: known architecture flags are:", progname);
for(i = 0; arch_flags[i].name != NULL; i++){
fprintf(stderr, " %s", arch_flags[i].name);
}
fprintf(stderr, "\n");
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,477 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stuff/ofile.h"
#include "stuff/breakout.h"
#include "stuff/allocate.h"
#include "stuff/errors.h"
#include "stuff/round.h"
#include "stuff/crc32.h"
static void breakout_internal(
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum,
struct ofile *ofile);
static void breakout_loop_through_archive(
char *filename,
struct arch *arch,
struct ofile *ofile);
static void cksum_object(
struct arch *arch,
enum bool calculate_input_prebind_cksum);
static struct arch *new_arch(
struct arch **archs,
unsigned long *narchs);
static struct member *new_member(
struct arch *arch);
__private_extern__
struct ofile *
breakout_mem(
void *membuf,
unsigned long length,
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum)
{
struct ofile *ofile;
unsigned long previous_errors;
*archs = NULL;
*narchs = 0;
ofile = allocate(sizeof(struct ofile));
/*
* If the file_name is NULL, we will use a dummy file name so
* that error reporting, etc. works.
*/
if(filename == NULL)
filename = "(broken out from memory)";
/*
* Rely on the ofile_*() routines to do all the checking and only
* return valid ofiles files broken out.
*/
if(ofile_map_from_memory((char *)membuf, length, filename, NULL, NULL,
ofile, FALSE) == FALSE){
free(ofile);
return(NULL);
}
previous_errors = errors;
breakout_internal(filename, archs, narchs,
calculate_input_prebind_cksum, ofile);
errors += previous_errors;
if(errors != 0){
free(ofile);
return(NULL);
}
return(ofile);
}
__private_extern__
struct ofile *
breakout(
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum)
{
struct ofile *ofile;
unsigned long previous_errors;
*archs = NULL;
*narchs = 0;
ofile = allocate(sizeof(struct ofile));
/*
* Rely on the ofile_*() routines to do all the checking and only
* return valid ofiles files broken out.
*/
if(ofile_map(filename, NULL, NULL, ofile, FALSE) == FALSE){
free(ofile);
return(NULL);
}
previous_errors = errors;
breakout_internal(filename, archs, narchs,
calculate_input_prebind_cksum, ofile);
errors += previous_errors;
if(errors != 0){
free(ofile);
return(NULL);
}
return(ofile);
}
static
void
breakout_internal(
char *filename,
struct arch **archs,
unsigned long *narchs,
enum bool calculate_input_prebind_cksum,
struct ofile *ofile)
{
struct arch *arch;
errors = 0;
if(ofile->file_type == OFILE_FAT && errors == 0){
/* loop through the fat architectures (can't have zero archs) */
(void)ofile_first_arch(ofile);
do{
if(errors != 0)
break;
arch = new_arch(archs, narchs);
arch->file_name = savestr(filename);
arch->type = ofile->arch_type;
arch->fat_arch = ofile->fat_archs + ofile->narch;
arch->fat_arch_name = savestr(ofile->arch_flag.name);
if(ofile->arch_type == OFILE_ARCHIVE){
breakout_loop_through_archive(filename, arch, ofile);
}
else if(ofile->arch_type == OFILE_Mach_O){
arch->object = allocate(sizeof(struct object));
memset(arch->object, '\0', sizeof(struct object));
arch->object->object_addr = ofile->object_addr;
arch->object->object_size = ofile->object_size;
arch->object->object_byte_sex = ofile->object_byte_sex;
arch->object->mh64 = ofile->mh64;
arch->object->mh = ofile->mh;
arch->object->mh_filetype = ofile->mh_filetype;
arch->object->mh_cputype = ofile->mh_cputype;
arch->object->mh_cpusubtype = ofile->mh_cpusubtype;
arch->object->load_commands = ofile->load_commands;
cksum_object(arch, calculate_input_prebind_cksum);
}
else{ /* ofile->arch_type == OFILE_UNKNOWN */
arch->unknown_addr = ofile->file_addr +
arch->fat_arch->offset;
arch->unknown_size = arch->fat_arch->size;
}
}while(ofile_next_arch(ofile) == TRUE);
}
else if(ofile->file_type == OFILE_ARCHIVE && errors == 0){
arch = new_arch(archs, narchs);
arch->file_name = savestr(filename);
arch->type = ofile->file_type;
breakout_loop_through_archive(filename, arch, ofile);
}
else if(ofile->file_type == OFILE_Mach_O && errors == 0){
arch = new_arch(archs, narchs);
arch->file_name = savestr(filename);
arch->type = ofile->file_type;
arch->object = allocate(sizeof(struct object));
memset(arch->object, '\0', sizeof(struct object));
arch->object->object_addr = ofile->object_addr;
arch->object->object_size = ofile->object_size;
arch->object->object_byte_sex = ofile->object_byte_sex;
arch->object->mh64 = ofile->mh64;
arch->object->mh = ofile->mh;
arch->object->mh_filetype = ofile->mh_filetype;
arch->object->mh_cputype = ofile->mh_cputype;
arch->object->mh_cpusubtype = ofile->mh_cpusubtype;
arch->object->load_commands = ofile->load_commands;
cksum_object(arch, calculate_input_prebind_cksum);
}
else if(errors == 0){ /* ofile->file_type == OFILE_UNKNOWN */
arch = new_arch(archs, narchs);
arch->file_name = savestr(filename);
arch->type = ofile->file_type;
arch->unknown_addr = ofile->file_addr;
arch->unknown_size = ofile->file_size;
}
if(errors != 0){
free_archs(*archs, *narchs);
*archs = NULL;
*narchs = 0;
}
}
static
void
breakout_loop_through_archive(
char *filename,
struct arch *arch,
struct ofile *ofile)
{
struct member *member;
enum bool flag;
struct ar_hdr *ar_hdr;
unsigned long size, ar_name_size;
char ar_name_buf[sizeof(ofile->member_ar_hdr->ar_name) + 1];
char ar_size_buf[sizeof(ofile->member_ar_hdr->ar_size) + 1];
/* loop through archive (can be empty) */
if((flag = ofile_first_member(ofile)) == TRUE && errors == 0){
/*
* If the first member is a table of contents then skip
* it as it is always rebuilt (so to get the time to
* match the modtime so it won't appear out of date).
* Also force it to be a long name so members can be 8 byte
* aligned.
*/
if(ofile->member_ar_hdr != NULL &&
strncmp(ofile->member_name, SYMDEF,
sizeof(SYMDEF) - 1) == 0){
arch->toc_long_name = TRUE;
flag = ofile_next_member(ofile);
}
while(flag == TRUE && errors == 0){
member = new_member(arch);
member->type = ofile->member_type;
member->member_name = ofile->member_name;
/*
* Determine the size this member will have in the library which
* includes the padding as a result of rounding the size of the
* member. To get all members on an 8 byte boundary (so that
* mapping in object files can be used directly) the size of the
* member is CHANGED to reflect this padding. In the UNIX
* definition of archives the size of the member is never
* changed but the offset to the next member is defined to be
* the offset of the previous member plus the size of the
* previous member rounded to 2. So to get 8 byte boundaries
* without breaking the UNIX definition of archives the size is
* changed here. As with the UNIX ar(1) program the padded
* bytes will be set to the character '\n'.
*/
if(ofile->mh != NULL || ofile->mh64 != NULL)
size = round(ofile->object_size, 8);
else
size = round(ofile->member_size, 8);
/*
* We will force the use of long names so we can make sure the
* size of the name and the size of struct ar_hdr are rounded to
* 8 bytes. And that rounded size is what will be in the
* ar_name with the AR_EFMT1 string. To avoid growing the size
* of names first trim the name size before rounding up.
*/
member->member_long_name = TRUE;
for(ar_name_size = ofile->member_name_size;
ar_name_size > 1 ;
ar_name_size--){
if(ofile->member_name[ar_name_size - 1] != '\0')
break;
}
member->member_name_size = ar_name_size;
ar_name_size = round(ar_name_size, 8) +
(round(sizeof(struct ar_hdr), 8) -
sizeof(struct ar_hdr));
size += ar_name_size;
/*
* Now with the output sizes of the long member name and rounded
* size of the member the offset to this member can be set and
* then left incremented for the next member's offset.
*/
member->offset = arch->library_size;
arch->library_size += sizeof(struct ar_hdr) + size;
/*
* Since we are rounding the member size and forcing a the use
* of a long name make a new ar_hdr with this information.
* Note the code in writeout() will do the padding with '\n'
* characters as needed.
*/
ar_hdr = allocate(sizeof(struct ar_hdr));
*ar_hdr = *(ofile->member_ar_hdr);
sprintf(ar_name_buf, "%s%-*lu", AR_EFMT1,
(int)(sizeof(ar_hdr->ar_name) -
(sizeof(AR_EFMT1) - 1)), ar_name_size);
memcpy(ar_hdr->ar_name, ar_name_buf,
sizeof(ar_hdr->ar_name));
sprintf(ar_size_buf, "%-*ld",
(int)sizeof(ar_hdr->ar_size), size);
memcpy(ar_hdr->ar_size, ar_size_buf,
sizeof(ar_hdr->ar_size));
member->ar_hdr = ar_hdr;
member->input_ar_hdr = ofile->member_ar_hdr;
member->input_file_name = filename;
if(ofile->member_type == OFILE_Mach_O){
member->object = allocate(sizeof(struct object));
memset(member->object, '\0', sizeof(struct object));
member->object->object_addr = ofile->object_addr;
member->object->object_size = ofile->object_size;
member->object->object_byte_sex = ofile->object_byte_sex;
member->object->mh64 = ofile->mh64;
member->object->mh = ofile->mh;
member->object->mh_filetype = ofile->mh_filetype;
member->object->mh_cputype = ofile->mh_cputype;
member->object->mh_cpusubtype = ofile->mh_cpusubtype;
member->object->load_commands = ofile->load_commands;
}
else{ /* ofile->member_type == OFILE_UNKNOWN */
member->unknown_addr = ofile->member_addr;
member->unknown_size = ofile->member_size;
}
flag = ofile_next_member(ofile);
}
}
}
/*
* cksum_object() is called to set the pointer to the LC_PREBIND_CKSUM load
* command in the object struct for the specified arch. If the parameter
* calculate_input_prebind_cksum is TRUE then calculate the value
* of the check sum for the input object if needed, set that into the
* the calculated_input_prebind_cksum field of the object struct for the
* specified arch. This is needed for prebound files where the original
* checksum (or zero) is recorded in the LC_PREBIND_CKSUM load command.
* Only redo_prebinding operations sets the value of the cksum field to
* non-zero and only if previously zero. All other operations will set this
* field to zero indicating a new original prebound file.
*/
static
void
cksum_object(
struct arch *arch,
enum bool calculate_input_prebind_cksum)
{
unsigned long i, buf_size, ncmds;
struct load_command *lc;
enum byte_sex host_byte_sex;
char *buf;
arch->object->cs = NULL;
lc = arch->object->load_commands;
if(arch->object->mh != NULL)
ncmds = arch->object->mh->ncmds;
else
ncmds = arch->object->mh64->ncmds;
for(i = 0;
i < ncmds && arch->object->cs == NULL;
i++){
if(lc->cmd == LC_PREBIND_CKSUM)
arch->object->cs = (struct prebind_cksum_command *)lc;
lc = (struct load_command *)((char *)lc + lc->cmdsize);
}
/*
* If we don't want to calculate the input check sum, or there is no
* LC_PREBIND_CKSUM load command or there is one and the check sum is
* not zero then return.
*/
if(calculate_input_prebind_cksum == FALSE ||
arch->object->cs == NULL ||
arch->object->cs->cksum != 0)
return;
host_byte_sex = get_host_byte_sex();
buf_size = 0;
buf = NULL;
if(arch->object->object_byte_sex != host_byte_sex){
if(arch->object->mh != NULL){
buf_size = sizeof(struct mach_header) +
arch->object->mh->sizeofcmds;
buf = allocate(buf_size);
memcpy(buf, arch->object->mh, buf_size);
if(swap_object_headers(arch->object->mh,
arch->object->load_commands) == FALSE)
return;
}
else{
buf_size = sizeof(struct mach_header_64) +
arch->object->mh64->sizeofcmds;
buf = allocate(buf_size);
memcpy(buf, arch->object->mh64, buf_size);
if(swap_object_headers(arch->object->mh64,
arch->object->load_commands) == FALSE)
return;
}
}
arch->object->calculated_input_prebind_cksum =
crc32(arch->object->object_addr, arch->object->object_size);
if(arch->object->object_byte_sex != host_byte_sex){
if(arch->object->mh != NULL)
memcpy(arch->object->mh, buf, buf_size);
else
memcpy(arch->object->mh64, buf, buf_size);
free(buf);
}
}
__private_extern__
void
free_archs(
struct arch *archs,
unsigned long narchs)
{
unsigned long i, j;
for(i = 0; i < narchs; i++){
if(archs[i].type == OFILE_ARCHIVE){
for(j = 0; j < archs[i].nmembers; j++){
if(archs[i].members[j].type == OFILE_Mach_O)
free(archs[i].members[j].object);
}
if(archs[i].nmembers > 0 && archs[i].members != NULL)
free(archs[i].members);
}
else if(archs[i].type == OFILE_Mach_O){
free(archs[i].object);
}
}
if(narchs > 0 && archs != NULL)
free(archs);
}
static
struct arch *
new_arch(
struct arch **archs,
unsigned long *narchs)
{
struct arch *arch;
*archs = reallocate(*archs, (*narchs + 1) * sizeof(struct arch));
arch = *archs + *narchs;
*narchs = *narchs + 1;
memset(arch, '\0', sizeof(struct arch));
return(arch);
}
static
struct member *
new_member(
struct arch *arch)
{
struct member *member;
arch->members = reallocate(arch->members,
(arch->nmembers + 1) * sizeof(struct member));
member = arch->members + arch->nmembers;
arch->nmembers++;
memset(member, '\0', sizeof(struct member));
return(member);
}
#endif /* !defined(RLD) */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,583 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdio.h>
#include <string.h>
#include "stuff/ofile.h"
#include "stuff/breakout.h"
#include "stuff/round.h"
static void check_object(
struct arch *arch,
struct member *member,
struct object *object);
static void symbol_string_at_end(
struct arch *arch,
struct member *member,
struct object *object);
static void dyld_order(
struct arch *arch,
struct member *member,
struct object *object);
static void order_error(
struct arch *arch,
struct member *member,
char *reason);
__private_extern__
void
checkout(
struct arch *archs,
unsigned long narchs)
{
unsigned long i, j;
for(i = 0; i < narchs; i++){
if(archs[i].type == OFILE_ARCHIVE){
for(j = 0; j < archs[i].nmembers; j++){
if(archs[i].members[j].type == OFILE_Mach_O){
check_object(archs + i, archs[i].members + j,
archs[i].members[j].object);
}
}
}
else if(archs[i].type == OFILE_Mach_O){
check_object(archs + i, NULL, archs[i].object);
}
}
}
static
void
check_object(
struct arch *arch,
struct member *member,
struct object *object)
{
unsigned long i, ncmds, flags;
struct load_command *lc;
struct segment_command *sg;
struct segment_command_64 *sg64;
struct dylib_command *dl_id;
/*
* Set up the symtab load command field and link edit segment feilds in
* the object structure.
*/
object->st = NULL;
object->dyst = NULL;
object->hints_cmd = NULL;
object->seg_linkedit = NULL;
object->seg_linkedit64 = NULL;
object->code_sig_cmd = NULL;
dl_id = NULL;
lc = object->load_commands;
if(object->mh != NULL){
ncmds = object->mh->ncmds;
flags = object->mh->flags;
}
else{
ncmds = object->mh64->ncmds;
flags = object->mh64->flags;
}
for(i = 0; i < ncmds; i++){
if(lc->cmd == LC_SYMTAB){
if(object->st != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_SYMTAB load command): ");
object->st = (struct symtab_command *)lc;
}
else if(lc->cmd == LC_DYSYMTAB){
if(object->dyst != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_DYSYMTAB load command): ");
object->dyst = (struct dysymtab_command *)lc;
}
else if(lc->cmd == LC_TWOLEVEL_HINTS){
if(object->hints_cmd != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_TWOLEVEL_HINTS load command): ");
object->hints_cmd = (struct twolevel_hints_command *)lc;
}
else if(lc->cmd == LC_CODE_SIGNATURE){
if(object->code_sig_cmd != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_CODE_SIGNATURE load command): ");
object->code_sig_cmd = (struct linkedit_data_command *)lc;
}
else if(lc->cmd == LC_SEGMENT_SPLIT_INFO){
if(object->split_info_cmd != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_SEGMENT_SPLIT_INFO load command): ");
object->split_info_cmd = (struct linkedit_data_command *)lc;
}
else if(lc->cmd == LC_SEGMENT){
sg = (struct segment_command *)lc;
if(strcmp(sg->segname, SEG_LINKEDIT) == 0){
if(object->seg_linkedit != NULL)
fatal_arch(arch, member, "malformed file (more than "
"one " SEG_LINKEDIT "segment): ");
object->seg_linkedit = sg;
}
}
else if(lc->cmd == LC_SEGMENT_64){
sg64 = (struct segment_command_64 *)lc;
if(strcmp(sg64->segname, SEG_LINKEDIT) == 0){
if(object->seg_linkedit64 != NULL)
fatal_arch(arch, member, "malformed file (more than "
"one " SEG_LINKEDIT "segment): ");
object->seg_linkedit64 = sg64;
}
}
else if(lc->cmd == LC_ID_DYLIB){
if(dl_id != NULL)
fatal_arch(arch, member, "malformed file (more than one "
"LC_ID_DYLIB load command): ");
dl_id = (struct dylib_command *)lc;
if(dl_id->dylib.name.offset >= dl_id->cmdsize)
fatal_arch(arch, member, "malformed file (name.offset of "
"load command %lu extends past the end of the load "
"command): ", i);
}
lc = (struct load_command *)((char *)lc + lc->cmdsize);
}
if((object->mh_filetype == MH_DYLIB ||
(object->mh_filetype == MH_DYLIB_STUB && ncmds > 0)) &&
dl_id == NULL)
fatal_arch(arch, member, "malformed file (no LC_ID_DYLIB load "
"command in %s file): ", object->mh_filetype == MH_DYLIB ?
"MH_DYLIB" : "MH_DYLIB_STUB");
if(object->hints_cmd != NULL){
if(object->dyst == NULL && object->hints_cmd->nhints != 0)
fatal_arch(arch, member, "malformed file (LC_TWOLEVEL_HINTS "
"load command present without an LC_DYSYMTAB load command):");
if(object->hints_cmd->nhints != 0 &&
object->hints_cmd->nhints != object->dyst->nundefsym)
fatal_arch(arch, member, "malformed file (LC_TWOLEVEL_HINTS "
"load command's nhints does not match LC_DYSYMTAB load "
"command's nundefsym):");
}
/*
* For objects without a dynamic symbol table check to see that the
* string table is at the end of the file and that the symbol table is
* just before it.
*/
if(object->dyst == NULL){
symbol_string_at_end(arch, member, object);
}
else{
/*
* This file has a dynamic symbol table command. We handle three
* cases, a dynamic shared library, a file for the dynamic linker,
* and a relocatable object file. Since it has a dynamic symbol
* table command it could have an indirect symbol table.
*/
if(object->mh_filetype == MH_DYLIB /* ||
object->mh_filetype == MH_DYLIB_STUB */ ){
/*
* This is a dynamic shared library.
* The order of the symbolic info is:
* local relocation entries
* symbol table
* local symbols
* defined external symbols
* undefined symbols
* two-level namespace hints
* external relocation entries
* indirect symbol table
* table of contents
* module table
* reference table
* string table
* strings for external symbols
* strings for local symbols
* code signature data (16 byte aligned)
*/
dyld_order(arch, member, object);
}
else if(flags & MH_DYLDLINK){
/*
* This is a file for the dynamic linker (output of ld(1) with
* -output_for_dyld . That is the relocation entries are split
* into local and external and hanging off the dysymtab not off
* the sections.
* The order of the symbolic info is:
* local relocation entries
* symbol table
* local symbols (in order as appeared in stabs)
* defined external symbols (sorted by name)
* undefined symbols (sorted by name)
* external relocation entries
* indirect symbol table
* string table
* strings for external symbols
* strings for local symbols
* code signature data (16 byte aligned)
*/
dyld_order(arch, member, object);
}
else{
/*
* This is a relocatable object file either the output of the
* assembler or output of ld(1) with -r. For the output of
* the assembler:
* The order of the symbolic info is:
* relocation entries (by section)
* indirect symbol table
* symbol table
* local symbols (in order as appeared in stabs)
* defined external symbols (sorted by name)
* undefined symbols (sorted by name)
* string table
* strings for external symbols
* strings for local symbols
* With this order the symbol table can be replaced and the
* relocation entries and the indirect symbol table entries
* can be updated in the file and not moved.
* For the output of ld -r:
* The order of the symbolic info is:
* relocation entries (by section)
* symbol table
* local symbols (in order as appeared in stabs)
* defined external symbols (sorted by name)
* undefined symbols (sorted by name)
* indirect symbol table
* string table
* strings for external symbols
* strings for local symbols
*/
symbol_string_at_end(arch, member, object);
}
}
}
static
void
dyld_order(
struct arch *arch,
struct member *member,
struct object *object)
{
unsigned long offset, rounded_offset, isym;
if(object->mh != NULL){
if(object->seg_linkedit == NULL)
fatal_arch(arch, member, "malformed file (no " SEG_LINKEDIT
" segment): ");
if(object->seg_linkedit->filesize != 0 &&
object->seg_linkedit->fileoff +
object->seg_linkedit->filesize != object->object_size)
fatal_arch(arch, member, "the " SEG_LINKEDIT " segment "
"does not cover the end of the file (can't "
"be processed) in: ");
offset = object->seg_linkedit->fileoff;
}
else{
if(object->seg_linkedit64 == NULL)
fatal_arch(arch, member, "malformed file (no " SEG_LINKEDIT
" segment): ");
if(object->seg_linkedit64->filesize != 0 &&
object->seg_linkedit64->fileoff +
object->seg_linkedit64->filesize != object->object_size)
fatal_arch(arch, member, "the " SEG_LINKEDIT " segment "
"does not cover the end of the file (can't "
"be processed) in: ");
offset = object->seg_linkedit64->fileoff;
}
if(object->dyst->nlocrel != 0){
if(object->dyst->locreloff != offset)
order_error(arch, member, "local relocation entries "
"out of place");
offset += object->dyst->nlocrel *
sizeof(struct relocation_info);
}
if(object->split_info_cmd != NULL){
if(object->split_info_cmd->dataoff != offset)
order_error(arch, member, "split info data out of place");
offset += object->split_info_cmd->datasize;
}
if(object->st->nsyms != 0){
if(object->st->symoff != offset)
order_error(arch, member, "symbol table out of place");
if(object->mh != NULL)
offset += object->st->nsyms * sizeof(struct nlist);
else
offset += object->st->nsyms * sizeof(struct nlist_64);
}
isym = 0;
if(object->dyst->nlocalsym != 0){
if(object->dyst->ilocalsym != isym)
order_error(arch, member, "local symbols out of place");
isym += object->dyst->nlocalsym;
}
if(object->dyst->nextdefsym != 0){
if(object->dyst->iextdefsym != isym)
order_error(arch, member, "externally defined symbols out of "
"place");
isym += object->dyst->nextdefsym;
}
if(object->dyst->nundefsym != 0){
if(object->dyst->iundefsym != isym)
order_error(arch, member, "undefined symbols out of place");
isym += object->dyst->nundefsym;
}
if(object->hints_cmd != NULL && object->hints_cmd->nhints != 0){
if(object->hints_cmd->offset != offset)
order_error(arch, member, "hints table out of place");
offset += object->hints_cmd->nhints * sizeof(struct twolevel_hint);
}
if(object->dyst->nextrel != 0){
if(object->dyst->extreloff != offset)
order_error(arch, member, "external relocation entries"
" out of place");
offset += object->dyst->nextrel *
sizeof(struct relocation_info);
}
if(object->dyst->nindirectsyms != 0){
if(object->dyst->indirectsymoff != offset)
order_error(arch, member, "indirect symbol table "
"out of place");
offset += object->dyst->nindirectsyms *
sizeof(uint32_t);
}
/*
* If this is a 64-bit Mach-O file and has an odd number of indirect
* symbol table entries the next offset MAYBE rounded to a multiple of
* 8 or MAY NOT BE. This should done to keep all the tables aligned but
* was not done for 64-bit Mach-O in Mac OS X 10.4.
*/
object->input_indirectsym_pad = 0;
if(object->mh64 != NULL &&
(object->dyst->nindirectsyms % 2) != 0){
rounded_offset = round(offset, 8);
}
else{
rounded_offset = offset;
}
if(object->dyst->ntoc != 0){
if(object->dyst->tocoff != offset &&
object->dyst->tocoff != rounded_offset)
order_error(arch, member, "table of contents out of place");
if(object->dyst->tocoff == offset){
offset += object->dyst->ntoc *
sizeof(struct dylib_table_of_contents);
rounded_offset = offset;
}
else if(object->dyst->tocoff == rounded_offset){
object->input_indirectsym_pad = rounded_offset - offset;
rounded_offset += object->dyst->ntoc *
sizeof(struct dylib_table_of_contents);
offset = rounded_offset;
}
}
if(object->dyst->nmodtab != 0){
if(object->dyst->modtaboff != offset &&
object->dyst->modtaboff != rounded_offset)
order_error(arch, member, "module table out of place");
if(object->mh != NULL){
offset += object->dyst->nmodtab *
sizeof(struct dylib_module);
rounded_offset = offset;
}
else{
if(object->dyst->modtaboff == offset){
offset += object->dyst->nmodtab *
sizeof(struct dylib_module_64);
rounded_offset = offset;
}
else if(object->dyst->modtaboff == rounded_offset){
object->input_indirectsym_pad = rounded_offset - offset;
rounded_offset += object->dyst->nmodtab *
sizeof(struct dylib_module_64);
offset = rounded_offset;
}
}
}
if(object->dyst->nextrefsyms != 0){
if(object->dyst->extrefsymoff != offset &&
object->dyst->extrefsymoff != rounded_offset)
order_error(arch, member, "reference table out of place");
if(object->dyst->extrefsymoff == offset){
offset += object->dyst->nextrefsyms *
sizeof(struct dylib_reference);
rounded_offset = offset;
}
else if(object->dyst->extrefsymoff == rounded_offset){
object->input_indirectsym_pad = rounded_offset - offset;
rounded_offset += object->dyst->nextrefsyms *
sizeof(struct dylib_reference);
offset = rounded_offset;
}
}
if(object->st->strsize != 0){
if(object->st->stroff != offset &&
object->st->stroff != rounded_offset)
order_error(arch, member, "string table out of place");
if(object->st->stroff == offset){
offset += object->st->strsize;
rounded_offset = offset;
}
else if(object->st->stroff == rounded_offset){
object->input_indirectsym_pad = rounded_offset - offset;
rounded_offset += object->st->strsize;
offset = rounded_offset;
}
}
if(object->code_sig_cmd != NULL){
rounded_offset = round(rounded_offset, 16);
if(object->code_sig_cmd->dataoff != rounded_offset)
order_error(arch, member, "code signature data out of place");
rounded_offset += object->code_sig_cmd->datasize;
offset = rounded_offset;
}
if(offset != object->object_size &&
rounded_offset != object->object_size)
order_error(arch, member, "link edit information does not fill the "
SEG_LINKEDIT " segment");
}
static
void
order_error(
struct arch *arch,
struct member *member,
char *reason)
{
fatal_arch(arch, member, "file not in an order that can be processed "
"(%s): ", reason);
}
static
void
symbol_string_at_end(
struct arch *arch,
struct member *member,
struct object *object)
{
unsigned long end, strend, rounded_strend;
unsigned long indirectend, rounded_indirectend;
if(object->st != NULL && object->st->nsyms != 0){
end = object->object_size;
if(object->st->strsize != 0){
strend = object->st->stroff + object->st->strsize;
/*
* Since archive member sizes are now rounded to 8 bytes the
* string table may not be exactly at the end of the
* object_size due to rounding.
*/
rounded_strend = round(strend, 8);
if(strend != end && rounded_strend != end)
fatal_arch(arch, member, "string table not at the end "
"of the file (can't be processed) in file: ");
/*
* To make the code work that assumes the end of string table is
* at the end of the object file change the object_size to be
* the end of the string table here. This could be done at the
* end of this routine but since all the later checks are fatal
* we'll just do this here.
*/
if(rounded_strend != strend)
object->object_size = strend;
end = object->st->stroff;
}
if(object->dyst != NULL &&
object->dyst->nindirectsyms != 0 &&
object->st->nsyms != 0 &&
object->dyst->indirectsymoff > object->st->symoff){
indirectend = object->dyst->indirectsymoff +
object->dyst->nindirectsyms * sizeof(uint32_t);
/*
* If this is a 64-bit Mach-O file and has an odd number of indirect
* symbol table entries the next offset MAYBE rounded to a multiple of
* 8 or MAY NOT BE. This should done to keep all the tables aligned but
* was not done for 64-bit Mach-O in Mac OS X 10.4.
*/
if(object->mh64 != NULL &&
(object->dyst->nindirectsyms % 2) != 0){
rounded_indirectend = round(indirectend, 8);
}
else{
rounded_indirectend = indirectend;
}
if(indirectend != end && rounded_indirectend != end){
fatal_arch(arch, member, "indirect symbol table does not "
"directly preceed the string table (can't be "
"processed) in file: ");
}
object->input_indirectsym_pad = end - indirectend;
end = object->dyst->indirectsymoff;
if(object->mh != NULL){
if(object->st->symoff +
object->st->nsyms * sizeof(struct nlist) != end)
fatal_arch(arch, member, "symbol table does not "
"directly preceed the indirect symbol table (can't "
"be processed) in file: ");
}
else{
if(object->st->symoff +
object->st->nsyms * sizeof(struct nlist_64) != end)
fatal_arch(arch, member, "symbol table does not "
"directly preceed the indirect symbol table (can't "
"be processed) in file: ");
}
}
else{
if(object->mh != NULL){
if(object->st->symoff +
object->st->nsyms * sizeof(struct nlist) != end)
fatal_arch(arch, member, "symbol table and string "
"table not at the end of the file (can't be "
"processed) in file: ");
}
else{
if(object->st->symoff +
object->st->nsyms * sizeof(struct nlist_64) != end)
fatal_arch(arch, member, "symbol table and string "
"table not at the end of the file (can't be "
"processed) in file: ");
}
}
if(object->seg_linkedit != NULL &&
(object->seg_linkedit->flags & SG_FVMLIB) != SG_FVMLIB &&
object->seg_linkedit->filesize != 0){
if(object->seg_linkedit->fileoff +
object->seg_linkedit->filesize != object->object_size)
fatal_arch(arch, member, "the " SEG_LINKEDIT " segment "
"does not cover the symbol and string table (can't "
"be processed) in file: ");
}
}
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,138 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* James W. Williams of NASA Goddard Space Flight Center.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
static const u_int32_t crctab[] = {
0x0,
0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b,
0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6,
0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac,
0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f,
0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a,
0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039,
0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58,
0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033,
0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe,
0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95,
0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4,
0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0,
0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5,
0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16,
0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07,
0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c,
0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1,
0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba,
0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b,
0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698,
0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d,
0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e,
0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f,
0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34,
0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80,
0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb,
0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a,
0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629,
0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c,
0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff,
0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e,
0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65,
0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8,
0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3,
0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2,
0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71,
0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74,
0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640,
0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21,
0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a,
0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087,
0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec,
0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d,
0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce,
0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb,
0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09,
0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662,
0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf,
0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4
};
#define COMPUTE(var, ch) (var) = (var) << 8 ^ crctab[(var) >> 24 ^ (ch)]
__private_extern__
unsigned long
crc32(
const void *buf,
unsigned int len)
{
register const u_char *p;
register int nr;
register u_int32_t crc;
crc = 0;
for (nr = len, p = buf; nr--; ++p) {
COMPUTE(crc, *p);
}
for (; len != 0; len >>= 8) {
COMPUTE(crc, len & 0xff);
}
return(~crc);
}

Просмотреть файл

@ -0,0 +1,136 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include "stuff/errors.h"
__private_extern__ unsigned long errors = 0; /* number of calls to error() */
/*
* Just print the message in the standard format without setting an error.
*/
__private_extern__
void
warning(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
}
/*
* Print the error message and return to the caller after setting the error
* indication.
*/
__private_extern__
void
error(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
errors++;
}
/*
* Print the error message, the architecture if not NULL and return to the
* caller after setting the error indication.
*/
__private_extern__
void
error_with_arch(
const char *arch_name,
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
if(arch_name != NULL)
fprintf(stderr, "for architecture: %s ", arch_name);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
errors++;
}
/*
* Print the error message along with the system error message and return to
* the caller after setting the error indication.
*/
__private_extern__
void
system_error(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, " (%s)\n", strerror(errno));
va_end(ap);
errors++;
}
/*
* Print the error message along with the mach error string.
*/
__private_extern__
void
my_mach_error(
kern_return_t r,
char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, " (%s)\n", mach_error_string(r));
va_end(ap);
errors++;
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,121 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "stuff/breakout.h"
#include "stuff/errors.h"
/*
* Print the warning message and the input file.
*/
__private_extern__
void
warning_arch(
struct arch *arch,
struct member *member,
char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
va_end(ap);
if(member != NULL){
fprintf(stderr, "%s(%.*s)", arch->file_name,
(int)member->member_name_size, member->member_name);
}
else
fprintf(stderr, "%s", arch->file_name);
if(arch->fat_arch_name != NULL)
fprintf(stderr, " (for architecture %s)\n", arch->fat_arch_name);
else
fprintf(stderr, "\n");
va_end(ap);
}
/*
* Print the error message the input file and increment the error count
*/
__private_extern__
void
error_arch(
struct arch *arch,
struct member *member,
char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
va_end(ap);
if(member != NULL){
fprintf(stderr, "%s(%.*s)", arch->file_name,
(int)member->member_name_size, member->member_name);
}
else
fprintf(stderr, "%s", arch->file_name);
if(arch->fat_arch_name != NULL)
fprintf(stderr, " (for architecture %s)\n", arch->fat_arch_name);
else
fprintf(stderr, "\n");
va_end(ap);
errors++;
}
/*
* Print the fatal error message the input file and exit non-zero.
*/
__private_extern__
void
fatal_arch(
struct arch *arch,
struct member *member,
char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
va_end(ap);
if(member != NULL){
fprintf(stderr, "%s(%.*s)", arch->file_name,
(int)member->member_name_size, member->member_name);
}
else
fprintf(stderr, "%s", arch->file_name);
if(arch->fat_arch_name != NULL)
fprintf(stderr, " (for architecture %s)\n", arch->fat_arch_name);
else
fprintf(stderr, "\n");
va_end(ap);
exit(EXIT_FAILURE);
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,91 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include "stuff/errors.h"
/*
* Print the fatal error message and exit.
*/
__private_extern__
void
fatal(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
va_end(ap);
exit(1);
}
/*
* Print the fatal error message along with the system error message and exit.
*/
__private_extern__
void
system_fatal(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, " (%s)\n", strerror(errno));
va_end(ap);
exit(1);
}
/*
* Print the fatal error message along with the mach error string and exit.
*/
__private_extern__
void
mach_fatal(
kern_return_t r,
char *format,
...)
{
va_list ap;
va_start(ap, format);
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, format, ap);
fprintf(stderr, " (%s)\n", mach_error_string(r));
va_end(ap);
exit(1);
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,403 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <mach/mach.h>
#include "stuff/openstep_mach.h"
#include "stuff/arch.h"
#include "stuff/allocate.h"
/*
* get_arch_from_host() gets the architecture from the host this is running on
* and returns zero if the architecture is not known and zero if the
* architecture is known. If the parameters family_arch_flag and
* specific_arch_flag are not NULL they get fill in with the family
* architecture and specific architecure for the host. If the architecture
* is unknown and the parameters are not NULL then all fields are set to zero.
*/
__private_extern__
int
get_arch_from_host(
struct arch_flag *family_arch_flag,
struct arch_flag *specific_arch_flag)
{
struct host_basic_info host_basic_info;
unsigned int count;
kern_return_t r;
mach_port_t my_mach_host_self;
if(family_arch_flag != NULL)
memset(family_arch_flag, '\0', sizeof(struct arch_flag));
if(specific_arch_flag != NULL)
memset(specific_arch_flag, '\0', sizeof(struct arch_flag));
count = HOST_BASIC_INFO_COUNT;
my_mach_host_self = mach_host_self();
if((r = host_info(my_mach_host_self, HOST_BASIC_INFO,
(host_info_t)(&host_basic_info),
&count)) != KERN_SUCCESS){
mach_port_deallocate(mach_task_self(), my_mach_host_self);
return(0);
}
mach_port_deallocate(mach_task_self(), my_mach_host_self);
if(family_arch_flag != NULL){
family_arch_flag->cputype = host_basic_info.cpu_type;
}
if(specific_arch_flag != NULL){
specific_arch_flag->cputype = host_basic_info.cpu_type;
specific_arch_flag->cpusubtype = host_basic_info.cpu_subtype;
}
switch(host_basic_info.cpu_type){
case CPU_TYPE_MC680x0:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_MC680x0_ALL:
case CPU_SUBTYPE_MC68030_ONLY:
if(family_arch_flag != NULL){
family_arch_flag->name = "m68k";
family_arch_flag->cpusubtype = CPU_SUBTYPE_MC680x0_ALL;
}
if(specific_arch_flag != NULL){
specific_arch_flag->name = "m68030";
/*
* There is a "bug" in the kernel for compatiblity that on
* an 030 machine host_info() returns cpusubtype
* CPU_SUBTYPE_MC680x0_ALL and not CPU_SUBTYPE_MC68030_ONLY.
*/
specific_arch_flag->cpusubtype = CPU_SUBTYPE_MC68030_ONLY;
}
return(1);
case CPU_SUBTYPE_MC68040:
if(family_arch_flag != NULL){
family_arch_flag->name = "m68k";
family_arch_flag->cpusubtype = CPU_SUBTYPE_MC680x0_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "m68040";
return(1);
}
break;
case CPU_TYPE_POWERPC:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_POWERPC_ALL:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc";
return(1);
case CPU_SUBTYPE_POWERPC_601:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc601";
return(1);
case CPU_SUBTYPE_POWERPC_603:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc603";
return(1);
case CPU_SUBTYPE_POWERPC_603e:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc603e";
return(1);
case CPU_SUBTYPE_POWERPC_603ev:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc603ev";
return(1);
case CPU_SUBTYPE_POWERPC_604:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc604";
return(1);
case CPU_SUBTYPE_POWERPC_604e:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc604e";
return(1);
case CPU_SUBTYPE_POWERPC_750:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc750";
return(1);
case CPU_SUBTYPE_POWERPC_7400:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc7400";
return(1);
case CPU_SUBTYPE_POWERPC_7450:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc7450";
return(1);
case CPU_SUBTYPE_POWERPC_970:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "ppc970";
return(1);
default:
if(family_arch_flag != NULL){
family_arch_flag->name = "ppc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
}
if(specific_arch_flag != NULL){
specific_arch_flag->name =
savestr("PowerPC cpusubtype 1234567890");
if(specific_arch_flag->name != NULL)
sprintf(specific_arch_flag->name,
"PowerPC cpusubtype %u",
host_basic_info.cpu_subtype);
}
return(1);
}
break;
case CPU_TYPE_VEO:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_VEO_1:
if(family_arch_flag != NULL){
family_arch_flag->name = "veo";
family_arch_flag->cpusubtype = CPU_SUBTYPE_VEO_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "veo1";
return(1);
case CPU_SUBTYPE_VEO_2:
if(family_arch_flag != NULL){
family_arch_flag->name = "veo";
family_arch_flag->cpusubtype = CPU_SUBTYPE_VEO_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "veo2";
return(1);
case CPU_SUBTYPE_VEO_3:
if(family_arch_flag != NULL){
family_arch_flag->name = "veo";
family_arch_flag->cpusubtype = CPU_SUBTYPE_VEO_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "veo3";
return(1);
case CPU_SUBTYPE_VEO_4:
if(family_arch_flag != NULL){
family_arch_flag->name = "veo";
family_arch_flag->cpusubtype = CPU_SUBTYPE_VEO_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "veo4";
return(1);
default:
if(family_arch_flag != NULL){
family_arch_flag->name = "veo";
family_arch_flag->cpusubtype = CPU_SUBTYPE_VEO_ALL;
}
if(specific_arch_flag != NULL){
specific_arch_flag->name =
savestr("VEO cpusubtype 1234567890");
sprintf(specific_arch_flag->name,
"VEO cpusubtype %u",
host_basic_info.cpu_subtype);
}
return(1);
}
break;
case CPU_TYPE_MC88000:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_MC88000_ALL:
case CPU_SUBTYPE_MC88110:
if(family_arch_flag != NULL){
family_arch_flag->name = "m88k";
family_arch_flag->cpusubtype = CPU_SUBTYPE_MC88000_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "m88k";
return(1);
}
break;
case CPU_TYPE_I386:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_I386_ALL:
/* case CPU_SUBTYPE_386: same value as above */
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "i386";
return(1);
case CPU_SUBTYPE_486:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "i486";
return(1);
case CPU_SUBTYPE_486SX:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "i486SX";
return(1);
case CPU_SUBTYPE_PENT: /* same as CPU_SUBTYPE_586 */
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "pentium";
return(1);
case CPU_SUBTYPE_PENTPRO:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "pentpro";
return(1);
case CPU_SUBTYPE_PENTII_M3:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "pentIIm3";
return(1);
case CPU_SUBTYPE_PENTII_M5:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "pentIIm5";
return(1);
case CPU_SUBTYPE_PENTIUM_4:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "pentium4";
return(1);
default:
if(family_arch_flag != NULL){
family_arch_flag->name = "i386";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I386_ALL;
}
if(specific_arch_flag != NULL){
specific_arch_flag->name =
savestr("Intel family 12 model 12345678");
if(specific_arch_flag->name != NULL)
sprintf(specific_arch_flag->name,
"Intel family %u model %u",
CPU_SUBTYPE_INTEL_FAMILY(host_basic_info.cpu_subtype),
CPU_SUBTYPE_INTEL_MODEL(host_basic_info.cpu_subtype));
}
return(1);
}
break;
case CPU_TYPE_I860:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_I860_ALL:
case CPU_SUBTYPE_I860_860:
if(family_arch_flag != NULL){
family_arch_flag->name = "i860";
family_arch_flag->cpusubtype = CPU_SUBTYPE_I860_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "i860";
return(1);
}
break;
case CPU_TYPE_HPPA:
switch(host_basic_info.cpu_subtype){
case CPU_SUBTYPE_HPPA_ALL:
if(family_arch_flag != NULL){
family_arch_flag->name = "hppa";
family_arch_flag->cpusubtype = CPU_SUBTYPE_HPPA_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "hppa";
return(1);
case CPU_SUBTYPE_HPPA_7100LC:
if(family_arch_flag != NULL){
family_arch_flag->name = "hppa";
family_arch_flag->cpusubtype = CPU_SUBTYPE_HPPA_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "hppa7100LC";
return(1);
}
break;
case CPU_TYPE_SPARC:
switch(host_basic_info.cpu_subtype){
case /*CPU_SUBTYPE_SPARC_ALL*/0:
if(family_arch_flag != NULL){
family_arch_flag->name = "sparc";
family_arch_flag->cpusubtype = CPU_SUBTYPE_SPARC_ALL;
}
if(specific_arch_flag != NULL)
specific_arch_flag->name = "sparc";
return(1);
}
break;
}
return(0);
}
#endif /* !defined(RLD) */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,114 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdarg.h>
#include "stuff/ofile.h"
#include "stuff/print.h"
#include "stuff/errors.h"
__private_extern__
void
archive_error(
struct ofile *ofile,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
if(ofile->file_type == OFILE_FAT){
print("%s: for architecture %s archive: %s ",
progname, ofile->arch_flag.name, ofile->file_name);
}
else{
print("%s: archive: %s ", progname, ofile->file_name);
}
vprint(format, ap);
print("\n");
va_end(ap);
errors++;
}
__private_extern__
void
archive_member_error(
struct ofile *ofile,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
if(ofile->file_type == OFILE_FAT){
print("%s: for architecture %s archive member: %s(%.*s) ",
progname, ofile->arch_flag.name, ofile->file_name,
(int)ofile->member_name_size, ofile->member_name);
}
else{
print("%s: archive member: %s(%.*s) ", progname, ofile->file_name,
(int)ofile->member_name_size, ofile->member_name);
}
vprint(format, ap);
print("\n");
va_end(ap);
errors++;
}
#ifndef OTOOL
__private_extern__
void
Mach_O_error(
struct ofile *ofile,
const char *format, ...)
{
va_list ap;
va_start(ap, format);
if(ofile->file_type == OFILE_FAT){
if(ofile->arch_type == OFILE_ARCHIVE){
print("%s: for architecture %s object: %s(%.*s) ", progname,
ofile->arch_flag.name, ofile->file_name,
(int)ofile->member_name_size, ofile->member_name);
}
else{
print("%s: for architecture %s object: %s ", progname,
ofile->arch_flag.name, ofile->file_name);
}
}
else if(ofile->file_type == OFILE_ARCHIVE){
if(ofile->member_type == OFILE_FAT){
print("%s: for object: %s(%.*s) architecture %s ", progname,
ofile->file_name, (int)ofile->member_name_size,
ofile->arch_flag.name, ofile->member_name);
}
else{
print("%s: object: %s(%.*s) ", progname, ofile->file_name,
(int)ofile->member_name_size, ofile->member_name);
}
}
else{
print("%s: object: %s ", progname, ofile->file_name);
}
vprint(format, ap);
print("\n");
va_end(ap);
errors++;
}
#endif /* !defined(OTOOL) */

Просмотреть файл

@ -0,0 +1,56 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdio.h>
#include <stdarg.h>
#include "stuff/print.h"
/*
* All printing of all messages for ofile functions goes through this function.
* It is broken out here so it can be overridden for some uses.
*/
__private_extern__
void
vprint(
const char *format,
va_list ap)
{
vfprintf(stderr, format, ap);
}
/*
* The print function that just calls the above vprint() function.
*/
__private_extern__
void
print(
const char *format,
...)
{
va_list ap;
va_start(ap, format);
vprint(format, ap);
va_end(ap);
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,213 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <mach/machine.h>
#include <mach-o/reloc.h>
#include <mach-o/m88k/reloc.h>
#include <mach-o/ppc/reloc.h>
#include <mach-o/i860/reloc.h>
#include <mach-o/hppa/reloc.h>
#include <mach-o/sparc/reloc.h>
#include <mach-o/x86_64/reloc.h>
#include "stuff/bool.h"
#include "stuff/errors.h"
#include "stuff/reloc.h"
/*
* reloc_pair_r_type() returns the PAIR constant for the specific cputype for
* a paired relocation entry.
*/
__private_extern__
unsigned long
reloc_pair_r_type(
cpu_type_t cputype)
{
switch(cputype){
case CPU_TYPE_MC680x0:
case CPU_TYPE_I386:
return(GENERIC_RELOC_PAIR);
break;
case CPU_TYPE_X86_64:
/*
* We should never hit this case for x86-64, so drop down to the
* fatal error below.
*/
break;
case CPU_TYPE_MC88000:
return(M88K_RELOC_PAIR);
break;
case CPU_TYPE_I860:
return(I860_RELOC_PAIR);
break;
case CPU_TYPE_POWERPC:
case CPU_TYPE_POWERPC64:
case CPU_TYPE_VEO:
return(PPC_RELOC_PAIR);
break;
case CPU_TYPE_HPPA:
return(HPPA_RELOC_PAIR);
break;
case CPU_TYPE_SPARC:
return(SPARC_RELOC_PAIR);
break;
}
fatal("internal error: reloc_pair_r_type() called with unknown "
"cputype (%u)", cputype);
/* can't get here but to shut up the compiler warning ... */
return(0);
}
/*
* reloc_has_pair() returns TRUE if the specified r_type for the specified
* cputype for has a paired relocation entry.
*/
__private_extern__
enum bool
reloc_has_pair(
cpu_type_t cputype,
unsigned long r_type)
{
switch(cputype){
case CPU_TYPE_MC680x0:
case CPU_TYPE_I386:
if(r_type == GENERIC_RELOC_SECTDIFF ||
r_type == GENERIC_RELOC_LOCAL_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_X86_64:
return(FALSE);
break;
case CPU_TYPE_MC88000:
if(r_type == M88K_RELOC_HI16 ||
r_type == M88K_RELOC_LO16 ||
r_type == M88K_RELOC_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_I860:
if(r_type == I860_RELOC_HIGH ||
r_type == I860_RELOC_HIGHADJ ||
r_type == I860_RELOC_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_POWERPC:
case CPU_TYPE_POWERPC64:
case CPU_TYPE_VEO:
if(r_type == PPC_RELOC_HI16 ||
r_type == PPC_RELOC_LO16 ||
r_type == PPC_RELOC_HA16 ||
r_type == PPC_RELOC_LO14 ||
r_type == PPC_RELOC_SECTDIFF ||
r_type == PPC_RELOC_LOCAL_SECTDIFF ||
r_type == PPC_RELOC_HI16_SECTDIFF ||
r_type == PPC_RELOC_LO16_SECTDIFF ||
r_type == PPC_RELOC_LO14_SECTDIFF ||
r_type == PPC_RELOC_HA16_SECTDIFF ||
r_type == PPC_RELOC_JBSR)
return(TRUE);
break;
case CPU_TYPE_HPPA:
if(r_type == HPPA_RELOC_HI21 ||
r_type == HPPA_RELOC_LO14 ||
r_type == HPPA_RELOC_BR17 ||
r_type == HPPA_RELOC_JBSR ||
r_type == HPPA_RELOC_SECTDIFF ||
r_type == HPPA_RELOC_HI21_SECTDIFF ||
r_type == HPPA_RELOC_LO14_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_SPARC:
if (r_type == SPARC_RELOC_HI22 ||
r_type == SPARC_RELOC_LO10 ||
r_type == SPARC_RELOC_HI22_SECTDIFF ||
r_type == SPARC_RELOC_LO10_SECTDIFF ||
r_type == SPARC_RELOC_SECTDIFF)
return(TRUE);
break;
default:
fatal("internal error: reloc_has_pair() called with unknown "
"cputype (%u)", cputype);
}
return(FALSE);
}
/*
* reloc_is_sectdiff() returns TRUE if the specified r_type for the specified
* cputype is a section difference relocation type.
*/
__private_extern__
enum bool
reloc_is_sectdiff(
cpu_type_t cputype,
unsigned long r_type)
{
switch(cputype){
case CPU_TYPE_MC680x0:
case CPU_TYPE_I386:
if(r_type == GENERIC_RELOC_SECTDIFF ||
r_type == GENERIC_RELOC_LOCAL_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_X86_64:
/* No sectdiff relocs for x86-64. */
return(FALSE);
break;
case CPU_TYPE_MC88000:
if(r_type == M88K_RELOC_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_I860:
if(r_type == I860_RELOC_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_POWERPC:
case CPU_TYPE_VEO:
if(r_type == PPC_RELOC_SECTDIFF ||
r_type == PPC_RELOC_LOCAL_SECTDIFF ||
r_type == PPC_RELOC_HI16_SECTDIFF ||
r_type == PPC_RELOC_LO16_SECTDIFF ||
r_type == PPC_RELOC_LO14_SECTDIFF ||
r_type == PPC_RELOC_HA16_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_HPPA:
if(r_type == HPPA_RELOC_SECTDIFF ||
r_type == HPPA_RELOC_HI21_SECTDIFF ||
r_type == HPPA_RELOC_LO14_SECTDIFF)
return(TRUE);
break;
case CPU_TYPE_SPARC:
if(r_type == SPARC_RELOC_SECTDIFF ||
r_type == SPARC_RELOC_HI22_SECTDIFF ||
r_type == SPARC_RELOC_LO10_SECTDIFF)
return(TRUE);
break;
default:
fatal("internal error: reloc_is_sectdiff() called with unknown "
"cputype (%u)", cputype);
}
return(FALSE);
}

Просмотреть файл

@ -0,0 +1,42 @@
/*
* Copyright (c) 2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stuff/round.h"
/*
* round() rounds v to a multiple of r.
*/
__private_extern__
unsigned long
round(
unsigned long v,
unsigned long r)
{
r--;
v += r;
v &= ~(long)r;
return(v);
}

Просмотреть файл

@ -0,0 +1,57 @@
/*
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdio.h>
#include "stuff/arch.h"
#include "stuff/allocate.h"
/*
* set_arch_flag_name() sets the name field of the specified arch_flag to
* match it's cputype and cpusubtype. The string is allocated via malloc by
* the routines in "allocate.h" and errors are handled by the routines in
* "error.h".
*/
__private_extern__
void
set_arch_flag_name(
struct arch_flag *p)
{
const struct arch_flag *arch_flag;
arch_flag = get_arch_flags();
while(arch_flag->name != NULL){
if(arch_flag->cputype == p->cputype &&
(arch_flag->cpusubtype & ~CPU_SUBTYPE_MASK) ==
(p->cpusubtype & ~CPU_SUBTYPE_MASK)){
p->name = savestr(arch_flag->name);
break;
}
arch_flag++;
}
if(p->name == NULL){
p->name = savestr("cputype (1234567890) cpusubtype (1234567890)");
sprintf(p->name, "cputype (%d) cpusubtype (%d)",
p->cputype, p->cpusubtype);
}
}
#endif /* !defined(RLD) */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,182 @@
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <stuff/symbol_list.h>
#include <stuff/allocate.h>
#include <stuff/errors.h>
static int cmp_qsort_name(
const struct symbol_list *sym1,
const struct symbol_list *sym2);
/*
* This is called to setup a symbol list from a file. It reads the file with
* the strings in it and places them in an array of symbol_list structures and
* then sorts them by name.
*
* The file that contains the symbol names must have symbol names one per line,
* leading and trailing white space is removed and lines starting with a '#'
* and lines with only white space are ignored.
*/
__private_extern__
void
setup_symbol_list(
char *file,
struct symbol_list **list,
unsigned long *size)
{
int fd;
unsigned long i, j, len, strings_size;
struct stat stat_buf;
char *strings, *p, *line;
if((fd = open(file, O_RDONLY)) < 0){
system_error("can't open: %s", file);
return;
}
if(fstat(fd, &stat_buf) == -1){
system_error("can't stat: %s", file);
close(fd);
return;
}
strings_size = stat_buf.st_size;
strings = (char *)allocate(strings_size + 2);
strings[strings_size] = '\n';
strings[strings_size + 1] = '\0';
if(read(fd, strings, strings_size) != (int)strings_size){
system_error("can't read: %s", file);
close(fd);
return;
}
/*
* Change the newlines to '\0' and count the number of lines with
* symbol names. Lines starting with '#' are comments and lines
* contain all space characters do not contain symbol names.
*/
p = strings;
line = p;
for(i = 0; i < strings_size + 1; i++){
if(*p == '\n' || *p == '\r'){
*p = '\0';
if(*line != '#'){
while(*line != '\0' && isspace(*line))
line++;
if(*line != '\0')
(*size)++;
}
p++;
line = p;
}
else{
p++;
}
}
*list = (struct symbol_list *)
allocate((*size) * sizeof(struct symbol_list));
/*
* Place the strings in the list trimming leading and trailing spaces
* from the lines with symbol names.
*/
p = strings;
line = p;
for(i = 0; i < (*size); ){
p += strlen(p) + 1;
if(*line != '#' && *line != '\0'){
while(*line != '\0' && isspace(*line))
line++;
if(*line != '\0'){
(*list)[i].name = line;
(*list)[i].seen = FALSE;
i++;
len = strlen(line);
j = len - 1;
while(j > 0 && isspace(line[j])){
j--;
}
if(j > 0 && j + 1 < len && isspace(line[j+1]))
line[j+1] = '\0';
}
}
line = p;
}
qsort(*list, *size, sizeof(struct symbol_list),
(int (*)(const void *, const void *))cmp_qsort_name);
/* remove duplicates on the list */
for(i = 0; i < (*size); i++){
if(i + 1 < (*size)){
if(strcmp((*list)[i].name, (*list)[i+1].name) == 0){
for(j = 1; j < ((*size) - i - 1); j++){
(*list)[i + j].name = (*list)[i + j + 1].name;
}
*size = *size - 1;
/*
* Since there may be more than two of the same name
* check this one again against the next one in the
* list before moving on.
*/
i--;
}
}
}
#ifdef DEBUG
printf("symbol list:\n");
for(i = 0; i < (*size); i++){
printf("0x%x name = %s\n", &((*list)[i]),(*list)[i].name);
}
#endif /* DEBUG */
}
/*
* Function for qsort for comparing symbol list names.
*/
static
int
cmp_qsort_name(
const struct symbol_list *sym1,
const struct symbol_list *sym2)
{
return(strcmp(sym1->name, sym2->name));
}
/*
* Function for bsearch for finding a symbol name.
*/
__private_extern__
int
symbol_list_bsearch(
const char *name,
const struct symbol_list *sym)
{
return(strcmp(name, sym->name));
}
#endif /* !defined(RLD) */

Просмотреть файл

@ -0,0 +1,55 @@
/*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef RLD
#include <stdlib.h>
#include <strings.h>
#include "stuff/bool.h"
#include "stuff/unix_standard_mode.h"
/*
* get_unix_standard_mode() returns TRUE if we are running in UNIX standard
* command mode (the default).
*/
__private_extern__
enum bool
get_unix_standard_mode(
void)
{
static enum bool checked_environment_variable = FALSE;
static enum bool unix_standard_mode = TRUE;
char *p;
if(checked_environment_variable == FALSE){
checked_environment_variable = TRUE;
/*
* Pick up the UNIX standard command mode environment variable.
*/
p = getenv("COMMAND_MODE");
if(p != NULL){
if(strcasecmp("legacy", p) == 0)
unix_standard_mode = FALSE;
}
}
return(unix_standard_mode);
}
#endif /* !defined(RLD) */

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -54,6 +54,7 @@ static char *sfile; /* filename of global symbol names to keep */
static char *Rfile; /* filename of global symbol names to remove */
static long Aflag; /* save only absolute symbols with non-zero value and
.objc_class_name_* symbols */
static long aflag; /* -a save all symbols, just regenerate symbol table */
static long iflag; /* -i ignore symbols in -s file not in object */
#ifdef NMEDIT
static long pflag; /* make all defined global symbols private extern */
@ -65,9 +66,13 @@ static long nflag; /* save N_SECT global symbols */
static long Sflag; /* -S strip only debugger symbols N_STAB */
static long xflag; /* -x strip non-globals */
static long Xflag; /* -X strip local symbols with 'L' names */
static long tflag; /* -t strip local symbols except those in the text
section with names that don't begin with 'L' */
static long cflag; /* -c strip section contents from dynamic libraries
files to create stub libraries */
static long no_uuid; /* -no_uuid strip LC_UUID load commands */
static long no_code_signature;
/* -no_code_signature strip LC_CODE_SIGNATURE cmds */
static long strip_all = 1;
/*
* This is set on an object by object basis if the strip_all flag is still set
@ -378,6 +383,9 @@ char *envp[])
else if(strcmp(argv[i], "-no_uuid") == 0){
no_uuid = 1;
}
else if(strcmp(argv[i], "-no_code_signature") == 0){
no_code_signature = 1;
}
#endif /* !defined(NMEDIT) */
else if(strcmp(argv[i], "-arch") == 0){
if(i + 1 == argc){
@ -432,6 +440,10 @@ char *envp[])
xflag = 1;
strip_all = 0;
break;
case 't':
tflag = 1;
strip_all = 0;
break;
case 'i':
iflag = 1;
break;
@ -455,6 +467,10 @@ char *envp[])
#endif /* !defined(NMEDIT) */
break;
#ifndef NMEDIT
case 'a':
aflag = 1;
strip_all = 0;
break;
case 'c':
cflag = 1;
strip_all = 0;
@ -560,8 +576,9 @@ usage(
void)
{
#ifndef NMEDIT
fprintf(stderr, "Usage: %s [-AnuSXx] [-] [-d filename] [-s filename] "
"[-R filename] [-o output] file [...] \n", progname);
fprintf(stderr, "Usage: %s [-AanuStXx] [-no_uuid] [-no_code_signature] "
"[-] [-d filename] [-s filename] [-R filename] [-o output] "
"file [...]\n", progname);
#else /* defined(NMEDIT) */
fprintf(stderr, "Usage: %s -s filename [-R filename] [-p] [-A] [-] "
"[-o output] file [...] \n",
@ -1179,8 +1196,8 @@ struct object *object)
#endif /* !defined(NMEDIT) */
#ifndef NMEDIT
if(sfile != NULL || Rfile != NULL || dfile != NULL || Aflag || uflag ||
Sflag || xflag || Xflag || nflag || rflag ||
if(sfile != NULL || Rfile != NULL || dfile != NULL || Aflag || aflag ||
uflag || Sflag || xflag || Xflag || tflag || nflag || rflag ||
default_dyld_executable || object->mh_filetype == MH_DYLIB ||
object->mh_filetype == MH_DYLINKER)
#endif /* !defined(NMEDIT) */
@ -1226,7 +1243,7 @@ struct object *object)
}
if(object->code_sig_cmd != NULL){
#ifndef NMEDIT
if(!cflag)
if(!cflag && !no_code_signature)
#endif /* !(NMEDIT) */
{
object->output_code_sig_data = object->object_addr +
@ -1354,7 +1371,7 @@ struct object *object)
object->input_sym_info_size +=
object->code_sig_cmd->datasize;
#ifndef NMEDIT
if(cflag){
if(cflag || no_code_signature){
strip_LC_CODE_SIGNATURE_commands(arch, member, object);
}
else
@ -2260,6 +2277,7 @@ unsigned long nindirectsyms)
uint64_t n_value;
uint32_t module_name, iextdefsym, nextdefsym, ilocalsym, nlocalsym;
uint32_t irefsym, nrefsym;
unsigned char text_nsect;
save_debug = 0;
if(saves != NULL)
@ -2292,6 +2310,7 @@ unsigned long nindirectsyms)
* statics.
*/
nsects = 0;
text_nsect = NO_SECT;
lc = object->load_commands;
if(object->mh != NULL)
ncmds = object->mh->ncmds;
@ -2323,15 +2342,23 @@ unsigned long nindirectsyms)
sg = (struct segment_command *)lc;
s = (struct section *)((char *)sg +
sizeof(struct segment_command));
for(j = 0; j < sg->nsects; j++)
for(j = 0; j < sg->nsects; j++){
if(strcmp((s + j)->sectname, SECT_TEXT) == 0 &&
strcmp((s + j)->segname, SEG_TEXT) == 0)
text_nsect = nsects + 1;
sections[nsects++] = s++;
}
}
else if(lc->cmd == LC_SEGMENT_64){
sg64 = (struct segment_command_64 *)lc;
s64 = (struct section_64 *)((char *)sg64 +
sizeof(struct segment_command_64));
for(j = 0; j < sg64->nsects; j++)
for(j = 0; j < sg64->nsects; j++){
if(strcmp((s64 + j)->sectname, SECT_TEXT) == 0 &&
strcmp((s64 + j)->segname, SEG_TEXT) == 0)
text_nsect = nsects + 1;
sections64[nsects++] = s64++;
}
}
lc = (struct load_command *)((char *)lc + lc->cmdsize);
}
@ -2387,13 +2414,7 @@ unsigned long nindirectsyms)
}
}
if((n_type & N_EXT) == 0){ /* local symbol */
/*
* strip -x or -X on an x86_64 .o file should do nothing.
*/
if(object->mh == NULL &&
object->mh64->cputype == CPU_TYPE_X86_64 &&
object->mh64->filetype == MH_OBJECT &&
(xflag == 1 || Xflag == 1)){
if(aflag){
if(n_strx != 0)
new_strsize += strlen(strings + n_strx) + 1;
new_nlocalsym++;
@ -2401,10 +2422,23 @@ unsigned long nindirectsyms)
saves[i] = new_nsyms;
}
/*
* The cases a local symbol might be saved is with -X -S or
* with -d filename.
* strip -x, -X, or -t on an x86_64 .o file should do nothing.
*/
else if((!strip_all && (Xflag || Sflag)) || dfile){
else if(object->mh == NULL &&
object->mh64->cputype == CPU_TYPE_X86_64 &&
object->mh64->filetype == MH_OBJECT &&
(xflag == 1 || Xflag == 1 || tflag == 1)){
if(n_strx != 0)
new_strsize += strlen(strings + n_strx) + 1;
new_nlocalsym++;
new_nsyms++;
saves[i] = new_nsyms;
}
/*
* The cases a local symbol might be saved are with -X, -S, -t,
* or with -d filename.
*/
else if((!strip_all && (Xflag || tflag || Sflag)) || dfile){
if(n_type & N_STAB){ /* debug symbol */
if(dfile && n_type == N_SO){
if(n_strx != 0){
@ -2458,10 +2492,18 @@ unsigned long nindirectsyms)
}
}
else{ /* non-debug local symbol */
if(xflag == 0 && (Sflag || Xflag)){
if(Xflag == 0 ||
(n_strx != 0 &&
strings[n_strx] != 'L')){
if(xflag == 0 && (Sflag || Xflag || tflag)){
/*
* No -x (strip all local), and one of -S (strip
* debug), -X (strip 'L' local), or -t (strip
* local except non-'L' text) was given.
*/
if((Xflag && n_strx != 0 &&
strings[n_strx] != 'L') ||
(tflag && (n_type & N_TYPE) == N_SECT &&
n_sect == text_nsect && n_strx != 0 &&
strings[n_strx] != 'L') ||
(Sflag && !Xflag && !tflag)) {
/*
* If this file is a for the dynamic linker and
* this symbol is in a section marked so that
@ -2714,7 +2756,8 @@ unsigned long nindirectsyms)
new_nsyms++;
saves[i] = new_nsyms;
}
if(saves[i] == 0 && ((Xflag || Sflag || xflag) ||
if(saves[i] == 0 &&
((Xflag || Sflag || xflag || tflag || aflag) ||
((rflag || default_dyld_executable) &&
n_desc & REFERENCED_DYNAMICALLY))){
len = strlen(strings + n_strx) + 1;
@ -3500,32 +3543,35 @@ struct object *object)
lc1 = (struct load_command *)((char *)lc1 + lc1->cmdsize);
}
/*
* To get the right amount of the file copied out by writeout() for the
* case when we are stripping out the section contents we already reduce
* the object size by the size of the section contents including the
* padding after the load commands. So here we need to further reduce
* it by the load command for the LC_CODE_SIGNATURE (a struct
* linkedit_data_command) we are removing.
*/
object->object_size -= sizeof(struct linkedit_data_command);
/*
* Then this size minus the size of the input symbolic information is
* what is copied out from the file by writeout(). Which in this case
* is just the new headers.
*/
if(cflag){
/*
* To get the right amount of the file copied out by writeout() for
* the case when we are stripping out the section contents we
* already reduce the object size by the size of the section
* contents including the padding after the load commands. So here
* we need to further reduce it by the load command for the
* LC_CODE_SIGNATURE (a struct linkedit_data_command) we are
* removing.
*/
object->object_size -= sizeof(struct linkedit_data_command);
/*
* Then this size minus the size of the input symbolic information
* is what is copied out from the file by writeout(). Which in this
* case is just the new headers.
*/
/*
* Finally for -c the file offset to the link edit information is to be
* right after the load commands. So reset this for the updated size
* of the load commands without the LC_CODE_SIGNATURE.
*/
if(object->mh != NULL)
object->seg_linkedit->fileoff = sizeof(struct mach_header) +
sizeofcmds;
else
object->seg_linkedit64->fileoff = sizeof(struct mach_header_64) +
sizeofcmds;
/*
* Finally for -c the file offset to the link edit information is to
* be right after the load commands. So reset this for the updated
* size of the load commands without the LC_CODE_SIGNATURE.
*/
if(object->mh != NULL)
object->seg_linkedit->fileoff = sizeof(struct mach_header) +
sizeofcmds;
else
object->seg_linkedit64->fileoff =
sizeof(struct mach_header_64) + sizeofcmds;
}
}
#endif /* !(NMEDIT) */