2010-07-16 08:52:01 -07:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07: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 08:52:01 -07:00
|
|
|
|
|
|
|
#include <jni.h>
|
2012-04-11 05:12:34 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_MEMORY
|
2012-02-16 00:02:25 -08:00
|
|
|
// Wrap malloc and free to use jemalloc
|
|
|
|
#define malloc __wrap_malloc
|
|
|
|
#define free __wrap_free
|
2012-04-11 05:12:34 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-16 08:52:01 -07:00
|
|
|
#include <stdlib.h>
|
2012-04-24 13:34:03 -07:00
|
|
|
#include <fcntl.h>
|
2012-04-11 05:12:34 -07:00
|
|
|
|
2011-09-28 21:39:03 -07:00
|
|
|
extern "C"
|
2010-07-16 08:52:01 -07:00
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
void JNICALL
|
2013-02-07 06:37:06 -08:00
|
|
|
Java_org_mozilla_gecko_mozglue_GeckoLoader_putenv(JNIEnv *jenv, jclass, jstring map)
|
2010-07-16 08:52:01 -07:00
|
|
|
{
|
|
|
|
const char* str;
|
2012-07-31 15:54:29 -07:00
|
|
|
// XXX: java doesn't give us true UTF8, we should figure out something
|
2010-07-16 08:52:01 -07:00
|
|
|
// better to do here
|
|
|
|
str = jenv->GetStringUTFChars(map, NULL);
|
|
|
|
if (str == NULL)
|
|
|
|
return;
|
|
|
|
putenv(strdup(str));
|
|
|
|
jenv->ReleaseStringUTFChars(map, str);
|
|
|
|
}
|
|
|
|
|
2011-11-30 18:28:04 -08:00
|
|
|
extern "C"
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
jobject JNICALL
|
2012-07-31 15:54:29 -07:00
|
|
|
Java_org_mozilla_gecko_mozglue_DirectBufferAllocator_nativeAllocateDirectBuffer(JNIEnv *jenv, jclass, jlong size)
|
2011-11-30 18:28:04 -08:00
|
|
|
{
|
2012-05-10 10:15:56 -07:00
|
|
|
jobject buffer = NULL;
|
|
|
|
void* mem = malloc(size);
|
|
|
|
if (mem) {
|
|
|
|
buffer = jenv->NewDirectByteBuffer(mem, size);
|
|
|
|
if (!buffer)
|
|
|
|
free(mem);
|
|
|
|
}
|
|
|
|
return buffer;
|
2011-11-30 18:28:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
__attribute__ ((visibility("default")))
|
|
|
|
void JNICALL
|
2012-07-31 15:54:29 -07:00
|
|
|
Java_org_mozilla_gecko_mozglue_DirectBufferAllocator_nativeFreeDirectBuffer(JNIEnv *jenv, jclass, jobject buf)
|
2011-11-30 18:28:04 -08:00
|
|
|
{
|
|
|
|
free(jenv->GetDirectBufferAddress(buf));
|
|
|
|
}
|