2010-07-16 19:52:01 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-07-16 19:52:01 +04:00
|
|
|
|
|
|
|
#include <jni.h>
|
2012-04-11 16:12:34 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_MEMORY
|
2012-02-16 12:02:25 +04:00
|
|
|
// Wrap malloc and free to use jemalloc
|
|
|
|
#define malloc __wrap_malloc
|
|
|
|
#define free __wrap_free
|
2012-04-11 16:12:34 +04:00
|
|
|
#endif
|
|
|
|
|
2010-07-16 19:52:01 +04:00
|
|
|
#include <stdlib.h>
|
2012-04-25 00:34:03 +04:00
|
|
|
#include <fcntl.h>
|
2012-04-11 16:12:34 +04:00
|
|
|
|
2011-09-29 08:39:03 +04:00
|
|
|
extern "C"
|
2010-07-16 19:52:01 +04:00
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_putenv(JNIEnv *jenv, jclass, jstring map)
|
|
|
|
{
|
|
|
|
const char* str;
|
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
|
|
|
// better to do here
|
|
|
|
str = jenv->GetStringUTFChars(map, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
return;
|
|
|
|
putenv(strdup(str));
|
|
|
|
jenv->ReleaseStringUTFChars(map, str);
|
|
|
|
}
|
|
|
|
|
2011-12-01 06:28:04 +04:00
|
|
|
extern "C"
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
jobject JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_allocateDirectBuffer(JNIEnv *jenv, jclass, jlong size)
|
|
|
|
{
|
2012-05-10 21:15:56 +04:00
|
|
|
jobject buffer = NULL;
|
|
|
|
void* mem = malloc(size);
|
|
|
|
if (mem) {
|
|
|
|
buffer = jenv->NewDirectByteBuffer(mem, size);
|
|
|
|
if (!buffer)
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
return buffer;
|
2011-12-01 06:28:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
void JNICALL
|
|
|
|
Java_org_mozilla_gecko_GeckoAppShell_freeDirectBuffer(JNIEnv *jenv, jclass, jobject buf)
|
|
|
|
{
|
|
|
|
free(jenv->GetDirectBufferAddress(buf));
|
|
|
|
}
|