2019-03-19 00:21:48 +08:00
|
|
|
#ifndef SANDBOXED_API_SANDBOX2_SYSCALL_DEFS_H_
|
|
|
|
#define SANDBOXED_API_SANDBOX2_SYSCALL_DEFS_H_
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2020-01-07 21:26:10 +08:00
|
|
|
|
2024-01-20 08:27:34 +08:00
|
|
|
#include <array>
|
2019-03-19 00:21:48 +08:00
|
|
|
#include <cstdint>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2024-01-20 08:27:34 +08:00
|
|
|
#include "absl/status/statusor.h"
|
2020-01-07 21:26:10 +08:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
#include "absl/types/span.h"
|
2021-01-14 01:25:25 +08:00
|
|
|
#include "sandboxed_api/config.h"
|
2020-01-07 21:26:10 +08:00
|
|
|
#include "sandboxed_api/sandbox2/syscall.h"
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
namespace sandbox2 {
|
|
|
|
namespace syscalls {
|
2020-01-07 21:26:10 +08:00
|
|
|
|
2019-03-19 00:21:48 +08:00
|
|
|
constexpr int kMaxArgs = 6;
|
2020-01-07 21:26:10 +08:00
|
|
|
|
2024-01-20 08:27:34 +08:00
|
|
|
// Type of a given syscall argument. Used with argument conversion routines.
|
|
|
|
enum ArgType {
|
|
|
|
kGen = 1,
|
|
|
|
kInt,
|
|
|
|
kPath,
|
|
|
|
kHex,
|
|
|
|
kOct,
|
|
|
|
kSocketCall,
|
|
|
|
kSocketCallPtr,
|
|
|
|
kSignal,
|
|
|
|
kString,
|
|
|
|
kAddressFamily,
|
|
|
|
kSockaddr,
|
|
|
|
kSockmsghdr,
|
|
|
|
kCloneFlag,
|
|
|
|
};
|
|
|
|
|
2020-01-07 21:26:10 +08:00
|
|
|
} // namespace syscalls
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
class SyscallTable {
|
|
|
|
public:
|
2024-01-20 08:27:34 +08:00
|
|
|
// Single syscall definition
|
|
|
|
struct Entry {
|
|
|
|
// Returns the number of arguments which given syscall takes.
|
|
|
|
int GetNumArgs() const {
|
|
|
|
if (num_args < 0 || num_args > syscalls::kMaxArgs) {
|
|
|
|
return syscalls::kMaxArgs;
|
|
|
|
}
|
|
|
|
return num_args;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string GetArgumentDescription(uint64_t value,
|
|
|
|
syscalls::ArgType type,
|
|
|
|
pid_t pid);
|
|
|
|
|
|
|
|
static constexpr bool BySyscallNr(const SyscallTable::Entry& a,
|
|
|
|
const SyscallTable::Entry& b) {
|
|
|
|
return a.nr < b.nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nr;
|
|
|
|
absl::string_view name;
|
|
|
|
int num_args;
|
|
|
|
std::array<syscalls::ArgType, syscalls::kMaxArgs> arg_types;
|
|
|
|
};
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2020-01-07 21:26:10 +08:00
|
|
|
// Returns the syscall table for the architecture.
|
2021-01-14 01:25:25 +08:00
|
|
|
static SyscallTable get(sapi::cpu::Architecture arch);
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2020-01-07 21:26:10 +08:00
|
|
|
int size() { return data_.size(); }
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2020-01-07 21:26:10 +08:00
|
|
|
absl::string_view GetName(int syscall) const;
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2022-08-16 13:55:16 +08:00
|
|
|
std::vector<std::string> GetArgumentsDescription(int syscall,
|
|
|
|
const uint64_t values[],
|
|
|
|
pid_t pid) const;
|
2019-03-19 00:21:48 +08:00
|
|
|
|
2024-01-20 08:27:34 +08:00
|
|
|
absl::StatusOr<Entry> GetEntry(int syscall) const;
|
|
|
|
// Returns the first entry matching the provided name.
|
2024-01-22 15:42:05 +08:00
|
|
|
absl::StatusOr<Entry> GetEntry(absl::string_view name) const;
|
2024-01-20 08:27:34 +08:00
|
|
|
|
|
|
|
absl::Span<const Entry> GetEntries() const { return data_; }
|
|
|
|
|
2020-01-07 21:26:10 +08:00
|
|
|
private:
|
2019-03-19 00:21:48 +08:00
|
|
|
constexpr SyscallTable() = default;
|
2020-01-07 21:26:10 +08:00
|
|
|
explicit constexpr SyscallTable(absl::Span<const Entry> data) : data_(data) {}
|
2019-03-19 00:21:48 +08:00
|
|
|
|
|
|
|
const absl::Span<const Entry> data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace sandbox2
|
|
|
|
|
|
|
|
#endif // SANDBOXED_API_SANDBOX2_SYSCALL_DEFS_H_
|