mylib v0.45
36 posts
• Page 2 of 4 • 1, 2, 3, 4
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Re: mylib v0.4
linkliststart is always 0x88024000 for the designated OSes. Line 2 and 3 of the doc list the memory locations, where the value 0x88024000 is stored. These locations are indeed OS dependent. But they are listed for reference only. They are not needed.hayzel wrote:Looking at the code and reading that page , I cannot figure out what the linkliststart pointer value is.
Is it always 0x88024000 as line 5 says, or it is version depended as lines 2-3 say?
If it is version depended I may need a getOSVersion function.
Concerning OS 2.02, I had no time to check, yet. I'm on it. This afternoon (CET).
I'll be back!
- hayzel
- Member
- Posts: 43
- Joined: Thu May 31, 2012 5:45 pm
- Location: Greece
- Calculators: Casio fx-9860G SD
Re: mylib v0.4
Doesn't seems to work. In the first call (no mallocs in my program , no fragmentation) the function runs ok ,(doesn't go into while) and returns 49148 which seems fine.
Then I do some mallocs to test it and call the function again.
I get result=35840, and then I enter for the first time the while () . The first pointer to .next points at 0x252E3366 which causes the app to crash ofcourse cause it is out of range.
Any ideas?
Then I do some mallocs to test it and call the function again.
I get result=35840, and then I enter for the first time the while () . The first pointer to .next points at 0x252E3366 which causes the app to crash ofcourse cause it is out of range.
- Code: Select all
typedef struct {
unsigned int FreePieceLength;
void* next;
} THeapFreePieceLinkedListItem;
int GetFreeMemory(void)
{
int result,freespace;
unsigned int linkliststart=0x88024000;
THeapFreePieceLinkedListItem* FreePiece;
result=Heap_SetTopChunk(0);
result=0x88030000 - result;
freespace=result;
FreePiece=(THeapFreePieceLinkedListItem*)(linkliststart);
while(FreePiece->next)
{
freespace = freespace + FreePiece->FreePieceLength;
FreePiece=(THeapFreePieceLinkedListItem*)(FreePiece->next);
};
freespace = freespace + FreePiece->FreePieceLength;
return freespace;
}
Any ideas?
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Re: mylib v0.4
At present...no.hayzel wrote:Any ideas?
I just tried the following code on a fx-9860GII(SH4) SD, fx-9860GII(SH3) SD and fx-9860G SD.
- Code: Select all
//
int F01_2_Handler(){
unsigned int key;
int freespace, maxpiece, i;
unsigned char x[21];
void* p[7];
Bdisp_AllClr_VRAM();
for ( i = 1; i < 7; i = i +1 ){
maxpiece = HeapMaxContiguousPiece( &freespace );
LongToAsc( freespace, (unsigned char*)x, 8 );
locate(1,i);
Print( (unsigned char*)x );
LongToAsc( maxpiece, (unsigned char*)x, 8 );
locate(11,i);
Print( (unsigned char*)x );
p[i-1] = malloc( 0x400 );
}
GetKey( &key );
for ( i = 1; i < 7; i = i +1 ){
free( p[i-1] );
maxpiece = HeapMaxContiguousPiece( &freespace );
LongToAsc( freespace, (unsigned char*)x, 8 );
locate(1,i);
Print( (unsigned char*)x );
LongToAsc( maxpiece, (unsigned char*)x, 8 );
locate(11,i);
Print( (unsigned char*)x );
}
GetKey( &key );
return 1;
}
No errors encountered. Even with a blocksize of 0x2000, with eats up the heap nearly completely. Heap shrinking and growing nicely.
The same if I use your code!
Give me the exact mallocs, you applied, please. Perhaps some bordercase.
I'll be back!
- hayzel
- Member
- Posts: 43
- Joined: Thu May 31, 2012 5:45 pm
- Location: Greece
- Calculators: Casio fx-9860G SD
Re: mylib v0.4
SimonLothar wrote:No errors encountered. Even with a blocksize of 0x2000, with eats up the heap nearly completely. Heap shrinking and growing nicely.
The same if I use your code!
Give me the exact mallocs, you applied, please. Perhaps some bordercase.
You mean a memory leak in my structs ? oh god not again.

