use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagIterator method internalNext.
private J9MemTagPointer internalNext() {
long result;
this.isFooterCorrupted = false;
/* Hunt for the header eyecatcher */
do {
result = DataType.getProcess().findPattern(headerEyecatcherBytes, UDATA.SIZEOF, currentSearchAddress);
if (result == -1) {
return null;
}
if (Addresses.greaterThan(result, topAddress)) {
return null;
}
/* Move the current search address beyond the current result */
currentSearchAddress = result + UDATA.SIZEOF;
/* Address is in range - does it point to a valid block? */
VoidPointer memoryBase = j9mem_get_memory_base(J9MemTagPointer.cast(result));
try {
IDATA corruption = j9mem_check_tags(VoidPointer.cast(memoryBase), headerEyecatcher, footerEyecatcher);
if (corruption.allBitsIn(J9PORT_MEMTAG_NOT_A_TAG.longValue())) {
/* This is not a memory tag */
continue;
}
if (corruption.allBitsIn(J9PORT_MEMTAG_FOOTER_TAG_CORRUPTED.longValue()) || corruption.allBitsIn(J9PORT_MEMTAG_FOOTER_PADDING_CORRUPTED.longValue())) {
/*
* A block with corrupted footer is accepted only and only if
* we are dealing with freed memory. Therefore, following check is double check.
* If we are here, then it is freed memory is being looked for with the current algorithm.
*
*/
if (headerEyecatcher == J9MEMTAG_EYECATCHER_FREED_HEADER && footerEyecatcher == J9MEMTAG_EYECATCHER_FREED_FOOTER) {
this.isFooterCorrupted = true;
return J9MemTagPointer.cast(result);
}
}
} catch (J9MemTagCheckError e) {
/* Tag is readable, but corrupt */
if (!lookingForFreedCallSites) {
EventManager.raiseCorruptDataEvent("Corrupt memory section found", e, false);
}
/* Find the next section */
continue;
}
return J9MemTagPointer.cast(result);
} while (true);
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagHelper method j9mem_check_tags.
/**
* Performs validation checks on the memory block starting at memoryPointer.
*
* The memory passed in could fall into one of three categories:
* 1) It could be a valid J9MemTag region with valid headers and footers
* 2) It could be not be a J9MemTag region
* 3) It could be a J9MemTag region with some corruption in either the header, footer or padding
*
* @param[in] portLibrary The port library
* @param[in] memoryPointer address returned by @ref j9mem_allocate_memory()
*
* @throws CorruptDataException if the tags are corrupted, or the memory is inaccessible. (Option 3)
* @return J9PORT_MEMTAG_NOT_A_TAG if memoryPointer address is not a tag
* J9PORT_MEMTAG_HEADER_TAG_CORRUPTED if memoryPointer address is valid tag region but header tag is corrupted.
* J9PORT_MEMTAG_FOOTER_TAG_CORRUPTED if memoryPointer address is valid tag region but footer tag is corrupted.
* J9PORT_MEMTAG_FOOTER_PADDING_CORRUPTED if memoryPointer address is valid tag region but footer padding is corrupted.
* J9PORT_MEMTAG_VALID_TAG if memoryPointer address is valid tag and header/footer are not corrupted.
* @note memoryPointer may not be NULL.
*/
public static IDATA j9mem_check_tags(VoidPointer memoryPointer, long headerEyecatcher, long footerEyecatcher) throws J9MemTagCheckError {
J9MemTagPointer headerTagAddress, footerTagAddress = J9MemTagPointer.NULL;
headerTagAddress = j9mem_get_header_tag(memoryPointer);
try {
footerTagAddress = j9mem_get_footer_tag(headerTagAddress);
checkTagSumCheck(headerTagAddress, headerEyecatcher);
} catch (J9MemTagCheckError e) {
/* Corruption here either means the header tag is mangled, or the header eyecatcher isn't actually the start of a
* J9MemTag block.
*
* If we can find a valid footerTag, then we'll believe this is a mangled header.
*/
try {
if (checkEyecatcher(footerTagAddress, footerEyecatcher)) {
/* Footer eyecatcher is valid - header tag is corrupt */
throw e;
} else {
/* Footer eyecatcher is invalid - this isn't a memory tag */
return J9PORT_MEMTAG_NOT_A_TAG;
}
} catch (CorruptDataException e1) {
/* Can't read the footer tag - assume memoryPointer isn't a tag */
return J9PORT_MEMTAG_NOT_A_TAG;
}
} catch (CorruptDataException e) {
/* CorruptDataException here will mean MemoryFault. Which means we can't read the
* entire header tag - so we assume this isn't a valid J9MemTag
*/
return J9PORT_MEMTAG_NOT_A_TAG;
}
try {
checkTagSumCheck(footerTagAddress, footerEyecatcher);
} catch (J9MemTagCheckError e) {
if (headerEyecatcher == J9MEMTAG_EYECATCHER_FREED_HEADER && footerEyecatcher == J9MEMTAG_EYECATCHER_FREED_FOOTER) {
/* When dealing with already freed memory, it is reasonable to accept
* a block that is missing the footer instead of throwing an exception.
*/
return J9PORT_MEMTAG_FOOTER_TAG_CORRUPTED;
} else {
throw e;
}
} catch (CorruptDataException e) {
/* If we got here, the header was valid. A memory fault here suggests
* we're missing the storage for the footer - which is corruption
*/
throw new J9MemTagCheckError(headerTagAddress, e);
}
try {
checkPadding(headerTagAddress);
} catch (J9MemTagCheckError e) {
if (headerEyecatcher == J9MEMTAG_EYECATCHER_FREED_HEADER && footerEyecatcher == J9MEMTAG_EYECATCHER_FREED_FOOTER) {
/* When dealing with already freed memory, it is reasonable to accept
* a block that is missing the footer instead of throwing an exception.
*/
return J9PORT_MEMTAG_FOOTER_PADDING_CORRUPTED;
} else {
throw e;
}
} catch (CorruptDataException e) {
/* If we got here, the header was valid. A memory fault here suggests
* we're missing the storage for the padding - which is corruption
*/
throw new J9MemTagCheckError(headerTagAddress, e);
}
return J9PORT_MEMTAG_VALID_TAG;
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagCommands method runFindHeader.
private void runFindHeader(String command, String[] args, Context context) throws DDRInteractiveCommandException {
long address = 0;
J9MemTagPointer header = null;
if (args.length != 1) {
out.println("Usage: ");
out.println(" !findheader <address> (e.g. !findheader 0xa2b4c6d8)");
return;
}
address = CommandUtils.parsePointer(args[0], J9BuildFlags.env_data64);
out.println(String.format("Searching memory allocation header for %s", U8Pointer.cast(address).getHexAddress()));
/*
* Search for an eyecatcher on or before the specified address. Start
* the search on the specified address since an eyecatcher may start on
* the address. Ensure that the eyecatcher that is found is on or before
* the address. If this condition is not satisfied, start searching for
* an eyecatcher 1K before the previous start address. Continue until an
* eyecatcher is found, or the start address of 0 is reached.
*/
long searchBase = address - SEARCH_SLAB_SIZE;
SEARCH_LOOP: do {
/* Add 3 (length of eyecatcher - 1) to the top address, to catch eyecatchers written between search slabs */
J9MemTagIterator it = J9MemTagIterator.iterateAllocatedHeaders(searchBase, searchBase + SEARCH_SLAB_SIZE + 3);
while (it.hasNext()) {
J9MemTagPointer potential = it.next();
if (Addresses.greaterThan(potential.getAddress(), address)) {
/* Walked past address */
break;
}
VoidPointer start = J9MemTagHelper.j9mem_get_memory_base(potential);
VoidPointer end;
try {
end = start.addOffset(potential.allocSize().longValue());
} catch (CorruptDataException e) {
continue;
}
if (Addresses.greaterThanOrEqual(address, start.getAddress()) && Addresses.lessThan(address, end.getAddress())) {
/* Match */
header = potential;
break SEARCH_LOOP;
}
}
if (Addresses.lessThan(searchBase, SEARCH_SLAB_SIZE)) {
searchBase = 0;
} else {
searchBase = searchBase - SEARCH_SLAB_SIZE;
}
} while (searchBase != 0);
if (header == null) {
out.println("No memory allocation header found");
} else {
String callsite;
try {
callsite = header.callSite().getCStringAtOffset(0);
} catch (CorruptDataException ex) {
callsite = "<FAULT> reading callsite string: " + ex.getMessage();
}
String categoryName;
try {
categoryName = header.category().name().getCStringAtOffset(0);
} catch (CorruptDataException ex) {
categoryName = "<FAULT> reading category name string: " + ex.getMessage();
}
try {
out.println(String.format("Found memory allocation header, !j9x %s,0x%#x", J9MemTagHelper.j9mem_get_memory_base(header).getHexAddress(), header.allocSize().longValue()));
out.println(String.format("J9MemTag at %s {", header.getHexAddress()));
out.println(String.format(" U_32 eyeCatcher = 0x%x;", header.eyeCatcher().longValue()));
out.println(String.format(" U_32 sumCheck = 0x%x;", header.sumCheck().longValue()));
out.println(String.format(" UDATA allocSize = 0x%x;", header.allocSize().longValue()));
out.println(String.format(" char* callSite = %s;", callsite));
out.println(String.format(" struct OMRMemCategory* category = !omrmemcategory 0x%x (%s);", header.category().longValue(), categoryName));
out.println("}");
} catch (CorruptDataException ex) {
out.println("CDE formatting J9MemTag at " + header.getHexAddress());
}
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagIterator method next.
public J9MemTagPointer next() {
if (hasNext()) {
J9MemTagPointer toReturn = current;
current = null;
return toReturn;
} else {
throw new NoSuchElementException();
}
}
use of com.ibm.j9ddr.vm29.pointer.generated.J9MemTagPointer in project openj9 by eclipse.
the class J9MemTagHelper method j9mem_get_footer_padding.
/**
* Given the address of the headerEyecatcher for the memory block, return
* the address of the footer padding.
*
* Note that there not be any padding, in which case this returns the same
* as @ref j9mem_get_footer_tag(), the address of the footer tag.
*
* @throws CorruptDataException
*/
public static VoidPointer j9mem_get_footer_padding(J9MemTagPointer headerEyeCatcherAddress) throws CorruptDataException {
UDATA cursor = UDATA.cast(U8Pointer.cast(headerEyeCatcherAddress).add(J9MemTag.SIZEOF));
U8Pointer padding = U8Pointer.cast(cursor.add(headerEyeCatcherAddress.allocSize()));
return VoidPointer.cast(padding);
}
Aggregations