- Timestamp:
- Sep 3, 2010 1:42:19 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/DBGFCoreWrite.cpp
r32222 r32236 69 69 #define DBGFLOG_NAME "DGBFCoreWrite" 70 70 71 static const int s_NoteAlign = 4; 71 /* 72 * For now use Solaris-specific padding and namesz length (i.e. includes NULL terminator) 73 */ 74 static const int s_NoteAlign = 4; /* @todo see #5211 comment 3 */ 75 static const int s_cbNoteName = 16; 76 static const char *s_pcszCoreVBoxCpu = "VBOXCPU"; 72 77 73 78 /** … … 78 83 const char *pszDumpPath; /* File path to dump the core into. */ 79 84 } DBGFCOREDATA, *PDBGFCOREDATA; 80 81 typedef struct82 {83 Elf64_Nhdr Hdr; /* 64-bit NOTE Header */84 char achName[8]; /* Name of NOTE section */85 } ELFNOTEHDR;86 85 87 86 … … 164 163 165 164 /** 166 * Returns the size of the NOTE section given the size of the data. 167 * 168 * @param cb Size of the data part of the NOTE. 165 * Returns the size of the NOTE section given the name and size of the data. 166 * 167 * @param pszName Name of the note section. 168 * @param cb Size of the data portion of the note section. 169 169 * 170 170 * @return The size of the NOTE section as rounded to the file alignment. 171 171 */ 172 static inline uint64_t Elf64NoteSectionSize(uint64_t cb) 173 { 174 return sizeof(ELFNOTEHDR) + RT_ALIGN_64(cb, s_NoteAlign); 172 static inline uint64_t Elf64NoteSectionSize(const char *pszName, uint64_t cbData) 173 { 174 uint64_t cbNote = sizeof(Elf64_Nhdr); 175 176 size_t cbName = strlen(pszName) + 1; 177 size_t cbNameAlign = RT_ALIGN_Z(cbName, s_NoteAlign); 178 179 cbNote += cbNameAlign; 180 cbNote += RT_ALIGN_64(cbData, s_NoteAlign); 181 return cbNote; 175 182 } 176 183 … … 181 188 * @param hFile The file to write to. 182 189 * @param Type Type of this section. 183 * @param pszName Name of this section , will be limited to 16 bytes.190 * @param pszName Name of this section. 184 191 * @param pcv Opaque pointer to the data, if NULL only computes size. 185 * @param cb 192 * @param cbData Size of the data. 186 193 * @param pcbNoteHdr Where to store the size of written header to file, 187 194 * can be NULL. … … 189 196 * @return IPRT status code. 190 197 */ 191 static int Elf64WriteNoteHdr(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcv, uint64_t cb, uint64_t *pcbNoteHdr) 192 { 193 AssertReturn(pcv, VERR_INVALID_POINTER); 194 AssertReturn(cb > 0, VERR_NO_DATA); 195 196 ELFNOTEHDR ElfNoteHdr; 198 static int Elf64WriteNoteHdr(RTFILE hFile, uint16_t Type, const char *pszName, const void *pcvData, uint64_t cbData, uint64_t *pcbNoteHdr) 199 { 200 AssertReturn(pcvData, VERR_INVALID_POINTER); 201 AssertReturn(cbData > 0, VERR_NO_DATA); 202 203 char szNoteName[s_cbNoteName]; 204 RT_ZERO(szNoteName); 205 RTStrCopy(szNoteName, sizeof(szNoteName), pszName); 206 207 size_t cbName = strlen(szNoteName) + 1; 208 size_t cbNameAlign = RT_ALIGN_Z(cbName, s_NoteAlign); 209 uint64_t cbDataAlign = RT_ALIGN_64(cbData, s_NoteAlign); 210 211 static const char s_achPad[7] = { 0, 0, 0, 0, 0, 0, 0 }; 212 AssertCompile(sizeof(s_achPad) >= s_NoteAlign - 1); 213 214 Elf64_Nhdr ElfNoteHdr; 197 215 RT_ZERO(ElfNoteHdr); 198 RTStrCopy(ElfNoteHdr.achName, sizeof(ElfNoteHdr.achName), pszName); 199 ElfNoteHdr.Hdr.n_namesz = (Elf64_Word)strlen(ElfNoteHdr.achName); 200 ElfNoteHdr.Hdr.n_type = Type; 201 size_t cbNameAlign = RT_ALIGN_Z(ElfNoteHdr.Hdr.n_namesz, 8); 202 203 static const char s_achPad[7] = { 0, 0, 0, 0, 0, 0, 0 }; 204 uint64_t cbAlign = RT_ALIGN_64(cb, s_NoteAlign); 205 ElfNoteHdr.Hdr.n_descsz = (Elf64_Word)cbAlign; 206 207 /* 208 * Write note header and description. 216 ElfNoteHdr.n_namesz = (Elf64_Word)cbName; /* @todo fix this later to NOT include NULL terminator */ 217 ElfNoteHdr.n_type = Type; 218 ElfNoteHdr.n_descsz = (Elf64_Word)cbDataAlign; 219 220 /* 221 * Write note header. 209 222 */ 210 223 int rc = RTFileWrite(hFile, &ElfNoteHdr, sizeof(ElfNoteHdr), NULL /* full write */); 211 224 if (RT_SUCCESS(rc)) 212 225 { 213 if (cbNameAlign > ElfNoteHdr.Hdr.n_namesz)214 rc = RTFileWrite(hFile, s_achPad, cbNameAlign - ElfNoteHdr.Hdr.n_namesz, NULL);215 216 rc = RTFileWrite(hFile, pcv, cb, NULL /* full write */);226 /* 227 * Write note name. 228 */ 229 rc = RTFileWrite(hFile, szNoteName, cbName, NULL /* full write */); 217 230 if (RT_SUCCESS(rc)) 218 231 { 219 if (cbAlign > cb) 220 rc = RTFileWrite(hFile, s_achPad, cbAlign - cb, NULL /* full write*/); 232 /* 233 * Write note name padding if required. 234 */ 235 if (cbNameAlign > cbName) 236 rc = RTFileWrite(hFile, s_achPad, cbNameAlign - cbName, NULL); 237 238 if (RT_SUCCESS(rc)) 239 { 240 /* 241 * Write note data. 242 */ 243 rc = RTFileWrite(hFile, pcvData, cbData, NULL /* full write */); 244 if (RT_SUCCESS(rc)) 245 { 246 /* 247 * Write note data padding if required. 248 */ 249 if (cbDataAlign > cbData) 250 rc = RTFileWrite(hFile, s_achPad, cbDataAlign - cbData, NULL /* full write*/); 251 } 252 } 221 253 } 222 254 } 223 255 224 256 if (RT_FAILURE(rc)) 225 LogRel((DBGFLOG_NAME ":RTFileWrite failed. rc=%Rrc pszName=%s cb =%u cbAlign=%u\n", rc, pszName, cb, cbAlign));257 LogRel((DBGFLOG_NAME ":RTFileWrite failed. rc=%Rrc pszName=%s cbData=%u cbDataAlign=%u\n", rc, pszName, cbData, cbDataAlign)); 226 258 227 259 return rc; … … 278 310 * Compute size of the note section. 279 311 */ 280 uint64_t cbNoteSection = Elf64NoteSectionSize(pVM->cCpus *sizeof(CPUMCTX));312 uint64_t cbNoteSection = pVM->cCpus * Elf64NoteSectionSize(s_pcszCoreVBoxCpu, sizeof(CPUMCTX)); 281 313 uint64_t off = 0; 282 314 … … 358 390 { 359 391 PCPUMCTX pCpuCtx = &pVM->aCpus[i].cpum.s.Guest; 360 rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, "VBOXCPU", pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */);392 rc = Elf64WriteNoteHdr(hFile, NT_VBOXCPU, s_pcszCoreVBoxCpu, pCpuCtx, sizeof(CPUMCTX), NULL /* pcbNoteHdr */); 361 393 if (RT_FAILURE(rc)) 362 394 {
Note:
See TracChangeset
for help on using the changeset viewer.