From: John Hodge Date: Fri, 10 Dec 2010 04:57:57 +0000 (+0800) Subject: AcessNative - ld-acess initial commmit (non-compile) X-Git-Tag: rel0.07~37 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=824973b161a176419750512e62a3385e4f4419b1;p=tpg%2Facess2.git AcessNative - ld-acess initial commmit (non-compile) --- diff --git a/AcessNative/ld-acess.so_src/Makefile b/AcessNative/ld-acess.so_src/Makefile new file mode 100644 index 00000000..3531f710 --- /dev/null +++ b/AcessNative/ld-acess.so_src/Makefile @@ -0,0 +1,31 @@ +# +# + +ifeq ($(PLATFORM),) + PLATFORM := lin +endif + +OBJ := syscalls.$(PLATFORM).o request.$(PLATFORM).o + +ifeq ($(PLATFORM),win) + BIN := ../libacess.dll +endif +ifeq ($(PLATFORM),lin) + BIN := ../libacess.so + CFLAGS += -fPIC +endif + + +.PHONY: all clean + +all: $(BIN) + +clean: + $(RM) $(BIN) $(OBJ) + +$(BIN): $(OBJ) + $(CC) -shared -o $@ $< + +%.$(PLATFORM).o: %.c + $(CC) -c $< -o $@ $(CFLAGS) $(CPPFLAGS) + diff --git a/AcessNative/ld-acess.so_src/request.c b/AcessNative/ld-acess.so_src/request.c new file mode 100644 index 00000000..5a641194 --- /dev/null +++ b/AcessNative/ld-acess.so_src/request.c @@ -0,0 +1,70 @@ +/* + */ +#include +#include +#include + +#define SERVER_PORT 0xACE + +// === GLOBALS === +#ifdef __WIN32__ +WSADATA gWinsock; +SOCKET gSocket; +#endif + +// === CODE === +int _InitSyscalls() +{ + struct sockaddr_in server; + struct sockaddr_in client; + + #ifdef __WIN32__ + /* Open windows connection */ + if (WSAStartup(0x0101, &gWinsock) != 0) + { + fprintf(stderr, "Could not open Windows connection.\n"); + exit(0); + } + #endif + + // Open UDP Connection + gSocket = socket(AF_INET, SOCK_DGRAM, 0); + if (gSocket == INVALID_SOCKET) + { + fprintf(stderr, "Could not create socket.\n"); + WSACleanup(); + exit(0); + } + + // Set server address + memset((void *)&server, '\0', sizeof(struct sockaddr_in)); + server.sin_family = AF_INET; + server.sin_port = htons(SERVER_PORT); + server.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127; + server.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0; + server.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0; + server.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1; + + // Set client address + memset((void *)&client, '\0', sizeof(struct sockaddr_in)); + client.sin_family = AF_INET; + client.sin_port = htons(0); + client.sin_addr.S_un.S_un_b.s_b1 = (unsigned char)127; + client.sin_addr.S_un.S_un_b.s_b2 = (unsigned char)0; + client.sin_addr.S_un.S_un_b.s_b3 = (unsigned char)0; + client.sin_addr.S_un.S_un_b.s_b4 = (unsigned char)1; + + // Bind + if( bind(gSocket, (struct sockaddr *)&client, sizeof(struct sockaddr_in)) == -1 ) + { + fprintf(stderr, "Cannot bind address to socket.\n"); + closesocket(gSocket); + WSACleanup(); + exit(0); + } +} + +int _Syscall(const char *ArgTypes, ...) +{ + return 0; +} diff --git a/AcessNative/ld-acess.so_src/syscalls.c b/AcessNative/ld-acess.so_src/syscalls.c new file mode 100644 index 00000000..35fa6aeb --- /dev/null +++ b/AcessNative/ld-acess.so_src/syscalls.c @@ -0,0 +1,55 @@ +/* + */ +//#include +#include +#include +#include + +// === IMPORTS === +/** + * \param ArgTypes + * + * Whitespace is ignored + * >i: Input Integer + * >I: Input Long Integer (64-bits) + * >s: Input String + * >d: Input Buffer (Preceded by valid size) + * s >i", Path, Flags); +} + +void close(int FD) { + _Syscall(">i", FD); +} + +size_t read(int FD, size_t Bytes, void *Dest) { + return _Syscall(">i >i i >i >d", FD, Bytes, Bytes, Src); +} + +uint64_t tell(int FD) { + uint64_t ret; + _Syscall("i", &ret, FD); + return ret; +} + +int seek(int FD, uint64_t Ofs, int Dir) { + return _Syscall(">i >I >i", FD, Ofs, Dir); +} +