Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/tcmalloc/chromium/src/base/sysinfo.cc

Issue 440027: Merge r77 from upstream tcmalloc to the local chromium branch.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 434
435 #if defined __linux__ || defined __FreeBSD__ || defined __sun__ || defined __CYG WIN__ || defined __CYGWIN32__ 435 #if defined __linux__ || defined __FreeBSD__ || defined __sun__ || defined __CYG WIN__ || defined __CYGWIN32__
436 static void ConstructFilename(const char* spec, pid_t pid, 436 static void ConstructFilename(const char* spec, pid_t pid,
437 char* buf, int buf_size) { 437 char* buf, int buf_size) {
438 CHECK_LT(snprintf(buf, buf_size, 438 CHECK_LT(snprintf(buf, buf_size,
439 spec, 439 spec,
440 pid ? pid : getpid()), buf_size); 440 pid ? pid : getpid()), buf_size);
441 } 441 }
442 #endif 442 #endif
443 443
444 // A templatized helper function instantiated for Mach (OS X) only.
445 // It can handle finding info for both 32 bits and 64 bits.
446 // Returns true if it successfully handled the hdr, false else.
447 #ifdef __MACH__ // Mac OS X, almost certainly
448 template<uint32_t kMagic, uint32_t kLCSegment,
449 typename MachHeader, typename SegmentCommand>
450 static bool NextExtMachHelper(const mach_header* hdr,
451 int current_image, int current_load_cmd,
452 uint64 *start, uint64 *end, char **flags,
453 uint64 *offset, int64 *inode, char **filename,
454 uint64 *file_mapping, uint64 *file_pages,
455 uint64 *anon_mapping, uint64 *anon_pages,
456 dev_t *dev) {
457 static char kDefaultPerms[5] = "r-xp";
458 if (hdr->magic != kMagic)
459 return false;
460 const char* lc = (const char *)hdr + sizeof(MachHeader);
461 // TODO(csilvers): make this not-quadradic (increment and hold state)
462 for (int j = 0; j < current_load_cmd; j++) // advance to *our* load_cmd
463 lc += ((const load_command *)lc)->cmdsize;
464 if (((const load_command *)lc)->cmd == kLCSegment) {
465 const intptr_t dlloff = _dyld_get_image_vmaddr_slide(current_image);
466 const SegmentCommand* sc = (const SegmentCommand *)lc;
467 if (start) *start = sc->vmaddr + dlloff;
468 if (end) *end = sc->vmaddr + sc->vmsize + dlloff;
469 if (flags) *flags = kDefaultPerms; // can we do better?
470 if (offset) *offset = sc->fileoff;
471 if (inode) *inode = 0;
472 if (filename)
473 *filename = const_cast<char*>(_dyld_get_image_name(current_image));
474 if (file_mapping) *file_mapping = 0;
475 if (file_pages) *file_pages = 0; // could we use sc->filesize?
476 if (anon_mapping) *anon_mapping = 0;
477 if (anon_pages) *anon_pages = 0;
478 if (dev) *dev = 0;
479 return true;
480 }
481
482 return false;
483 }
484 #endif
485
486 ProcMapsIterator::ProcMapsIterator(pid_t pid) { 444 ProcMapsIterator::ProcMapsIterator(pid_t pid) {
487 Init(pid, NULL, false); 445 Init(pid, NULL, false);
488 } 446 }
489 447
490 ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer) { 448 ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer) {
491 Init(pid, buffer, false); 449 Init(pid, buffer, false);
492 } 450 }
493 451
494 ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer, 452 ProcMapsIterator::ProcMapsIterator(pid_t pid, Buffer *buffer,
495 bool use_maps_backing) { 453 bool use_maps_backing) {
496 Init(pid, buffer, use_maps_backing); 454 Init(pid, buffer, use_maps_backing);
497 } 455 }
498 456
499 void ProcMapsIterator::Init(pid_t pid, Buffer *buffer, 457 void ProcMapsIterator::Init(pid_t pid, Buffer *buffer,
500 bool use_maps_backing) { 458 bool use_maps_backing) {
501 pid_ = pid;
502 using_maps_backing_ = use_maps_backing; 459 using_maps_backing_ = use_maps_backing;
503 dynamic_buffer_ = NULL; 460 dynamic_buffer_ = NULL;
504 if (!buffer) { 461 if (!buffer) {
505 // If the user didn't pass in any buffer storage, allocate it 462 // If the user didn't pass in any buffer storage, allocate it
506 // now. This is the normal case; the signal handler passes in a 463 // now. This is the normal case; the signal handler passes in a
507 // static buffer. 464 // static buffer.
508 buffer = dynamic_buffer_ = new Buffer; 465 buffer = dynamic_buffer_ = new Buffer;
509 } else { 466 } else {
510 dynamic_buffer_ = NULL; 467 dynamic_buffer_ = NULL;
511 } 468 }
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 684
728 return true; 685 return true;
729 } while (etext_ > ibuf_); 686 } while (etext_ > ibuf_);
730 #elif defined(__sun__) 687 #elif defined(__sun__)
731 // This is based on MA_READ == 4, MA_WRITE == 2, MA_EXEC == 1 688 // This is based on MA_READ == 4, MA_WRITE == 2, MA_EXEC == 1
732 static char kPerms[8][4] = { "---", "--x", "-w-", "-wx", 689 static char kPerms[8][4] = { "---", "--x", "-w-", "-wx",
733 "r--", "r-x", "rw-", "rwx" }; 690 "r--", "r-x", "rw-", "rwx" };
734 COMPILE_ASSERT(MA_READ == 4, solaris_ma_read_must_equal_4); 691 COMPILE_ASSERT(MA_READ == 4, solaris_ma_read_must_equal_4);
735 COMPILE_ASSERT(MA_WRITE == 2, solaris_ma_write_must_equal_2); 692 COMPILE_ASSERT(MA_WRITE == 2, solaris_ma_write_must_equal_2);
736 COMPILE_ASSERT(MA_EXEC == 1, solaris_ma_exec_must_equal_1); 693 COMPILE_ASSERT(MA_EXEC == 1, solaris_ma_exec_must_equal_1);
737 Buffer object_path;
738 int nread = 0; // fill up buffer with text 694 int nread = 0; // fill up buffer with text
739 NO_INTR(nread = read(fd_, ibuf_, sizeof(prmap_t))); 695 NO_INTR(nread = read(fd_, ibuf_, sizeof(prmap_t)));
740 if (nread == sizeof(prmap_t)) { 696 if (nread == sizeof(prmap_t)) {
741 long inode_from_mapname = 0; 697 long inode_from_mapname = 0;
742 prmap_t* mapinfo = reinterpret_cast<prmap_t*>(ibuf_); 698 prmap_t* mapinfo = reinterpret_cast<prmap_t*>(ibuf_);
743 // Best-effort attempt to get the inode from the filename. I think the 699 // Best-effort attempt to get the inode from the filename. I think the
744 // two middle ints are major and minor device numbers, but I'm not sure. 700 // two middle ints are major and minor device numbers, but I'm not sure.
745 sscanf(mapinfo->pr_mapname, "ufs.%*d.%*d.%ld", &inode_from_mapname); 701 sscanf(mapinfo->pr_mapname, "ufs.%*d.%*d.%ld", &inode_from_mapname);
746 702
747 if (pid_ == 0) {
748 CHECK_LT(snprintf(object_path.buf_, Buffer::kBufSize,
749 "/proc/self/path/%s", mapinfo->pr_mapname),
750 Buffer::kBufSize);
751 } else {
752 CHECK_LT(snprintf(object_path.buf_, Buffer::kBufSize,
753 "/proc/%d/path/%s", pid_, mapinfo->pr_mapname),
754 Buffer::kBufSize);
755 }
756 ssize_t len = readlink(object_path.buf_, current_filename_, PATH_MAX);
757 CHECK_LT(len, PATH_MAX);
758 if (len < 0)
759 len = 0;
760 current_filename_[len] = '\0';
761
762 if (start) *start = mapinfo->pr_vaddr; 703 if (start) *start = mapinfo->pr_vaddr;
763 if (end) *end = mapinfo->pr_vaddr + mapinfo->pr_size; 704 if (end) *end = mapinfo->pr_vaddr + mapinfo->pr_size;
764 if (flags) *flags = kPerms[mapinfo->pr_mflags & 7]; 705 if (flags) *flags = kPerms[mapinfo->pr_mflags & 7];
765 if (offset) *offset = mapinfo->pr_offset; 706 if (offset) *offset = mapinfo->pr_offset;
766 if (inode) *inode = inode_from_mapname; 707 if (inode) *inode = inode_from_mapname;
767 if (filename) *filename = current_filename_; 708 // TODO(csilvers): How to map from /proc/map/object to filename?
709 if (filename) *filename = mapinfo->pr_mapname; // format is ufs.?.?.inode
768 if (file_mapping) *file_mapping = 0; 710 if (file_mapping) *file_mapping = 0;
769 if (file_pages) *file_pages = 0; 711 if (file_pages) *file_pages = 0;
770 if (anon_mapping) *anon_mapping = 0; 712 if (anon_mapping) *anon_mapping = 0;
771 if (anon_pages) *anon_pages = 0; 713 if (anon_pages) *anon_pages = 0;
772 if (dev) *dev = 0; 714 if (dev) *dev = 0;
773 return true; 715 return true;
774 } 716 }
775 #elif defined(__MACH__) 717 #elif defined(__MACH__)
718 static char kDefaultPerms[5] = "r-xp";
776 // We return a separate entry for each segment in the DLL. (TODO(csilvers): 719 // We return a separate entry for each segment in the DLL. (TODO(csilvers):
777 // can we do better?) A DLL ("image") has load-commands, some of which 720 // can we do better?) A DLL ("image") has load-commands, some of which
778 // talk about segment boundaries. 721 // talk about segment boundaries.
779 // cf image_for_address from http://svn.digium.com/view/asterisk/team/oej/mini voicemail/dlfcn.c?revision=53912 722 // cf image_for_address from http://svn.digium.com/view/asterisk/team/oej/mini voicemail/dlfcn.c?revision=53912
780 for (; current_image_ >= 0; current_image_--) { 723 for (; current_image_ >= 0; current_image_--) {
781 const mach_header* hdr = _dyld_get_image_header(current_image_); 724 const mach_header* hdr = _dyld_get_image_header(current_image_);
782 if (!hdr) continue; 725 if (!hdr) continue;
783 if (current_load_cmd_ < 0) // set up for this image 726 if (current_load_cmd_ < 0) // set up for this image
784 current_load_cmd_ = hdr->ncmds; // again, go from the top down 727 current_load_cmd_ = hdr->ncmds; // again, go from the top down
785 728
786 // We start with the next load command (we've already looked at this one). 729 // We start with the next load command (we've already looked at this one).
787 for (current_load_cmd_--; current_load_cmd_ >= 0; current_load_cmd_--) { 730 for (current_load_cmd_--; current_load_cmd_ >= 0; current_load_cmd_--) {
788 #ifdef MH_MAGIC_64 731 const char* lc = ((const char *)hdr + sizeof(struct mach_header));
789 if (NextExtMachHelper<MH_MAGIC_64, LC_SEGMENT_64, 732 // TODO(csilvers): make this not-quadradic (increment and hold state)
790 struct mach_header_64, struct segment_command_64>( 733 for (int j = 0; j < current_load_cmd_; j++) // advance to *our* load_cmd
791 hdr, current_image_, current_load_cmd_, 734 lc += ((const load_command *)lc)->cmdsize;
792 start, end, flags, offset, inode, filename, 735 if (((const load_command *)lc)->cmd == LC_SEGMENT) {
793 file_mapping, file_pages, anon_mapping, 736 const intptr_t dlloff = _dyld_get_image_vmaddr_slide(current_image_);
794 anon_pages, dev)) { 737 const segment_command* sc = (const segment_command *)lc;
795 return true; 738 if (start) *start = sc->vmaddr + dlloff;
796 } 739 if (end) *end = sc->vmaddr + sc->vmsize + dlloff;
797 #endif 740 if (flags) *flags = kDefaultPerms; // can we do better?
798 if (NextExtMachHelper<MH_MAGIC, LC_SEGMENT, 741 if (offset) *offset = sc->fileoff;
799 struct mach_header, struct segment_command>( 742 if (inode) *inode = 0;
800 hdr, current_image_, current_load_cmd_, 743 if (filename)
801 start, end, flags, offset, inode, filename, 744 *filename = const_cast<char*>(_dyld_get_image_name(current_image_));
802 file_mapping, file_pages, anon_mapping, 745 if (file_mapping) *file_mapping = 0;
803 anon_pages, dev)) { 746 if (file_pages) *file_pages = 0; // could we use sc->filesize?
747 if (anon_mapping) *anon_mapping = 0;
748 if (anon_pages) *anon_pages = 0;
749 if (dev) *dev = 0;
804 return true; 750 return true;
805 } 751 }
806 } 752 }
807 // If we get here, no more load_cmd's in this image talk about 753 // If we get here, no more load_cmd's in this image talk about
808 // segments. Go on to the next image. 754 // segments. Go on to the next image.
809 } 755 }
810 #elif defined(PLATFORM_WINDOWS) 756 #elif defined(PLATFORM_WINDOWS)
811 static char kDefaultPerms[5] = "r-xp"; 757 static char kDefaultPerms[5] = "r-xp";
812 BOOL ok; 758 BOOL ok;
813 if (module_.dwSize == 0) { // only possible before first call 759 if (module_.dwSize == 0) { // only possible before first call
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 ProcMapsIterator::Buffer linebuf; 838 ProcMapsIterator::Buffer linebuf;
893 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) { 839 while (it.Next(&start, &end, &flags, &offset, &inode, &filename)) {
894 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_), 840 int written = it.FormatLine(linebuf.buf_, sizeof(linebuf.buf_),
895 start, end, flags, offset, inode, filename, 841 start, end, flags, offset, inode, filename,
896 0); 842 0);
897 RawWrite(fd, linebuf.buf_, written); 843 RawWrite(fd, linebuf.buf_, written);
898 } 844 }
899 } 845 }
900 846
901 } // namespace tcmalloc 847 } // namespace tcmalloc
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/base/sysinfo.h ('k') | third_party/tcmalloc/chromium/src/debugallocation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698