Skip to content

Commit

Permalink
RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Oct 15, 2012
1 parent 76c3766 commit 450b054
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 0 deletions.
110 changes: 110 additions & 0 deletions RPC/RPC.cpp
@@ -0,0 +1,110 @@
#include <cstdio>
#include <cstring>
#include <algorithm>

template<size_t Size>
struct ArgmentData
{
ArgmentData() {}

template<typename T>
ArgmentData(const T &arg)
{
assert(sizeof(T) <= Size);
*((T*)data) = arg;
}

template<typename T, size_t S>
ArgmentData(const T (&arg)[S])
{
assert(sizeof(T)*s <= Size);
std::copy(arg, arg+S, (T*)data);
}

char data[Size];
};

enum ArgTypes {
ArgType_Int,
ArgType_Float,
ArgType_Other,
};

struct ArgmentTypeInfo
{
int type; // ArgTypes
int size;
};

struct APCInfo
{
char module_name[64];
void *function;
int num_args;
// ArgmentTypeInfo types[num_args];
// ArgmentData<types[0].size> data[0]
// ArgmentData<types[1].size> data[1]
// ...
};


template<typename Ret>
APCInfo* CreateRPCInfo(Ret (*f)())
{
size_t num_args = 0;
size_t alloc_size = sizeof(ArgmentTypeInfo) + sizeof(APCInfo)*num_args;
}

template<typename Ret, typename Arg1>
APCInfo* CreateRPCInfo(Ret (*f)(Arg1), Arg1 arg1)
{
size_t num_args = 1;
size_t alloc_size = sizeof(ArgmentTypeInfo) + sizeof(APCInfo)*num_args
+ sizeof(Arg1);
}

template<typename Ret, typename Arg1, typename Arg2>
APCInfo* CreateRPCInfo(Ret (*f)(Arg1, Arg2), Arg1 arg1, Arg2 arg2)
{
size_t num_args = 2;
size_t alloc_size = sizeof(ArgmentTypeInfo) + sizeof(APCInfo)*num_args
+ sizeof(Arg1) + sizeof(Arg2);
}

template<typename Ret, typename Arg1, typename Arg2, typename Arg3>
APCInfo* CreateRPCInfo(Ret (*f)(Arg1, Arg2, Arg3), Arg1 arg1, Arg2 arg2, Arg3 arg3)
{
size_t num_args = 3;
size_t alloc_size = sizeof(ArgmentTypeInfo) + sizeof(APCInfo)*num_args
+ sizeof(Arg1) + sizeof(Arg2) + sizeof(Arg3);
}

template<typename Ret, typename Arg1, typename Arg2, typename Arg3, typename Arg4>
APCInfo* CreateRPCInfo(Ret (*f)(Arg1, Arg2, Arg3, Arg4), Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4)
{
size_t num_args = 4;
size_t alloc_size = sizeof(ArgmentTypeInfo) + sizeof(APCInfo)*num_args
+ sizeof(Arg1) + sizeof(Arg2) + sizeof(Arg3) + sizeof(Arg4);
}

extern "C" void RPCCall(const void *args);



void TestFunc(void* arg1, short arg2, ArgmentData<8> arg3, float arg4)
{
printf("hoge\n");
}


int main()
{
struct Test {
void *fp;
const char *format;
size_t idata;
} testdata = {&printf, "data: %d\n", 100};
RPCCall(&testdata);

TestFunc(NULL, 10, ArgmentData<8>(), 10.0f);
}
10 changes: 10 additions & 0 deletions RPC/RPCCall_x64.asm
@@ -0,0 +1,10 @@
.code
RPCCall PROC
mov rax, rcx
mov rcx, qword ptr [rax + 08h]
mov rdx, qword ptr [rax + 010h]
mov r8, qword ptr [rax + 018h]
mov r9, qword ptr [rax + 018h]
jmp qword ptr [rax + 00h]
RPCCall ENDP
END
2 changes: 2 additions & 0 deletions RPC/make_x64.bat
@@ -0,0 +1,2 @@
ml64 /c RPCCall_x64.asm
cl /FaRPC.asm RPC.cpp RPCCall_x64.obj
15 changes: 15 additions & 0 deletions ReloadClass/after.cpp
Expand Up @@ -2,6 +2,21 @@
#define IMPLEMENT_MODULE
#include "module.h"

class Test
{
public:
Test()
{
printf("Test::Test()\n");
}

~Test()
{
printf("Test::~Test()\n");
}
} g_test;


DEFINE_MODULE_MEMFUN(void, Hoge, doSomething, ())
{
printf("Hoge::doSomethingImpl() after: %d\n", m_data);
Expand Down

0 comments on commit 450b054

Please sign in to comment.