OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:35 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Crash in memmove function
PostPosted: Wed Sep 28, 2022 11:36 pm 
Offline

Joined: Wed Sep 14, 2022 12:42 pm
Posts: 10
Hi everyone,

It ís me again :(.

I have an issue with memmove function. When my OS run into memmove function. Everything works correctly if there is no interrupt happened. If there is interrupt happened, when the memmove's thread back, it raises exception General Protection. The context is saved correctly. Please help

Quote:
void* memmove(void* des, void* src, size_t size)
{
size_t numq = size >> 3;
size_t numb = size & 0b111;
if (des < src)
{
uint64 *qdes = (uint64*)des;
uint64 *qsrc = (uint64*)src;
for (size_t i = 0; i < numq; ++i)
{
qdes[i] = qsrc[i];
// printf(" %d ", i);
}
uint8 *bdes = (uint8*)(des + numq * 8);
uint8 *bsrc = (uint8*)(src + numq * 8);
for (size_t i = 0; i < numb; ++i)
{
bdes[i] = bsrc[i];
}
}
return des;
}


Top
 Profile  
 
 Post subject: Re: Crash in memmove function
PostPosted: Thu Sep 29, 2022 1:13 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 898
zungnguyen wrote:
The context is saved correctly.

Is it restored correctly? Clearly both can't be true.

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Crash in memmove function
PostPosted: Thu Sep 29, 2022 1:44 am 
Offline

Joined: Wed Sep 14, 2022 12:42 pm
Posts: 10
kzinti wrote:
zungnguyen wrote:
The context is saved correctly.

Is it restored correctly? Clearly both can't be true.


Yep, but i handle interrupt in the same stack, can it change data in function stack? I see that the saved rbp is the same with saved rsp , so that when interruptHanler is call, it change the local in my function


Top
 Profile  
 
 Post subject: Re: Crash in memmove function
PostPosted: Thu Sep 29, 2022 3:41 am 
Offline
Member
Member

Joined: Sat Nov 21, 2009 5:11 pm
Posts: 852
If you are using a compiler that uses the SystemV AMD64 ABI, such as GCC, you must remember to disable the red zone for code that runs in kernel mode (-mno-red-zone on GCC), because it will be overwritten on every interrupt.


Top
 Profile  
 
 Post subject: Re: Crash in memmove function
PostPosted: Thu Sep 29, 2022 9:51 am 
Offline

Joined: Wed Sep 14, 2022 12:42 pm
Posts: 10
Gigasoft wrote:
If you are using a compiler that uses the SystemV AMD64 ABI, such as GCC, you must remember to disable the red zone for code that runs in kernel mode (-mno-red-zone on GCC), because it will be overwritten on every interrupt.


Thank you. It works!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 73 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group