AcessNative - ld-acess initial commmit (non-compile)
authorJohn Hodge <[email protected]>
Fri, 10 Dec 2010 04:57:57 +0000 (12:57 +0800)
committerJohn Hodge <[email protected]>
Fri, 10 Dec 2010 04:57:57 +0000 (12:57 +0800)
AcessNative/ld-acess.so_src/Makefile [new file with mode: 0644]
AcessNative/ld-acess.so_src/request.c [new file with mode: 0644]
AcessNative/ld-acess.so_src/syscalls.c [new file with mode: 0644]

diff --git a/AcessNative/ld-acess.so_src/Makefile b/AcessNative/ld-acess.so_src/Makefile
new file mode 100644 (file)
index 0000000..3531f71
--- /dev/null
@@ -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 (file)
index 0000000..5a64119
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ */
+#include <windows.h>
+#include <stdio.h>
+#include <winsock.h>
+
+#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 (file)
index 0000000..35fa6ae
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ */
+//#include <acess/sys.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+// === 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)
+ * <I: Output long integer
+ * <d: Output Buffer (Preceded by valid size)
+ */
+int _Syscall(const char *ArgTypes, ...)
+{
+        int    outBufSize = 0;
+       va_list args;
+       
+       va_start(args, ArgTypes);
+       va_end(args);
+       
+}
+
+int open(const char *Path, int Flags) {
+       return _Syscall(">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 <d", FD, Bytes, Bytes, Dest);
+}
+
+size_t write(int FD, size_t Bytes, void *Src) {
+       return _Syscall(">i >i >d", FD, Bytes, Bytes, Src);
+}
+
+uint64_t tell(int FD) {
+       uint64_t        ret;
+       _Syscall("<I >i", &ret, FD);
+       return ret;
+}
+
+int seek(int FD, uint64_t Ofs, int Dir) {
+       return _Syscall(">i >I >i", FD, Ofs, Dir);
+}
+

UCC git Repository :: git.ucc.asn.au