ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dwarfget.c
Go to the documentation of this file.
00001 /*
00002  * Dwarf data format parsing routines.
00003  */
00004 
00005 #define NTOSAPI
00006 #include <ntddk.h>
00007 #include <reactos/rossym.h>
00008 #include "rossympriv.h"
00009 #include <ntimage.h>
00010 
00011 #define NDEBUG
00012 #include <debug.h>
00013 
00014 #include "dwarf.h"
00015 #include "pe.h"
00016 
00017 ulong
00018 dwarfget1(DwarfBuf *b)
00019 {
00020     if(b->p==nil || b->p+1 > b->ep){
00021         b->p = nil;
00022         return 0;
00023     }
00024     return *b->p++;
00025 }
00026 
00027 int
00028 dwarfgetn(DwarfBuf *b, uchar *a, int n)
00029 {
00030     if(b->p==nil || b->p+n > b->ep){
00031         b->p = nil;
00032         memset(a, 0, n);
00033         return -1;
00034     }
00035     memmove(a, b->p, n);
00036     b->p += n;
00037     return 0;
00038 }
00039 
00040 uchar*
00041 dwarfgetnref(DwarfBuf *b, ulong n)
00042 {
00043     uchar *p;
00044 
00045     if(b->p==nil || b->p+n > b->ep){
00046         b->p = nil;
00047         return nil;
00048     }
00049     p = b->p;
00050     b->p += n;
00051     return p;
00052 }
00053 
00054 char*
00055 dwarfgetstring(DwarfBuf *b)
00056 {
00057     char *s;
00058 
00059     if(b->p == nil)
00060         return nil;
00061     s = (char*)b->p;
00062     while(b->p < b->ep && *b->p)
00063         b->p++;
00064     if(b->p >= b->ep){
00065         b->p = nil;
00066         return nil;
00067     }
00068     b->p++;
00069     return s;
00070 }
00071 
00072 void
00073 dwarfskip(DwarfBuf *b, int n)
00074 {
00075     if(b->p==nil || b->p+n > b->ep)
00076         b->p = nil;
00077     else
00078         b->p += n;
00079 }
00080 
00081 ulong
00082 dwarfget2(DwarfBuf *b)
00083 {
00084     ulong v;
00085 
00086     if(b->p==nil || b->p+2 > b->ep){
00087         b->p = nil;
00088         return 0;
00089     }
00090     v = b->d->pe->e2(b->p);
00091     b->p += 2;
00092     return v;
00093 }
00094 
00095 ulong
00096 dwarfget4(DwarfBuf *b)
00097 {
00098     ulong v;
00099 
00100     if(b->p==nil || b->p+4 > b->ep){
00101         b->p = nil;
00102         return 0;
00103     }
00104     v = b->d->pe->e4(b->p);
00105     b->p += 4;
00106     return v;
00107 }
00108 
00109 uvlong
00110 dwarfget8(DwarfBuf *b)
00111 {
00112     uvlong v;
00113 
00114     if(b->p==nil || b->p+8 > b->ep){
00115         b->p = nil;
00116         return 0;
00117     }
00118     v = b->d->pe->e8(b->p);
00119     b->p += 8;
00120     return v;
00121 }
00122 
00123 ulong
00124 dwarfgetaddr(DwarfBuf *b)
00125 {
00126     static int nbad;
00127 
00128     if(b->addrsize == 0)
00129         b->addrsize = b->d->addrsize;
00130 
00131     switch(b->addrsize){
00132     case 1:
00133         return dwarfget1(b);
00134     case 2:
00135         return dwarfget2(b);
00136     case 4:
00137         return dwarfget4(b);
00138     case 8:
00139         return dwarfget8(b);
00140     default:
00141         if(++nbad == 1)
00142             werrstr("dwarf: unexpected address size %lud in dwarfgetaddr\n", b->addrsize);
00143         b->p = nil;
00144         return 0;
00145     }
00146 }
00147 
00148 int n1, n2, n3, n4, n5;
00149 
00150 /* An inline function picks off the calls to dwarfget128 for 1-byte encodings,
00151  * more than by far the common case (99.999% on most binaries!). */
00152 ulong
00153 dwarfget128(DwarfBuf *b)
00154 {
00155     static int nbad;
00156     ulong c, d;
00157 
00158     if(b->p == nil)
00159         return 0;
00160     c = *b->p++;
00161     if(!(c&0x80))
00162 {n1++;
00163         return c;
00164 }
00165     c &= ~0x80;
00166     d = *b->p++;
00167     c |= (d&0x7F)<<7;
00168     if(!(d&0x80))
00169 {n2++;
00170         return c;
00171 }
00172     d = *b->p++;
00173     c |= (d&0x7F)<<14;
00174     if(!(d&0x80))
00175 {n3++;
00176         return c;
00177 }
00178     d = *b->p++;
00179     c |= (d&0x7F)<<21;
00180     if(!(d&0x80))
00181 {n4++;
00182         return c;
00183 }
00184     d = *b->p++;
00185     c |= (d&0x7F)<<28;
00186     if(!(d&0x80))
00187 {n5++;
00188         return c;
00189 }
00190     while(b->p<b->ep && *b->p&0x80)
00191         b->p++;
00192     if(++nbad == 1)
00193         werrstr("dwarf: overflow during parsing of uleb128 integer\n");
00194     return c;
00195 }
00196 
00197 long
00198 dwarfget128s(DwarfBuf *b)
00199 {
00200     int nb, c;
00201     ulong v;
00202     static int nbad;
00203 
00204     v = 0;
00205     nb = 0;
00206     if(b->p==nil)
00207         return 0;
00208     while(b->p<b->ep){
00209         c = *b->p++;
00210         v |= (c & 0x7F)<<nb;
00211         nb += 7;
00212         if(!(c&0x80))
00213             break;
00214     }
00215     if(v&(1<<(nb-1)))
00216         v |= ~(((ulong)1<<nb)-1);
00217     if(nb > 8*sizeof(ulong)){
00218         if(0)
00219         if(++nbad == 1)
00220             werrstr("dwarf: overflow during parsing of sleb128 integer: got %d bits", nb);
00221     }
00222     return v;
00223 }
00224 
00225 

Generated on Sun May 27 2012 04:36:17 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.