Changeset 5914 for trunk/src


Ignore:
Timestamp:
Jun 6, 2001, 12:01:48 PM (24 years ago)
Author:
phaller
Message:

.

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimagepeldr.cpp

    r5912 r5914  
    1 /* $Id: winimagepeldr.cpp,v 1.83 2001-06-05 21:38:42 sandervl Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.84 2001-06-06 10:01:48 phaller Exp $ */
    22
    33/*
     
    111111    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    112112    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    113     memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL)
     113    memmap(NULL), pFixups(NULL), dwFixupSize(0), curnameexport(NULL), curordexport(NULL),
     114    nrOrdExportsRegistered(0)
    114115{
    115116 HFILE  dllfile;
     
    13831384    }
    13841385  }
     1386 
    13851387  return(TRUE);
    13861388}
     
    14341436    curordexport->ordinal  = ordinal;
    14351437    curordexport++;
     1438    nrOrdExportsRegistered++;
    14361439}
    14371440//******************************************************************************
     
    18821885ULONG Win32PeLdrImage::getApi(int ordinal)
    18831886{
    1884  ULONG       apiaddr, i;
    1885  OrdExport  *curexport;
    1886  NameExport *nexport;
    1887 
    1888     curexport = ordexports;
    1889 
    1890   /* accelerated resolving of ordinal exports
    1891    * is based on the assumption the ordinal export
    1892    * table is always sorted ascending.
    1893    *
    1894    * When the step size is too small, we continue
    1895    * with the linear search.
    1896    */
     1887  ULONG       apiaddr, i;
     1888  OrdExport  *curexport;
     1889  NameExport *nexport;
     1890  register int iDiff;
     1891
     1892  curexport = ordexports;
    18971893 
    1898   // start in the middle of the tree
    1899   i = nrOrdExports >> 1;
    1900   int iStep = i;
    1901  
    1902   for(;;)
     1894  i = 0;
     1895  if (nrOrdExportsRegistered > 1000)
    19031896  {
    1904     int iThisExport = curexport[i].ordinal;
    1905    
    1906     iStep >>= 1;                    // next step will be narrower
    1907 
    1908     if (iThisExport < ordinal)
    1909       i += min(iStep, (ordinal-iThisExport)); // move farther down the list
    1910     else
    1911       if (iThisExport == ordinal)   // found the export?
    1912         return curexport[i].virtaddr;
    1913       else
    1914         i -= min(iStep, (iThisExport-ordinal));                 // move farther up the list
    1915 
    1916     // if we're in the direct neighbourhood search linearly
    1917     if (iStep <= 1)
    1918     {
    1919       // decide if we're to search backward or forward
    1920       if (ordinal > curexport[i].ordinal)
    1921       {
    1922         // As a certain number of exports are 0 at the end
    1923         // of the array, this case will hit fairly often.
    1924         // the last comparison will send the loop off into the
    1925         // wrong direction!
    1926         if (curexport[i].ordinal == 0)
    1927         {
    1928           // start over with plain dump search
    1929           for(i = 0; i < nrOrdExports; i++)
    1930           {
    1931             if(curexport[i].ordinal == ordinal)
    1932               return(curexport[i].virtaddr);
    1933           }
    1934           break; // not found yet!
    1935         }
    1936        
    1937         for (;i<nrOrdExports;i++) // scan forward
    1938         {
    1939           iThisExport = curexport[i].ordinal;
    1940           if(iThisExport == ordinal)
    1941             return(curexport[i].virtaddr);
    1942           else
    1943             if (iThisExport > ordinal)
    1944             {
    1945               // Oops, cannot find the ordinal in the sorted list
    1946               break;
    1947             }
    1948         }
     1897    for(i=0;i<nrOrdExportsRegistered;i+=1000) {
     1898      iDiff = curexport[i].ordinal - ordinal;
     1899      if(iDiff > 0) {
     1900        if(i) i -= 1000;
     1901        break;
    19491902      }
    19501903      else
    1951       {
    1952         for (;i>=0;i--) // scan backward
    1953         {
    1954           iThisExport = curexport[i].ordinal;
    1955           if(curexport[i].ordinal == ordinal)
    1956             return(curexport[i].virtaddr);
    1957           else
    1958             if (iThisExport < ordinal)
    1959               // Oops, cannot find the ordinal in the sorted list
    1960               break;
    1961         }
     1904        if(iDiff == 0)
     1905          return(curexport[i].virtaddr);
     1906    }
     1907    if (i > nrOrdExportsRegistered) i -= 1000;
     1908  }
     1909
     1910  if (nrOrdExportsRegistered > 100)
     1911  {
     1912    for(i;i<nrOrdExportsRegistered;i+=100) {
     1913      iDiff = curexport[i].ordinal - ordinal;
     1914      if(iDiff > 0) {
     1915        if(i) i -= 100;
     1916        break;
    19621917      }
    1963      
    1964       // not found yet.
    1965       break;
    1966     }
     1918      else
     1919        if(iDiff == 0)
     1920          return(curexport[i].virtaddr);
     1921    }
     1922    if (i > nrOrdExportsRegistered) i -= 100;
    19671923  }
    19681924
    1969     //Name exports also contain an ordinal, so check this
    1970     nexport = nameexports;
    1971     for(i=0;i<nrNameExports;i++) {
    1972         if(nexport->ordinal == ordinal)
    1973             return(nexport->virtaddr);
    1974 
    1975         nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
    1976     }
    1977     return(0);
     1925  if (nrOrdExportsRegistered > 10)
     1926  {
     1927    for(i;i<nrOrdExportsRegistered;i+=10) {
     1928      iDiff = curexport[i].ordinal - ordinal;
     1929      if(iDiff > 0) {
     1930        if(i) i -= 10;
     1931        break;
     1932      }
     1933      else
     1934        if(iDiff == 0)
     1935          return(curexport[i].virtaddr);
     1936    }
     1937    if (i > nrOrdExportsRegistered) i -= 10;
     1938  }
     1939 
     1940  for(i;i<nrOrdExportsRegistered;i++) {
     1941    if(curexport[i].ordinal == ordinal)
     1942      return(curexport[i].virtaddr);
     1943  }
     1944
     1945  //Name exports also contain an ordinal, so check this
     1946  nexport = nameexports;
     1947  for(i=0;i<nrNameExports;i++) {
     1948    if(nexport->ordinal == ordinal)
     1949      return(nexport->virtaddr);
     1950
     1951    nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     1952  }
     1953  return(0);
    19781954}
    19791955//******************************************************************************
  • trunk/src/kernel32/winimagepeldr.h

    r5912 r5914  
    1 /* $Id: winimagepeldr.h,v 1.15 2001-06-05 21:38:42 sandervl Exp $ */
     1/* $Id: winimagepeldr.h,v 1.16 2001-06-06 10:01:48 phaller Exp $ */
    22
    33/*
     
    131131        ULONG                 nrNameExports, nameExportSize;
    132132        ULONG                 nrOrdExports;
     133        ULONG                 nrOrdExportsRegistered;
    133134        NameExport           *nameexports, *curnameexport;
    134135        OrdExport            *ordexports, *curordexport;
Note: See TracChangeset for help on using the changeset viewer.