forked from M-Labs/nac3
1
0
Fork 0

runtime/kernel: fixed memory corruption for cache and DMA.

This commit is contained in:
pca006132 2020-08-06 10:12:22 +08:00 committed by Gitea
parent e7752a3d6d
commit 5becf0af0a
2 changed files with 5 additions and 6 deletions

View File

@ -1,6 +1,6 @@
use alloc::string::String;
use cslice::{CSlice, AsCSlice};
use core::mem::transmute;
use core::mem::{transmute, forget};
use super::{KERNEL_CHANNEL_0TO1, KERNEL_CHANNEL_1TO0, Message};
pub extern fn get(key: CSlice<u8>) -> CSlice<'static, i32> {
@ -8,12 +8,11 @@ pub extern fn get(key: CSlice<u8>) -> CSlice<'static, i32> {
KERNEL_CHANNEL_1TO0.lock().as_mut().unwrap().send(Message::CacheGetRequest(key));
let msg = KERNEL_CHANNEL_0TO1.lock().as_mut().unwrap().recv();
if let Message::CacheGetReply(v) = msg {
let slice = v.as_c_slice();
let slice = unsafe { transmute(v.as_c_slice()) };
// we intentionally leak the memory here,
// which does not matter as core1 would restart
unsafe {
transmute(slice)
}
forget(v);
slice
} else {
panic!("Expected CacheGetReply for CacheGetRequest");
}

View File

@ -180,7 +180,7 @@ pub extern fn dma_playback(timestamp: i64, ptr: i32) {
while csr::rtio_dma::enable_read() != 0 {}
csr::cri_con::selected_write(0);
mem::drop(v);
mem::forget(v);
debug!("DMA playback finished");
let error = csr::rtio_dma::error_read();