struct load_command *doloadcommand(void *start, struct load_command *lc, bool needsFlip, bool is32, struct gcinfo *gcip) { if (needsFlip) { lc->cmd = OSSwapInt32(lc->cmd); lc->cmdsize = OSSwapInt32(lc->cmdsize); } switch(lc->cmd) { case LC_SEGMENT_64: if (debug) printf("...segment64\n"); if (is32) printf("XXX we have a 64-bit segment in a 32-bit mach-o\n"); doseg64(start, (struct segment_command_64 *)lc, needsFlip, gcip); break; case LC_SEGMENT: if (debug) printf("...segment32\n"); doseg32(start, (struct segment_command *)lc, needsFlip, gcip); break; case LC_SYMTAB: if (debug) printf("...dynamic symtab\n"); break; case LC_DYSYMTAB: if (debug) printf("...symtab\n"); break; case LC_LOAD_DYLIB: dodylib(start, (struct dylib_command *)lc, needsFlip); break; case LC_SUB_UMBRELLA: if (debug) printf("...load subumbrella\n"); break; default: if (debug) printf("cmd is %x\n", lc->cmd); break; } return (struct load_command *)((void *)lc + lc->cmdsize); }
IOReturn SamplePCIUserClientClassName::method1( UInt32 * dataIn, UInt32 * dataOut, IOByteCount inputSize, IOByteCount * outputSize ) { IOReturn ret; IOItemCount count; IOLog("SamplePCIUserClient::method1("); if (*outputSize < inputSize) return( kIOReturnNoSpace ); count = inputSize / sizeof( UInt32 ); for (UInt32 i = 0; i < count; i++ ) { // Client app is running using Rosetta if (fCrossEndian) { dataIn[i] = OSSwapInt32(dataIn[i]); } IOLog("" UInt32_x_FORMAT ", ", dataIn[i]); dataOut[i] = dataIn[i] ^ 0xffffffff; // Rosetta again if (fCrossEndian) { dataOut[i] = OSSwapInt32(dataOut[i]); } } ret = kIOReturnSuccess; IOLog(")\n"); *outputSize = count * sizeof( UInt32 ); return( ret ); }
void swap_thread_command( struct thread_command *ut, enum NXByteOrder target_byte_sex) { ut->cmd = OSSwapInt32(ut->cmd); ut->cmdsize = OSSwapInt32(ut->cmdsize); }
void swap_x86_state_hdr( x86_state_hdr_t *hdr, enum NXByteOrder target_byte_sex) { hdr->flavor = OSSwapInt32(hdr->flavor); hdr->count = OSSwapInt32(hdr->count); }
void swap_uuid_command( struct uuid_command *uuid_cmd, enum NXByteOrder target_byte_sex) { uuid_cmd->cmd = OSSwapInt32(uuid_cmd->cmd); uuid_cmd->cmdsize = OSSwapInt32(uuid_cmd->cmdsize); }
void swap_fat_header( struct fat_header *fat_header, enum NXByteOrder target_byte_sex) { fat_header->magic = OSSwapInt32(fat_header->magic); fat_header->nfat_arch = OSSwapInt32(fat_header->nfat_arch); }
void swap_ident_command( struct ident_command *id_cmd, enum NXByteOrder target_byte_sex) { id_cmd->cmd = OSSwapInt32(id_cmd->cmd); id_cmd->cmdsize = OSSwapInt32(id_cmd->cmdsize); }
void swap_load_command( struct load_command *lc, enum NXByteOrder target_byte_sex) { lc->cmd = OSSwapInt32(lc->cmd); lc->cmdsize = OSSwapInt32(lc->cmdsize); }
void swap_sub_client_command( struct sub_client_command *csub, enum NXByteOrder target_byte_sex) { csub->cmd = OSSwapInt32(csub->cmd); csub->cmdsize = OSSwapInt32(csub->cmdsize); csub->client.offset = OSSwapInt32(csub->client.offset); }
void swap_sub_library_command( struct sub_library_command *lsub, enum NXByteOrder target_byte_sex) { lsub->cmd = OSSwapInt32(lsub->cmd); lsub->cmdsize = OSSwapInt32(lsub->cmdsize); lsub->sub_library.offset = OSSwapInt32(lsub->sub_library.offset); }
void swap_sub_umbrella_command( struct sub_umbrella_command *usub, enum NXByteOrder target_byte_sex) { usub->cmd = OSSwapInt32(usub->cmd); usub->cmdsize = OSSwapInt32(usub->cmdsize); usub->sub_umbrella.offset = OSSwapInt32(usub->sub_umbrella.offset); }
void swap_sub_framework_command( struct sub_framework_command *sub, enum NXByteOrder target_byte_sex) { sub->cmd = OSSwapInt32(sub->cmd); sub->cmdsize = OSSwapInt32(sub->cmdsize); sub->umbrella.offset = OSSwapInt32(sub->umbrella.offset); }
void swap_dylinker_command( struct dylinker_command *dyld, enum NXByteOrder target_byte_sex) { dyld->cmd = OSSwapInt32(dyld->cmd); dyld->cmdsize = OSSwapInt32(dyld->cmdsize); dyld->name.offset = OSSwapInt32(dyld->name.offset); }
void swap_prebind_cksum_command( struct prebind_cksum_command *cksum_cmd, enum NXByteOrder target_byte_sex) { cksum_cmd->cmd = OSSwapInt32(cksum_cmd->cmd); cksum_cmd->cmdsize = OSSwapInt32(cksum_cmd->cmdsize); cksum_cmd->cksum = OSSwapInt32(cksum_cmd->cksum); }
void swap_i386_exception_state( i386_exception_state_t *exc, enum NXByteOrder target_byte_sex) { exc->trapno = OSSwapInt32(exc->trapno); exc->err = OSSwapInt32(exc->err); exc->faultvaddr = OSSwapInt32(exc->faultvaddr); }
PhysicalAddressSpace::PhysicalAddressSpace( Device& inUserClient, UserObjectHandle inKernPhysicalAddrSpaceRef, UInt32 inSize, void* inBackingStore, UInt32 inFlags) : IOFireWireIUnknown( reinterpret_cast<const IUnknownVTbl &>( sInterface ) ), mUserClient(inUserClient), mKernPhysicalAddrSpaceRef(inKernPhysicalAddrSpaceRef), mSize(inSize), mBackingStore(inBackingStore), mSegments( NULL ), mSegmentCount(0) { inUserClient.AddRef() ; if (!mKernPhysicalAddrSpaceRef) throw kIOReturnNoMemory ; uint32_t outputCnt = 1; uint64_t outputVal = 0; IOReturn error = IOConnectCallScalarMethod( mUserClient.GetUserClientConnection(), mUserClient.MakeSelectorWithObject( kPhysicalAddrSpace_GetSegmentCount_d, mKernPhysicalAddrSpaceRef ), NULL,0, &outputVal,&outputCnt); mSegmentCount = outputVal & 0xFFFFFFFF; if ( error || mSegmentCount == 0) throw error ; mSegments = new FWPhysicalSegment32[mSegmentCount] ; if (!mSegments) { throw kIOReturnNoMemory ; } outputCnt = 1; outputVal = 0; const uint64_t inputs[3] = {(const uint64_t)mKernPhysicalAddrSpaceRef, mSegmentCount, (const uint64_t)mSegments}; error = IOConnectCallScalarMethod( mUserClient.GetUserClientConnection(), kPhysicalAddrSpace_GetSegments, inputs,3, &outputVal,&outputCnt); mSegmentCount = outputVal & 0xFFFFFFFF; if (error) { throw error ; } #ifndef __LP64__ ROSETTA_ONLY( { UInt32 i; for( i = 0; i < mSegmentCount; i++ ) { mSegments[i].location = OSSwapInt32( mSegments[i].location ); mSegments[i].length = OSSwapInt32( mSegments[i].length ); } } );
void swap_symseg_command( struct symseg_command *ss, enum NXByteOrder target_byte_sex) { ss->cmd = OSSwapInt32(ss->cmd); ss->cmdsize = OSSwapInt32(ss->cmdsize); ss->offset = OSSwapInt32(ss->offset); ss->size = OSSwapInt32(ss->size); }
void swap_fvmfile_command( struct fvmfile_command *ff, enum NXByteOrder target_byte_sex) { ff->cmd = OSSwapInt32(ff->cmd); ff->cmdsize = OSSwapInt32(ff->cmdsize); ff->name.offset = OSSwapInt32(ff->name.offset); ff->header_addr = OSSwapInt32(ff->header_addr); }
/* * This routine returns the section structure for the named section in the * named segment for the mach_header pointer passed to it if it exist. * Otherwise it returns zero. If fSwap == YES (the mach header has been * swapped to the endiannes of the current machine, but the segments and * sections are different) then the segment and sections are swapped. */ const struct section * getsectbynamefromheaderwithswap( struct mach_header *mhp, const char *segname, const char *sectname, int fSwap) { struct segment_command *sgp; struct section *sp; uint32_t i, j; sgp = (struct segment_command *) ((char *)mhp + sizeof(struct mach_header)); for(i = 0; i < mhp->ncmds; i++) { if(sgp->cmd == (fSwap ? OSSwapInt32(LC_SEGMENT) : LC_SEGMENT)) { if (fSwap) { #ifdef __LITTLE_ENDIAN__ swap_segment_command(sgp, NX_BigEndian); #else swap_segment_command(sgp, NX_LittleEndian); #endif /* __LITTLE_ENDIAN__ */ } if(strncmp(sgp->segname, segname, sizeof(sgp->segname)) == 0 || mhp->filetype == MH_OBJECT) { sp = (struct section *)((char *)sgp + sizeof(struct segment_command)); if (fSwap) { #ifdef __LITTLE_ENDIAN__ swap_section(sp, sgp->nsects, NX_BigEndian); #else swap_section(sp, sgp->nsects, NX_LittleEndian); #endif /* __LITTLE_ENDIAN__ */ } for(j = 0; j < sgp->nsects; j++) { if(strncmp(sp->sectname, sectname, sizeof(sp->sectname)) == 0 && strncmp(sp->segname, segname, sizeof(sp->segname)) == 0) return(sp); sp = (struct section *)((char *)sp + sizeof(struct section)); } } sgp = (struct segment_command *)((char *)sgp + sgp->cmdsize); } else { sgp = (struct segment_command *)((char *)sgp + (fSwap ? OSSwapInt32(sgp->cmdsize) : sgp->cmdsize)); } } return((struct section *)0); }
void swap_fvmlib_command( struct fvmlib_command *fl, enum NXByteOrder target_byte_sex) { fl->cmd = OSSwapInt32(fl->cmd); fl->cmdsize = OSSwapInt32(fl->cmdsize); fl->fvmlib.name.offset = OSSwapInt32(fl->fvmlib.name.offset); fl->fvmlib.minor_version = OSSwapInt32(fl->fvmlib.minor_version); fl->fvmlib.header_addr = OSSwapInt32(fl->fvmlib.header_addr); }
void swap_prebound_dylib_command( struct prebound_dylib_command *pbdylib, enum NXByteOrder target_byte_sex) { pbdylib->cmd = OSSwapInt32(pbdylib->cmd); pbdylib->cmdsize = OSSwapInt32(pbdylib->cmdsize); pbdylib->name.offset = OSSwapInt32(pbdylib->name.offset); pbdylib->nmodules = OSSwapInt32(pbdylib->nmodules); pbdylib->linked_modules.offset = OSSwapInt32(pbdylib->linked_modules.offset); }
void swap_dylib_table_of_contents( struct dylib_table_of_contents *tocs, uint32_t ntocs, enum NXByteOrder target_byte_sex) { uint32_t i; for(i = 0; i < ntocs; i++){ tocs[i].symbol_index = OSSwapInt32(tocs[i].symbol_index); tocs[i].module_index = OSSwapInt32(tocs[i].module_index); } }
void swap_ranlib( struct ranlib *ranlibs, uint32_t nranlibs, enum NXByteOrder target_byte_sex) { uint32_t i; for(i = 0; i < nranlibs; i++){ ranlibs[i].ran_un.ran_strx = OSSwapInt32(ranlibs[i].ran_un.ran_strx); ranlibs[i].ran_off = OSSwapInt32(ranlibs[i].ran_off); } }
void dosect32(void *start, struct section *sect, bool needsFlip, struct gcinfo *gcip) { if (debug) printf("section %s from segment %s\n", sect->sectname, sect->segname); if (strcmp(sect->segname, "__OBJC")) return; gcip->hasObjC = true; if (strcmp(sect->sectname, "__image_info")) return; gcip->hasInfo = true; if (needsFlip) { sect->offset = OSSwapInt32(sect->offset); sect->size = OSSwapInt32(sect->size); } // these guys aren't inline - they point elsewhere gcip->flags = iiflags(start + sect->offset, sect->size, needsFlip); }
void swap_m68k_thread_state_regs( struct m68k_thread_state_regs *cpu, enum NXByteOrder target_byte_sex) { uint32_t i; for(i = 0; i < 8; i++) cpu->dreg[i] = OSSwapInt32(cpu->dreg[i]); for(i = 0; i < 8; i++) cpu->areg[i] = OSSwapInt32(cpu->areg[i]); cpu->pad0 = OSSwapInt16(cpu->pad0); cpu->sr = OSSwapInt16(cpu->sr); cpu->pc = OSSwapInt32(cpu->pc); }
/* * driver initialization after the matching has completed... */ bool SamplePCIUserClientClassName::start(IOService* provider) { IOLog("%s[%p]::%s(provider = %p)\n", getName(), this, __FUNCTION__, provider); if (!super::start(provider)) return false; /* * Our provider should be a SamplePCI object. Verify that before proceeding. */ assert(OSDynamicCast(SamplePCIClassName, provider)); fDriver = (SamplePCIClassName*) provider; /* * Set up some memory to be shared between this user client instance and its * client process. The client will call in to map this memory, and I/O Kit * will call clientMemoryForType to obtain this memory descriptor. */ fClientSharedMemory = IOBufferMemoryDescriptor::withOptions(kIOMemoryKernelUserShared, sizeof(SampleSharedMemory)); if (!fClientSharedMemory) return false; fClientShared = (SampleSharedMemory *) fClientSharedMemory->getBytesNoCopy(); fClientShared->field1 = 0x11111111; // same in all endianesses... fClientShared->field2 = 0x22222222; // ditto fClientShared->field3 = 0x33333333; // ditto if (fCrossEndian) { // Swap the fields so the user process sees the proper endianness fClientShared->field1 = OSSwapInt32(fClientShared->field1); fClientShared->field2 = OSSwapInt32(fClientShared->field2); fClientShared->field3 = OSSwapInt32(fClientShared->field3); } #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 // strlcpy() doesn't exist in the MacOSX10.4u SDK. (void)strncpy(fClientShared->string, "some data", sizeof(fClientShared->string) - 1); fClientShared->string[sizeof(fClientShared->string) - 1] = '\0'; #else (void) strlcpy(fClientShared->string, "some data", sizeof(fClientShared->string)); #endif fOpenCount = 1; return true; }
void swap_m68k_thread_state_user_reg( struct m68k_thread_state_user_reg *user_reg, enum NXByteOrder target_byte_sex) { user_reg->user_reg = OSSwapInt32(user_reg->user_reg); }
static unsigned long swap(unsigned long x) { if (swap_ends) return OSSwapInt32(x); else return x; }
void swap_nlist( struct nlist *symbols, uint32_t nsymbols, enum NXByteOrder target_byte_sex) { uint32_t i; for(i = 0; i < nsymbols; i++){ symbols[i].n_un.n_strx = OSSwapInt32(symbols[i].n_un.n_strx); /* n_type */ /* n_sect */ symbols[i].n_desc = OSSwapInt16(symbols[i].n_desc); symbols[i].n_value = OSSwapInt32(symbols[i].n_value); } }
static void avcCommandHandlerCallback( void *refcon, IOReturn result, io_user_reference_t *args, int numArgs) { AVCProtocol *me = (AVCProtocol *)refcon; UInt32 pos; UInt32 len; const UInt8* src; UInt32 fixedArgs[kMaxAsyncArgs]; UInt32 i; uint64_t inArg[4]; uint32_t outputScalarCnt = 0; size_t outputStructSize = 0; //printf("DEBUG: AVCProtocol::avcCommandHandlerCallback\n"); // First copy all the args with endian byte-swapping. Note that only // the args that contain command-bytes need this, but doing them all // here simplifies the logic below. IF_ROSETTA() { // Note: This code assumes ROSETTA only happens for in 32-bit mode! for (i=0;i<numArgs;i++) fixedArgs[i] = (OSSwapInt32(args[i]) & 0xFFFFFFFF); } else { for (i=0;i<numArgs;i++)