Skip to content

Commit

Permalink
Modified to use gc_malloc + mprotect instead of mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
n ddrylliog committed Dec 2, 2009
1 parent 73111d6 commit 4927cb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 13 additions & 2 deletions BinarySeq.ooc
@@ -1,4 +1,8 @@
import os/mmap
include errno

errno: extern Int
strerror: extern func (Int) -> String

BinarySeq: class {

Expand All @@ -14,8 +18,15 @@ BinarySeq: class {

init: func ~withSize (=size) {
memsize := size * sizeof(UChar)
//data = gc_malloc(memsize)
data = mmap(null, memsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS, -1, 0)
// at least 4096, and a multiple of 4096 that is bigger than memsize
realsize := memsize + 4096 - (memsize % 4096)
data = gc_malloc(realsize)
result := mprotect(data, realsize, PROT_READ | PROT_WRITE | PROT_EXEC)
if(result != 0) {
printf("mprotect(%p, %d) failed with code %d. Message = %s\n", data, realsize, result, strerror(errno))
}
// mmap is leaking (cause we don't know when to free), and apparently not needed, but just in case, here's the correct call
//data = mmap(null, memsize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_LOCKED | MAP_ANONYMOUS, -1, 0)
}

append: func ~other (other: This) -> This {
Expand Down
3 changes: 0 additions & 3 deletions yajit.ooc
Expand Up @@ -9,9 +9,6 @@ TestStruct : class {
init: func (=number, =name) {}
}

errno: extern Int
strerror: extern func (Int) -> String

genCode: func <T> (funcPtr: Func, closure: T, argSizes: Int*, argLen: Int) -> Pointer {

op := BinarySeq new(1024)
Expand Down

0 comments on commit 4927cb6

Please sign in to comment.