ffos:gecko 内核之ProcLoader,进程加载器分析PProcLoader--ipdl

b2g与nuwa相互通信的具体ipdl源码分析:

ipdl机制分析:

PProcLoader.ipdl接口定义文件:

objdir-gecko/ipc/ipdl/PProcLoader
PProcLoaderChild.cpp  

PProcLoader.cpp       

PProcLoaderParent.cpp

 

接口文件:

 PProcLoader.ipdl

 

protocol PProcLoader
{
child:
  /**
   * Request B2G loader service to load content process.
   *
   * It actually calls the main() function of plugin-container.
   */
  async Load(nsCString[] argv, nsCString[] env,
             FDRemap[] fdsRemap, uint32_t privs,
             int32_t cookie);

//child send,parent那里有个recv

parent:
  /**
   * The acknowledgement of Load().
   */
  async LoadComplete(int32_t pid, int32_t cookie);

//这里parent send,child那边revc
};

故,有两对send ,recv

 

B2G loader service指的是nuwa那端吗?它会调用plugin-container的main()函数,

没错。

PProcLoaderChild.cpp  部分源码分析:

共享内存,send, recv,open

PProcLoaderChild::SendLoadComplete

PProcLoaderChild::GetIPCChannel()

  if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Send, PProcLoader::Msg_Load__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
 if ((!(RecvLoad(mozilla::Move(argv), mozilla::Move(env), mozilla::Move(fdsRemap), mozilla::Move(privs), mozilla::Move(cookie))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler for Load returned error code");
                return MsgProcessingError;
            }

PProcLoaderChild::Write()

PProcLoaderChild::Read()

 

 

PProcLoaderParent.cpp部分源码

PProcLoaderParent::PProcLoaderParent()

PProcLoaderParent::Open()

PProcLoaderParent::SendLoad()

PProcLoaderParent::CreateSharedMemory()

PProcLoaderParent::AdoptSharedMemory(

PProcLoaderParent::LookupSharedMemory(Shmem::id_t aId)

 PProcLoaderParent::OnMessageReceived(const Message& msg__){压根没收到消息,为什么???

 if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Recv, PProcLoader::Msg_LoadComplete__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvLoadComplete(mozilla::Move(pid), mozilla::Move(cookie))))) {//一直不能complete,使一直服务???
                mozilla::ipc::ProtocolErrorBreakpoint("Handler for LoadComplete returned error code");
                return MsgProcessingError;

            }

}

PProcLoaderParent::Write()

PProcLoaderParent::Read()

ipdl里的两个接口,

child: Load  //目的在于与加载某某某

parent: LoadComplete//目的是告诉child Load 结束了,完成了

 

child .cpp里实现的是SendLoadComplete以及它所接收的消息是RecvLoad,

parent.cpp里实现的是SendLoad  ,比较奇怪,它只发而似乎永远没收到RecvLoadComplete,OnMessageReceived都没执行,不知为何?

 

 

 

 

PProcLoader.cpp     源码分析,

//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/ipc/PProcLoader.h"

namespace mozilla {
namespace ipc {
namespace PProcLoader {

bool
Transition(//过渡
        State from,
        mozilla::ipc::Trigger trigger,
        State* next)
{
    switch (from) {
    case __Null:
    case __Error:
        return (__Null) == (from);
    case __Dead:
        NS_RUNTIMEABORT("__delete__()d actor");
        return false;
    case __Dying:
        NS_RUNTIMEABORT("__delete__()d (and unexpectedly dying) actor");
        return false;
    default:
        NS_RUNTIMEABORT("corrupted actor state");
        return false;
    }
}

} // namespace PProcLoader
} // namespace ipc
} // namespace mozilla

//-----------------------------------------------------------------------------
// Method definitions for the IPDL type |struct FDRemap|
//
namespace mozilla {
namespace ipc {
MOZ_IMPLICIT FDRemap::FDRemap() :
    mapto_()
{
    Init();
}

FDRemap::~FDRemap()
{
}

auto FDRemap::operator==(const FDRemap& _o) const -> bool
{
    if ((!((fd()) == ((_o).fd())))) {
        return false;
    }
    if ((!((mapto()) == ((_o).mapto())))) {
        return false;
    }
    return true;
}

auto FDRemap::Init() -> void
{
}

auto FDRemap::Assign(//分派,调派
        const FileDescriptor& _fd,
        const int& _mapto) -> void
{
    fd_ = _fd;
    mapto_ = _mapto;
}

} // namespace ipc
} // namespace mozilla

 

 

 

 

 

PProcLoaderChild.cpp  部分源码分析:

共享内存,send, recv,open

PProcLoaderChild::SendLoadComplete

PProcLoaderChild::GetIPCChannel()

PProcLoaderChild::OnMessageReceived(const Message& msg__){

if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Send, PProcLoader::Msg_Load__ID), (&(mState)))))) {}

if ((!(RecvLoad(mozilla::Move(argv), mozilla::Move(env), mozilla::Move(fdsRemap), mozilla::Move(privs), mozilla::Move(cookie)))))

{}

}

PProcLoaderChild::Write()

PProcLoaderChild::Read()

 

 

 

//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/ipc/PProcLoaderChild.h"
#ifdef MOZ_CRASHREPORTER
#  include "nsXULAppAPI.h"
#endif


