2020-01-17 21:05:03 +08:00
|
|
|
// Copyright 2019 Google LLC
|
2019-03-19 00:21:48 +08:00
|
|
|
//
|
|
|
|
// 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>
|
|
|
|
|
2020-02-28 01:23:44 +08:00
|
|
|
#include "absl/status/status.h"
|
2020-09-02 23:46:48 +08:00
|
|
|
#include "absl/status/statusor.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
#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
|
|
|
|
|
|
|
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.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Call(const FuncCall& call, uint32_t tag, FuncRet* ret,
|
2019-08-23 23:08:23 +08:00
|
|
|
v::Type exp_type);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Allocates memory.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Allocate(size_t size, void** addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Reallocates memory.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Reallocate(void* old_addr, size_t size, void** new_addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Frees memory.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Free(void* addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Returns address of a symbol.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Symbol(const char* symname, void** addr);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Makes the remote part exit.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status Exit();
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Transfers fd to sandboxee.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status SendFD(int local_fd, int* remote_fd);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Retrieves fd from sandboxee.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::Status RecvFD(int remote_fd, int* local_fd);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
// Closes fd in sandboxee.
|
2020-02-28 01:23:44 +08:00
|
|
|
absl::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).
|
2020-09-02 23:46:48 +08:00
|
|
|
absl::StatusOr<uint64_t> Strlen(void* str);
|
2019-11-22 22:44:03 +08:00
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
sandbox2::Comms* comms() const { return comms_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Receives the result after a call.
|
2020-09-02 23:46:48 +08:00
|
|
|
absl::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_
|