Changeset 5915 for trunk/src


Ignore:
Timestamp:
Jun 6, 2001, 12:33:16 PM (24 years ago)
Author:
sandervl
Message:

* empty log message *

File:
1 edited

Legend:

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

    r5914 r5915  
    1 /* $Id: winimagepeldr.cpp,v 1.84 2001-06-06 10:01:48 phaller Exp $ */
     1/* $Id: winimagepeldr.cpp,v 1.85 2001-06-06 10:33:16 sandervl Exp $ */
    22
    33/*
     
    18851885ULONG Win32PeLdrImage::getApi(int ordinal)
    18861886{
    1887   ULONG       apiaddr, i;
    1888   OrdExport  *curexport;
    1889   NameExport *nexport;
    1890   register int iDiff;
    1891 
    1892   curexport = ordexports;
     1887 ULONG       apiaddr, i;
     1888 OrdExport  *curexport;
     1889 NameExport *nexport;
     1890
     1891    curexport = ordexports;
     1892
     1893  /* accelerated resolving of ordinal exports
     1894   * is based on the assumption the ordinal export
     1895   * table is always sorted ascending.
     1896   *
     1897   * When the step size is too small, we continue
     1898   * with the linear search.
     1899   */
    18931900 
    1894   i = 0;
    1895   if (nrOrdExportsRegistered > 1000)
     1901  // start in the middle of the tree
     1902  i = nrOrdExportsRegistered >> 1;
     1903  int iStep = i;
     1904 
     1905  for(;;)
    18961906  {
    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;
     1907    int iThisExport = curexport[i].ordinal;
     1908   
     1909    iStep >>= 1;                    // next step will be narrower
     1910
     1911    if (iThisExport < ordinal)
     1912      i += min(iStep, (ordinal-iThisExport)); // move farther down the list
     1913    else
     1914      if (iThisExport == ordinal)   // found the export?
     1915        return curexport[i].virtaddr;
     1916      else
     1917        i -= min(iStep, (iThisExport-ordinal));                 // move farther up the list
     1918
     1919    // if we're in the direct neighbourhood search linearly
     1920    if (iStep <= 1)
     1921    {
     1922      // decide if we're to search backward or forward
     1923      if (ordinal > curexport[i].ordinal)
     1924      {
     1925        // As a certain number of exports are 0 at the end
     1926        // of the array, this case will hit fairly often.
     1927        // the last comparison will send the loop off into the
     1928        // wrong direction!
     1929#ifdef DEBUG
     1930        if (curexport[i].ordinal == 0)
     1931        {
     1932            DebugInt3();
     1933        }
     1934#endif
     1935
     1936        for (;i<nrOrdExports;i++) // scan forward
     1937        {
     1938          iThisExport = curexport[i].ordinal;
     1939          if(iThisExport == ordinal)
     1940            return(curexport[i].virtaddr);
     1941          else
     1942            if (iThisExport > ordinal)
     1943            {
     1944              // Oops, cannot find the ordinal in the sorted list
     1945              break;
     1946            }
     1947        }
    19021948      }
    19031949      else
    1904         if(iDiff == 0)
    1905           return(curexport[i].virtaddr);
    1906     }
    1907     if (i > nrOrdExportsRegistered) i -= 1000;
     1950      {
     1951        for (;i>=0;i--) // scan backward
     1952        {
     1953          iThisExport = curexport[i].ordinal;
     1954          if(curexport[i].ordinal == ordinal)
     1955            return(curexport[i].virtaddr);
     1956          else
     1957            if (iThisExport < ordinal)
     1958              // Oops, cannot find the ordinal in the sorted list
     1959              break;
     1960        }
     1961      }
     1962     
     1963      // not found yet.
     1964      break;
     1965    }
    19081966  }
    19091967
    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;
    1917       }
    1918       else
    1919         if(iDiff == 0)
    1920           return(curexport[i].virtaddr);
    1921     }
    1922     if (i > nrOrdExportsRegistered) i -= 100;
    1923   }
    1924 
    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);
     1968    //Name exports also contain an ordinal, so check this
     1969    nexport = nameexports;
     1970    for(i=0;i<nrNameExports;i++) {
     1971        if(nexport->ordinal == ordinal)
     1972            return(nexport->virtaddr);
     1973
     1974        nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
     1975    }
     1976    return(0);
    19541977}
    19551978//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.