Skip to content

Commit b71e695

Browse files
committed
Sink directory_iterator violations from header into the implementations
1 parent 8929850 commit b71e695

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

llvm/include/llvm/Support/FileSystem.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "llvm/Support/ErrorHandling.h"
3737
#include "llvm/Support/ErrorOr.h"
3838
#include "llvm/Support/FileSystem/UniqueID.h"
39-
#include "llvm/Support/IOSandbox.h"
4039
#include "llvm/Support/MD5.h"
4140
#include <cassert>
4241
#include <cstdint>
@@ -1448,8 +1447,6 @@ class directory_iterator {
14481447
explicit directory_iterator(const Twine &path, std::error_code &ec,
14491448
bool follow_symlinks = true)
14501449
: FollowSymlinks(follow_symlinks) {
1451-
sandbox::violationIfEnabled();
1452-
14531450
State = std::make_shared<detail::DirIterState>();
14541451
SmallString<128> path_storage;
14551452
ec = detail::directory_iterator_construct(
@@ -1459,8 +1456,6 @@ class directory_iterator {
14591456
explicit directory_iterator(const directory_entry &de, std::error_code &ec,
14601457
bool follow_symlinks = true)
14611458
: FollowSymlinks(follow_symlinks) {
1462-
sandbox::violationIfEnabled();
1463-
14641459
State = std::make_shared<detail::DirIterState>();
14651460
ec = detail::directory_iterator_construct(
14661461
*State, de.path(), FollowSymlinks);
@@ -1471,8 +1466,6 @@ class directory_iterator {
14711466

14721467
// No operator++ because we need error_code.
14731468
directory_iterator &increment(std::error_code &ec) {
1474-
sandbox::violationIfEnabled();
1475-
14761469
ec = directory_iterator_increment(*State);
14771470
return *this;
14781471
}
@@ -1518,17 +1511,13 @@ class recursive_directory_iterator {
15181511
bool follow_symlinks = true)
15191512
: State(std::make_shared<detail::RecDirIterState>()),
15201513
Follow(follow_symlinks) {
1521-
sandbox::violationIfEnabled();
1522-
15231514
State->Stack.push_back(directory_iterator(path, ec, Follow));
15241515
if (State->Stack.back() == directory_iterator())
15251516
State.reset();
15261517
}
15271518

15281519
// No operator++ because we need error_code.
15291520
recursive_directory_iterator &increment(std::error_code &ec) {
1530-
sandbox::violationIfEnabled();
1531-
15321521
const directory_iterator end_itr = {};
15331522

15341523
if (State->HasNoPushRequest)

llvm/lib/Support/MemoryBuffer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/Support/Error.h"
2121
#include "llvm/Support/ErrorHandling.h"
2222
#include "llvm/Support/FileSystem.h"
23+
#include "llvm/Support/IOSandbox.h"
2324
#include "llvm/Support/Process.h"
2425
#include "llvm/Support/Program.h"
2526
#include "llvm/Support/SmallVectorMemoryBuffer.h"

llvm/lib/Support/Unix/Path.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
//===----------------------------------------------------------------------===//
1717

1818
#include "Unix.h"
19+
20+
#include "llvm/Support/IOSandbox.h"
21+
1922
#include <limits.h>
2023
#include <stdio.h>
2124
#include <sys/stat.h>
@@ -925,6 +928,8 @@ int mapped_file_region::alignment() { return Process::getPageSizeEstimate(); }
925928
std::error_code detail::directory_iterator_construct(detail::DirIterState &it,
926929
StringRef path,
927930
bool follow_symlinks) {
931+
sandbox::violationIfEnabled();
932+
928933
SmallString<128> path_null(path);
929934
DIR *directory = ::opendir(path_null.c_str());
930935
if (!directory)
@@ -960,6 +965,8 @@ static file_type direntType(dirent *Entry) {
960965
}
961966

962967
std::error_code detail::directory_iterator_increment(detail::DirIterState &It) {
968+
sandbox::violationIfEnabled();
969+
963970
errno = 0;
964971
dirent *CurDir = ::readdir(reinterpret_cast<DIR *>(It.IterationHandle));
965972
if (CurDir == nullptr && errno != 0) {

llvm/lib/Support/Windows/Path.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/Support/ConvertUTF.h"
20+
#include "llvm/Support/IOSandbox.h"
2021
#include "llvm/Support/WindowsError.h"
2122
#include <fcntl.h>
2223
#include <sys/stat.h>
@@ -1070,6 +1071,8 @@ static basic_file_status status_from_find_data(WIN32_FIND_DATAW *FindData) {
10701071
std::error_code detail::directory_iterator_construct(detail::DirIterState &IT,
10711072
StringRef Path,
10721073
bool FollowSymlinks) {
1074+
sandbox::violationIfEnabled();
1075+
10731076
SmallVector<wchar_t, 128> PathUTF16;
10741077

10751078
if (std::error_code EC = widenPath(Path, PathUTF16))
@@ -1135,6 +1138,8 @@ std::error_code detail::directory_iterator_destruct(detail::DirIterState &IT) {
11351138
}
11361139

11371140
std::error_code detail::directory_iterator_increment(detail::DirIterState &IT) {
1141+
sandbox::violationIfEnabled();
1142+
11381143
WIN32_FIND_DATAW FindData;
11391144
if (!::FindNextFileW(HANDLE(IT.IterationHandle), &FindData)) {
11401145
DWORD LastError = ::GetLastError();

0 commit comments

Comments
 (0)