diff --git a/RustPkg/Test/TestRustLangApp2/lib.rs b/RustPkg/Test/TestRustLangApp2/lib.rs index 1751319cf85a..01c2d5f79d18 100644 --- a/RustPkg/Test/TestRustLangApp2/lib.rs +++ b/RustPkg/Test/TestRustLangApp2/lib.rs @@ -1,4 +1,5 @@ // Copyright (c) 2019 Intel Corporation +// Copyright (c) Microsoft Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -203,7 +204,7 @@ fn release_buffer (test_table : &mut TestTableFixed) #[no_mangle] #[export_name = "TestBufferDrop"] pub extern fn test_buffer_drop ( - + ) { match get_buffer () { @@ -232,7 +233,7 @@ pub extern fn test_buffer_borrow ( //test_table2.r#type = 2; // error } -use core::alloc::{GlobalAlloc, Layout, Alloc}; +use core::alloc::{GlobalAlloc, Layout, AllocRef}; pub struct MyAllocator; @@ -262,7 +263,7 @@ static ALLOCATOR: MyAllocator = MyAllocator; #[no_mangle] #[export_name = "TestBufferAlloc"] pub extern fn test_buffer_alloc ( - + ) { let layout = unsafe { core::alloc::Layout::from_size_align_unchecked(32, 4) }; diff --git a/RustPkg/Test/TestRustLangLib/src/lib.rs b/RustPkg/Test/TestRustLangLib/src/lib.rs index bf4fd666ba20..454e2f0a7110 100644 --- a/RustPkg/Test/TestRustLangLib/src/lib.rs +++ b/RustPkg/Test/TestRustLangLib/src/lib.rs @@ -1,4 +1,5 @@ // Copyright (c) 2019 Intel Corporation +// Copyright (c) Microsoft Corporation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -48,7 +49,7 @@ extern crate alloc; use alloc::vec::Vec; use alloc::boxed::Box; use alloc::{ - alloc::{handle_alloc_error, Global, Layout}, + alloc::{handle_alloc_error, AllocInit, AllocRef, Global, Layout}, }; @@ -206,7 +207,7 @@ fn release_buffer (test_table : &mut TestTableFixed) #[no_mangle] #[export_name = "TestBufferDrop"] pub extern fn test_buffer_drop ( - + ) { match get_buffer () { @@ -238,16 +239,16 @@ pub extern fn test_buffer_borrow ( #[no_mangle] #[export_name = "TestBufferAlloc"] pub extern fn test_buffer_alloc ( - + ) { let layout = unsafe { core::alloc::Layout::from_size_align_unchecked(32, 4) }; unsafe { - match Global.alloc (layout) { + match Global.alloc (layout, AllocInit::Zeroed) { Ok(buffer) => { - let mut box_buffer = Box::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size())); + let mut box_buffer = Box::from_raw(from_raw_parts_mut(buffer.ptr.as_ptr(), layout.size())); box_buffer[0] = 1; - Global.dealloc (buffer, layout); + Global.dealloc (buffer.ptr, layout); drop (buffer); // It is useless box_buffer[0] = 1; // cannot catch }, @@ -257,9 +258,9 @@ pub extern fn test_buffer_alloc ( let layout = core::alloc::Layout::new::(); unsafe { - match Global.alloc (layout) { + match Global.alloc (layout, AllocInit::Zeroed) { Ok(buffer) => { - Global.dealloc (buffer, layout); + Global.dealloc (buffer.ptr, layout); }, Err(_) => handle_alloc_error (layout), } @@ -324,10 +325,10 @@ pub extern fn test_box_convert ( { let layout = unsafe { core::alloc::Layout::from_size_align_unchecked(size, 4) }; unsafe { - match Global.alloc (layout) { + match Global.alloc (layout, AllocInit::Zeroed) { Ok(buffer) => { - let mut box_buffer = Box::::from_raw(from_raw_parts_mut(buffer.as_ptr(), layout.size()) as *mut [u8] as *mut u8 ); - Global.dealloc (buffer, layout); + let mut box_buffer = Box::::from_raw(from_raw_parts_mut(buffer.ptr.as_ptr(), layout.size()) as *mut [u8] as *mut u8 ); + Global.dealloc (buffer.ptr, layout); *box_buffer = 1; Box::::into_raw(box_buffer) },