2019-03-19 00:21:48 +08:00
|
|
|
// Copyright 2019 Google LLC. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef SANDBOXED_API_RPCCHANNEL_H_
|
|
|
|
#define SANDBOXED_API_RPCCHANNEL_H_
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include "absl/synchronization/mutex.h"
|
|
|
|
#include "sandboxed_api/call.h"
|
|
|
|
#include "sandboxed_api/sandbox2/comms.h"
|
2019-04-24 01:29:37 +08:00
|
|
|
#include "sandboxed_api/var_type.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
#include "sandboxed_api/util/status.h"
|
|
|
|
#include "sandboxed_api/util/statusor.h"
|
|
|
|
|
|
|
|
namespace sapi {
|
|
|
|
|
|
|
|
// This class exposes functions which provide primitives operating over the
|
|
|
|
// Comms channel.
|
|
|
|
class RPCChannel {
|
|
|
|
public:
|
|
|
|
explicit RPCChannel(sandbox2::Comms* comms) : comms_(comms) {}
|
|
|
|
|
|
|
|
// Calls a function.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Call(const FuncCall& call, uint32_t tag, FuncRet* ret,
|
|
|
|
v::Type exp_type);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Allocates memory.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Allocate(size_t size, void** addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Reallocates memory.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Reallocate(void* old_addr, size_t size, void** new_addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Frees memory.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Free(void* addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Returns address of a symbol.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Symbol(const char* symname, void** addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Makes the remote part exit.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Exit();
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Transfers fd to sandboxee.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status SendFD(int local_fd, int* remote_fd);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Retrieves fd from sandboxee.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status RecvFD(int remote_fd, int* local_fd);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Closes fd in sandboxee.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::Status Close(int remote_fd);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2019-11-22 22:44:03 +08:00
|
|
|
// Returns length of a null-terminated c-style string (invokes strlen).
|
|
|
|
sapi::StatusOr<uint64_t> Strlen(void* str);
|
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
sandbox2::Comms* comms() const { return comms_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Receives the result after a call.
|
2019-08-23 23:08:23 +08:00
|
|
|
sapi::StatusOr<FuncRet> Return(v::Type exp_type);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
sandbox2::Comms* comms_; // Owned by sandbox2;
|
|
|
|
absl::Mutex mutex_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sapi
|
|
|
|
|
|
|
|
#endif // SANDBOXED_API_RPCCHANNEL_H_
|