#include "nsIFile.h"
#include "GeckoProfiler.h"

///
//personal debug switch//
/********************************************************************************
P_DEBUG:
0     turn off debug
1        turn on debug
 ********************************************************************************/
#ifndef P_LOGI

#include "utils/Log.h"
#define P_DEBUG    1
#if P_DEBUG
static char mark_label[64] = "pmain-PProcLoaderChild";
#define SEPARATOR_LINE "----------------------------------"
      #define STA_LINE ">>>>>>>>>>>>>>>>>>>>>>>>>>>st.func"
      #define END_LINE "<<<<<<<<<<<<<<<<<<<<<<<<<<<ed.func"
#define LONNG_LINE = "------------------------------------------------------------------------------"
//static char mark_label[18] = "";//for the label you wish to mark when you adb logcat or whatever
#define P_LOGI(fmt, ...) ALOGI("%s-,F:%s:%d, Fuc:%s  " fmt,mark_label,(char*)__FILE__,__LINE__,(char*)__FUNCTION__,##__VA_ARGS__)
//#define P_LOGI(fmt, ...) printf("%s-,F:%s:%d, Fuc:%s  " fmt,mark_label,(char*)__FILE__,__LINE__,(char*)__FUNCTION__,##__VA_ARGS__)
#else
#define P_LOGI(...)
#endif

#endif

///
    //P_LOGI(SEPARATOR_LINE);
///
namespace mozilla {
namespace ipc {


auto PProcLoaderChild::ActorDestroy(ActorDestroyReason aWhy) -> void
{
}

auto PProcLoaderChild::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PProcLoaderChild::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

auto PProcLoaderChild::EnteredCxxStack() -> void
{
}

auto PProcLoaderChild::ExitedCxxStack() -> void
{
}

auto PProcLoaderChild::EnteredCall() -> void
{
}

auto PProcLoaderChild::ExitedCall() -> void
{
}


MOZ_IMPLICIT PProcLoaderChild::PProcLoaderChild() : //用来初始化变量
    mozilla::ipc::IToplevelProtocol(PProcLoaderMsgStart),
    mChannel(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
    mLastRouteId(0),
    mOtherPid(mozilla::ipc::kInvalidProcessId),
    mLastShmemId(0),
    mState(PProcLoader::__Start)
{
    MOZ_COUNT_CTOR(PProcLoaderChild);
}


PProcLoaderChild::~PProcLoaderChild()
{
    MOZ_COUNT_DTOR(PProcLoaderChild);
}

auto PProcLoaderChild::Open(
        Channel::Transport* aTransport,
        base::ProcessId aOtherPid,
        MessageLoop* aThread,
        mozilla::ipc::Side aSide) -> bool
{
P_LOGI(SEPARATOR_LINE);
    mOtherPid = aOtherPid;
P_LOGI("call -- return (mChannel).Open(aTransport, aThread:XXXX, aSide:%d); --->", aSide);
    return (mChannel).Open(aTransport, aThread, aSide);
}

auto PProcLoaderChild::Open(//auto 返回值占位
        MessageChannel* aChannel,
        MessageLoop* aMessageLoop,
        mozilla::ipc::Side aSide) -> bool
{
P_LOGI(SEPARATOR_LINE);
    mOtherPid = base::GetCurrentProcId();
P_LOGI("call -- return (mChannel).Open(aChannel:XXXX, aMessageLoop:XXXXtype, aSide:%d); --->", aSide);
    return (mChannel).Open(aChannel, aMessageLoop, aSide);
}

auto PProcLoaderChild::Close() -> void
{
    (mChannel).Close();
}

auto PProcLoaderChild::state() -> PProcLoader::State
{
    return mState;
}

auto PProcLoaderChild::SendLoadComplete(
        const int32_t& pid,
        const int32_t& cookie) -> bool
{
    P_LOGI(SEPARATOR_LINE);
    PProcLoader::Msg_LoadComplete* msg__ = new PProcLoader::Msg_LoadComplete(MSG_ROUTING_CONTROL);

    Write(pid, msg__);
    Write(cookie, msg__);


    if (mozilla::ipc::LoggingEnabledFor("PProcLoader")) {
        (msg__)->Log("[PProcLoaderChild] Sending ", OtherPid(), false);
    }
    PROFILER_LABEL("IPDL::PProcLoader", "AsyncSendLoadComplete", js::ProfileEntry::Category::OTHER);
    if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Recv, PProcLoader::Msg_LoadComplete__ID), (&(mState)))))) {
        NS_WARNING("bad state transition!");
    }

    bool sendok__ = (mChannel).Send(msg__);
    return sendok__;
}

auto PProcLoaderChild::Register(ProtocolBase* aRouted) -> int32_t
{
    int32_t tmp = (--(mLastRouteId));
    (mActorMap).AddWithID(aRouted, tmp);
    return tmp;
}

auto PProcLoaderChild::RegisterID(
        ProtocolBase* aRouted,
        int32_t aId) -> int32_t
{
    (mActorMap).AddWithID(aRouted, aId);
P_LOGI("call -- return aId:%d; --->",aId);
    return aId;
}

auto PProcLoaderChild::Lookup(int32_t aId) -> ProtocolBase*
{
P_LOGI("call -- return (mActorMap).Lookup(aId:%d); --->",aId);
    return (mActorMap).Lookup(aId);
}

