use of com.ibm.j9ddr.vm29.pointer.helper.J9MemTagHelper.J9MemTagCheckError 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.helper.J9MemTagHelper.J9MemTagCheckError 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.helper.J9MemTagHelper.J9MemTagCheckError in project openj9 by eclipse.
the class J9MemTagHelper method checkTagSumCheck.
/**
* Checks that the memory tag is not corrupt.
*
* @param[in] tagAddress the in-process or out-of-process address of the
* header/footer memory tag
* @param[in] eyeCatcher the eyecatcher corresponding to the memory tag
*
* @return 0 if the sum check is successful, non-zero otherwise
* @throws CorruptDataException
*/
public static void checkTagSumCheck(J9MemTagPointer tag, long eyeCatcher) throws CorruptDataException {
int sum = 0;
U32Pointer slots;
if (!checkEyecatcher(tag, eyeCatcher)) {
throw new J9MemTagCheckError(tag, "Wrong eyecatcher. Expected 0x" + Long.toHexString(eyeCatcher) + " but was " + UDATA.cast(tag).getHexValue());
}
slots = U32Pointer.cast(tag);
/*
* Could be unrolled into chained xors with a J9VM_ENV_DATA64
* conditional on the extra 2 U_32s
*/
for (int i = 0; i < (J9MemTag.SIZEOF / U32.SIZEOF); i++) {
sum ^= slots.at(i).longValue();
}
if (J9BuildFlags.env_data64) {
U32 a = new U32(UDATA.cast(tag).rightShift(32));
U32 b = new U32(UDATA.cast(tag).bitAnd(U32.MAX));
sum ^= a.longValue() ^ b.longValue();
} else {
sum ^= tag.longValue();
}
if (sum != 0) {
throw new J9MemTagCheckError(tag, "J9MemTag sumcheck failed: " + sum);
}
}
use of com.ibm.j9ddr.vm29.pointer.helper.J9MemTagHelper.J9MemTagCheckError in project openj9 by eclipse.
the class J9MemTagCommands method corruptData.
/**
* CorruptData handler used with J9MemTagIterator
*/
public void corruptData(String message, CorruptDataException e, boolean fatal) {
if (e instanceof J9MemTagCheckError) {
J9MemTagCheckError casted = (J9MemTagCheckError) e;
out.println("J9MemTag check failed at " + Long.toHexString(casted.getAddress()) + ": " + message + " :" + e.getMessage());
} else {
e.printStackTrace(out);
}
}
Aggregations