summaryrefslogtreecommitdiffstats
path: root/courgette/encoded_program.cc
Commit message (Collapse)AuthorAgeFilesLines
* [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram with scoped_ptr.huangs2016-01-291-14/+10
| | | | | | | | | | | | | | | | | | | | | Previously naked pointers AssemblyProgram and EncodedProgram are used over the place, and are deallocated using Delete{AssemblyProgram, EncodedProgram}(). In this CL we use scoped_ptr to manage the life cycles of these objects. - Removed DeleteAssemblyProgram() and DeleteEncodedProgram() and replaced calls with e.g., program.reset(nullptr); if the manual deallocation is a peak memory optimization. - Moved Encode() and ReadEncodedProgram() to the .h files matching the .cc files. - Extracted DetectExecutableType() and ParseDetectedExecutable() from disassembly.* to new files program_detector*c, since Disassembly is really an implementation that caller's don't care about. Committed: https://crrev.com/0a9cbf1781a114b35a4e0f4a834f2d24ade2e917 Cr-Commit-Position: refs/heads/master@{#372212} Review URL: https://codereview.chromium.org/1629703002 Cr-Commit-Position: refs/heads/master@{#372436}
* Revert of [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram ↵dcheng2016-01-291-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with scoped_ptr. (patchset #5 id:80001 of https://codereview.chromium.org/1629703002/ ) Reason for revert: Breaks ninja build on Linux GN. Original issue's description: > [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram with scoped_ptr. > > Previously naked pointers AssemblyProgram and EncodedProgram are used over the > place, and are deallocated using Delete{AssemblyProgram, EncodedProgram}(). > In this CL we use scoped_ptr to manage the life cycles of these objects. > > - Removed DeleteAssemblyProgram() and DeleteEncodedProgram() and replaced calls > with e.g., program.reset(nullptr); if the manual deallocation is a peak > memory optimization. > - Moved Encode() and ReadEncodedProgram() to the .h files matching the .cc files. > - Extracted DetectExecutableType() and ParseDetectedExecutable() from > disassembly.* to new files program_detector*c, since Disassembly is really an > implementation that caller's don't care about. > > Committed: https://crrev.com/0a9cbf1781a114b35a4e0f4a834f2d24ade2e917 > Cr-Commit-Position: refs/heads/master@{#372212} TBR=wfh@chromium.org,grt@chromium.org,huangs@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1650013002 Cr-Commit-Position: refs/heads/master@{#372274}
* [Courgette] Refactor: Manage AssemblyProgram and EncodedProgram with scoped_ptr.huangs2016-01-291-14/+10
| | | | | | | | | | | | | | | | | | Previously naked pointers AssemblyProgram and EncodedProgram are used over the place, and are deallocated using Delete{AssemblyProgram, EncodedProgram}(). In this CL we use scoped_ptr to manage the life cycles of these objects. - Removed DeleteAssemblyProgram() and DeleteEncodedProgram() and replaced calls with e.g., program.reset(nullptr); if the manual deallocation is a peak memory optimization. - Moved Encode() and ReadEncodedProgram() to the .h files matching the .cc files. - Extracted DetectExecutableType() and ParseDetectedExecutable() from disassembly.* to new files program_detector*c, since Disassembly is really an implementation that caller's don't care about. Review URL: https://codereview.chromium.org/1629703002 Cr-Commit-Position: refs/heads/master@{#372212}
* [Courgette] Simplify EncodedProgram Label addition code; removed "1.01 x" ↵huangs2016-01-191-52/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | memory fix. This CL simplifies how Labels get flattened to a list of RVAs. In the past EncodedProgram used DefineAbs32Label() / DefineRel32Label(), which let callers add one Label at a time. Complexity arose from: - Function pointer usage to avoid duplicate code for abs32 and rel32. - Need for EncodedProgram to dynamically adjust size of RVA list. This led to inefficient array resizing, which was fixed by the "1.01 x" memory growth. Change: We now pass the collection of abs32 and rel32 Labels to EncodedProgram. This simplifies the interface, and allows EncodedProgram to find the max indexes and preallocated buffers. The trade-off is increased test code complexity, since we'd need to create Label collection. Other changes: - Update namespace{} for EncodedProgram and its tests. - Add more Label constructors (for testing). - Add LabelManager::GetIndexBound(), for LabelVector and RVAToLabel. - Add kUnassignedRVA in image_utils.h, with checks for its absence in images. Review URL: https://codereview.chromium.org/1571913003 Cr-Commit-Position: refs/heads/master@{#370200}
* Switch to standard integer types in courgette/.avi2015-12-211-63/+64
| | | | | | | | | | BUG=138542 TBR=wfh@chromium.org NOPRESUBMIT=true Review URL: https://codereview.chromium.org/1543643002 Cr-Commit-Position: refs/heads/master@{#366439}
* [Courgette] Move the "1.01 x" memory fix from NoThrowBuffer::reserve() to ↵huangs2015-11-191-1/+9
| | | | | | | | | | | | | | | | | | | | | caller. This amends crrev.com/565753002, which optimizes incessant calls to NoThrowBuffer::reserve() by reserving 1.01 times the requested memory. Key changes: - Exposing NoThrowBuffer::capacity(), like std::vector. - Fixing the single call site that's responsible for the incessant calls by using the same logic as the old fix. - Removing NoThrowBuffer::reserve()'s 1.01 factor. The change is verified for Courgette-apply and Courgette-gen. Cursory checks show no appreciable memory saving, but a ~2% speed up. BUG=167622 Review URL: https://codereview.chromium.org/1447323004 Cr-Commit-Position: refs/heads/master@{#360651}
* [Courgette] Store delta encoding as signed int32.huangs2015-09-091-31/+16
| | | | | | | | | | | | | | | | Owing to AdjustmentMethod permuting Rel32Address items, difference of successive items may be negative. Previously Courgette stores deltas vectors using uint32, so negative values can take 5 bytes each. This CL changes storage of deltas vectors to signed int32. Experiment (goo.gl/vvVADx) shows total diff file reduction of ~3%, and zipped diff file reduction of ~1.5%. We apply the same change for Abs32Address items for consistency. Review URL: https://codereview.chromium.org/1328703002 Cr-Commit-Position: refs/heads/master@{#348039}
* Add 64-bit absolute address support to courgette.wfh2015-03-131-12/+39
| | | | | | | | | | | | | | | | | | | | Turns out, courgette never really understood 64-bit addresses, and they were all being truncated to 32-bit values. This worked fine, as the high 32-bit part was just serialized as byte data, but would have broken for a 64-bit PE image that straddled the 32-bit boundary. This CL adds a new op code for ABS64 to ensure that 64-bit math is used when assembling them, but re-uses the existing abs32 streams (since RVA are always 32-bit). This always reduces the size of the patch, but only by a tiny amount, since the four bytes in the absolute addresses no longer need to be stored separately. This also fixes static cast by reading the 8-byte absolute address from 64-bit binaries. This change is virtually size neutral. Against test binaries (64-bit chrome.dll 40.0.2214.115->43.0.2317.0) the uncompressed patch sizes were: before: 10,948,152 after: 10,925,425 (0.2% reduction) BUG=419996 TEST=courgette_unittests Review URL: https://codereview.chromium.org/629643002 Cr-Commit-Position: refs/heads/master@{#320449}
* Using "static_assert" in lieu of "COMPILE_ASSERT" in courgete moduleanujk.sharma2015-01-201-1/+1
| | | | | | | | | | All our toolchains support c++'s static_assert now- COMPILE_ASSERT can be removed now. BUG=442514 Review URL: https://codereview.chromium.org/857153003 Cr-Commit-Position: refs/heads/master@{#312203}
* Cleanup: Get rid of more base::ASCIIToWide usage.thestig2014-12-041-10/+7
| | | | | | | | | | Also do some lint cleanups. BUG=23581 Review URL: https://codereview.chromium.org/777623002 Cr-Commit-Position: refs/heads/master@{#306905}
* Fix more MSVC warnings, courgette/ edition.pkasting2014-10-031-10/+8
| | | | | | | | | | | | This is mostly about changing types and inserting casts so as to avoid implicit value truncations. BUG=81439 TEST=none Review URL: https://codereview.chromium.org/613893002 Cr-Commit-Position: refs/heads/master@{#298069}
* Fixes for re-enabling more MSVC level 4 warnings: courgette/ editionpkasting@chromium.org2014-07-081-1/+1
| | | | | | | | | | | | This contains fixes for the following sorts of issues: * Signedness mismatch BUG=81439 TEST=none Review URL: https://codereview.chromium.org/371153002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@281696 0039d316-1c4b-4281-b951-d872f2087c98
* Update uses of UTF conversions in courgette/, device/, extensions/, ↵avi@chromium.org2013-12-251-1/+2
| | | | | | | | | | | | google_apis/, gpu/, ipc/, media/, net/ to use the base:: namespace. BUG=330556 TEST=no change TBR=ben@chromium.org Review URL: https://codereview.chromium.org/112963005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242496 0039d316-1c4b-4281-b951-d872f2087c98
* Add PE64 support to courgettewfh@chromium.org2013-09-251-14/+26
| | | | | | | | | | | Add tests for PE64 BUG=38784 NOTRY=true Review URL: https://chromiumcodereview.appspot.com/23600063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225224 0039d316-1c4b-4281-b951-d872f2087c98
* Revert 224789 "Add PE64 support to courgette"piman@chromium.org2013-09-231-26/+14
| | | | | | | | | | | | | | | | | | Caused failures: http://build.chromium.org/p/chromium.win/builders/Win7%20Tests%20%28dbg%29%281%29/builds/23037/steps/courgette_unittests/logs/stdio > Add PE64 support to courgette > > Add tests for PE64 > > BUG=38784 > > Review URL: https://chromiumcodereview.appspot.com/23600063 TBR=wfh@chromium.org Review URL: https://codereview.chromium.org/23591065 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224806 0039d316-1c4b-4281-b951-d872f2087c98
* Add PE64 support to courgettewfh@chromium.org2013-09-231-14/+26
| | | | | | | | | | Add tests for PE64 BUG=38784 Review URL: https://chromiumcodereview.appspot.com/23600063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224789 0039d316-1c4b-4281-b951-d872f2087c98
* Support for ARM 32-bit ELF binaries in Courgettepaulgazz@chromium.org2013-08-011-1/+121
| | | | | | | | | | | | Notes for reviewers: dgarrett: courgette correctness, ARM benchan: style, correctness BUG=258640,258645,258653 Review URL: https://chromiumcodereview.appspot.com/20099004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214873 0039d316-1c4b-4281-b951-d872f2087c98
* Fixed Courgette to correctly regenerate the ELF relocation table forpaulgazz@chromium.org2013-07-181-9/+28
| | | | | | | | | | | | | | ARM binaries. Note for reviewers: Don: general courgette correctness Ben: style, correctness BUG=258648 Review URL: https://chromiumcodereview.appspot.com/19022007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212449 0039d316-1c4b-4281-b951-d872f2087c98
* Use a direct include of strings headers in courgette/.avi@chromium.org2013-06-111-1/+1
| | | | | | | | | | BUG=247723 TEST=none TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/16739013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205524 0039d316-1c4b-4281-b951-d872f2087c98
* Use a direct include of utf_string_conversions.h in chrome_frame/, ↵avi@chromium.org2013-06-071-1/+1
| | | | | | | | | | | | chromeos/, cloud_print/, components/, courgette/, device/, extensions/. BUG=none TEST=none TBR=ben@chromium.org Review URL: https://chromiumcodereview.appspot.com/16614002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204961 0039d316-1c4b-4281-b951-d872f2087c98
* Add Elf 32 Support to Courgette.dgarrett@chromium.org2011-11-081-12/+53
| | | | | | | | | | | | | | | | | | | | | | | | | This change takes advantage of recent refactoring and adds support for Elf X86 32 executables to courgette. It should have no effect on handling of Windows PE executables. We have planned ahead to be able to restrict the code size of the courgette library in different cases to reduce patcher sizes, but this change does not yet take advantage of that (all platforms are supported everywhere). Also, the patcher class currently contains a very small amount of Elf/PE specific code for recreating relocation tables that cannot (currently) be compiled out. BUG=chromium-os:22149 TEST=Please verify that Chrome/Chromium patches can still be generated and work. Also, please see how much the updater executable which is downloaded to users has changed in size since R16. Review URL: http://codereview.chromium.org/8477045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109089 0039d316-1c4b-4281-b951-d872f2087c98
* Revert 108929 - Add Elf 32 Support to Courgette.csilv@chromium.org2011-11-071-55/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This change takes advantage of recent refactoring and adds support for Elf X86 32 executables to courgette. It should have no effect on handling of Windows PE executables. We have planned ahead to be able to restrict the code size of the courgette library in different cases to reduce patcher sizes, but this change does not yet take advantage of that (all platforms are supported everywhere). Also, the patcher class currently contains a very small amount of Elf/PE specific code for recreating relocation tables that cannot (currently) be compiled out. BUG=chromium-os:22149 TEST=Please verify that Chrome/Chromium patches can still be generated and work. Also, please see how much the updater executable which is downloaded to users has changed in size since R16. Review URL: http://codereview.chromium.org/8428009 TBR=dgarrett@chromium.org Review URL: http://codereview.chromium.org/8490023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108934 0039d316-1c4b-4281-b951-d872f2087c98
* Add Elf 32 Support to Courgette.dgarrett@chromium.org2011-11-071-12/+55
| | | | | | | | | | | | | | | | | | | | | | | | | This change takes advantage of recent refactoring and adds support for Elf X86 32 executables to courgette. It should have no effect on handling of Windows PE executables. We have planned ahead to be able to restrict the code size of the courgette library in different cases to reduce patcher sizes, but this change does not yet take advantage of that (all platforms are supported everywhere). Also, the patcher class currently contains a very small amount of Elf/PE specific code for recreating relocation tables that cannot (currently) be compiled out. BUG=chromium-os:22149 TEST=Please verify that Chrome/Chromium patches can still be generated and work. Also, please see how much the updater executable which is downloaded to users has changed in size since R16. Review URL: http://codereview.chromium.org/8428009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108929 0039d316-1c4b-4281-b951-d872f2087c98
* Switch out use of std::string and std::vector for large allocations for a ↵tommi@chromium.org2011-04-061-84/+70
| | | | | | | | | | | | | | | | | buffer class that doesn't throw exceptions. The new buffer class is pretty simple and relies on the MemoryAllocator class that I previously to back large allocations with mapped files when memory is scarce. That reduced the number of crashes quite a bit but we still crash on machines that are simply out of diskspace as well. So, the right thing to do is to expect and handle failures which is what this cl is all about. What we should see once this has landed is that crash dumps due to courgette running out of disk space should disappear from crash/ and instead we should see the number of users that run into this particular problem in dashboards. TEST=Courgette out-of-memory/out-of-diskspace errors should disappear from crash/ BUG=74777 Review URL: http://codereview.chromium.org/6677141 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80648 0039d316-1c4b-4281-b951-d872f2087c98
* Move some files from base to base/memory.levin@chromium.org2011-03-281-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | raw_scoped_refptr_mismatch_checker.h ref_counted.cc ref_counted.h ref_counted_memory.cc ref_counted_memory.h ref_counted_unittest.cc scoped_callback_factory.h scoped_comptr_win.h scoped_handle.h scoped_native_library.cc scoped_native_library.h scoped_native_library_unittest.cc scoped_nsobject.h scoped_open_process.h scoped_ptr.h scoped_ptr_unittest.cc scoped_temp_dir.cc scoped_temp_dir.h scoped_temp_dir_unittest.cc scoped_vector.h singleton.h singleton_objc.h singleton_unittest.cc linked_ptr.h linked_ptr_unittest.cc weak_ptr.cc weak_ptr.h weak_ptr_unittest.cc BUG=None TEST=Compile Review URL: http://codereview.chromium.org/6714032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79524 0039d316-1c4b-4281-b951-d872f2087c98
* Identifying call sites that need to handle out of memory situations in ↵tommi@chromium.org2011-03-221-57/+108
| | | | | | | | | | | | | | | | | Courgette. There's no functional change here, only interface changes: * Change methods that are known to fail out in the field to return bool instead of void. * Where those methods are called, check the return value and report errors * In debug builds use a specialized template class that forces callers to check return values (this is possible at compile time in gcc, but unfortunately not in VS). The next step will be to change the implementation to not use STL containers. TEST=Run courgette tests. BUG=74777 Review URL: http://codereview.chromium.org/6716006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79030 0039d316-1c4b-4281-b951-d872f2087c98
* Change other usages of .size() to .empty() when applicable.erg@google.com2011-03-041-1/+1
| | | | | | | | | BUG=carnitas TEST=compiles Review URL: http://codereview.chromium.org/6609008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76962 0039d316-1c4b-4281-b951-d872f2087c98
* Implementation of an STL compatible allocator for Courgette on Windows.tommi@chromium.org2011-03-011-20/+23
| | | | | | | | | | | | | | | | | This is to better handle low memory situations when applying a differential patch to a large Chrome setup. For reading input files, I'm also switching to using memory mapped files instead of ReadFileToString to reduce the load on the heap. TEST=courgette.exe should succeed in applying a patch between two chrome 10.x archives on an XP machine with 180MB of physical memory and no page file. BUG=72459,73209 Review URL: http://codereview.chromium.org/6597038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76320 0039d316-1c4b-4281-b951-d872f2087c98
* Also build a 64-bit exe version of the 32-bit courgettebradnelson@google.com2010-12-211-5/+5
| | | | | | | | | | | | utility + library to support larger input sizes. BUG=63793 TEST=None Review URL: http://codereview.chromium.org/5096007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69779 0039d316-1c4b-4281-b951-d872f2087c98
* Convert LOG(INFO) to VLOG(1) - courgette/.pkasting@chromium.org2010-10-211-10/+10
| | | | | | | | | | This eliminates the custom logging code as VLOG is per-module configurable. I did preserve the distinct log level numbers in the VLOG statements. BUG=none TEST=none Review URL: http://codereview.chromium.org/3904002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63407 0039d316-1c4b-4281-b951-d872f2087c98
* base: rename Environment::GetEnv to Environment::GetVar.tfarina@chromium.org2010-08-071-1/+1
| | | | | | | | | | | This is the part 4 and the latest of this series. BUG=None TEST=trybots Review URL: http://codereview.chromium.org/3029062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55326 0039d316-1c4b-4281-b951-d872f2087c98
* Add #include utf_string_conversions.h to all files that use ASCIIToWide andbrettw@chromium.org2010-08-031-1/+1
| | | | | | | | | | | | | | | ASCIIToUTF16. I removed string_util includes from a few places where it obviously wasn't needed. In a separate pass, I'm going to remove ASCIITo* from string_util, then I'm going to do an even later pass to find the unnecessary string_util.h includes and remove them. TEST=it compiles BUG=none Review URL: http://codereview.chromium.org/3058027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54746 0039d316-1c4b-4281-b951-d872f2087c98
* base: Rename EnvVarGetter to Environment.tfarina@chromium.org2010-08-031-2/+2
| | | | | | | | | | | | | | | Now EnvVarGetter do much more than getting environment variables. Per suggestion from Pawel in http://codereview.chromium.org/3043018/. BUG=None TEST=trybots Signed-off-by: Thiago Farina <tfarina@chromium.org> Review URL: http://codereview.chromium.org/3052034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54696 0039d316-1c4b-4281-b951-d872f2087c98
* base: Get rid of the deprecated SysInfo::GetEnvVar.tfarina@chromium.org2010-07-081-4/+8
| | | | | | | | | | | Use the new EnvVarGetter::GetEnv instead. BUG=None TEST=trybots Review URL: http://codereview.chromium.org/2876045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51829 0039d316-1c4b-4281-b951-d872f2087c98
* Coverity fixes to keep coverity quiet.sra@chromium.org2009-07-221-1/+1
| | | | | | | | | | | | | | | | | Only the first issue is remotely interesting. * Possibility (low) of using NULL SinkStream* courgette tool 'gen1a' command. * Added initializers for all class members to several constructors. * return 0 at end of from wmain. BUG=none TEST=existing Review URL: http://codereview.chromium.org/155820 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21253 0039d316-1c4b-4281-b951-d872f2087c98
* Code changes to get the code to compile under GCC.sra@google.com2009-07-181-27/+19
| | | | | | | | | | | | Courgette still only knows how to compress Windows x86 executables. But now you can compress them on linux. BUG=none TEST=none Review URL: http://codereview.chromium.org/149597 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21042 0039d316-1c4b-4281-b951-d872f2087c98
* Move Courgettesra@chromium.org2009-05-081-0/+573
from src\third_party\courgette to src\courgette and src\courgette\third_party Fixed #includes Added properties to ignore generated files: C:\c5\src>svn pg svn:ignore courgette courgette.xcodeproj courgette.sln courgette_fuzz.vcproj courgette_lib.vcproj courgette_minimal_tool.vcproj courgette_tool.vcproj courgette.vcproj courgette_unittests.vcproj SConstruct courgette_fuzz.scons courgette_lib.scons courgette_main.scons courgette_minimal_tool.scons courgette.scons courgette_tool.scons courgette_unittests.scons Review URL: http://codereview.chromium.org/115062 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15692 0039d316-1c4b-4281-b951-d872f2087c98