use of org.graalvm.word.WordFactory.nullPointer in project graal by oracle.
the class PosixVirtualMemoryProvider method reserve.
@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
public Pointer reserve(UnsignedWord nbytes, UnsignedWord alignment, boolean executable) {
if (nbytes.equal(0)) {
return WordFactory.nullPointer();
}
UnsignedWord granularity = getGranularity();
boolean customAlignment = !UnsignedUtils.isAMultiple(granularity, alignment);
UnsignedWord mappingSize = nbytes;
if (customAlignment) {
mappingSize = mappingSize.add(alignment);
}
mappingSize = UnsignedUtils.roundUp(mappingSize, granularity);
int flags = MAP_ANON() | MAP_PRIVATE() | MAP_NORESERVE();
if (Platform.includedIn(Platform.MACOS_AARCH64.class) && executable) {
flags |= MAP_JIT();
}
Pointer mappingBegin = mmap(nullPointer(), mappingSize, PROT_NONE(), flags, NO_FD, NO_FD_OFFSET);
if (mappingBegin.equal(MAP_FAILED())) {
return nullPointer();
}
if (!customAlignment) {
return mappingBegin;
}
Pointer begin = PointerUtils.roundUp(mappingBegin, alignment);
UnsignedWord clippedBegin = begin.subtract(mappingBegin);
if (clippedBegin.aboveOrEqual(granularity)) {
munmap(mappingBegin, UnsignedUtils.roundDown(clippedBegin, granularity));
}
Pointer mappingEnd = mappingBegin.add(mappingSize);
UnsignedWord clippedEnd = mappingEnd.subtract(begin.add(nbytes));
if (clippedEnd.aboveOrEqual(granularity)) {
UnsignedWord rounded = UnsignedUtils.roundDown(clippedEnd, granularity);
munmap(mappingEnd.subtract(rounded), rounded);
}
return begin;
}
use of org.graalvm.word.WordFactory.nullPointer in project graal by oracle.
the class AbstractCommittedMemoryProvider method allocate.
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
private Pointer allocate(UnsignedWord size, UnsignedWord alignment, boolean executable) {
int access = VirtualMemoryProvider.Access.READ | VirtualMemoryProvider.Access.WRITE;
if (executable) {
access |= VirtualMemoryProvider.Access.EXECUTE;
}
Pointer reserved = WordFactory.nullPointer();
if (!UnsignedUtils.isAMultiple(getGranularity(), alignment)) {
reserved = VirtualMemoryProvider.get().reserve(size, alignment, executable);
if (reserved.isNull()) {
return nullPointer();
}
}
Pointer committed = VirtualMemoryProvider.get().commit(reserved, size, access);
if (committed.isNull()) {
if (reserved.isNonNull()) {
VirtualMemoryProvider.get().free(reserved, size);
}
return nullPointer();
}
assert reserved.isNull() || reserved.equal(committed);
tracker.track(size);
return committed;
}
use of org.graalvm.word.WordFactory.nullPointer in project graal by oracle.
the class PosixVirtualMemoryProvider method commit.
@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
public Pointer commit(PointerBase start, UnsignedWord nbytes, int access) {
if ((start.isNonNull() && !isAligned(start)) || nbytes.equal(0)) {
return WordFactory.nullPointer();
}
int flags = MAP_ANON() | MAP_PRIVATE();
if (start.isNonNull()) {
flags |= MAP_FIXED();
}
boolean isWX = (access & Access.WRITE) != 0 && (access & Access.EXECUTE) != 0;
if (Platform.includedIn(Platform.MACOS_AARCH64.class) && isWX) {
flags |= MAP_JIT();
}
/* The memory returned by mmap is guaranteed to be zeroed. */
final Pointer result = mmap(start, nbytes, accessAsProt(access), flags, NO_FD, NO_FD_OFFSET);
return result.notEqual(MAP_FAILED()) ? result : nullPointer();
}
use of org.graalvm.word.WordFactory.nullPointer in project graal by oracle.
the class PosixVirtualMemoryProvider method mapFile.
@Override
@Uninterruptible(reason = "May be called from uninterruptible code.", mayBeInlined = true)
public Pointer mapFile(PointerBase start, UnsignedWord nbytes, WordBase fileHandle, UnsignedWord offset, int access) {
if ((start.isNonNull() && !isAligned(start)) || nbytes.equal(0)) {
return WordFactory.nullPointer();
}
int flags = MAP_PRIVATE();
if (start.isNonNull()) {
flags |= MAP_FIXED();
}
int fd = (int) fileHandle.rawValue();
Pointer result = mmap(start, nbytes, accessAsProt(access), flags, fd, offset.rawValue());
return result.notEqual(MAP_FAILED()) ? result : WordFactory.nullPointer();
}
Aggregations