Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review comments
  • Loading branch information
Gabriel Schulhof committed Apr 28, 2020
commit 19794299c53df5971f037ed95610d5b698839a2c
29 changes: 17 additions & 12 deletions src/large_pages/node_large_page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,14 @@ inline uintptr_t hugepage_align_down(uintptr_t addr) {
#endif // ifndef ElfW
#endif // defined(__FreeBSD__)

#define CONSTRUCT_ONLY(class_name) \
class_name(const class_name&) = delete; \
class_name(class_name&&) = delete; \
void operator= (const class_name&) = delete; \
void operator= (const class_name&&) = delete

// Functions in this class must always be inlined because they must end up in
// the `lpstub` section rather than the `.text` section.
class MemoryMapPointer {
public:
CONSTRUCT_ONLY(MemoryMapPointer);
MemoryMapPointer(const MemoryMapPointer&) = delete;
MemoryMapPointer(MemoryMapPointer&&) = delete;
void operator= (const MemoryMapPointer&) = delete;
void operator= (const MemoryMapPointer&&) = delete;
FORCE_INLINE explicit MemoryMapPointer() {}
FORCE_INLINE bool operator==(void* rhs) const { return mem_ == rhs; }
FORCE_INLINE void* mem() const { return mem_; }
Expand Down Expand Up @@ -175,19 +172,26 @@ class MemoryMapPointer {

class MappedFilePointer: public MemoryMapPointer {
public:
CONSTRUCT_ONLY(MappedFilePointer);
MappedFilePointer(const MappedFilePointer&) = delete;
MappedFilePointer(MappedFilePointer&&) = delete;
void operator= (const MappedFilePointer&) = delete;
void operator= (const MappedFilePointer&&) = delete;
FORCE_INLINE explicit MappedFilePointer() {}
FORCE_INLINE void Reset(void* start,
const char* fname,
int prot,
int flags,
size_t offset = 0) {
struct stat file_info;
if (stat(fname, &file_info) == -1) goto fail;
Debug("Hugepages info: attempting to open %s\n", fname);

fd_ = open(fname, O_RDONLY);
do
fd_ = open(fname, O_RDONLY);
while (fd_ == -1 && errno == EINTR);
if (fd_ == -1) goto fail;

struct stat file_info;
if (fstat(fd_, &file_info) == -1) goto fail;

MemoryMapPointer::Reset(start, file_info.st_size, prot, flags, fd_, offset);
return;
fail:
Expand All @@ -197,6 +201,7 @@ class MappedFilePointer: public MemoryMapPointer {
FORCE_INLINE ~MappedFilePointer() {
if (fd_ == -1) return;
if (close(fd_) == 0) return;
if (errno == EINTR || errno == EINPROGRESS) return;
PrintSystemError(errno);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you if (errno == EINTR || errno == EINPROGRESS) return;?

close(2) is interruptible but you shouldn't retry - it's going to get closed anyway - and printing an error isn't useful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this.

}

Expand Down Expand Up @@ -233,7 +238,7 @@ bool FindTextSection(const std::string& exename, ElfW(Shdr)* text_section) {
for (uint32_t idx = 0; idx < ehdr->e_shnum; idx++) {
const ElfW(Shdr)* sh = &shdrs[idx];
const char* section_name = static_cast<const char*>(&snames[sh->sh_name]);
if (std::string(section_name) == ".text") {
if (!strcmp(section_name, ".text")) {
*text_section = *sh;
return true;
}
Expand Down