From: John Hodge Date: Sun, 22 Aug 2010 02:41:05 +0000 (+0800) Subject: Just cleaning up some things that may be needed in the tree X-Git-Tag: rel0.06~49 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=7edeed66f89e03c3de5fb7d3b41421f23c1bc4f7;p=tpg%2Facess2.git Just cleaning up some things that may be needed in the tree --- diff --git a/Usermode/Applications/bomb_src/Makefile b/Usermode/Applications/bomb_src/Makefile new file mode 100644 index 00000000..b4483c02 --- /dev/null +++ b/Usermode/Applications/bomb_src/Makefile @@ -0,0 +1,9 @@ +# Project: bomb + +-include ../Makefile.cfg + +OBJ = main.o +BIN = ../bomb + +-include ../Makefile.tpl + diff --git a/Usermode/Applications/bomb_src/main.c b/Usermode/Applications/bomb_src/main.c new file mode 100644 index 00000000..f9ecfa0b --- /dev/null +++ b/Usermode/Applications/bomb_src/main.c @@ -0,0 +1,53 @@ +/* + * Acess2 Stress Tester + */ +#include +#include +#include + + //int giMallocSize = 1024; + int gbOverrideCOW = 0; + int gbForkBomb = 0; + +/** + * \fn int main(int argc, char *argv[]) + * \brief Entrypoint + */ +int main(int argc, char *argv[]) +{ + int i; + + for( i = 1; i < argc; i ++ ) + { + if( argv[i][0] != '-' ) { + //PrintUsage(argv[0]); + return 1; + } + + switch( argv[i][0] ) + { + case 'f': + gbForkBomb = 1; + break; + case 'c': + gbOverrideCOW = 1; + break; + //case 'm': + // giMallocSize = atoi(argv[++i]); + // break; + case 'h': + //PrintHelp(argv[0]); + return 0; + } + } + + if( gbForkBomb ) + { + for(;;) clone(CLONE_VM, 0); + } + else { + for(;;) clone(0, malloc(512-16)+512-16); + } + + return 0; +} diff --git a/Usermode/Applications/testclient_src/Makefile b/Usermode/Applications/testclient_src/Makefile new file mode 100644 index 00000000..33526835 --- /dev/null +++ b/Usermode/Applications/testclient_src/Makefile @@ -0,0 +1,9 @@ +# Project: testclient + +-include ../Makefile.cfg + +OBJ = main.o +BIN = ../testclient + +-include ../Makefile.tpl + diff --git a/Usermode/Applications/testclient_src/main.c b/Usermode/Applications/testclient_src/main.c new file mode 100644 index 00000000..5682a8d7 --- /dev/null +++ b/Usermode/Applications/testclient_src/main.c @@ -0,0 +1,50 @@ +/* + * Acess2 Test Client + */ +#include +#include +#include + +/** + * \fn int main(int argc, char *argv[]) + * \brief Entrypoint + */ +int main(int argc, char *argv[]) +{ + int con = -1; + int len; + uint16_t port; + uint8_t buf[4] = {10,0,2,1}; + uint8_t data[4096]; // Packet Data + + con = open("/Devices/ip/1/tcpc", OPENFLAG_READ|OPENFLAG_WRITE); + if(con == -1) { + fprintf(stderr, "Unable top open TCP client '/Devices/ip/1/tcpc'\n"); + return -1; + } + + port = 80; ioctl(con, 5, &port); // Set Remote Port + ioctl(con, 6, buf); // Set remote IP + ioctl(con, 7, NULL); // Connect + + #define REQ_STR "GET / HTTP/1.1\r\n"\ + "Host: prelude\r\n"\ + "User-Agent: Acess2 TCP Test Client\r\n"\ + "\r\n" + + write(con, sizeof(REQ_STR)-1, REQ_STR); + + len = read(con, 4096, data); + close(con); + if( len == -1 ) { + printf("Connection closed on us\n"); + return 0; + } + if( len != 0 ) + { + printf("Packet Data: (%i bytes)\n", len); + printf("%s\n", data); + printf("--- EOP ---\n"); + } + return 0; +} diff --git a/Usermode/Libraries/libimage_sif.so_src/Makefile b/Usermode/Libraries/libimage_sif.so_src/Makefile new file mode 100644 index 00000000..b4b94e20 --- /dev/null +++ b/Usermode/Libraries/libimage_sif.so_src/Makefile @@ -0,0 +1,13 @@ +# Acess 2 +# + +include ../Makefile.cfg + +CPPFLAGS += +CFLAGS += -Wall +LDFLAGS += -lc -soname libimage_sif.so + +OBJ = main.o +BIN = ../libimage_sif.so + +include ../Makefile.tpl diff --git a/Usermode/Libraries/libimage_sif.so_src/main.c b/Usermode/Libraries/libimage_sif.so_src/main.c new file mode 100644 index 00000000..455d3bce --- /dev/null +++ b/Usermode/Libraries/libimage_sif.so_src/main.c @@ -0,0 +1,165 @@ +/* + */ +#include +#include +#include +#include +#include +//#include + +// === CODE === +int SoMain(void) +{ + return 0; +} + +/** + */ +tImage *Image_SIF_Parse(void *Buffer, size_t Size) +{ + uint16_t magic; + uint16_t flags; + uint16_t w, h; + int ofs, i; + tImage_SIF *ret; + int bRevOrder; + int fileOfs = 0; + int comp, fmt; + int sampleSize = 4; + + // Get magic word and determine byte ordering + magic = *(uint16_t*)Buffer+fileOfs; fileOfs += 2; + if(magic == 0x51F0) + bRevOrder = 0; + else if(magic == 0xF051) + bRevOrder = 1; + else { + return NULL; + } + + // Read flags + flags = *(uint16_t*)Buffer+fileOfs; fileOfs += 2; + comp = flags & 7; + fmt = (flags >> 3) & 7; + + // Read dimensions + w = *(uint16_t*)Buffer+fileOfs; fileOfs += 2; + h = *(uint16_t*)Buffer+fileOfs; fileOfs += 2; + + + // Allocate space + ret = calloc(1, sizeof(tImage) + w * h * sampleSize); + ret->Width = w; + ret->Height = h; + + // Get image format + switch(fmt) + { + case 0: // ARGB + ret->Format = IMGFMT_ARGB; + sampleSize = 4; + break; + case 1: // RGB + ret->Format = IMGFMT_RGB; + sampleSize = 3; + break; + default: + free(ret); + return NULL; + } + + switch(comp) + { + // Uncompressed 32-bpp data + case 0: + if( fileOfs + w*h*sampleSize > Size ) { + memcpy(ret->Data, Buffer+fileOfs, Size-fileOfs); + } + else { + memcpy(ret->Data, Buffer+fileOfs, w*h*sampleSize); + } + return ret; + + // 1.7.n*8 RLE + // (1 Flag, 7-bit size, 32-bit value) + case 1: + ofs = 0; + while( ofs < w*h ) + { + uint8_t len; + if( fileOfs + 1 > Size ) return ret; + len = *(uint8_t*)Buffer+fileOfs; fileOfs += 1; + if(len & 0x80) { + len &= 0x7F; + if( fileOfs + len*sampleSize > Size ) { + memcpy(ret->Data + ofs*sampleSize, Buffer+fileOfs, Size-fileOfs); + return ret; + } + else { + memcpy(ret->Data + ofs*sampleSize, Buffer+fileOfs, len*sampleSize); + } + ofs += len; + } + else { + uint8_t tmp[sampleSize]; + + if( fileOfs + sampleSize > Size ) return ret; + + for(i=0;iData[ofs++] = tmp[i]; + } + } + } + return ret; + + // Channel 1.7.8 RLE + case 3: + // Alpha, Red, Green, Blue + for( i = 0; i < sampleSize; i++ ) + { + ofs = i; + while( ofs < w*h*sampleSize ) + { + uint8_t len, val; + if( fileOfs + 1 > Size ) return ret; + len = *(uint8_t*)Buffer+fileOfs; fileOfs += 1; + if(len & 0x80) { + len &= 0x7F; + while(len--) { + if( fileOfs + 1 > Size ) return ret; + val = *(uint8_t*)Buffer+fileOfs; fileOfs += 1; + if(i == 0) + ret->Data[ofs] = val; + else + ret->Data[ofs] |= val; + ofs += sampleSize; + } + } + else { + if( fileOfs + 1 > Size ) return ret; + val = *(uint8_t*)Buffer+fileOfs; fileOfs += 1; + if(i == 0) { + while(len--) { + ret->Data[ofs] = val; ofs += sampleSize; + } + } + else { + while(len--) { + ret->Data[ofs] |= val; ofs += sampleSize; + } + } + } + } + } + return ret; + + default: + fprintf(stderr, "Warning: Unknown compression scheme %i for SIF\n", comp); + return NULL; + } +} diff --git a/Usermode/include/spiderscript.h b/Usermode/include/spiderscript.h new file mode 100644 index 00000000..9d15d35f --- /dev/null +++ b/Usermode/include/spiderscript.h @@ -0,0 +1,186 @@ +/* + * + */ +#ifndef _SPIDERSCRIPT_H_ +#define _SPIDERSCRIPT_H_ + +#include + +#define ERRPTR ((void*)((intptr_t)0-1)) + +/** + * \brief Opaque script handle + */ +typedef struct sSpiderScript tSpiderScript; + +/** + * \brief Variant type + */ +typedef struct sSpiderVariant tSpiderVariant; +typedef struct sSpiderFunction tSpiderFunction; +typedef struct sSpiderValue tSpiderValue; +typedef struct sSpiderObjectDef tSpiderObjectDef; +typedef struct sSpiderObject tSpiderObject; + + +/** + * \brief SpiderScript Variable Datatypes + */ +enum eSpiderScript_DataTypes +{ + SS_DATATYPE_UNDEF, //!< Undefined + SS_DATATYPE_NULL, //!< NULL (Probably will never be used) + SS_DATATYPE_DYNAMIC, //!< Dynamically typed variable (will this be used?) + SS_DATATYPE_OBJECT, //!< Opaque object reference + SS_DATATYPE_ARRAY, //!< Array + SS_DATATYPE_INTEGER, //!< Integer (64-bits) + SS_DATATYPE_REAL, //!< Real Number (double) + SS_DATATYPE_STRING, //!< String + NUM_SS_DATATYPES +}; + +/** + * \brief Variant of SpiderScript + */ +struct sSpiderVariant +{ + const char *Name; // Just for debug + + int bDyamicTyped; + + int NFunctions; //!< Number of functions + tSpiderFunction *Functions; //!< Functions + + int NConstants; //!< Number of constants + tSpiderValue *Constants; //!< Number of constants +}; + +/** + * \brief SpiderScript data object + */ +struct sSpiderValue +{ + int Type; //!< Variable type + int ReferenceCount; //!< Reference count + + union { + uint64_t Integer; //!< Integer data + double Real; //!< Real Number data + /** + * \brief String data + */ + struct { + int Length; //!< Length + char Data[]; //!< Actual string (\a Length bytes) + } String; + /** + * \brief Variable data + */ + struct { + int Length; //!< Length of the array + tSpiderValue *Items[]; //!< Array elements (\a Length long) + } Array; + + tSpiderObject *Object; + }; +}; + +/** + * \brief Object Definition + * + * Internal representation of an arbitary object. + */ +struct sSpiderObjectDef +{ + /** + * \brief Construct an instance of the object + * \param NArgs Number of arguments + * \param Args Argument count + * \return Pointer to an object instance (which must be fully valid) + * \retval NULL Invalid parameter (usually, actually just a NULL value) + * \retval ERRPTR Invalid parameter count + */ + tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args); + + /** + * \brief Clean up and destroy the object + * \param This Object instace + * \note The object pointer (\a This) should be invalidated and freed + * by this function. + */ + void (*Destructor)(tSpiderObject *This); + + int NAttributes; //!< Number of attributes + + //! Attribute definitions + struct { + const char *Name; //!< Attribute Name + int bReadOnly; //!< Allow writes to the attribute? + } *AttributeDefs; + + + int NMethods; //!< Number of methods + tSpiderFunction *Methods; //!< Method Definitions +}; + +/** + * \brief Object Instance + */ +struct sSpiderObject +{ + tSpiderObjectDef *Type; //!< Object Type + int NReferences; //!< Number of references + void *OpaqueData; //!< Pointer to the end of the \a Attributes array + tSpiderValue *Attributes[]; //!< Attribute Array +}; + +/** + * \brief Represents a function avaliable to a script + */ +struct sSpiderFunction +{ + /** + * \brief Function name + */ + const char *Name; + /** + * \brief Function handler + */ + tSpiderValue *(*Handler)(tSpiderScript *Script, int nParams, tSpiderValue **Parameters); + /** + * \brief Argument types + * + * Zero or -1 terminated array of \a eSpiderScript_DataTypes. + * If the final entry is zero, the function has a fixed number of + * parameters, if the final entry is -1, the function has a variable + * number of arguments. + */ + int *ArgTypes; // Zero (or -1) terminated array of parameter types +}; + + +// === FUNCTIONS === +/** + * \brief Parse a file into a script + * \param Variant Variant structure + * \param Filename File to parse + * \return Script suitable for execution + */ +extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename); +/** + * \brief Execute a method from a script + * \param Script Script to run + * \param Function Name of function to run ("" for the 'main') + * \return Return value + */ +extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script, + const char *Function, + int NArguments, tSpiderValue **Arguments + ); + +/** + * \brief Free a script + */ +extern void SpiderScript_Free(tSpiderScript *Script); + +#endif