Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap initialization value other than zero. #68

Open
user2222222222 opened this issue Jun 6, 2024 · 4 comments
Open

Heap initialization value other than zero. #68

user2222222222 opened this issue Jun 6, 2024 · 4 comments

Comments

@user2222222222
Copy link

It would be nice to be able to initialize the heap to something other than zero (such as a checker pattern: 0x55).
#define UMM_HEAPINIT 0x55

It looks like these are the only changes needed in umm_multi_init_heap(), but thought I'd bring it up here in case you think it's worth adding, but mainly to make sure I'm not missing something:

    memset(UMM_HEAP, UMM_HEAPINIT, UMM_HEAPSIZE);

    UMM_NBLOCK(0) = 1;
    UMM_PBLOCK(0) = 0;
    UMM_NFREE(0) = 1;
    UMM_PFREE(0) = 1;

    UMM_NBLOCK(1) = UMM_BLOCK_LAST | UMM_FREELIST_MASK;
    UMM_PBLOCK(1) = 0;
    UMM_NFREE(1) = 0;
    UMM_PFREE(1) = 0;

    UMM_NBLOCK(UMM_BLOCK_LAST) = 0;
    UMM_PBLOCK(UMM_BLOCK_LAST) = 1;
    UMM_NFREE(UMM_BLOCK_LAST) = 0;
    UMM_PFREE(UMM_BLOCK_LAST) = 0;
@rhempel
Copy link
Owner

rhempel commented Jun 11, 2024

We have a compile time switch to add some safety padding around memory blocks already.

Do you have a use case for initializing the entire heap to some specific value?

@user2222222222
Copy link
Author

Not one useful in any kind of new design, but something I needed for virtualizing an old system. Some old embedded devices initialize the heap with a checker pattern. Needed to keep it the same when wrapping it with umm and that was the easiest thing to do without changing anything else. What I did is working fine, but didn't investigate the changes I made: just did what looked logical.

@rhempel
Copy link
Owner

rhempel commented Jun 20, 2024

Here is what I can do - there are a couple of options.

  1. We can make the init function WEAK, so that by default it is initialized to 0 as it is today. If the user supplies a custom initializer, then it is called
  2. We can make a #define that is defaulted to 0 and is overrideable either on the build command line or in a config file

I am leaning to option 2 since we already have a nice mechanism for overriding values :-)

@user2222222222
Copy link
Author

Option 2 is what works for me and considering the rarity of it's application, seems like the best thing to do. In the unlikely case someone needed a dynamic option, it would be an easy and thoughtless modification. And that's the only reason I brought it up at all: it would have been nice for it to be there so I didn't have to wonder whether I might be breaking some obscure special case (we've all been there before.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants