#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "sql/sandboxed_vfs_file.h"
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include <utility>
#include "base/check.h"
#include "base/check_op.h"
#include "base/dcheck_is_on.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "sql/sandboxed_vfs.h"
#include "third_party/sqlite/sqlite3.h"
namespace sql {
namespace {
int SandboxedClose(sqlite3_file* file) { … }
int SandboxedRead(sqlite3_file* file,
void* buffer,
int size,
sqlite3_int64 offset) { … }
int SandboxedWrite(sqlite3_file* file,
const void* buffer,
int size,
sqlite3_int64 offset) { … }
int SandboxedTruncate(sqlite3_file* file, sqlite3_int64 size) { … }
int SandboxedSync(sqlite3_file* file, int flags) { … }
int SandboxedFileSize(sqlite3_file* file, sqlite3_int64* result_size) { … }
int SandboxedLock(sqlite3_file* file, int mode) { … }
int SandboxedUnlock(sqlite3_file* file, int mode) { … }
int SandboxedCheckReservedLock(sqlite3_file* file, int* has_reserved_lock) { … }
int SandboxedFileControl(sqlite3_file* file, int opcode, void* data) { … }
int SandboxedSectorSize(sqlite3_file* file) { … }
int SandboxedDeviceCharacteristics(sqlite3_file* file) { … }
int SandboxedShmMap(sqlite3_file* file,
int page_index,
int page_size,
int extend_file_if_needed,
void volatile** result) { … }
int SandboxedShmLock(sqlite3_file* file, int offset, int size, int flags) { … }
void SandboxedShmBarrier(sqlite3_file* file) { … }
int SandboxedShmUnmap(sqlite3_file* file, int also_delete_file) { … }
int SandboxedFetch(sqlite3_file* file,
sqlite3_int64 offset,
int size,
void** result) { … }
int SandboxedUnfetch(sqlite3_file* file,
sqlite3_int64 offset,
void* fetch_result) { … }
const sqlite3_io_methods* GetSqliteIoMethods() { … }
}
void SandboxedVfsFile::Create(base::File file,
base::FilePath file_path,
#if DCHECK_IS_ON()
SandboxedVfsFileType file_type,
#endif
SandboxedVfs* vfs,
sqlite3_file& buffer) { … }
SandboxedVfsFile& SandboxedVfsFile::FromSqliteFile(sqlite3_file& sqlite_file) { … }
int SandboxedVfsFile::Close() { … }
int SandboxedVfsFile::Read(void* buffer, int size, sqlite3_int64 offset) { … }
int SandboxedVfsFile::Write(const void* buffer,
int size,
sqlite3_int64 offset) { … }
int SandboxedVfsFile::Truncate(sqlite3_int64 size) { … }
int SandboxedVfsFile::Sync(int flags) { … }
int SandboxedVfsFile::FileSize(sqlite3_int64* result_size) { … }
namespace {
bool IsExclusiveLockMode(int sqlite_lock_mode) { … }
}
int SandboxedVfsFile::Lock(int mode) { … }
int SandboxedVfsFile::Unlock(int mode) { … }
int SandboxedVfsFile::CheckReservedLock(int* has_reserved_lock) { … }
int SandboxedVfsFile::FileControl(int opcode, void* data) { … }
int SandboxedVfsFile::SectorSize() { … }
int SandboxedVfsFile::DeviceCharacteristics() { … }
int SandboxedVfsFile::ShmMap(int page_index,
int page_size,
int extend_file_if_needed,
void volatile** result) { … }
int SandboxedVfsFile::ShmLock(int offset, int size, int flags) { … }
void SandboxedVfsFile::ShmBarrier() { … }
int SandboxedVfsFile::ShmUnmap(int also_delete_file) { … }
int SandboxedVfsFile::Fetch(sqlite3_int64 offset, int size, void** result) { … }
int SandboxedVfsFile::Unfetch(sqlite3_int64 offset, void* fetch_result) { … }
SandboxedVfsFile::SandboxedVfsFile(base::File file,
base::FilePath file_path,
#if DCHECK_IS_ON()
SandboxedVfsFileType file_type,
#endif
SandboxedVfs* vfs)
: … { … }
SandboxedVfsFile::~SandboxedVfsFile() = default;
SandboxedVfsFileSqliteBridge& SandboxedVfsFileSqliteBridge::FromSqliteFile(
sqlite3_file& sqlite_file) { … }
}