VirtualBox

Changeset 86244 in vbox


Ignore:
Timestamp:
Sep 23, 2020 3:35:16 PM (4 years ago)
Author:
vboxsync
Message:

Debugger/DBGCRemoteKd: Implement search memory request

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Debugger/DBGCRemoteKd.cpp

    r86235 r86244  
    5151/** NT status code - Success. */
    5252#define NTSTATUS_SUCCESS                            0
     53/** NT status code - buffer overflow. */
     54#define NTSTATUS_BUFFER_OVERFLOW                    UINT32_C(0x80000005)
    5355/** NT status code - operation unsuccesful. */
    5456#define NTSTATUS_UNSUCCESSFUL                       UINT32_C(0xc0000001)
    5557/** NT status code - operation not implemented. */
    5658#define NTSTATUS_NOT_IMPLEMENTED                    UINT32_C(0xc0000002)
     59/** NT status code - Object not found. */
     60#define NTSTATUS_NOT_FOUND                          UINT32_C(0xc0000225)
    5761
    5862/** Offset where the KD version block pointer is stored in the KPCR.
     
    970974
    971975/**
     976 * Search memory payload.
     977 */
     978typedef struct KDPACKETMANIPULATE_SEARCHMEMORY
     979{
     980    /** The address to start searching at on input, found address on output. */
     981    uint64_t                    u64GCPtr;
     982    /** Number of bytes to search. */
     983    uint64_t                    cbSearch;
     984    /** Length of the pattern to search for following the payload. */
     985    uint32_t                    cbPattern;
     986    /** Padding to the required size. */
     987    uint32_t                    au32Pad[5];
     988} KDPACKETMANIPULATE_SEARCHMEMORY;
     989AssertCompileSize(KDPACKETMANIPULATE_SEARCHMEMORY, 40);
     990/** Pointer to a search memory properties payload. */
     991typedef KDPACKETMANIPULATE_SEARCHMEMORY *PKDPACKETMANIPULATE_SEARCHMEMORY;
     992/** Pointer to a const search memory properties payload. */
     993typedef const KDPACKETMANIPULATE_SEARCHMEMORY *PCKDPACKETMANIPULATE_SEARCHMEMORY;
     994
     995
     996/**
    972997 * Manipulate request packet header (Same for 32bit and 64bit).
    973998 */
     
    10221047        /** Query memory. */
    10231048        KDPACKETMANIPULATE_QUERYMEMORY     QueryMemory;
     1049        /** Search memory. */
     1050        KDPACKETMANIPULATE_SEARCHMEMORY    SearchMemory;
    10241051    } u;
    10251052} KDPACKETMANIPULATE64;
     
    10871114#define KD_PACKET_MANIPULATE_REQ_CAUSE_BUGCHECK             UINT32_C(0x00003149)
    10881115/** @todo */
     1116/** Search memory for a pattern request. */
     1117#define KD_PACKET_MANIPULATE_REQ_SEARCH_MEMORY              UINT32_C(0x00003156)
     1118/** @todo */
    10891119/** Clear all internal breakpoints request. */
    10901120#define KD_PACKET_MANIPULATE_REQ_CLEAR_ALL_INTERNAL_BKPT    UINT32_C(0x0000315a)
     
    12821312        case KD_PACKET_MANIPULATE_REQ_QUERY_MEMORY:             return "QueryMemory";
    12831313        case KD_PACKET_MANIPULATE_REQ_CAUSE_BUGCHECK:           return "CauseBugCheck";
     1314        case KD_PACKET_MANIPULATE_REQ_SEARCH_MEMORY:            return "SearchMemory";
    12841315        default:                                                break;
    12851316    }
     
    14171448                break;
    14181449            }
     1450            case KD_PACKET_MANIPULATE_REQ_SEARCH_MEMORY:
     1451            {
     1452                KDPACKETMANIPULATE_SEARCHMEMORY SearchMemory;
     1453                cbCopied = RTSgBufCopyToBuf(pSgBuf, &SearchMemory, sizeof(SearchMemory));
     1454                if (cbCopied == sizeof(SearchMemory))
     1455                {
     1456                    Log3(("        u64GCPtr:     %RX64\n"
     1457                          "        cbSearch:     %RX64\n"
     1458                          "        cbPattern:    %RX32\n",
     1459                          SearchMemory.u64GCPtr, SearchMemory.cbSearch, SearchMemory.cbPattern));
     1460                }
     1461                else
     1462                    Log3(("        Payload to small, expected %u, got %zu\n", sizeof(SearchMemory), cbCopied));
     1463                break;
     1464            }
    14191465            default:
    14201466                break;
     
    32823328
    32833329/**
     3330 * Processes a search memory 64 request.
     3331 *
     3332 * @returns VBox status code.
     3333 * @param   pThis               The KD context.
     3334 * @param   pPktManip           The manipulate packet request.
     3335 */
     3336static int dbgcKdCtxPktManipulate64SearchMemory(PKDCTX pThis, PCKDPACKETMANIPULATE64 pPktManip)
     3337{
     3338    KDPACKETMANIPULATEHDR RespHdr;
     3339    KDPACKETMANIPULATE_SEARCHMEMORY SearchMemory;
     3340    RT_ZERO(RespHdr); RT_ZERO(SearchMemory);
     3341
     3342    RTSGSEG aRespSegs[2];
     3343    RespHdr.idReq       = KD_PACKET_MANIPULATE_REQ_SEARCH_MEMORY;
     3344    RespHdr.u16CpuLvl   = pPktManip->Hdr.u16CpuLvl;
     3345    RespHdr.idCpu       = pPktManip->Hdr.idCpu;
     3346    RespHdr.u32NtStatus = NTSTATUS_SUCCESS;
     3347
     3348    SearchMemory.u64GCPtr  = pPktManip->u.SearchMemory.u64GCPtr;
     3349    SearchMemory.cbSearch  = pPktManip->u.SearchMemory.cbSearch;
     3350    SearchMemory.cbPattern = pPktManip->u.SearchMemory.cbPattern;
     3351
     3352    /* Validate the pattern length and start searching. */
     3353    if (pPktManip->u.SearchMemory.cbPattern < sizeof(pThis->abBody) - sizeof(*pPktManip))
     3354    {
     3355        DBGFADDRESS StartAddress;
     3356        DBGFADDRESS HitAddress;
     3357        VMCPUID idCpu = pPktManip->Hdr.idCpu;
     3358        DBGFR3AddrFromFlat(pThis->Dbgc.pUVM, &StartAddress, pPktManip->u.SearchMemory.u64GCPtr);
     3359
     3360        /** @todo WindDbg sends CPU ID 32 sometimes, maybe that means continue search on last used CPU?. */
     3361        if (idCpu >= DBGFR3CpuGetCount(pThis->Dbgc.pUVM))
     3362            idCpu = pThis->Dbgc.idCpu;
     3363
     3364        int rc = DBGFR3MemScan(pThis->Dbgc.pUVM, idCpu, &StartAddress, pPktManip->u.SearchMemory.cbSearch, 1,
     3365                               &pThis->abBody[sizeof(*pPktManip)], pPktManip->u.SearchMemory.cbPattern, &HitAddress);
     3366        if (RT_SUCCESS(rc))
     3367            SearchMemory.u64GCPtr = HitAddress.FlatPtr;
     3368        else if (rc == VERR_DBGF_MEM_NOT_FOUND)
     3369            RespHdr.u32NtStatus = NTSTATUS_NOT_FOUND;
     3370        else
     3371            RespHdr.u32NtStatus = NTSTATUS_UNSUCCESSFUL;
     3372    }
     3373    else
     3374        RespHdr.u32NtStatus = NTSTATUS_BUFFER_OVERFLOW;
     3375
     3376    aRespSegs[0].pvSeg = &RespHdr;
     3377    aRespSegs[0].cbSeg = sizeof(RespHdr);
     3378    aRespSegs[1].pvSeg = &SearchMemory;
     3379    aRespSegs[1].cbSeg = sizeof(SearchMemory);
     3380
     3381    return dbgcKdCtxPktSendSg(pThis, KD_PACKET_HDR_SIGNATURE_DATA, KD_PACKET_HDR_SUB_TYPE_STATE_MANIPULATE,
     3382                              &aRespSegs[0], RT_ELEMENTS(aRespSegs), true /*fAck*/);
     3383}
     3384
     3385
     3386/**
    32843387 * Processes a cause bugcheck 64 request.
    32853388 *
     
    33763479        {
    33773480            rc = dbgcKdCtxPktManipulate64QueryMemory(pThis, pPktManip);
     3481            break;
     3482        }
     3483        case KD_PACKET_MANIPULATE_REQ_SEARCH_MEMORY:
     3484        {
     3485            rc = dbgcKdCtxPktManipulate64SearchMemory(pThis, pPktManip);
    33783486            break;
    33793487        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette