Permalink
Browse files

Begin making use of TRAP_* for certain syscalls. Of these, validate m…

…emset, memcpy, memcmp and strncpy.

Initially, only those already defined or are in the standard C library.
  • Loading branch information...
1 parent 9bc3309 commit 17f1ecc99c60c601765c18f6380d894104734931 Darren Salt committed May 18, 2012
View
@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../qcommon/q_shared.h"
+#include "../qcommon/vm_traps.h"
#include "../renderer/tr_types.h"
#define CGAME_IMPORT_API_VERSION 3
@@ -70,7 +71,7 @@ typedef enum cgameEvent_e
typedef enum cgameImport_s
{
- CG_PRINT,
+ CG_PRINT = FIRST_VM_SYSCALL,
CG_ERROR,
CG_MILLISECONDS,
CG_CVAR_REGISTER,
@@ -181,16 +182,6 @@ typedef enum cgameImport_s
CG_KEY_GETKEY,
CG_KEY_GETOVERSTRIKEMODE,
CG_KEY_SETOVERSTRIKEMODE,
- CG_MEMSET,
- CG_MEMCPY,
- CG_STRNCPY,
- CG_SIN,
- CG_COS,
- CG_ATAN2,
- CG_SQRT,
- CG_FLOOR,
- CG_CEIL,
- CG_ACOS,
CG_PC_ADD_GLOBAL_DEFINE,
CG_PC_LOAD_SOURCE,
CG_PC_FREE_SOURCE,
@@ -206,8 +197,6 @@ typedef enum cgameImport_s
CG_CIN_DRAWCINEMATIC,
CG_CIN_SETEXTENTS,
CG_R_REMAP_SHADER,
- CG_TESTPRINTINT,
- CG_TESTPRINTFLOAT,
CG_LOADCAMERA,
CG_STARTCAMERA,
CG_STOPCAMERA,
@@ -250,9 +239,7 @@ typedef enum cgameImport_s
CG_COMPLETE_CALLBACK,
CG_REGISTER_BUTTON_COMMANDS,
CG_GETCLIPBOARDDATA,
- CG_MEMCMP,
- CG_ASIN,
- CG_GETTEXT = 300,
+ CG_GETTEXT,
CG_R_GLYPH,
CG_R_GLYPHCHAR,
CG_R_UREGISTERFONT
@@ -34,12 +34,6 @@ Maryland 20850 USA.
// cl_cgame.c -- client system interaction with client game
-#ifdef _MSC_VER
-#include "../../libs/msinttypes/inttypes.h"
-#else
-#include <inttypes.h>
-#endif
-
#include "client.h"
#include "libmumblelink.h"
@@ -1149,48 +1143,6 @@ intptr_t CL_CgameSystemCalls( intptr_t *args )
Key_SetOverstrikeMode( args[ 1 ] );
return 0;
- case CG_MEMCMP:
- return memcmp( VMA( 1 ), VMA( 2 ), args[ 3 ] );
-
- case CG_MEMSET:
- // we cannot return server-address to QVM !
- memset( VMA( 1 ), args[ 2 ], args[ 3 ] );
- return args[ 1 ];
-
- case CG_MEMCPY:
- // we cannot return server-address to QVM !
- memcpy( VMA( 1 ), VMA( 2 ), args[ 3 ] );
- return args[ 1 ];
-
- case CG_STRNCPY:
- // we cannot return server-address to QVM !
- strncpy( VMA( 1 ), VMA( 2 ), args[ 3 ] );
- return args[ 1 ];
-
- case CG_SIN:
- return FloatAsInt( sin( VMF( 1 ) ) );
-
- case CG_COS:
- return FloatAsInt( cos( VMF( 1 ) ) );
-
- case CG_ATAN2:
- return FloatAsInt( atan2( VMF( 1 ), VMF( 2 ) ) );
-
- case CG_SQRT:
- return FloatAsInt( sqrt( VMF( 1 ) ) );
-
- case CG_FLOOR:
- return FloatAsInt( floor( VMF( 1 ) ) );
-
- case CG_CEIL:
- return FloatAsInt( ceil( VMF( 1 ) ) );
-
- case CG_ASIN:
- return FloatAsInt( asin( VMF( 1 ) ) );
-
- case CG_ACOS:
- return FloatAsInt( Q_acos( VMF( 1 ) ) );
-
case CG_S_STOPBACKGROUNDTRACK:
S_StopBackgroundTrack();
return 0;
@@ -1223,14 +1175,6 @@ intptr_t CL_CgameSystemCalls( intptr_t *args )
re.RemapShader( VMA( 1 ), VMA( 2 ), VMA( 3 ) );
return 0;
- case CG_TESTPRINTINT:
- Com_Printf( "%s%" PRIiPTR "\n", ( char * ) VMA( 1 ), args[ 2 ] );
- return 0;
-
- case CG_TESTPRINTFLOAT:
- Com_Printf( "%s%f\n", ( char * ) VMA( 1 ), VMF( 2 ) );
- return 0;
-
case CG_LOADCAMERA:
//return loadCamera(args[1], VMA(2));
return 0;
View
@@ -1373,33 +1373,6 @@ intptr_t CL_UISystemCalls( intptr_t *args )
re.RegisterFontVM( VMA( 1 ), VMA( 2 ), args[ 3 ], VMA( 4 ) );
return 0;
- case UI_MEMSET:
- return ( intptr_t ) memset( VMA( 1 ), args[ 2 ], args[ 3 ] );
-
- case UI_MEMCPY:
- return ( intptr_t ) memcpy( VMA( 1 ), VMA( 2 ), args[ 3 ] );
-
- case UI_STRNCPY:
- return ( intptr_t ) strncpy( VMA( 1 ), VMA( 2 ), args[ 3 ] );
-
- case UI_SIN:
- return FloatAsInt( sin( VMF( 1 ) ) );
-
- case UI_COS:
- return FloatAsInt( cos( VMF( 1 ) ) );
-
- case UI_ATAN2:
- return FloatAsInt( atan2( VMF( 1 ), VMF( 2 ) ) );
-
- case UI_SQRT:
- return FloatAsInt( sqrt( VMF( 1 ) ) );
-
- case UI_FLOOR:
- return FloatAsInt( floor( VMF( 1 ) ) );
-
- case UI_CEIL:
- return FloatAsInt( ceil( VMF( 1 ) ) );
-
case UI_PARSE_ADD_GLOBAL_DEFINE:
return Parse_AddGlobalDefine( VMA( 1 ) );
@@ -1492,18 +1465,6 @@ intptr_t CL_UISystemCalls( intptr_t *args )
case UI_R_ANIMFRAMERATE:
return re.AnimFrameRate( args[ 1 ] );
#endif
- case UI_MEMCMP:
- return ( intptr_t ) memcmp( VMA( 1 ), VMA( 2 ), args[ 3 ] );
-
- case UI_ASIN:
- return FloatAsInt( asin( VMF( 1 ) ) );
-
- case UI_ATANF:
- return FloatAsInt( atan( VMF( 1 ) ) );
-
- case UI_TANF:
- return FloatAsInt( tan( VMF( 1 ) ) );
-
case UI_GETTEXT:
strncpy( VMA(1), VMA(2), args[3] );
return 0;
View
@@ -21,13 +21,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../qcommon/q_shared.h"
+#include "../qcommon/vm_traps.h"
#include "../renderer/tr_types.h"
#define UI_API_VERSION 4
typedef enum uiImport_s
{
- UI_ERROR,
+ UI_ERROR = FIRST_VM_SYSCALL,
UI_PRINT,
UI_MILLISECONDS,
UI_CVAR_REGISTER,
@@ -111,15 +112,6 @@ typedef enum uiImport_s
UI_GET_CDKEY,
UI_SET_CDKEY,
UI_R_REGISTERFONT,
- UI_MEMSET,
- UI_MEMCPY,
- UI_STRNCPY,
- UI_SIN,
- UI_COS,
- UI_ATAN2,
- UI_SQRT,
- UI_FLOOR,
- UI_CEIL,
UI_PARSE_ADD_GLOBAL_DEFINE,
UI_PARSE_LOAD_SOURCE,
UI_PARSE_FREE_SOURCE,
@@ -147,19 +139,15 @@ typedef enum uiImport_s
UI_GET_AUTOUPDATE,
UI_OPENURL,
UI_GETHUNKDATA,
-#if defined( USE_REFENTITY_ANIMATIONSYSTEM )
+//#if defined( USE_REFENTITY_ANIMATIONSYSTEM )
UI_R_REGISTERANIMATION,
UI_R_BUILDSKELETON,
UI_R_BLENDSKELETON,
UI_R_BONEINDEX,
UI_R_ANIMNUMFRAMES,
UI_R_ANIMFRAMERATE,
-#endif
- UI_MEMCMP,
- UI_ASIN,
- UI_ATANF,
- UI_TANF,
- UI_GETTEXT = 300,
+//#endif
+ UI_GETTEXT,
UI_R_GLYPH,
UI_R_GLYPHCHAR,
UI_R_UREGISTERFONT
@@ -378,6 +378,8 @@ VIRTUAL MACHINE
==============================================================
*/
+// See also vm_traps.h for syscalls common to all VMs
+
typedef struct vm_s vm_t;
typedef enum
@@ -389,28 +391,6 @@ typedef enum
VMI_COMPILED
} vmInterpret_t;
-// Comments in this enum are used by the QVM API scanner
-typedef enum sharedImport_s
-{
- TRAP_MEMSET = 300, // = memset
- TRAP_MEMCPY, // = memcpy
- TRAP_MEMCMP, // = memcmp
- TRAP_STRNCPY, // = strncpy
- TRAP_SIN, // = sin
- TRAP_COS, // = cos
- TRAP_ASIN, // = asin
- TRAP_ATAN2, // = atan2
- TRAP_SQRT, // = sqrt
- TRAP_MATRIXMULTIPLY, // unused
- TRAP_ANGLEVECTORS, // unused
- TRAP_PERPENDICULARVECTOR, // unused
- TRAP_FLOOR, // = floor
- TRAP_CEIL, // = ceil
-
- TRAP_TESTPRINTINT, // = testPrintInt
- TRAP_TESTPRINTFLOAT // = testPrintFloat
-} sharedTraps_t;
-
void VM_Init( void );
vm_t *VM_Create( const char *module, intptr_t ( *systemCalls )( intptr_t * ), vmInterpret_t interpret );
@@ -431,6 +411,8 @@ void VM_Debug( int level );
void *VM_ArgPtr( intptr_t intValue );
void *VM_ExplicitArgPtr( vm_t *vm, intptr_t intValue );
+intptr_t VM_SystemCall( intptr_t *args ); // common system calls
+
#define VMA(x) VM_ArgPtr(args[ x ])
static ID_INLINE float _vmf( intptr_t x )
{
Oops, something went wrong.

0 comments on commit 17f1ecc

Please sign in to comment.