2020-10-01 18:59:18 +08:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2020-10-14 04:03:04 +08:00
|
|
|
#ifndef RASTER_TO_GTIFF_GDAL_SANDBOX_H_
|
|
|
|
#define RASTER_TO_GTIFF_GDAL_SANDBOX_H_
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-07 16:33:20 +08:00
|
|
|
#include <syscall.h>
|
|
|
|
|
2020-10-01 18:59:18 +08:00
|
|
|
#include <string>
|
|
|
|
|
2020-10-07 16:33:20 +08:00
|
|
|
#include "gdal_sapi.sapi.h" // NOLINT(build/include)
|
|
|
|
|
2020-10-01 18:59:18 +08:00
|
|
|
namespace gdal::sandbox {
|
|
|
|
|
2020-10-15 23:13:11 +08:00
|
|
|
class GdalSapiSandbox : public GdalSandbox {
|
2020-10-01 18:59:18 +08:00
|
|
|
public:
|
2020-10-19 23:08:03 +08:00
|
|
|
GdalSapiSandbox(std::string out_directory_path, std::string proj_db_path,
|
2020-10-15 23:13:11 +08:00
|
|
|
time_t time_limit = 0)
|
2020-10-19 23:08:03 +08:00
|
|
|
: out_directory_path_(std::move(out_directory_path)),
|
|
|
|
proj_db_path_(std::move(proj_db_path)) {
|
|
|
|
SetWallTimeLimit(time_limit).IgnoreError();
|
|
|
|
}
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-06 02:01:15 +08:00
|
|
|
private:
|
2020-10-01 18:59:18 +08:00
|
|
|
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
|
|
|
|
sandbox2::PolicyBuilder*) override {
|
2020-10-19 23:08:03 +08:00
|
|
|
return sandbox2::PolicyBuilder()
|
2020-10-01 18:59:18 +08:00
|
|
|
.AllowDynamicStartup()
|
|
|
|
.AllowRead()
|
|
|
|
.AllowSystemMalloc()
|
|
|
|
.AllowWrite()
|
|
|
|
.AllowExit()
|
|
|
|
.AllowOpen()
|
|
|
|
.AllowSyscalls({
|
|
|
|
__NR_futex,
|
|
|
|
__NR_getdents64, // DriverRegisterAll()
|
2020-10-19 23:08:03 +08:00
|
|
|
__NR_lseek, // GDALCreate()
|
|
|
|
__NR_getpid, // GDALCreate()
|
|
|
|
__NR_sysinfo, // VSI_TIFFOpen_common()
|
|
|
|
__NR_prlimit64, // CPLGetUsablePhysicalRAM()
|
|
|
|
__NR_ftruncate, // GTiffDataset::FillEmptyTiles()
|
|
|
|
__NR_unlink, // GDALDriver::Delete()
|
2020-10-01 18:59:18 +08:00
|
|
|
})
|
2020-10-06 02:01:15 +08:00
|
|
|
.AddFile(proj_db_path_) // proj.db is required for some projections
|
|
|
|
.AddDirectory(out_directory_path_, /*is_ro=*/false)
|
2020-10-01 18:59:18 +08:00
|
|
|
.BuildOrDie();
|
2020-10-06 02:01:15 +08:00
|
|
|
}
|
2020-10-01 18:59:18 +08:00
|
|
|
|
2020-10-06 02:01:15 +08:00
|
|
|
std::string out_directory_path_;
|
|
|
|
std::string proj_db_path_;
|
2020-10-01 18:59:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace gdal::sandbox
|
|
|
|
|
2020-10-14 04:03:04 +08:00
|
|
|
#endif // RASTER_TO_GTIFF_GDAL_SANDBOX_H_
|