2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-03-06 21:09:17 -06:00
|
|
|
pub type HANDLE = u32;
|
|
|
|
pub type DWORD = u32;
|
|
|
|
pub type SIZE_T = u32;
|
|
|
|
pub type LPVOID = uint;
|
|
|
|
pub type BOOL = u8;
|
2011-11-09 17:27:11 -06:00
|
|
|
|
2013-11-10 16:57:53 -06:00
|
|
|
#[cfg(windows)]
|
2013-03-05 16:42:58 -06:00
|
|
|
mod kernel32 {
|
2013-03-06 21:09:17 -06:00
|
|
|
use super::{HANDLE, DWORD, SIZE_T, LPVOID, BOOL};
|
|
|
|
|
2013-11-10 16:57:53 -06:00
|
|
|
extern "system" {
|
2013-03-05 16:42:58 -06:00
|
|
|
pub fn GetProcessHeap() -> HANDLE;
|
|
|
|
pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T)
|
|
|
|
-> LPVOID;
|
|
|
|
pub fn HeapFree(hHeap: HANDLE, dwFlags: DWORD, lpMem: LPVOID) -> BOOL;
|
|
|
|
}
|
2011-11-09 17:27:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-10 16:57:53 -06:00
|
|
|
#[cfg(windows)]
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() {
|
2013-01-25 18:58:04 -06:00
|
|
|
let heap = unsafe { kernel32::GetProcessHeap() };
|
|
|
|
let mem = unsafe { kernel32::HeapAlloc(heap, 0u32, 100u32) };
|
2015-02-18 04:42:01 -06:00
|
|
|
assert!(mem != 0_usize);
|
2013-01-25 18:58:04 -06:00
|
|
|
let res = unsafe { kernel32::HeapFree(heap, 0u32, mem) };
|
2013-03-28 20:39:09 -05:00
|
|
|
assert!(res != 0u8);
|
2011-11-09 17:27:11 -06:00
|
|
|
}
|
|
|
|
|
2013-11-10 16:57:53 -06:00
|
|
|
#[cfg(not(windows))]
|
2013-02-01 21:43:17 -06:00
|
|
|
pub fn main() { }
|