Skip to content

Commit

Permalink
[VP] Fix potential access violation in VP hal
Browse files Browse the repository at this point in the history
Fix potential access violation in VP hal.
  • Loading branch information
VickyZengg authored and intel-mediadev committed Sep 12, 2023
1 parent 376eac5 commit 5100218
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace vp
#define MAX_LAYER_COUNT VPHAL_MAX_SOURCES

class VpInterface;
class VpPipelineParamFactory;

struct FeatureSet
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
//! \brief Factories for vp object creation.
//!
#include "vp_obj_factories.h"
#include "vp_pipeline.h"
#include "sw_filter_handle.h"
using namespace vp;

Expand Down Expand Up @@ -218,11 +217,12 @@ MOS_STATUS SwFilterPipeFactory::Update(VP_PIPELINE_PARAMS &params, int index)
return MOS_STATUS_SUCCESS;
}

MOS_STATUS SwFilterPipeFactory::Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe*> &swFilterPipe)
MOS_STATUS SwFilterPipeFactory::Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe *> &swFilterPipe, VpPipelineParamFactory *pipelineParamFactory)
{
VP_FUNC_CALL();

VP_PUBLIC_CHK_NULL_RETURN(params);
VP_PUBLIC_CHK_NULL_RETURN(pipelineParamFactory);
int pipeCnt = GetPipeCountForProcessing(*params);
if (pipeCnt == 0)
{
Expand All @@ -233,14 +233,17 @@ MOS_STATUS SwFilterPipeFactory::Create(PVP_PIPELINE_PARAMS params, std::vector<S

for (int index = 0; index < pipeCnt; index++)
{
VP_PIPELINE_PARAMS tempParams = *params;
VP_PUBLIC_CHK_STATUS_RETURN(Update(tempParams, index));
VP_PIPELINE_PARAMS *tempParams = pipelineParamFactory->Clone(params);
VP_PUBLIC_CHK_NULL_RETURN(tempParams);
VP_PUBLIC_CHK_STATUS_RETURN(Update(*tempParams, index));

SwFilterPipe *pipe = m_allocator.Create();
VP_PUBLIC_CHK_NULL_RETURN(pipe);

FeatureRule featureRule;
MOS_STATUS status = pipe->Initialize(tempParams, featureRule);
MOS_STATUS status = pipe->Initialize(*tempParams, featureRule);

VP_PUBLIC_CHK_STATUS_RETURN(pipelineParamFactory->Destroy(tempParams));

if (MOS_FAILED(status))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class SwFilterPipeFactory
SwFilterPipeFactory(VpInterface &vpInterface);
virtual ~SwFilterPipeFactory();

MOS_STATUS Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe*> &swFilterPipe);
MOS_STATUS Create(PVP_PIPELINE_PARAMS params, std::vector<SwFilterPipe *> &swFilterPipe, VpPipelineParamFactory *pipelineParamFactory);
MOS_STATUS Create(VEBOX_SFC_PARAMS *params, std::vector<SwFilterPipe*> &swFilterPipe);

// Create empty swFilter
Expand Down
10 changes: 8 additions & 2 deletions media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ VpPipeline::~VpPipeline()
MOS_Delete(m_userFeatureControl);
m_vpMhwInterface.m_userFeatureControl = nullptr;
}
if (m_pipelineParamFactory)
{
MOS_Delete(m_pipelineParamFactory);
}
}

MOS_STATUS VpPipeline::GetStatusReport(void *status, uint16_t numStatus)
Expand Down Expand Up @@ -594,11 +598,10 @@ MOS_STATUS VpPipeline::UpdateExecuteStatus(uint32_t frameCnt)
MOS_STATUS VpPipeline::CreateSwFilterPipe(VP_PARAMS &params, std::vector<SwFilterPipe*> &swFilterPipe)
{
VP_FUNC_CALL();

switch (m_pvpParams.type)
{
case PIPELINE_PARAM_TYPE_LEGACY:
VP_PUBLIC_CHK_STATUS_RETURN(m_vpInterface->GetSwFilterPipeFactory().Create(m_pvpParams.renderParams, swFilterPipe));
VP_PUBLIC_CHK_STATUS_RETURN(m_vpInterface->GetSwFilterPipeFactory().Create(m_pvpParams.renderParams, swFilterPipe, m_pipelineParamFactory));
break;
case PIPELINE_PARAM_TYPE_MEDIA_SFC_INTERFACE:
VP_PUBLIC_CHK_STATUS_RETURN(m_vpInterface->GetSwFilterPipeFactory().Create(m_pvpParams.sfcParams, swFilterPipe));
Expand Down Expand Up @@ -742,6 +745,9 @@ MOS_STATUS VpPipeline::CreateFeatureManager(VpResourceManager *vpResourceManager

VP_PUBLIC_CHK_STATUS_RETURN(((VpFeatureManagerNext *)m_featureManager)->Init(nullptr));

m_pipelineParamFactory = MOS_New(VpPipelineParamFactory);
VP_PUBLIC_CHK_NULL_RETURN(m_pipelineParamFactory);

return MOS_STATUS_SUCCESS;
}

Expand Down
52 changes: 52 additions & 0 deletions media_softlet/agnostic/common/vp/hal/pipeline/vp_pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,57 @@ struct VP_PARAMS
};
};

class VpPipelineParamFactory
{
public:
VpPipelineParamFactory(){};
virtual ~VpPipelineParamFactory()
{
while (!m_Pool.empty())
{
PVP_PIPELINE_PARAMS param = m_Pool.back();
m_Pool.pop_back();
MOS_Delete(param);
}
}

virtual PVP_PIPELINE_PARAMS Clone(PVP_PIPELINE_PARAMS param)
{
PVP_PIPELINE_PARAMS paramDst = nullptr;

if (m_Pool.empty())
{
paramDst = MOS_New(VP_PIPELINE_PARAMS);
*paramDst = *param;
}
else
{
paramDst = m_Pool.back();
if (paramDst)
{
m_Pool.pop_back();
*paramDst = *param;
}
}
return paramDst;
}

virtual MOS_STATUS Destroy(PVP_PIPELINE_PARAMS &param)
{
if (param == nullptr)
{
return MOS_STATUS_SUCCESS;
}
m_Pool.push_back(param);
param = nullptr;
return MOS_STATUS_SUCCESS;
}

std::vector<PVP_PIPELINE_PARAMS> m_Pool;

MEDIA_CLASS_DEFINE_END(vp__VpPipelineParamFactory)
};

class VpPipeline : public MediaPipeline
{
public:
Expand Down Expand Up @@ -415,6 +466,7 @@ class VpPipeline : public MediaPipeline
VP_SETTINGS *m_vpSettings = nullptr;
VpUserFeatureControl *m_userFeatureControl = nullptr;
std::vector<VpSinglePipeContext *> m_vpPipeContexts = {};
VpPipelineParamFactory *m_pipelineParamFactory = nullptr;

MEDIA_CLASS_DEFINE_END(vp__VpPipeline)
};
Expand Down

0 comments on commit 5100218

Please sign in to comment.