backend/codegen, runtime: support interop intrinsics and natives

This commit is contained in:
Svyatoslav Scherbina
2017-01-31 13:32:43 +07:00
committed by SvyatoslavScherbina
parent 3892820052
commit 4b694225c1
2 changed files with 45 additions and 4 deletions
+21
View File
@@ -1,3 +1,6 @@
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -187,4 +190,22 @@ OBJ_GETTER0(Kotlin_konan_internal_undefined) {
RETURN_OBJ(nullptr);
}
void* Kotlin_interop_malloc(KLong size, KInt align) {
if (size > SIZE_MAX) {
return nullptr;
}
void* result = malloc(size);
if ((reinterpret_cast<uintptr_t>(result) & (align - 1)) != 0) {
// Unaligned!
RuntimeAssert(false, "unsupported alignment");
}
return result;
}
void Kotlin_interop_free(void* ptr) {
free(ptr);
}
} // extern "C"