Skip to content

Commit

Permalink
Adding a potential fix for issue rustwasm#85, enforcing appropriate b…
Browse files Browse the repository at this point in the history
…yte alignment
  • Loading branch information
aclifford committed Oct 16, 2019
1 parent 43ed066 commit c14364c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions wee_alloc/src/imp_static_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub(crate) unsafe fn alloc_pages<B: Into<Bytes>>(pages: Pages, align: B) -> Resu
if ptr as usize & (align.0 - 1) != 0{
loop {
*offset += 1;
count += 1;
ptr = SCRATCH_HEAP[*offset..end + count].as_mut_ptr() as *mut u8;
end += 1;
ptr = SCRATCH_HEAP[*offset..end].as_mut_ptr() as *mut u8;
if ptr as usize & (align.0 - 1) == 0 { break; }
}
}
*offset = end + count;
*offset = end;
NonNull::new(ptr).ok_or_else(|| AllocErr)
} else {
Err(AllocErr)
Expand Down
2 changes: 1 addition & 1 deletion wee_alloc/src/imp_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::ptr;
use libc;
use memory_units::{Bytes, Pages};

pub(crate) fn alloc_pages(pages: Pages) -> Result<ptr::NonNull<u8>, AllocErr> {
pub(crate) fn alloc_pages<B: Into<Bytes>>(pages: Pages, _align: B) -> Result<ptr::NonNull<u8>, AllocErr> {
unsafe {
let bytes: Bytes = pages.into();
let addr = libc::mmap(
Expand Down
4 changes: 2 additions & 2 deletions wee_alloc/src/imp_wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use super::AllocErr;
use core::arch::wasm32;
use core::cell::UnsafeCell;
use core::ptr::NonNull;
use memory_units::Pages;
use memory_units::{Pages, Bytes};

pub(crate) unsafe fn alloc_pages(n: Pages) -> Result<NonNull<u8>, AllocErr> {
pub(crate) unsafe fn alloc_pages<B: Into<Bytes>>(n: Pages, _align: B) -> Result<NonNull<u8>, AllocErr> {
let ptr = wasm32::memory_grow(0, n.0);
if ptr != usize::max_value() {
let ptr = (ptr * PAGE_SIZE.0) as *mut u8;
Expand Down

0 comments on commit c14364c

Please sign in to comment.