7
* Copyright (C) 2011 Oracle Corporation
7
* Copyright (C) 2011-2012 Oracle Corporation
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;
353
355
* Looks up a kernel symbol.
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;
379
380
/** @todo binary search. */
583
586
RETURN_VERR_BAD_EXE_FORMAT;
584
587
const char *pszSym = &pThis->pachStrTab[(uint32_t)pSym->n_un.n_strx];
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);
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;
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)
614
if (pSym->n_sect > pThis->cSections)
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;
989
1012
if (RT_SUCCESS(rc))
990
1013
rc = rtR0MachKernelLoadSymTab(pThis);
991
1014
if (RT_SUCCESS(rc))
1018
* Determine the load displacement (10.8 kernels are PIE).
1020
uintptr_t uLinkAddr = rtR0MachKernelLookup(pThis, "kernel_map");
1022
pThis->offLoad = (uintptr_t)&kernel_map - uLinkAddr;
992
1024
rc = rtR0MachKernelCheckStandardSymbols(pThis);
994
1027
rtR0MachKernelLoadDone(pThis);
995
1028
if (RT_SUCCESS(rc))