@ -116,21 +116,26 @@ static bool initialized = false;
static int initialize_environment ( )
static int initialize_environment ( )
{
{
if ( ! initialized ) {
if ( ! initialized ) {
EGLBoolean ok ;
// Force SW rendering unless env variable is already set.
// Force SW rendering unless env variable is already set.
setenv ( SWRAST_ENV , " true " , 0 ) ;
setenv ( SWRAST_ENV , " true " , 0 ) ;
cookie . display = eglGetDisplay ( EGL_DEFAULT_DISPLAY ) ;
cookie . display = eglGetDisplay ( EGL_DEFAULT_DISPLAY ) ;
assert ( cookie . display ! = EGL_NO_DISPLAY ) ;
assert ( cookie . display ! = EGL_NO_DISPLAY ) ;
assert ( eglInitialize ( cookie . display , NULL , NULL ) ) ;
ok = eglInitialize ( cookie . display , NULL , NULL ) ;
assert ( ok ) ;
const EGLint config_attribs [ ] = { EGL_SURFACE_TYPE , EGL_DONT_CARE ,
const EGLint config_attribs [ ] = { EGL_SURFACE_TYPE , EGL_DONT_CARE ,
EGL_NONE } ;
EGL_NONE } ;
EGLint num_configs ;
EGLint num_configs ;
assert ( eglChooseConfig ( cookie . display , config_attribs ,
ok = eglChooseConfig ( cookie . display , config_attribs ,
& cookie . egl_config , 1 , & num_configs ) ) ;
& cookie . egl_config , 1 , & num_configs ) ;
assert ( ok ) ;
assert ( eglBindAPI ( EGL_OPENGL_ES_API ) ) ;
ok = eglBindAPI ( EGL_OPENGL_ES_API ) ;
assert ( ok ) ;
const EGLint context_attribs [ ] = { EGL_CONTEXT_CLIENT_VERSION , 3 ,
const EGLint context_attribs [ ] = { EGL_CONTEXT_CLIENT_VERSION , 3 ,
EGL_NONE } ;
EGL_NONE } ;
@ -138,8 +143,9 @@ static int initialize_environment()
EGL_NO_CONTEXT , context_attribs ) ;
EGL_NO_CONTEXT , context_attribs ) ;
assert ( cookie . ctx ! = EGL_NO_CONTEXT ) ;
assert ( cookie . ctx ! = EGL_NO_CONTEXT ) ;
assert ( eglMakeCurrent ( cookie . display , EGL_NO_SURFACE , EGL_NO_SURFACE ,
ok = eglMakeCurrent ( cookie . display , EGL_NO_SURFACE , EGL_NO_SURFACE ,
cookie . ctx ) ) ;
cookie . ctx ) ;
assert ( ok ) ;
initialized = true ;
initialized = true ;
}
}
@ -166,6 +172,7 @@ static void cleanup_environment()
int LLVMFuzzerTestOneInput ( const uint8_t * data , size_t size )
int LLVMFuzzerTestOneInput ( const uint8_t * data , size_t size )
{
{
uint32_t ctx_id = initialize_environment ( ) ;
uint32_t ctx_id = initialize_environment ( ) ;
int ret ;
// There are trade-offs here between ensuring that state is not persisted
// There are trade-offs here between ensuring that state is not persisted
// between invocations of virgl_renderer_submit_cmd, and to avoid leaking
// between invocations of virgl_renderer_submit_cmd, and to avoid leaking
@ -173,10 +180,12 @@ int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
// driver with each eglInitialize()/eglTerminate() if CLEANUP_EACH_INPUT
// driver with each eglInitialize()/eglTerminate() if CLEANUP_EACH_INPUT
// is set.
// is set.
assert ( ! virgl_renderer_init ( & cookie , 0 , & fuzzer_cbs ) ) ;
ret = virgl_renderer_init ( & cookie , 0 , & fuzzer_cbs ) ;
assert ( ! ret ) ;
const char * name = " fuzzctx " ;
const char * name = " fuzzctx " ;
assert ( ! virgl_renderer_context_create ( ctx_id , strlen ( name ) , name ) ) ;
ret = virgl_renderer_context_create ( ctx_id , strlen ( name ) , name ) ;
assert ( ! ret ) ;
virgl_renderer_submit_cmd ( ( void * ) data , ctx_id , size / sizeof ( uint32_t ) ) ;
virgl_renderer_submit_cmd ( ( void * ) data , ctx_id , size / sizeof ( uint32_t ) ) ;