~ubuntu-branches/ubuntu/quantal/virtualbox/quantal

« back to all changes in this revision

Viewing changes to src/VBox/Runtime/r0drv/darwin/mach_kernel-r0drv-darwin.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2012-05-29 10:09:31 UTC
  • mfrom: (3.1.15 sid)
  • Revision ID: package-import@ubuntu.com-20120529100931-2xayrbh5hyzm6e9p
Tags: 4.1.16-dfsg-1
* New upstream release.
* Drop 37-fix-build-gcc47.patch, fixed upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 */
5
5
 
6
6
/*
7
 
 * Copyright (C) 2011 Oracle Corporation
 
7
 * Copyright (C) 2011-2012 Oracle Corporation
8
8
 *
9
9
 * This file is part of VirtualBox Open Source Edition (OSE), as
10
10
 * available from http://www.virtualbox.org. This file is free software;
138
138
    uint32_t            cSyms;
139
139
    /** The file offset of the symbol table. */
140
140
    uint32_t            offSyms;
 
141
    /** Offset between link address and actual load address. */
 
142
    uintptr_t           offLoad;
141
143
    /** @} */
142
144
 
143
145
    /** @name Used during loading.
352
354
/**
353
355
 * Looks up a kernel symbol.
354
356
 *
355
 
 *
356
357
 * @returns The symbol address on success, 0 on failure.
357
358
 * @param   pThis               The internal scratch data.
358
359
 * @param   pszSymbol           The symbol to resolve.  Automatically prefixed
373
374
        const char *pszTabName= &pThis->pachStrTab[(uint32_t)pSym->n_un.n_strx];
374
375
        if (   *pszTabName == '_'
375
376
            && strcmp(pszTabName + 1, pszSymbol) == 0)
376
 
            return pSym->n_value;
 
377
            return pSym->n_value + pThis->offLoad;
377
378
    }
378
379
#else
379
380
    /** @todo binary search. */
517
518
        KNOWN_ENTRY(vm_region),
518
519
        KNOWN_ENTRY(vm_map_wire),
519
520
        KNOWN_ENTRY(PE_kputc),
 
521
        KNOWN_ENTRY(kernel_map),
 
522
        KNOWN_ENTRY(kernel_pmap),
520
523
    };
521
524
 
522
525
    for (unsigned i = 0; i < RT_ELEMENTS(s_aStandardCandles); i++)
583
586
            RETURN_VERR_BAD_EXE_FORMAT;
584
587
        const char *pszSym = &pThis->pachStrTab[(uint32_t)pSym->n_un.n_strx];
585
588
#ifdef IN_RING3
586
 
        RTAssertMsg2("%05i: %02x:%08x %02x %04x %s\n", iSym, pSym->n_sect, pSym->n_value, pSym->n_type, pSym->n_desc, pszSym);
 
589
        RTAssertMsg2("%05i: %02x:%08llx %02x %04x %s\n", iSym, pSym->n_sect, (uint64_t)pSym->n_value, pSym->n_type, pSym->n_desc, pszSym);
587
590
#endif
588
591
 
589
592
        if (strcmp(pszSym, pszPrev) < 0)
600
603
                        RETURN_VERR_BAD_EXE_FORMAT;
601
604
                    if (pSym->n_desc & ~(REFERENCED_DYNAMICALLY))
602
605
                        RETURN_VERR_BAD_EXE_FORMAT;
603
 
                    if (pSym->n_value < pThis->apSections[pSym->n_sect - 1]->addr)
 
606
                    if (   pSym->n_value < pThis->apSections[pSym->n_sect - 1]->addr
 
607
                        && strcmp(pszSym, "__mh_execute_header"))    /* in 10.8 it's no longer absolute (PIE?). */
604
608
                        RETURN_VERR_BAD_EXE_FORMAT;
605
 
                    if (   pSym->n_value - pThis->apSections[pSym->n_sect - 1]->addr
606
 
                        > pThis->apSections[pSym->n_sect - 1]->size)
 