auto PProcLoaderChild::Unregister(int32_t aId) -> void
{
    return (mActorMap).Remove(aId);
}

auto PProcLoaderChild::RemoveManagee(
        int32_t aProtocolId,
        ProtocolBase* aListener) -> void
{
    NS_RUNTIMEABORT("unreached");
    return;
}

auto PProcLoaderChild::CreateSharedMemory(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        bool aUnsafe,
        Shmem::id_t* aId) -> Shmem::SharedMemory*
{
    RefPtr<Shmem::SharedMemory> segment(Shmem::Alloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), aSize, aType, aUnsafe));
    if ((!(segment))) {
        return nullptr;
    }
    Shmem shmem(
            Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(),
            (segment).get(),
            (--(mLastShmemId)));
    Message* descriptor = (shmem).ShareTo(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);
    if ((!(descriptor))) {
        return nullptr;
    }
    if ((!((mChannel).Send(descriptor)))) {
    }
    (*(aId)) = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    Shmem::SharedMemory* rawSegment = (segment).get();
    (mShmemMap).AddWithID(((segment).forget()).take(), (*(aId)));
    return rawSegment;
}

auto PProcLoaderChild::AdoptSharedMemory(
        Shmem::SharedMemory* segment,
        Shmem::id_t* aId) -> bool
{
    Shmem shmem(
            Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(),
            segment,
            (--(mLastShmemId)));
    Message* descriptor = (shmem).ShareTo(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);
    if ((!(descriptor))) {
        return false;
    }
    if ((!((mChannel).Send(descriptor)))) {
    }
    (*(aId)) = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    (mShmemMap).AddWithID(segment, (*(aId)));
    (segment)->AddRef();
    return true;
}

auto PProcLoaderChild::LookupSharedMemory(Shmem::id_t aId) -> Shmem::SharedMemory*
{
    return (mShmemMap).Lookup(aId);
}

auto PProcLoaderChild::IsTrackingSharedMemory(Shmem::SharedMemory* segment) -> bool
{
    return (mShmemMap).HasData(segment);
}

auto PProcLoaderChild::DestroySharedMemory(Shmem& shmem) -> bool
{
    Shmem::id_t aId = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    Shmem::SharedMemory* segment = LookupSharedMemory(aId);
    if ((!(segment))) {
        return false;
    }

    Message* descriptor = (shmem).UnshareFrom(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);

    (mShmemMap).Remove(aId);
    Shmem::Dealloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), segment);

    if ((!((mChannel).CanSend()))) {
        delete descriptor;
        return true;
    }

    return (descriptor) && ((mChannel).Send(descriptor));
}

auto PProcLoaderChild::OtherPid() const -> base::ProcessId
{
    P_LOGI(SEPARATOR_LINE);
    P_LOGI("mOtherPid:%d",(int)mOtherPid);
    return mOtherPid;
}

auto PProcLoaderChild::GetIPCChannel() -> MessageChannel*
{
    P_LOGI(SEPARATOR_LINE);
    return (&(mChannel));
}

auto PProcLoaderChild::CloneManagees(
        ProtocolBase* aSource,
        ProtocolCloneContext* aCtx) -> void
{
}

auto PProcLoaderChild::CloneProtocol(
        Channel* aChannel,
        ProtocolCloneContext* aCtx) -> mozilla::ipc::IProtocol*
{
    NS_RUNTIMEABORT("Clone() for PProcLoader has not yet been implemented");
    return nullptr;
}

