@@ -198,6 +198,8 @@ TimePoint<> basic_file_status::getLastModificationTime() const {
198198uint32_t file_status::getLinkCount () const { return NumLinks; }
199199
200200std::error_code current_path (SmallVectorImpl<char > &result) {
201+ sandbox::violationIfEnabled ();
202+
201203 SmallVector<wchar_t , MAX_PATH> cur_path;
202204 DWORD len = MAX_PATH;
203205
@@ -226,6 +228,8 @@ std::error_code current_path(SmallVectorImpl<char> &result) {
226228}
227229
228230std::error_code set_current_path (const Twine &path) {
231+ sandbox::violationIfEnabled ();
232+
229233 // Convert to utf-16.
230234 SmallVector<wchar_t , 128 > wide_path;
231235 if (std::error_code ec = widenPath (path, wide_path))
@@ -350,6 +354,8 @@ static std::error_code is_local_internal(SmallVectorImpl<wchar_t> &Path,
350354}
351355
352356std::error_code is_local (const Twine &path, bool &result) {
357+ sandbox::violationIfEnabled ();
358+
353359 if (!llvm::sys::fs::exists (path) || !llvm::sys::path::has_root_path (path))
354360 return make_error_code (errc::no_such_file_or_directory);
355361
@@ -413,6 +419,8 @@ static std::error_code realPathFromHandle(HANDLE H,
413419}
414420
415421std::error_code is_local (int FD, bool &Result) {
422+ sandbox::violationIfEnabled ();
423+
416424 SmallVector<wchar_t , 128 > FinalPath;
417425 HANDLE Handle = reinterpret_cast <HANDLE>(_get_osfhandle (FD));
418426
@@ -635,6 +643,8 @@ std::error_code resize_file_sparse(int FD, uint64_t Size) {
635643}
636644
637645std::error_code access (const Twine &Path, AccessMode Mode) {
646+ sandbox::violationIfEnabled ();
647+
638648 SmallVector<wchar_t , 128 > PathUtf16;
639649
640650 if (std::error_code EC = widenPath (Path, PathUtf16))
@@ -674,6 +684,8 @@ bool equivalent(file_status A, file_status B) {
674684}
675685
676686std::error_code equivalent (const Twine &A, const Twine &B, bool &result) {
687+ sandbox::violationIfEnabled ();
688+
677689 file_status fsA, fsB;
678690 if (std::error_code ec = status (A, fsA))
679691 return ec;
@@ -789,6 +801,8 @@ handle_status_error:
789801}
790802
791803std::error_code status (const Twine &path, file_status &result, bool Follow) {
804+ sandbox::violationIfEnabled ();
805+
792806 SmallString<128 > path_storage;
793807 SmallVector<wchar_t , 128 > path_utf16;
794808
@@ -823,11 +837,15 @@ std::error_code status(const Twine &path, file_status &result, bool Follow) {
823837}
824838
825839std::error_code status (int FD, file_status &Result) {
840+ sandbox::violationIfEnabled ();
841+
826842 HANDLE FileHandle = reinterpret_cast <HANDLE>(_get_osfhandle (FD));
827843 return getStatus (FileHandle, Result);
828844}
829845
830846std::error_code status (file_t FileHandle, file_status &Result) {
847+ sandbox::violationIfEnabled ();
848+
831849 return getStatus (FileHandle, Result);
832850}
833851
@@ -1242,6 +1260,8 @@ static std::error_code openNativeFileInternal(const Twine &Name,
12421260Expected<file_t > openNativeFile (const Twine &Name, CreationDisposition Disp,
12431261 FileAccess Access, OpenFlags Flags,
12441262 unsigned Mode) {
1263+ sandbox::violationIfEnabled ();
1264+
12451265 // Verify that we don't have both "append" and "excl".
12461266 assert ((!(Disp == CD_CreateNew) || !(Flags & OF_Append)) &&
12471267 " Cannot specify both 'CreateNew' and 'Append' file creation flags!" );
@@ -1277,6 +1297,8 @@ Expected<file_t> openNativeFile(const Twine &Name, CreationDisposition Disp,
12771297std::error_code openFile (const Twine &Name, int &ResultFD,
12781298 CreationDisposition Disp, FileAccess Access,
12791299 OpenFlags Flags, unsigned int Mode) {
1300+ sandbox::violationIfEnabled ();
1301+
12801302 Expected<file_t > Result = openNativeFile (Name, Disp, Access, Flags);
12811303 if (!Result)
12821304 return errorToErrorCode (Result.takeError ());
@@ -1300,12 +1322,16 @@ static std::error_code directoryRealPath(const Twine &Name,
13001322std::error_code openFileForRead (const Twine &Name, int &ResultFD,
13011323 OpenFlags Flags,
13021324 SmallVectorImpl<char > *RealPath) {
1325+ sandbox::violationIfEnabled ();
1326+
13031327 Expected<HANDLE> NativeFile = openNativeFileForRead (Name, Flags, RealPath);
13041328 return nativeFileToFd (std::move (NativeFile), ResultFD, OF_None);
13051329}
13061330
13071331Expected<file_t > openNativeFileForRead (const Twine &Name, OpenFlags Flags,
13081332 SmallVectorImpl<char > *RealPath) {
1333+ sandbox::violationIfEnabled ();
1334+
13091335 Expected<file_t > Result =
13101336 openNativeFile (Name, CD_OpenExisting, FA_Read, Flags);
13111337
@@ -1324,9 +1350,9 @@ file_t getStdinHandle() { return ::GetStdHandle(STD_INPUT_HANDLE); }
13241350file_t getStdoutHandle () { return ::GetStdHandle (STD_OUTPUT_HANDLE); }
13251351file_t getStderrHandle () { return ::GetStdHandle (STD_ERROR_HANDLE); }
13261352
1327- Expected<size_t > readNativeFileImpl (file_t FileHandle,
1328- MutableArrayRef<char > Buf,
1329- OVERLAPPED *Overlap) {
1353+ static Expected<size_t > readNativeFileImpl (file_t FileHandle,
1354+ MutableArrayRef<char > Buf,
1355+ OVERLAPPED *Overlap) {
13301356 // ReadFile can only read 2GB at a time. The caller should check the number of
13311357 // bytes and read in a loop until termination.
13321358 DWORD BytesToRead =
@@ -1342,12 +1368,16 @@ Expected<size_t> readNativeFileImpl(file_t FileHandle,
13421368}
13431369
13441370Expected<size_t > readNativeFile (file_t FileHandle, MutableArrayRef<char > Buf) {
1371+ sandbox::violationIfEnabled ();
1372+
13451373 return readNativeFileImpl (FileHandle, Buf, /* Overlap=*/ nullptr );
13461374}
13471375
13481376Expected<size_t > readNativeFileSlice (file_t FileHandle,
13491377 MutableArrayRef<char > Buf,
13501378 uint64_t Offset) {
1379+ sandbox::violationIfEnabled ();
1380+
13511381 OVERLAPPED Overlapped = {};
13521382 Overlapped.Offset = uint32_t (Offset);
13531383 Overlapped.OffsetHigh = uint32_t (Offset >> 32 );
@@ -1492,6 +1522,8 @@ void expand_tilde(const Twine &path, SmallVectorImpl<char> &dest) {
14921522
14931523std::error_code real_path (const Twine &path, SmallVectorImpl<char > &dest,
14941524 bool expand_tilde) {
1525+ sandbox::violationIfEnabled ();
1526+
14951527 dest.clear ();
14961528 if (path.isTriviallyEmpty ())
14971529 return std::error_code ();
0 commit comments