The code is too complicated to post right now, for you to debug it. It will just evaporate your time.
Can you paste your exact HeapMaxContiguousPiece implementation?
Notice though i run the program only casio sdk emulator.
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Re: mylib v0.4
No. I mean a special behaviour of the OSes heap management in certain situations, which we don't know yet. F. i. in the vicinity of the 0x400 byte heap chunk borders.hayzel wrote:You mean a memory leak in my structs ? oh god not again.
I used your code, too. Successfully.hayzel wrote:Can you paste your exact HeapMaxContiguousPiece implementation?
This could be the reason. I do not use the emulator. I'll try it this afternoon (CET).hayzel wrote:Notice though i run the program only casio sdk emulator.
I'll be back!
- hayzel
- Member
- Posts: 43
- Joined: Thu May 31, 2012 5:45 pm
- Location: Greece
- Calculators: Casio fx-9860G SD
Re: mylib v0.4
Oh, I get it.
Anyway for safety reasons I ported the code to ncurses, and compiled it with gcc and run it on valgrind. No memory leaks.
I will make a test case project to send you, If you want to reverse engineer the behavior, if you can't see the problem in casio 9860 emulator also.
Anyway for safety reasons I ported the code to ncurses, and compiled it with gcc and run it on valgrind. No memory leaks.
I will make a test case project to send you, If you want to reverse engineer the behavior, if you can't see the problem in casio 9860 emulator also.
- hayzel
- Member
- Posts: 43
- Joined: Thu May 31, 2012 5:45 pm
- Location: Greece
- Calculators: Casio fx-9860G SD
Re: mylib v0.4
Here the sample project:
Removed all the uneeded code, and leaved only some initialization routines.
The bug is happening on the third call of the GetFreeMemory()
http://koppermind.homelinux.org/files/civiltest.zip
Removed all the uneeded code, and leaved only some initialization routines.
The bug is happening on the third call of the GetFreeMemory()
http://koppermind.homelinux.org/files/civiltest.zip
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Re: mylib v0.4
Downloaded and checked. Could reproduce the error on a fx-9860G SD. My fault. The free heap piece walk procedure has to be more complicated. The start of the free heap piece list is not constantly at 0x88024000 (of course, after I reconsidered). I'm on it. Stay put and don't move. Sorry.hayzel wrote:http://koppermind.homelinux.org/files/civiltest.zip
I'll be back!
- SimonLothar
- Senior Member
-
- Posts: 605
- Joined: Sat Sep 15, 2012 6:59 am
- Location: Krautland ****
- Calculators: Casio fx-7400GII, Casio fx-7400GII (SH4), Casio fx-9750GII, Casio fx-9750GII (SH4), Casio fx-9860G, Casio fx-9860G SD, Casio fx-9860G Slim, Casio fx-9860GII SD, Casio fx-9860GII SD Power Graphic 2, Casio Classpad 330 plus, Casio fx-CG20, Casio fx-CG50, Casio Classpad fx-CP400
Re: mylib v0.4
The following piece accounts for the fact that linkliststart is not constant throughout an OSes lifetime between full resets. It is based on the observation, that the first "MOV.L @(disp,PC),Rn" of syscall 0x0ACC (free), loads the pointer, which contains the actual linkliststart.
- Code: Select all
//
unsigned int GetHeapFreeListStartPointer(){
unsigned int ea;
unsigned int j;
ea = *(unsigned int*)0x8001007C;
ea = ea + 0x0ACC*4; // syscall no of the heap function "free"
ea = *(unsigned int*)( ea );
// find the first "MOV.L @(disp,PC),Rn"
while ( (*(unsigned short*)( ea ) & 0xF000 ) != 0xD000 ){
if ( *(unsigned short*)( ea ) == 0x000B ) return 0; // check for RTS, just in case
ea = ea + 2;
};
// calculate disp, t. i. find the pool
j = *(unsigned char*)( ea + 1 );
j = 4*j;
// adjust alignment
j = ( ea + j + 4 ) & 0xFFFFFFFC;
return *(unsigned int*)( j );
}
//
int GetFreeMemory(void)
{
int result,freespace;
// unsigned int linkliststart=0x88024000;
unsigned int linkliststart=GetHeapFreeListStartPointer();
THeapFreePieceLinkedListItem* FreePiece;
result=Heap_SetTopChunk(0);
result=0x88030000 - result;
freespace=result;
FreePiece=(THeapFreePieceLinkedListItem*)(*(int*)linkliststart);
if ( FreePiece ){
while(FreePiece->next){
freespace = freespace + FreePiece->FreePieceLength;
FreePiece=(THeapFreePieceLinkedListItem*)(FreePiece->next);
};
freespace = freespace + FreePiece->FreePieceLength;
}
return freespace;
}
I'll be back!
- hayzel
- Member
- Posts: 43
- Joined: Thu May 31, 2012 5:45 pm
- Location: Greece
- Calculators: Casio fx-9860G SD
Re: mylib v0.4
Great!
But why you search with a "while" the MOV.L @(disp,PC),Rn, isn't it constant position, or changes with versions?
But why you search with a "while" the MOV.L @(disp,PC),Rn, isn't it constant position, or changes with versions?
36 posts
• Page 2 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: No registered users and 19 guests