15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef SANDBOX_SRC_CROSSCALL_SERVER_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define SANDBOX_SRC_CROSSCALL_SERVER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/strings/string16.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sandbox/win/src/crosscall_params.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This is the IPC server interface for CrossCall: The  IPC for the Sandbox
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// On the server, CrossCall needs two things:
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1) threads: Or better said, someone to provide them, that is what the
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             ThreadProvider interface is defined for. These thread(s) are
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//             the ones that will actually execute the  IPC data retrieval.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2) a dispatcher: This interface represents the way to route and process
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                  an  IPC call given the  IPC tag.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The other class included here CrossCallParamsEx is the server side version
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// of the CrossCallParams class of /sandbox/crosscall_params.h The difference
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is that the sever version is paranoid about the correctness of the IPC
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// message and will do all sorts of verifications.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A general diagram of the interaction is as follows:
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                                 ------------
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                                 |          |
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  ThreadProvider <--(1)Register--|  IPC     |
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//      |                          | Implemen |
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//      |                          | -tation  |
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     (2)                         |          |  OnMessage
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     IPC fired --callback ------>|          |--(3)---> Dispatcher
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                                 |          |
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//                                 ------------
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  The  IPC implementation sits as a middleman between the handling of the
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  specifics of scheduling a thread to service the  IPC and the multiple
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  entities that can potentially serve each particular IPC.
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace sandbox {
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class InterceptionManager;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This function signature is required as the callback when an  IPC call fires.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// context: a user-defined pointer that was set using  ThreadProvider
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// reason: 0 if the callback was fired because of a timeout.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//         1 if the callback was fired because of an event.
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef void (__stdcall * CrossCallIPCCallback)(void* context,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                                unsigned char reason);
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ThreadProvider models a thread factory. The idea is to decouple thread
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// creation and lifetime from the inner guts of the IPC. The contract is
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// simple:
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   - the IPC implementation calls RegisterWait with a waitable object that
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     becomes signaled when an IPC arrives and needs to be serviced.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   - when the waitable object becomes signaled, the thread provider conjures
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     a thread that calls the callback (CrossCallIPCCallback) function
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   - the callback function tries its best not to block and return quickly
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     and should not assume that the next callback will use the same thread
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//   - when the callback returns the ThreadProvider owns again the thread
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     and can destroy it or keep it around.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ThreadProvider {
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Registers a waitable object with the thread provider.
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // client: A number to associate with all the RegisterWait calls, typically
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //         this is the address of the caller object. This parameter cannot
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //         be zero.
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // waitable_object : a kernel object that can be waited on
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // callback: a function pointer which is the function that will be called
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //           when the waitable object fires
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // context: a user-provider pointer that is passed back to the callback
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //          when its called
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool RegisterWait(const void* client, HANDLE waitable_object,
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            CrossCallIPCCallback callback,
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            void* context) = 0;
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Removes all the registrations done with the same cookie parameter.
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This frees internal thread pool resources.
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool UnRegisterWaits(void* cookie) = 0;
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~ThreadProvider() {}
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Models the server-side of the original input parameters.
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Provides IPC buffer validation and it is capable of reading the parameters
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// out of the IPC buffer.
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CrossCallParamsEx : public CrossCallParams {
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Factory constructor. Pass an IPCbuffer (and buffer size) that contains a
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // pending IPCcall. This constructor will:
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 1) validate the IPC buffer. returns NULL is the IPCbuffer is malformed.
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // 2) make a copy of the IPCbuffer (parameter capture)
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static CrossCallParamsEx* CreateFromBuffer(void* buffer_base,
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             uint32 buffer_size,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                             uint32* output_size);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Provides IPCinput parameter raw access:
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // index : the parameter to read; 0 is the first parameter
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returns NULL if the parameter is non-existent. If it exists it also
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // returns the size in *size
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void* GetRawParameter(uint32 index, uint32* size, ArgType* type);
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a parameter that is four bytes in size.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns false if the parameter does not exist or is not 32 bits wide.
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetParameter32(uint32 index, uint32* param);
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a parameter that is void pointer in size.
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns false if the parameter does not exist or is not void pointer sized.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetParameterVoidPtr(uint32 index, void** param);
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a parameter that is a string. Returns false if the parameter does not
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // exist.
1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  bool GetParameterStr(uint32 index, base::string16* string);
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Gets a parameter that is an in/out buffer. Returns false is the parameter
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // does not exist or if the size of the actual parameter is not equal to the
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // expected size.
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool GetParameterPtr(uint32 index, uint32 expected_size, void** pointer);
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Frees the memory associated with the IPC parameters.
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void operator delete(void* raw_memory) throw();
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Only the factory method CreateFromBuffer can construct these objects.
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrossCallParamsEx();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ParamInfo param_info_[1];
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(CrossCallParamsEx);
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Simple helper function that sets the members of CrossCallReturn
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to the proper state to signal a basic error.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetCallError(ResultCode error, CrossCallReturn* call_return);
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Sets the internal status of call_return to signify the that IPC call
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// completed successfully.
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void SetCallSuccess(CrossCallReturn* call_return);
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Represents the client process that initiated the IPC which boils down to the
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// process handle and the job object handle that contains the client process.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct ClientInfo {
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HANDLE process;
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  HANDLE job_object;
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DWORD process_id;
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// All IPC-related information to be passed to the IPC handler.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct IPCInfo {
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ipc_tag;
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const ClientInfo* client_info;
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  CrossCallReturn return_info;
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This structure identifies IPC signatures.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct IPCParams {
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int ipc_tag;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ArgType args[kMaxIpcParams];
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool Matches(IPCParams* other) const {
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return !memcmp(this, other, sizeof(*other));
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Models an entity that can process an IPC message or it can route to another
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// one that could handle it. When an IPC arrives the IPC implementation will:
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 1) call OnMessageReady() with the tag of the pending IPC. If the dispatcher
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    returns NULL it means that it cannot handle this IPC but if it returns
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    non-null, it must be the pointer to a dispatcher that can handle it.
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 2) When the  IPC finally obtains a valid Dispatcher the IPC
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    implementation creates a CrossCallParamsEx from the raw IPC buffer.
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 3) It calls the returned callback, with the IPC info and arguments.
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Dispatcher {
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called from the  IPC implementation to handle a specific IPC message.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*CallbackGeneric)();
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback0)(IPCInfo* ipc);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback1)(IPCInfo* ipc, void* p1);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback2)(IPCInfo* ipc, void* p1, void* p2);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback3)(IPCInfo* ipc, void* p1, void* p2,
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3);
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback4)(IPCInfo* ipc, void* p1, void* p2,
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4);
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback5)(IPCInfo* ipc, void* p1, void* p2,
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4, void* p5);
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback6)(IPCInfo* ipc, void* p1, void* p2,
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4, void* p5, void* p6);
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback7)(IPCInfo* ipc, void* p1, void* p2,
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4, void* p5, void* p6,
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p7);
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback8)(IPCInfo* ipc, void* p1, void* p2,
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4, void* p5, void* p6,
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p7, void* p8);
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef bool (Dispatcher::*Callback9)(IPCInfo* ipc, void* p1, void* p2,
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p3, void* p4, void* p5, void* p6,
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                        void* p7, void* p8, void* p9);
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called from the  IPC implementation when an  IPC message is ready override
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on a derived class to handle a set of  IPC messages. Return NULL if your
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // subclass does not handle the message or return the pointer to the subclass
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // that can handle it.
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual Dispatcher* OnMessageReady(IPCParams* ipc, CallbackGeneric* callback);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when a target proces is created, to setup the interceptions related
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // with the given service (IPC).
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool SetupService(InterceptionManager* manager, int service) = 0;
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~Dispatcher() {}
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Structure that defines an IPC Call with all the parameters and the handler.
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct IPCCall {
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IPCParams params;
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CallbackGeneric callback;
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // List of IPC Calls supported by the class.
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::vector<IPCCall> ipc_calls_;
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace sandbox
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // SANDBOX_SRC_CROSSCALL_SERVER_H_
226