Skip to content
Permalink
Browse files

Fix PowerPC register dumping having compile errors on linux and OSX p…

…anther
  • Loading branch information...
UnknownShadow200 committed Jul 10, 2019
1 parent 7753ad8 commit 037115708417c2b14c68a177d3d1715096e344e7
Showing with 51 additions and 52 deletions.
  1. +38 −46 src/Http.c
  2. +13 −6 src/Logger.c
@@ -725,6 +725,22 @@ static void Http_SysFree(void) {
#include <jni.h>
struct HttpRequest* java_req;

static jobject MakeJavaString(JNIEnv* env, const String* str) {
String tmp; char tmpBuffer[1024];
String_InitArray_NT(tmp, tmpBuffer);

String_Copy(&tmp, str);
tmp.buffer[tmp.length] = '\0';
return (*env)->NewStringUTF(env, tmp.buffer);
}

static jbyteArray MakeJavaBytes(JNIEnv* env, const uint8_t* src, uint32_t len) {
if (!len) return NULL;
jbyteArray arr = (*env)->NewByteArray(env, len);
(*env)->SetByteArrayRegion(env, arr, 0, len, src);
return arr;
}

static void CallJavaVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
jclass clazz = (*env)->FindClass(env, "com/classicube/Wrappers");
jmethodID method = (*env)->GetStaticMethodID(env, clazz, name, sig);
@@ -738,24 +754,19 @@ static int CallJavaInt(JNIEnv* env, const char* name, const char* sig, jvalue* a
}

bool Http_DescribeError(ReturnCode res, String* dst) {
/* TODO: Retrieve from jni */
jni
}

static void Http_SysInit(void) { }

static void Http_AddHeader(const char* key, const String* value) {
String tmp; char tmpBuffer[1024];
JavaVM* vm = (JavaVM*)VM_Handle;
JNIEnv* env;
JavaVM* vm = (JavaVM*)VM_Handle; JNIEnv* env;
jvalue args[2];

String_InitArray_NT(tmp, tmpBuffer);
String_Copy(&tmp, value);
tmp.buffer[tmp.length] = '\0';

(*vm)->AttachCurrentThread(vm, &env, NULL);
args[0].l = (*env)->NewStringUTF(env, key);
args[1].l = (*env)->NewStringUTF(env, tmp.buffer);
args[1].l = MakeJavaString(env, value);

CallJavaVoid(env, "httpSetHeader", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", args);
(*env)->DeleteLocalRef(env, args[0].l);
@@ -786,54 +797,35 @@ static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpAppendData(JNIEnv
(*env)->ReleaseByteArrayElements(env, arr, src, JNI_ABORT);
}

/* Sets general curl options for a request */
static void Http_SetCurlOpts(struct HttpRequest* req) {
curl_easy_setopt(curl, CURLOPT_USERAGENT, GAME_APP_NAME);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
}

static ReturnCode Http_SysDo(struct HttpRequest* req) {
static const String userAgent = String_FromConst(GAME_APP_NAME);
java_req = req;
String url = String_FromRawArray(req->URL);
char urlStr[600];
void* post_data = req->Data;
long status = 0;
CURLcode res;
static const char* verbs[3] = { "GET", "HEAD", "POST" };

curl_easy_reset(curl);
headers_list = NULL;
Http_SetRequestHeaders(req);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers_list);
JavaVM* vm = (JavaVM*)VM_Handle; JNIEnv* env;
jvalue args[3];
String url;
jint res;

Http_SetCurlOpts(req);
Platform_ConvertString(urlStr, &url);
curl_easy_setopt(curl, CURLOPT_URL, urlStr);
(*vm)->AttachCurrentThread(vm, &env, NULL);
url = String_FromRawArray(req->URL);

if (req->RequestType == REQUEST_TYPE_HEAD) {
curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
} else if (req->RequestType == REQUEST_TYPE_POST) {
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, req->Size);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req->Data);
args[0].l = MakeJavaString(env, &url);
args[1].l = (*env)->NewStringUTF(env, verbs[req->RequestType]);
args[2].l = MakeJavaBytes(env, req->Data, req->Size);

/* per curl docs, we must persist POST data until request finishes */
req->Data = NULL;
HttpRequest_Free(req);
}
res = CallJavaInt(env, "httpInit", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;[B)I", args);
(*env)->DeleteLocalRef(env, args[0].l);
(*env)->DeleteLocalRef(env, args[1].l);
(*env)->DeleteLocalRef(env, args[2].l);

if (res) return res;
java_req = req;
Http_AddHeader("User-Agent", &userAgent);

bufferSize = 0;
http_curProgress = ASYNC_PROGRESS_FETCHING_DATA;
res = curl_easy_perform(curl);
res = CallJavaInt(env, "httpPerform", "()I", args);
http_curProgress = 100;

/* non-obsolete is CURLINFO_RESPONSE_CODE */
curl_easy_getinfo(curl, CURLINFO_HTTP_CODE, &status);
req->StatusCode = status;

curl_slist_free_all(headers_list);
/* can free now that request has finished */
Mem_Free(post_data);
return res;
}

@@ -407,7 +407,7 @@ String_Format4(str, "r16=%x r17=%x r18=%x r19=%x" _NL, REG_GNUM(16), REG_GNUM(17
String_Format4(str, "r20=%x r21=%x r22=%x r23=%x" _NL, REG_GNUM(20), REG_GNUM(21), REG_GNUM(22), REG_GNUM(23)); \
String_Format4(str, "r24=%x r25=%x r26=%x r27=%x" _NL, REG_GNUM(24), REG_GNUM(25), REG_GNUM(26), REG_GNUM(27)); \
String_Format4(str, "r28=%x r29=%x r30=%x r31=%x" _NL, REG_GNUM(28), REG_GNUM(29), REG_GNUM(30), REG_GNUM(31)); \
String_Format3(str, "pc =%x lr =%x ctr=%x" _NL, REG_GET(srr0, SRR0), REG_GET(lr, LR), REG_GET(ctr,CTR));
String_Format3(str, "pc =%x lr =%x ctr=%x" _NL, REG_GET_PC(), REG_GET_LR(), REG_GET_CTR());

#define Logger_Dump_ARM32() \
String_Format3(str, "r0 =%x r1 =%x r2 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2));\
@@ -462,7 +462,9 @@ static void Logger_PrintRegisters(String* str, void* ctx) {
Logger_Dump_X64()
#elif defined __ppc__
#define REG_GNUM(num) &r->__ss.__r##num
#define REG_GET(reg, ign) &r->__ss.__##reg
#define REG_GET_PC() &r->__ss.__srr0
#define REG_GET_LR() &r->__ss.__lr
#define REG_GET_CTR() &r->__ss.__ctr
Logger_Dump_PPC()
#else
#error "Unknown CPU architecture"
@@ -480,7 +482,9 @@ static void Logger_PrintRegisters(String* str, void* ctx) {
Logger_Dump_X64()
#elif defined __ppc__
#define REG_GNUM(num) &r->ss.r##num
#define REG_GET(reg, ign) &r->ss.##reg
#define REG_GET_PC() &r->ss.srr0
#define REG_GET_LR() &r->ss.lr
#define REG_GET_CTR() &r->ss.ctr
Logger_Dump_PPC()
#else
#error "Unknown CPU architecture"
@@ -502,9 +506,6 @@ static void Logger_PrintRegisters(String* str, void* ctx) {
#elif defined __x86_64__
#define REG_GET(ign, reg) &r.gregs[REG_R##reg]
Logger_Dump_X64()
#elif defined __PPC__
#define REG_GNUM(num) &r.gregs[num]
Logger_Dump_PPC()
#elif defined __aarch64__
#define REG_GNUM(num) &r.regs[num]
#define REG_GET(reg, ign) &r.##reg
@@ -516,6 +517,12 @@ static void Logger_PrintRegisters(String* str, void* ctx) {
#elif defined __sparc__
#define REG_GET(ign, reg) &r.gregs[REG_##reg]
Logger_Dump_SPARC()
#elif defined __PPC__
#define REG_GNUM(num) &r.gregs[num]
#define REG_GET_PC() &r.gregs[32]
#define REG_GET_LR() &r.gregs[35]
#define REG_GET_CTR() &r.gregs[34]
Logger_Dump_PPC()
#else
#error "Unknown CPU architecture"
#endif

0 comments on commit 0371157

Please sign in to comment.
You can’t perform that action at this time.