зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1879433 - Scoped.h use removed from mozglue. r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D201174
This commit is contained in:
Родитель
6a6849626c
Коммит
eb13723b60
|
@ -7,6 +7,7 @@
|
|||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <dlfcn.h>
|
||||
#include <optional>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <algorithm>
|
||||
|
@ -18,6 +19,7 @@
|
|||
#include "Logging.h"
|
||||
#include "Utils.h"
|
||||
#include <inttypes.h>
|
||||
#include "mozilla/ScopeExit.h"
|
||||
|
||||
// From Utils.h
|
||||
mozilla::Atomic<size_t, mozilla::ReleaseAcquire> gPageSize;
|
||||
|
@ -152,8 +154,8 @@ class DlIteratePhdrHelper {
|
|||
DlIteratePhdrHelper() {
|
||||
int pipefd[2];
|
||||
valid_pipe = (pipe(pipefd) == 0);
|
||||
read_fd.reset(pipefd[0]);
|
||||
write_fd.reset(pipefd[1]);
|
||||
read_fd.emplace(pipefd[0]);
|
||||
write_fd.emplace(pipefd[1]);
|
||||
}
|
||||
|
||||
int fill_and_call(dl_phdr_cb callback, const void* l_addr, const char* l_name,
|
||||
|
@ -161,8 +163,8 @@ class DlIteratePhdrHelper {
|
|||
|
||||
private:
|
||||
bool valid_pipe;
|
||||
AutoCloseFD read_fd;
|
||||
AutoCloseFD write_fd;
|
||||
std::optional<AutoCloseFD> read_fd;
|
||||
std::optional<AutoCloseFD> write_fd;
|
||||
};
|
||||
|
||||
// This function is called for each shared library iterated over by
|
||||
|
@ -199,7 +201,7 @@ int DlIteratePhdrHelper::fill_and_call(dl_phdr_cb callback, const void* l_addr,
|
|||
static_assert(sizeof(raw_ehdr) < PIPE_BUF, "PIPE_BUF is too small");
|
||||
do {
|
||||
// writes are atomic when smaller than PIPE_BUF, per POSIX.1-2008.
|
||||
ret = write(write_fd, l_addr, sizeof(raw_ehdr));
|
||||
ret = write(*write_fd, l_addr, sizeof(raw_ehdr));
|
||||
} while (ret == -1 && errno == EINTR);
|
||||
if (ret != sizeof(raw_ehdr)) {
|
||||
if (ret == -1 && errno == EFAULT) {
|
||||
|
@ -212,7 +214,7 @@ int DlIteratePhdrHelper::fill_and_call(dl_phdr_cb callback, const void* l_addr,
|
|||
do {
|
||||
// Per POSIX.1-2008, interrupted reads can return a length smaller
|
||||
// than the given one instead of failing with errno EINTR.
|
||||
ret = read(read_fd, raw_ehdr + nbytes, sizeof(raw_ehdr) - nbytes);
|
||||
ret = read(*read_fd, raw_ehdr + nbytes, sizeof(raw_ehdr) - nbytes);
|
||||
if (ret > 0) nbytes += ret;
|
||||
} while ((nbytes != sizeof(raw_ehdr) && ret > 0) ||
|
||||
(ret == -1 && errno == EINTR));
|
||||
|
@ -834,7 +836,10 @@ class EnsureWritable {
|
|||
/* The interesting part of the /proc/self/maps format looks like:
|
||||
* startAddr-endAddr rwxp */
|
||||
int result = 0;
|
||||
AutoCloseFILE f(fopen("/proc/self/maps", "r"));
|
||||
FILE* const f = fopen("/proc/self/maps", "r");
|
||||
const auto cleanup = mozilla::MakeScopeExit([&]() {
|
||||
if (f) fclose(f);
|
||||
});
|
||||
while (f) {
|
||||
unsigned long long startAddr, endAddr;
|
||||
char perms[5];
|
||||
|
|
|
@ -15,20 +15,20 @@ Mappable* Mappable::Create(const char* path) {
|
|||
|
||||
MemoryRange Mappable::mmap(const void* addr, size_t length, int prot, int flags,
|
||||
off_t offset) {
|
||||
MOZ_ASSERT(fd != -1);
|
||||
MOZ_ASSERT(fd && *fd != -1);
|
||||
MOZ_ASSERT(!(flags & MAP_SHARED));
|
||||
flags |= MAP_PRIVATE;
|
||||
|
||||
return MemoryRange::mmap(const_cast<void*>(addr), length, prot, flags, fd,
|
||||
return MemoryRange::mmap(const_cast<void*>(addr), length, prot, flags, *fd,
|
||||
offset);
|
||||
}
|
||||
|
||||
void Mappable::finalize() {
|
||||
/* Close file ; equivalent to close(fd.forget()) */
|
||||
fd = -1;
|
||||
fd.emplace(-1);
|
||||
}
|
||||
|
||||
size_t Mappable::GetLength() const {
|
||||
struct stat st;
|
||||
return fstat(fd, &st) ? 0 : st.st_size;
|
||||
return fstat(*fd, &st) ? 0 : st.st_size;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef Mappable_h
|
||||
#define Mappable_h
|
||||
|
||||
#include <optional>
|
||||
#include "mozilla/RefCounted.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
@ -48,7 +49,7 @@ class Mappable : public mozilla::RefCounted<Mappable> {
|
|||
|
||||
private:
|
||||
/* File descriptor */
|
||||
AutoCloseFD fd;
|
||||
std::optional<AutoCloseFD> fd;
|
||||
};
|
||||
|
||||
#endif /* Mappable_h */
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <unistd.h>
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
|
||||
/**
|
||||
* On architectures that are little endian and that support unaligned reads,
|
||||
|
@ -75,29 +74,15 @@ typedef le_to_cpu<unsigned char> le_uint16;
|
|||
typedef le_to_cpu<le_uint16> le_uint32;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* AutoCloseFD is a RAII wrapper for POSIX file descriptors
|
||||
*/
|
||||
struct AutoCloseFDTraits {
|
||||
typedef int type;
|
||||
static int empty() { return -1; }
|
||||
static void release(int fd) {
|
||||
struct AutoCloseFD {
|
||||
const int fd;
|
||||
|
||||
MOZ_IMPLICIT AutoCloseFD(int fd) : fd(fd) {}
|
||||
~AutoCloseFD() {
|
||||
if (fd != -1) close(fd);
|
||||
}
|
||||
operator int() const { return fd; }
|
||||
};
|
||||
typedef mozilla::Scoped<AutoCloseFDTraits> AutoCloseFD;
|
||||
|
||||
/**
|
||||
* AutoCloseFILE is a RAII wrapper for POSIX streams
|
||||
*/
|
||||
struct AutoCloseFILETraits {
|
||||
typedef FILE* type;
|
||||
static FILE* empty() { return nullptr; }
|
||||
static void release(FILE* f) {
|
||||
if (f) fclose(f);
|
||||
}
|
||||
};
|
||||
typedef mozilla::Scoped<AutoCloseFILETraits> AutoCloseFILE;
|
||||
|
||||
extern mozilla::Atomic<size_t, mozilla::ReleaseAcquire> gPageSize;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче