This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Query regarding initializing memory to specific byte patterns.


Hello GCC Team,

We have inherited a piece of software which checks for illegal memory writes due to memory overrun/underrun and writing to released memory.
This software is written for windows platform.
The implementation of this software is dependent on setting specific magic byte patterns to memory, using support provided by Microsoft Visual Studio compiler.

A quick summary of what Microsoft's compilers use for various bits of unowned/uninitialized memory when compiled for debug mode (support may vary by compiler version):
Value     Name           Description
------   --------        -------------------------
0xCD     Clean Memory    Allocated memory via malloc or new but never
                                                written by the application.

0xDD     Dead Memory     Memory that has been released with delete or free.
                                                 Used to detect writing through dangling pointers.

0xED or  Aligned Fence   'No man's land' for aligned allocations. Using a
0xBD                                      different value here than 0xFD allows the runtime
                                                to detect not only writing outside the allocation,
                                                but to also detect mixing alignment-specific
                                                allocation/deallocation routines with the regular
                                                ones.

0xFD     Fence Memory    Also known as "no mans land." This is used to wrap
                                                the allocated memory (surrounding it with a fence)
                                                and is used to detect indexing arrays out of
                                                bounds or other accesses (especially writes) past
                                                the end (or start) of an allocated block.

0xFD or  Buffer slack    Used to fill slack space in some memory buffers
0xFE                                       (unused parts of `std::string` or the user buffer
                                                passed to `fread()`). 0xFD is used in VS 2005 (maybe
                                                some prior versions, too), 0xFE is used in VS 2008
                                                and later.

0xCC                     When the code is compiled with the /GZ option,
                         uninitialized variables are automatically assigned
                         to this value (at byte level).

We are investigating whether there are similar options available in GCC compiler for Linux platform.
From browsing the GCC options, I came across the below options.
But, they don't seem to support everything similar to what the Microsoft compiler supports.

GCC supports a number of command-line options that control adding run-time instrumentation to the code it normally generates.
-fsanitize=address

Enable AddressSanitizer, a fast memory error detector. Memory access instructions are instrumented to detect out-of-bounds and use-after-free bugs. The option enables -fsanitize-address-use-after-scope. See https://github.com/google/sanitizers/wiki/AddressSanitizer for more details. The run-time behavior can be influenced using the ASAN_OPTIONS environment variable. When set to help=1, the available options are shown at startup of the instrumented program. See https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags for a list of supported options. The option cannot be combined with -fsanitize=thread and/or -fcheck-pointer-bounds.

There is a sanitizer flag "malloc_fill_byte" which can be used to fill newly allocated memory.
-fcheck-pointer-bounds
Enable Pointer Bounds Checker instrumentation. Each memory reference is instrumented with checks of the pointer used for memory access against bounds associated with that pointer.



Could you please guide us in this regard?
Our main aim is to make this proprietary software written for the Windows platform portable and usable across all platforms.
Many Thanks.


Regards,
Abhijit Verma G


___________________________________________________________________________

This e-mail message is intended for the recipient only and contains information which is 
CONFIDENTIAL and which may be proprietary to ECI Telecom. If you have received this 
transmission in error, please inform us by e-mail, phone or fax, and then delete the original 
and all copies thereof.
___________________________________________________________________________

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]