Skip to content

Commit

Permalink
mmal: Allow /dev/vchiq to be opened initialised prior to mmal_vc_init
Browse files Browse the repository at this point in the history
This avoids an issue with Chromium sandbox
  • Loading branch information
popcornmix committed Aug 10, 2016
1 parent a63658c commit ca1243e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
5 changes: 5 additions & 0 deletions interface/mmal/vc/mmal_vc_api.h
Expand Up @@ -145,7 +145,12 @@ typedef enum
MMAL_STATS_INVALID = 0x7fffffff
} MMAL_STATS_RESULT_T;

/* If opening dev_vchiq outside mmal/vchiq this is the file path and mode */
#define MMAL_DEV_VCHIQ_PATH "/dev/vchiq"
#define MMAL_DEV_VCHIQ_MODE O_RDWR

MMAL_STATUS_T mmal_vc_init(void);
MMAL_STATUS_T mmal_vc_init_fd(int dev_vchiq_fd);
void mmal_vc_deinit(void);

MMAL_STATUS_T mmal_vc_use(void);
Expand Down
9 changes: 7 additions & 2 deletions interface/mmal/vc/mmal_vc_client.c
Expand Up @@ -693,7 +693,7 @@ MMAL_STATUS_T mmal_vc_release(void)
return status;
}

MMAL_STATUS_T mmal_vc_init(void)
MMAL_STATUS_T mmal_vc_init_fd(int dev_vchiq_fd)
{
VCHIQ_SERVICE_PARAMS_T vchiq_params;
MMAL_BOOL_T vchiq_initialised = 0, waitpool_initialised = 0;
Expand All @@ -717,7 +717,7 @@ MMAL_STATUS_T mmal_vc_init(void)
vcos_log_register("mmalipc", VCOS_LOG_CATEGORY);

/* Initialise a VCHIQ instance */
vchiq_status = vchiq_initialise(&mmal_vchiq_instance);
vchiq_status = vchiq_initialise_fd(&mmal_vchiq_instance, dev_vchiq_fd);
if (vchiq_status != VCHIQ_SUCCESS)
{
LOG_ERROR("failed to initialise vchiq");
Expand Down Expand Up @@ -792,6 +792,11 @@ MMAL_STATUS_T mmal_vc_init(void)
return status;
}

MMAL_STATUS_T mmal_vc_init(void)
{
return mmal_vc_init_fd(-1);
}

void mmal_vc_deinit(void)
{
int count;
Expand Down
1 change: 1 addition & 0 deletions interface/vchiq_arm/vchiq_if.h
Expand Up @@ -132,6 +132,7 @@ typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void* cb_arg);


extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
extern VCHIQ_STATUS_T vchiq_initialise_fd(VCHIQ_INSTANCE_T *pinstance, int dev_vchiq_fd);
extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
Expand Down
26 changes: 20 additions & 6 deletions interface/vchiq_arm/vchiq_lib.c
Expand Up @@ -85,7 +85,7 @@ vcos_static_assert(IS_POWER_2(VCHIQ_MAX_INSTANCE_SERVICES));

/* Local utility functions */
static VCHIQ_INSTANCE_T
vchiq_lib_init(void);
vchiq_lib_init(const int dev_vchiq_fd);

static void *completion_thread(void *);

Expand Down Expand Up @@ -137,12 +137,18 @@ find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
* VCHIQ API
*/

// If dev_vchiq_fd == -1 then /dev/vchiq will be opened by this fn (as normal)
//
// Otherwise the given fd will be used. N.B. in this case the fd is duped
// so the caller will probably want to close whatever fd was passed once
// this call has returned. This slightly odd behaviour makes shutdown and
// error cases much simpler.
VCHIQ_STATUS_T
vchiq_initialise(VCHIQ_INSTANCE_T *pinstance)
vchiq_initialise_fd(VCHIQ_INSTANCE_T *pinstance, int dev_vchiq_fd)
{
VCHIQ_INSTANCE_T instance;

instance = vchiq_lib_init();
instance = vchiq_lib_init(dev_vchiq_fd);

vcos_log_trace( "%s: returning instance handle %p", __func__, instance );

Expand All @@ -151,6 +157,12 @@ vchiq_initialise(VCHIQ_INSTANCE_T *pinstance)
return (instance != NULL) ? VCHIQ_SUCCESS : VCHIQ_ERROR;
}

VCHIQ_STATUS_T
vchiq_initialise(VCHIQ_INSTANCE_T *pinstance)
{
vchiq_initialise_fd(pinstance, -1);
}

VCHIQ_STATUS_T
vchiq_shutdown(VCHIQ_INSTANCE_T instance)
{
Expand Down Expand Up @@ -1083,7 +1095,7 @@ vchi_initialise( VCHI_INSTANCE_T *instance_handle )
{
VCHIQ_INSTANCE_T instance;

instance = vchiq_lib_init();
instance = vchiq_lib_init(-1);

vcos_log_trace( "%s: returning instance handle %p", __func__, instance );

Expand Down Expand Up @@ -1405,7 +1417,7 @@ VCHIQ_STATUS_T vchiq_dump_phys_mem( VCHIQ_SERVICE_HANDLE_T handle,
*/

static VCHIQ_INSTANCE_T
vchiq_lib_init(void)
vchiq_lib_init(const int dev_vchiq_fd)
{
static int mutex_initialised = 0;
static VCOS_MUTEX_T vchiq_lib_mutex;
Expand All @@ -1427,7 +1439,9 @@ vchiq_lib_init(void)

if (instance->initialised == 0)
{
instance->fd = open("/dev/vchiq", O_RDWR);
instance->fd = dev_vchiq_fd == -1 ?
open("/dev/vchiq", O_RDWR) :
dup(dev_vchiq_fd);
if (instance->fd >= 0)
{
VCHIQ_GET_CONFIG_T args;
Expand Down

0 comments on commit ca1243e

Please sign in to comment.