Changes in uspace/app/taskdump/elf_core.c [ce04ea44:6afc9d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/taskdump/elf_core.c
rce04ea44 r6afc9d7 54 54 #include <errno.h> 55 55 #include <sys/types.h> 56 #include <sys/stat.h> 56 57 #include <unistd.h> 58 #include <fcntl.h> 57 59 #include <mem.h> 58 60 #include <stdint.h> … … 61 63 #include <macros.h> 62 64 #include <libarch/istate.h> 63 #include <vfs/vfs.h>64 65 65 66 #include "elf_core.h" 66 67 67 68 static off64_t align_foff_up(off64_t, uintptr_t, size_t); 68 static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *); 69 static int align_pos(int, size_t); 70 static int write_mem_area(int, as_area_info_t *, async_sess_t *); 69 71 70 72 #define BUFFER_SIZE 0x1000 … … 95 97 elf_note_t note; 96 98 size_t word_size; 97 aoff64_t pos = 0;98 99 99 100 int fd; … … 123 124 } 124 125 125 fd = vfs_lookup_open(file_name, WALK_REGULAR | WALK_MAY_CREATE, 126 MODE_WRITE); 126 fd = open(file_name, O_CREAT | O_WRONLY, 0644); 127 127 if (fd < 0) { 128 128 printf("Failed opening file.\n"); … … 207 207 } 208 208 209 rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr));209 rc = write(fd, &elf_hdr, sizeof(elf_hdr)); 210 210 if (rc != sizeof(elf_hdr)) { 211 211 printf("Failed writing ELF header.\n"); … … 215 215 216 216 for (i = 0; i < n_ph; ++i) { 217 rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));217 rc = write(fd, &p_hdr[i], sizeof(p_hdr[i])); 218 218 if (rc != sizeof(p_hdr[i])) { 219 219 printf("Failed writing program header.\n"); … … 223 223 } 224 224 225 pos = p_hdr[0].p_offset; 225 if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) { 226 printf("Failed writing memory data.\n"); 227 free(p_hdr); 228 return EIO; 229 } 226 230 227 231 /* … … 232 236 note.type = NT_PRSTATUS; 233 237 234 rc = vfs_write(fd, &pos, ¬e, sizeof(elf_note_t));238 rc = write(fd, ¬e, sizeof(elf_note_t)); 235 239 if (rc != sizeof(elf_note_t)) { 236 240 printf("Failed writing note header.\n"); … … 239 243 } 240 244 241 rc = vfs_write(fd, &pos, "CORE", note.namesz);245 rc = write(fd, "CORE", note.namesz); 242 246 if (rc != (ssize_t) note.namesz) { 243 247 printf("Failed writing note header.\n"); … … 246 250 } 247 251 248 pos = ALIGN_UP(pos, word_size); 249 250 rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t)); 252 rc = align_pos(fd, word_size); 253 if (rc != EOK) { 254 printf("Failed writing note header.\n"); 255 free(p_hdr); 256 return EIO; 257 } 258 259 rc = write(fd, &pr_status, sizeof(elf_prstatus_t)); 251 260 if (rc != sizeof(elf_prstatus_t)) { 252 261 printf("Failed writing register data.\n"); … … 256 265 257 266 for (i = 1; i < n_ph; ++i) { 258 pos = p_hdr[i].p_offset; 259 if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) { 267 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) { 268 printf("Failed writing memory data.\n"); 269 free(p_hdr); 270 return EIO; 271 } 272 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) { 260 273 printf("Failed writing memory data.\n"); 261 274 free(p_hdr); … … 284 297 * 285 298 * @param fd File to write to. 286 * @param pos Pointer to the position to write to.287 299 * @param area Memory area info structure. 288 300 * @param sess Debugging session. … … 291 303 * 292 304 */ 293 static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area, 294 async_sess_t *sess) 305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess) 295 306 { 296 307 size_t to_copy; … … 310 321 } 311 322 312 rc = vfs_write(fd, pos, buffer, to_copy);323 rc = write(fd, buffer, to_copy); 313 324 if (rc != (ssize_t) to_copy) { 314 325 printf("Failed writing memory contents.\n"); … … 323 334 } 324 335 336 static int align_pos(int fd, size_t align) 337 { 338 off64_t cur_pos; 339 size_t rem, adv; 340 341 cur_pos = lseek(fd, 0, SEEK_CUR); 342 if (cur_pos < 0) 343 return -1; 344 345 rem = cur_pos % align; 346 adv = align - rem; 347 348 cur_pos = lseek(fd, adv, SEEK_CUR); 349 if (cur_pos < 0) 350 return -1; 351 352 return EOK; 353 } 354 325 355 /** @} 326 356 */
Note:
See TracChangeset
for help on using the changeset viewer.