auto PProcLoaderChild::OnMessageReceived(const Message& msg__) -> PProcLoaderChild::Result
{
    P_LOGI(SEPARATOR_LINE);
    switch ((msg__).type()) {判断消息类型,如果是load类型的就处理,其他的忽略?
    case PProcLoader::Msg_Load__ID:
        {
            (const_cast<Message&>(msg__)).set_name("PProcLoader::Msg_Load");
            if (mozilla::ipc::LoggingEnabledFor("PProcLoader")) {
                (static_cast<const PProcLoader::Msg_Load*>((&(msg__))))->Log("[PProcLoaderChild] Received ", OtherPid(), true);
            }
            PROFILER_LABEL("IPDL::PProcLoader", "RecvLoad", js::ProfileEntry::Category::OTHER);

            void* iter__ = nullptr;
            nsTArray<nsCString> argv;
            nsTArray<nsCString> env;
            nsTArray<FDRemap> fdsRemap;
            uint32_t privs;
            int32_t cookie;

            if ((!(Read((&(argv)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsTArray'");
                return MsgValueError;
            }
            if ((!(Read((&(env)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsTArray'");
                return MsgValueError;
            }
            if ((!(Read((&(fdsRemap)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'nsTArray'");
                return MsgValueError;
            }
            if ((!(Read((&(privs)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'uint32_t'");
                return MsgValueError;
            }
            if ((!(Read((&(cookie)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'int32_t'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Send, PProcLoader::Msg_Load__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
P_LOGI("call -- if ((!(RecvLoad(mozilla::Move(argv), mozilla::Move(env), mozilla::Move(fdsRemap), mozilla::Move(privs), mozilla::Move(cookie))))) { --->");
            if ((!(RecvLoad(mozilla::Move(argv), mozilla::Move(env), mozilla::Move(fdsRemap), mozilla::Move(privs), mozilla::Move(cookie))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler for Load returned error code");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        {
            return MsgNotKnown;
        }
    case SHMEM_CREATED_MESSAGE_TYPE: 消息类型为创建共享内存,不处理???
        {
            NS_RUNTIMEABORT("this protocol tree does not use shmem");
            return MsgNotKnown;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:消息类型为销毁共享内存,不处理???
        {
            NS_RUNTIMEABORT("this protocol tree does not use shmem");
            return MsgNotKnown;
        }
    }
}

auto PProcLoaderChild::OnMessageReceived(
        const Message& msg__,
        Message*& reply__) -> PProcLoaderChild::Result
{
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}

auto PProcLoaderChild::OnCallReceived(
        const Message& msg__,
        Message*& reply__) -> PProcLoaderChild::Result
{
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}

auto PProcLoaderChild::OnProcessingError(
        Result aCode,
        const char* aReason) -> void
{
    return ProcessingError(aCode, aReason);
}

auto PProcLoaderChild::GetProtocolTypeId() -> int32_t
{
    return PProcLoaderMsgStart;
}

auto PProcLoaderChild::OnEnteredCxxStack() -> void
{
    return EnteredCxxStack();
}

auto PProcLoaderChild::OnExitedCxxStack() -> void
{
    return ExitedCxxStack();
}

auto PProcLoaderChild::OnEnteredCall() -> void
{
    return EnteredCall();
}

auto PProcLoaderChild::OnExitedCall() -> void
{
    return ExitedCall();
}

auto PProcLoaderChild::IsOnCxxStack() const -> bool
{
    return (mChannel).IsOnCxxStack();
}

auto PProcLoaderChild::FlushPendingInterruptQueue() -> void
{
    ((this)->mChannel).FlushPendingInterruptQueue();
}

auto PProcLoaderChild::OnChannelClose() -> void
{
    DestroySubtree(NormalShutdown);
    DeallocSubtree();
    DeallocShmems();
}

auto PProcLoaderChild::OnChannelError() -> void
{
    DestroySubtree(AbnormalShutdown);
    DeallocSubtree();
    DeallocShmems();
}

auto PProcLoaderChild::OnChannelConnected(int32_t aPid) -> void
{
}

auto PProcLoaderChild::AllocShmem(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        Shmem* aOutMem) -> bool
{
    Shmem::id_t id;
    Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, false, (&(id))));
    if ((!(rawmem))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderChild::AllocUnsafeShmem(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        Shmem* aOutMem) -> bool
{
    Shmem::id_t id;
    Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, true, (&(id))));
    if ((!(rawmem))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderChild::AdoptShmem(
        Shmem& aMem,
        Shmem* aOutMem) -> bool
{
    Shmem::SharedMemory* rawmem = (aMem).Segment(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    if (((!(rawmem))) || (IsTrackingSharedMemory(rawmem))) {
        NS_RUNTIMEABORT("bad Shmem");
        return false;
    }

    Shmem::id_t id;
    if ((!(AdoptSharedMemory(rawmem, (&(id)))))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderChild::DeallocShmem(Shmem& aMem) -> bool
{
    bool ok = DestroySharedMemory(aMem);
#ifdef DEBUG
    if ((!(ok))) {
        NS_RUNTIMEABORT("bad Shmem");
        return false;
    }
#endif // DEBUG
    (aMem).forget(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    return ok;
}

auto PProcLoaderChild::FatalError(const char* const aMsg) const -> void
{
    mozilla::ipc::FatalError("PProcLoaderChild", aMsg, 0, false);
}

auto PProcLoaderChild::DestroySubtree(ActorDestroyReason why) -> void
{
    // Finally, destroy "us".
    ActorDestroy(why);
}

auto PProcLoaderChild::DeallocSubtree() -> void
{
}

auto PProcLoaderChild::DeallocShmems() -> void
{
    for (IDMap<SharedMemory>::const_iterator cit = (mShmemMap).begin(); (cit) != ((mShmemMap).end()); (++(cit))) {
        Shmem::Dealloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), (cit)->second);
    }
    (mShmemMap).Clear();
}

auto PProcLoaderChild::Write(
        const nsTArray<FDRemap>& v__,
        Message* msg__) -> void
{
    uint32_t length = (v__).Length();
    Write(length, msg__);

    for (uint32_t i = 0; (i) < (length); (++(i))) {
        Write(v__[i], msg__);
    }
}

auto PProcLoaderChild::Read(
        nsTArray<FDRemap>* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    FallibleTArray<FDRemap> fa;
    uint32_t length;
    if ((!(Read((&(length)), msg__, iter__)))) {
        FatalError("Error deserializing 'length' (uint32_t) of 'FDRemap[]'");
        return false;
    }

    if ((!((fa).SetLength(length, mozilla::fallible)))) {
        FatalError("Error setting the array length");
        return false;
    }
    for (uint32_t i = 0; (i) < (length); (++(i))) {
        if ((!(Read((&(fa[i])), msg__, iter__)))) {
            FatalError("Error deserializing 'FDRemap[i]'");
            return false;
        }
    }
    (v__)->SwapElements(fa);
    return true;
}

auto PProcLoaderChild::Write(
        const FDRemap& v__,
        Message* msg__) -> void
{
    Write((v__).fd(), msg__);
    Write((v__).mapto(), msg__);
}

auto PProcLoaderChild::Read(
        FDRemap* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    if ((!(Read((&((v__)->fd())), msg__, iter__)))) {
        FatalError("Error deserializing 'fd' (FileDescriptor) member of 'FDRemap'");
        return false;
    }
    if ((!(Read((&((v__)->mapto())), msg__, iter__)))) {
        FatalError("Error deserializing 'mapto' (int) member of 'FDRemap'");
        return false;
    }
    return true;
}

auto PProcLoaderChild::Write(
        const FileDescriptor& v__,
        Message* msg__) -> void
{
    FileDescriptor::PickleType pfd = (v__).ShareTo(FileDescriptor::IPDLPrivate(), OtherPid());
    IPC::WriteParam(msg__, pfd);
}

auto PProcLoaderChild::Read(
        FileDescriptor* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    FileDescriptor::PickleType pfd;
    if ((!(IPC::ReadParam(msg__, iter__, (&(pfd)))))) {
        return false;
    }

    FileDescriptor fd = FileDescriptor(FileDescriptor::IPDLPrivate(), pfd);
    if ((!((fd).IsValid()))) {
        mozilla::ipc::ProtocolErrorBreakpoint("[PProcLoaderChild] Received an invalid file descriptor!");
    }

    (*(v__)) = fd;
    return true;
}

 

} // namespace ipc
} // namespace mozilla

 

 

 

 

 

 

PProcLoaderParent.cpp部分源码

PProcLoaderParent::PProcLoaderParent()

PProcLoaderParent::Open()

PProcLoaderParent::SendLoad()

PProcLoaderParent::CreateSharedMemory()

PProcLoaderParent::AdoptSharedMemory(

PProcLoaderParent::LookupSharedMemory(Shmem::id_t aId)

 PProcLoaderParent::OnMessageReceived(const Message& msg__){

 if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Recv, PProcLoader::Msg_LoadComplete__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            if ((!(RecvLoadComplete(mozilla::Move(pid), mozilla::Move(cookie))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler for LoadComplete returned error code");
                return MsgProcessingError;
            }

}

 

 

//
// Automatically generated by ipdlc.
// Edit at your own risk
//


#include "mozilla/ipc/PProcLoaderParent.h"
#ifdef MOZ_CRASHREPORTER
#  include "nsXULAppAPI.h"
#endif


#include "nsIFile.h"
#include "GeckoProfiler.h"

///
//personal debug switch//
/********************************************************************************
P_DEBUG:
0     turn off debug
1        turn on debug
 ********************************************************************************/
#ifndef P_LOGI

#include "utils/Log.h"
#define P_DEBUG    1
#if P_DEBUG
static char mark_label[64] = "pmain-PProcLoaderParent";
#define SEPARATOR_LINE "----------------------------------"
      #define STA_LINE ">>>>>>>>>>>>>>>>>>>>>>>>>>>st.func"
      #define END_LINE "<<<<<<<<<<<<<<<<<<<<<<<<<<<ed.func"
#define LONNG_LINE = "------------------------------------------------------------------------------"
//static char mark_label[18] = "";//for the label you wish to mark when you adb logcat or whatever
#define P_LOGI(fmt, ...) ALOGI("%s-,F:%s:%d, Fuc:%s  " fmt,mark_label,(char*)__FILE__,__LINE__,(char*)__FUNCTION__,##__VA_ARGS__)
//#define P_LOGI(fmt, ...) printf("%s-,F:%s:%d, Fuc:%s  " fmt,mark_label,(char*)__FILE__,__LINE__,(char*)__FUNCTION__,##__VA_ARGS__)
#else
#define P_LOGI(...)
#endif

#endif

///
///
namespace mozilla {
namespace ipc {

 

auto PProcLoaderParent::ProcessingError(
        Result aCode,
        const char* aReason) -> void
{
}

auto PProcLoaderParent::ShouldContinueFromReplyTimeout() -> bool
{
    return true;
}

auto PProcLoaderParent::EnteredCxxStack() -> void
{
}

auto PProcLoaderParent::ExitedCxxStack() -> void
{
}

auto PProcLoaderParent::EnteredCall() -> void
{
}

auto PProcLoaderParent::ExitedCall() -> void
{
}

MOZ_IMPLICIT PProcLoaderParent::PProcLoaderParent() :
    mozilla::ipc::IToplevelProtocol(PProcLoaderMsgStart),
    mChannel(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
    mLastRouteId(1),
    mOtherPid(mozilla::ipc::kInvalidProcessId),
    mLastShmemId(1),
    mState(PProcLoader::__Start)
{
    MOZ_COUNT_CTOR(PProcLoaderParent);
}

PProcLoaderParent::~PProcLoaderParent()
{
    MOZ_COUNT_DTOR(PProcLoaderParent);
}

auto PProcLoaderParent::Open(
        Channel::Transport* aTransport,
        base::ProcessId aOtherPid,
        MessageLoop* aThread,
        mozilla::ipc::Side aSide) -> bool
{
    mOtherPid = aOtherPid;
P_LOGI("call -- mOtherPid = base::ProcessId aOtherPid: %d; --->",mOtherPid);
P_LOGI("call -- return (mChannel).Open(aTransport, aThread, aSide); --->");
    return (mChannel).Open(aTransport, aThread, aSide);
}

auto PProcLoaderParent::Open(
        MessageChannel* aChannel,
        MessageLoop* aMessageLoop,
        mozilla::ipc::Side aSide) -> bool
{
P_LOGI(SEPARATOR_LINE);
    mOtherPid = base::GetCurrentProcId();
P_LOGI("call -- mOtherPid = base::GetCurrentProcId():%d; --->",mOtherPid);
P_LOGI("call -- return (mChannel).Open(aChannel, aMessageLoop, aSide); --->");
    return (mChannel).Open(aChannel, aMessageLoop, aSide);
}

auto PProcLoaderParent::Close() -> void
{
    (mChannel).Close();
}

auto PProcLoaderParent::state() -> PProcLoader::State
{
    return mState;
}

auto PProcLoaderParent::SendLoad(
        const nsTArray<nsCString>& argv,
        const nsTArray<nsCString>& env,
        const nsTArray<FDRemap>& fdsRemap,
        const uint32_t& privs,
        const int32_t& cookie) -> bool
{
    P_LOGI(SEPARATOR_LINE);
    PProcLoader::Msg_Load* msg__ = new PProcLoader::Msg_Load(MSG_ROUTING_CONTROL);

    Write(argv, msg__);
    Write(env, msg__);
    Write(fdsRemap, msg__);
    Write(privs, msg__);
    Write(cookie, msg__);

 


    if (mozilla::ipc::LoggingEnabledFor("PProcLoader")) {
        (msg__)->Log("[PProcLoaderParent] Sending ", OtherPid(), false);
    }
    PROFILER_LABEL("IPDL::PProcLoader", "AsyncSendLoad", js::ProfileEntry::Category::OTHER);
    if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Send, PProcLoader::Msg_Load__ID), (&(mState)))))) {
        NS_WARNING("bad state transition!");
    }

    bool sendok__ = (mChannel).Send(msg__);
    return sendok__;
}

auto PProcLoaderParent::Register(ProtocolBase* aRouted) -> int32_t
{
    int32_t tmp = (++(mLastRouteId));
    (mActorMap).AddWithID(aRouted, tmp);
    return tmp;
}

auto PProcLoaderParent::RegisterID(
        ProtocolBase* aRouted,
        int32_t aId) -> int32_t
{
P_LOGI("call -- (mActorMap).AddWithID(aRouted, aId:%d); --->",aId);
    (mActorMap).AddWithID(aRouted, aId);
P_LOGI("call -- return aId: %d; --->",aId );
    return aId;
}

auto PProcLoaderParent::Lookup(int32_t aId) -> ProtocolBase*
{
P_LOGI(SEPARATOR_LINE);
P_LOGI("call -- return (mActorMap).Lookup(aId:%d); --->",aId);
    return (mActorMap).Lookup(aId);
}

auto PProcLoaderParent::Unregister(int32_t aId) -> void
{
    return (mActorMap).Remove(aId);
}

auto PProcLoaderParent::RemoveManagee(
        int32_t aProtocolId,
        ProtocolBase* aListener) -> void
{
    NS_RUNTIMEABORT("unreached");
    return;
}

auto PProcLoaderParent::CreateSharedMemory(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        bool aUnsafe,
        Shmem::id_t* aId) -> Shmem::SharedMemory*
{
    RefPtr<Shmem::SharedMemory> segment(Shmem::Alloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), aSize, aType, aUnsafe));
    if ((!(segment))) {
        return nullptr;
    }
    Shmem shmem(
            Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(),
            (segment).get(),
            (++(mLastShmemId)));
    Message* descriptor = (shmem).ShareTo(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);
    if ((!(descriptor))) {
        return nullptr;
    }
    if ((!((mChannel).Send(descriptor)))) {
    }
    (*(aId)) = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    Shmem::SharedMemory* rawSegment = (segment).get();
    (mShmemMap).AddWithID(((segment).forget()).take(), (*(aId)));
    return rawSegment;
}

auto PProcLoaderParent::AdoptSharedMemory(
        Shmem::SharedMemory* segment,
        Shmem::id_t* aId) -> bool
{
    Shmem shmem(
            Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(),
            segment,
            (++(mLastShmemId)));
    Message* descriptor = (shmem).ShareTo(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);
    if ((!(descriptor))) {
        return false;
    }
    if ((!((mChannel).Send(descriptor)))) {
    }
    (*(aId)) = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    (mShmemMap).AddWithID(segment, (*(aId)));
    (segment)->AddRef();
    return true;
}

auto PProcLoaderParent::LookupSharedMemory(Shmem::id_t aId) -> Shmem::SharedMemory*
{
    return (mShmemMap).Lookup(aId);
}

auto PProcLoaderParent::IsTrackingSharedMemory(Shmem::SharedMemory* segment) -> bool
{
    return (mShmemMap).HasData(segment);
}

auto PProcLoaderParent::DestroySharedMemory(Shmem& shmem) -> bool
{
    Shmem::id_t aId = (shmem).Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    Shmem::SharedMemory* segment = LookupSharedMemory(aId);
    if ((!(segment))) {
        return false;
    }

    Message* descriptor = (shmem).UnshareFrom(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);

    (mShmemMap).Remove(aId);
    Shmem::Dealloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), segment);

    if ((!((mChannel).CanSend()))) {
        delete descriptor;
        return true;
    }

    return (descriptor) && ((mChannel).Send(descriptor));
}

auto PProcLoaderParent::OtherPid() const -> base::ProcessId
{
    P_LOGI(SEPARATOR_LINE);
P_LOGI("call -- return mOtherPid:%d; --->",mOtherPid);
    return mOtherPid;
}

auto PProcLoaderParent::GetIPCChannel() -> MessageChannel*
{
    return (&(mChannel));
}

auto PProcLoaderParent::CloneManagees(
        ProtocolBase* aSource,
        ProtocolCloneContext* aCtx) -> void
{
}

auto PProcLoaderParent::CloneProtocol(
        Channel* aChannel,
        ProtocolCloneContext* aCtx) -> mozilla::ipc::IProtocol*
{
    NS_RUNTIMEABORT("Clone() for PProcLoader has not yet been implemented");
    return nullptr;
}

auto PProcLoaderParent::OnMessageReceived(const Message& msg__) -> PProcLoaderParent::Result
{
    P_LOGI(SEPARATOR_LINE);
    switch ((msg__).type()) {
    case PProcLoader::Msg_LoadComplete__ID:
        {
            (const_cast<Message&>(msg__)).set_name("PProcLoader::Msg_LoadComplete");
            if (mozilla::ipc::LoggingEnabledFor("PProcLoader")) {
                (static_cast<const PProcLoader::Msg_LoadComplete*>((&(msg__))))->Log("[PProcLoaderParent] Received ", OtherPid(), true);
            }
            PROFILER_LABEL("IPDL::PProcLoader", "RecvLoadComplete", js::ProfileEntry::Category::OTHER);

            void* iter__ = nullptr;
            int32_t pid;
            int32_t cookie;

            if ((!(Read((&(pid)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'int32_t'");
                return MsgValueError;
            }
            if ((!(Read((&(cookie)), (&(msg__)), (&(iter__)))))) {
                FatalError("Error deserializing 'int32_t'");
                return MsgValueError;
            }
            (msg__).EndRead(iter__);
            if ((!(PProcLoader::Transition(mState, Trigger(Trigger::Recv, PProcLoader::Msg_LoadComplete__ID), (&(mState)))))) {
                NS_WARNING("bad state transition!");
            }
            P_LOGI("call -- if ((!(RecvLoadComplete(mozilla::Move(pid:%d), mozilla::Move(cookie))))) { --->",pid);
            if ((!(RecvLoadComplete(mozilla::Move(pid), mozilla::Move(cookie))))) {
                mozilla::ipc::ProtocolErrorBreakpoint("Handler for LoadComplete returned error code");
                return MsgProcessingError;
            }

            return MsgProcessed;
        }
    default:
        {
            return MsgNotKnown;
        }
    case SHMEM_CREATED_MESSAGE_TYPE:
        {
            NS_RUNTIMEABORT("this protocol tree does not use shmem");
            return MsgNotKnown;
        }
    case SHMEM_DESTROYED_MESSAGE_TYPE:
        {
            NS_RUNTIMEABORT("this protocol tree does not use shmem");
            return MsgNotKnown;
        }
    }
}

auto PProcLoaderParent::OnMessageReceived(
        const Message& msg__,
        Message*& reply__) -> PProcLoaderParent::Result
{
    P_LOGI(SEPARATOR_LINE);
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}

auto PProcLoaderParent::OnCallReceived(
        const Message& msg__,
        Message*& reply__) -> PProcLoaderParent::Result
{
    P_LOGI(SEPARATOR_LINE);
    MOZ_ASSERT_UNREACHABLE("message protocol not supported");
    return MsgNotKnown;
}

auto PProcLoaderParent::OnProcessingError(
        Result aCode,
        const char* aReason) -> void
{
    return ProcessingError(aCode, aReason);
}

auto PProcLoaderParent::GetProtocolTypeId() -> int32_t
{
    return PProcLoaderMsgStart;
}

auto PProcLoaderParent::OnEnteredCxxStack() -> void
{
    return EnteredCxxStack();
}

auto PProcLoaderParent::OnExitedCxxStack() -> void
{
    return ExitedCxxStack();
}

auto PProcLoaderParent::OnEnteredCall() -> void
{
    return EnteredCall();
}

auto PProcLoaderParent::OnExitedCall() -> void
{
    return ExitedCall();
}

auto PProcLoaderParent::IsOnCxxStack() const -> bool
{
    return (mChannel).IsOnCxxStack();
}

auto PProcLoaderParent::FlushPendingInterruptQueue() -> void
{
    ((this)->mChannel).FlushPendingInterruptQueue();
}

auto PProcLoaderParent::OnChannelClose() -> void
{
    DestroySubtree(NormalShutdown);
    DeallocSubtree();
    DeallocShmems();
}

auto PProcLoaderParent::OnChannelError() -> void
{
    DestroySubtree(AbnormalShutdown);
    DeallocSubtree();
    DeallocShmems();
}

auto PProcLoaderParent::OnChannelConnected(int32_t aPid) -> void
{
    P_LOGI(SEPARATOR_LINE);
P_LOGI("call -- auto PProcLoaderParent::OnChannelConnected(int32_t aPid:%d) -> void --->",aPid);
}

auto PProcLoaderParent::AllocShmem(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        Shmem* aOutMem) -> bool
{
    Shmem::id_t id;
    Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, false, (&(id))));
    if ((!(rawmem))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderParent::AllocUnsafeShmem(
        size_t aSize,
        Shmem::SharedMemory::SharedMemoryType aType,
        Shmem* aOutMem) -> bool
{
    Shmem::id_t id;
    Shmem::SharedMemory* rawmem(CreateSharedMemory(aSize, aType, true, (&(id))));
    if ((!(rawmem))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderParent::AdoptShmem(
        Shmem& aMem,
        Shmem* aOutMem) -> bool
{
    Shmem::SharedMemory* rawmem = (aMem).Segment(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    if (((!(rawmem))) || (IsTrackingSharedMemory(rawmem))) {
        NS_WARNING("bad Shmem");
        return false;
    }

    Shmem::id_t id;
    if ((!(AdoptSharedMemory(rawmem, (&(id)))))) {
        return false;
    }

    (*(aOutMem)) = Shmem(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), rawmem, id);
    return true;
}

auto PProcLoaderParent::DeallocShmem(Shmem& aMem) -> bool
{
    bool ok = DestroySharedMemory(aMem);
#ifdef DEBUG
    if ((!(ok))) {
        NS_WARNING("bad Shmem");
        return false;
    }
#endif // DEBUG
    (aMem).forget(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
    return ok;
}

auto PProcLoaderParent::SetOtherProcessId(base::ProcessId aOtherPid) -> void
{
    mOtherPid = aOtherPid;
}

auto PProcLoaderParent::TakeMinidump(
        nsIFile** aDump,
        uint32_t* aSequence) const -> bool
{
#ifdef MOZ_CRASHREPORTER
    return XRE_TakeMinidumpForChild(OtherPid(), aDump, aSequence);
#else
    return false;
#endif
}

auto PProcLoaderParent::FatalError(const char* const aMsg) const -> void
{
    mozilla::ipc::FatalError("PProcLoaderParent", aMsg, OtherPid(), true);
}

auto PProcLoaderParent::DestroySubtree(ActorDestroyReason why) -> void
{
    // Finally, destroy "us".
    ActorDestroy(why);
}

auto PProcLoaderParent::DeallocSubtree() -> void
{
}

auto PProcLoaderParent::DeallocShmems() -> void
{
    for (IDMap<SharedMemory>::const_iterator cit = (mShmemMap).begin(); (cit) != ((mShmemMap).end()); (++(cit))) {
        Shmem::Dealloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), (cit)->second);
    }
    (mShmemMap).Clear();
}

auto PProcLoaderParent::Write(
        const nsTArray<FDRemap>& v__,
        Message* msg__) -> void
{
    uint32_t length = (v__).Length();
    Write(length, msg__);

    for (uint32_t i = 0; (i) < (length); (++(i))) {
        Write(v__[i], msg__);
    }
}

auto PProcLoaderParent::Read(
        nsTArray<FDRemap>* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    FallibleTArray<FDRemap> fa;
    uint32_t length;
    if ((!(Read((&(length)), msg__, iter__)))) {
        FatalError("Error deserializing 'length' (uint32_t) of 'FDRemap[]'");
        return false;
    }

    if ((!((fa).SetLength(length, mozilla::fallible)))) {
        FatalError("Error setting the array length");
        return false;
    }
    for (uint32_t i = 0; (i) < (length); (++(i))) {
        if ((!(Read((&(fa[i])), msg__, iter__)))) {
            FatalError("Error deserializing 'FDRemap[i]'");
            return false;
        }
    }
    (v__)->SwapElements(fa);
    return true;
}

auto PProcLoaderParent::Write(
        const FDRemap& v__,
        Message* msg__) -> void
{
    Write((v__).fd(), msg__);
    Write((v__).mapto(), msg__);
}

auto PProcLoaderParent::Read(
        FDRemap* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    if ((!(Read((&((v__)->fd())), msg__, iter__)))) {
        FatalError("Error deserializing 'fd' (FileDescriptor) member of 'FDRemap'");
        return false;
    }
    if ((!(Read((&((v__)->mapto())), msg__, iter__)))) {
        FatalError("Error deserializing 'mapto' (int) member of 'FDRemap'");
        return false;
    }
    return true;
}

auto PProcLoaderParent::Write(
        const FileDescriptor& v__,
        Message* msg__) -> void
{
    FileDescriptor::PickleType pfd = (v__).ShareTo(FileDescriptor::IPDLPrivate(), OtherPid());
    IPC::WriteParam(msg__, pfd);
}

auto PProcLoaderParent::Read(
        FileDescriptor* v__,
        const Message* msg__,
        void** iter__) -> bool
{
    FileDescriptor::PickleType pfd;
    if ((!(IPC::ReadParam(msg__, iter__, (&(pfd)))))) {
        return false;
    }

    FileDescriptor fd = FileDescriptor(FileDescriptor::IPDLPrivate(), pfd);
    if ((!((fd).IsValid()))) {
        mozilla::ipc::ProtocolErrorBreakpoint("[PProcLoaderParent] Received an invalid file descriptor!");
    }

    (*(v__)) = fd;
    return true;
}

 

} // namespace ipc
} // namespace mozilla

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值