From 5becf0af0a12f6947b65c03770cf5cea71fe4b31 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 6 Aug 2020 10:12:22 +0800 Subject: [PATCH] runtime/kernel: fixed memory corruption for cache and DMA. --- src/runtime/src/kernel/cache.rs | 9 ++++----- src/runtime/src/kernel/dma.rs | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/runtime/src/kernel/cache.rs b/src/runtime/src/kernel/cache.rs index 56b2d093..996cec3e 100644 --- a/src/runtime/src/kernel/cache.rs +++ b/src/runtime/src/kernel/cache.rs @@ -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) -> CSlice<'static, i32> { @@ -8,12 +8,11 @@ pub extern fn get(key: CSlice) -> 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"); } diff --git a/src/runtime/src/kernel/dma.rs b/src/runtime/src/kernel/dma.rs index b8f435f8..4827f342 100644 --- a/src/runtime/src/kernel/dma.rs +++ b/src/runtime/src/kernel/dma.rs @@ -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();