609
                    if (      pSym->n_value - pThis->apSections[pSym->n_sect - 1]->addr
 
610
                           > pThis->apSections[pSym->n_sect - 1]->size
 
611
                        && strcmp(pszSym, "__mh_execute_header"))    /* see above. */
607
612
                        RETURN_VERR_BAD_EXE_FORMAT;
608
613
                    break;
609
614
 
610
615
                case MACHO_N_ABS:
611
 
#if 0 /* Spec say MACHO_NO_SECT, __mh_execute_header has 1 with 10.7/amd64 */
612
 
                    if (pSym->n_sect != MACHO_NO_SECT)
613
 
#else
614
 
                    if (pSym->n_sect > pThis->cSections)
615
 
#endif
 
616
                    if (   pSym->n_sect != MACHO_NO_SECT
 
617
                        && (   strcmp(pszSym, "__mh_execute_header") /* n_sect=1 in 10.7/amd64 */
 
618
                            || pSym->n_sect > pThis->cSections) )
616
619
                        RETURN_VERR_BAD_EXE_FORMAT;
617
620
                    if (pSym->n_desc & ~(REFERENCED_DYNAMICALLY))
618
621
                        RETURN_VERR_BAD_EXE_FORMAT;
821
824
 
822
825
            case LC_DYSYMTAB:
823
826
            case LC_UNIXTHREAD:
 
827
            case LC_CODE_SIGNATURE:
 
828
            case LC_VERSION_MIN_MACOSX:
 
829
            case LC_FUNCTION_STARTS:
 
830
            case LC_MAIN:
 
831
            case LC_DATA_IN_CODE:
 
832
            case LC_SOURCE_VERSION:
824
833
                break;
825
834
 
826
835
            /* not observed */
840
849
            case LC_PREPAGE:
841
850
            case LC_TWOLEVEL_HINTS:
842
851
            case LC_PREBIND_CKSUM:
 
852
            case LC_SEGMENT_SPLIT_INFO:
 
853
            case LC_ENCRYPTION_INFO:
 
854
                RETURN_VERR_LDR_UNEXPECTED;
 
855
 
 
856
            /* no phones here yet */
 
857
            case LC_VERSION_MIN_IPHONEOS:
843
858
                RETURN_VERR_LDR_UNEXPECTED;
844
859
 
845
860
            /* dylib */
853
868
            case LC_SUB_UMBRELLA:
854
869
            case LC_SUB_CLIENT:
855
870
            case LC_SUB_LIBRARY:
 
871
            case LC_RPATH:
 
872
            case LC_REEXPORT_DYLIB:
 
873
            case LC_LAZY_LOAD_DYLIB:
 
874
            case LC_DYLD_INFO:
 
875
            case LC_DYLD_INFO_ONLY:
 
876
            case LC_LOAD_UPWARD_DYLIB:
 
877
            case LC_DYLD_ENVIRONMENT:
 
878
            case LC_DYLIB_CODE_SIGN_DRS:
856
879
                RETURN_VERR_LDR_UNEXPECTED;
857
880
 
858
881
            default:
989
1012
    if (RT_SUCCESS(rc))
990
1013
        rc = rtR0MachKernelLoadSymTab(pThis);
991
1014
    if (RT_SUCCESS(rc))
 
1015
    {
 
1016
#ifdef IN_RING0
 
1017
        /*
 
1018
         * Determine the load displacement (10.8 kernels are PIE).
 
1019
         */
 
1020
        uintptr_t uLinkAddr = rtR0MachKernelLookup(pThis, "kernel_map");
 
1021
        if (uLinkAddr != 0)
 
1022
            pThis->offLoad = (uintptr_t)&kernel_map - uLinkAddr;
 
1023
#endif
992
1024
        rc = rtR0MachKernelCheckStandardSymbols(pThis);
 
1025
    }
993
1026
 
994
1027
    rtR0MachKernelLoadDone(pThis);
995
1028
    if (RT_SUCCESS(rc))