Home away from home 
Joined: 2006/11/20 16:26 Last Login
: Yesterday 17:18
From Norway
Group:
Registered Users
|
@BSzili
What are you trying to do?
If I read your code correct, you allocated memory, you protect it, and then return memory after the MEM_GUARD_SIZE? what is that supposed to do?
Typically, if you have broken for loop or while loop… it’s the end of the memory you need to protect, not the beginning of memory. even if did protect end of memory. you have problem with the memory page size, [protected][data][alignment][protected]… you might not catch bug sense you likely to write into alignment part.
pointer are not well understood by many developers, a pointer is a element. “Ptr+=10;” is the offset: “sizeof(*ptr) * 10”; 10 is not in bytes its number of elements of the pointer to increment, this why always need to cast to byte pointers, before doing any additions, unless you intend something else.
wont it be better to create a memory copy protect, concept instead..
APTR DoublicateAsReadOnly(APTR src, size_s size); void FreeReadOnly(APTR addr);
1. Allocate memory, 2. copy memory, 3. protect memory.
Crashes are often caused by non-initialized offsets, or pointers. Random crap in memory, causing pointers to be set, or offsets being set to something else than 0. It should be one of the prime suspects. Besides making sure you actually got memory after an allocation. Also, se lot developers who do not set pointer to NULL after freeing. yeh sure it faster if you don’t but it’s not uncommon to create a cleanup routine and accidentally call it twice because you forgot a return or a break. stack corruption can be a issue, lets say you array with 10 items, it’s easy to accidently writ 11 items into it and corrupt next variable in the stack, its easy add extra variable after the array with 0xCAFECAFE or something like that, if want to check that array do not overwrite next variable on the stack..
Crashes on addresses like 0xFFFFF424, is good indication of zero pointer somewhere in the code.
Edited by LiveForIt on 2025/7/4 13:26:26 Edited by LiveForIt on 2025/7/4 14:25:18 Edited by LiveForIt on 2025/7/4 14:28:21
|