10000 Move unjit::FileDescriptor un main header · randomstuff/unjit@33e8f00 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33e8f00

Browse files
author
Gabriel Corona
committed
Move unjit::FileDescriptor un main header
Will be needed for reading /dev/$pid/mem with process_vm_readv. With this, it might be possible to make the software work on FreeBSD.
1 parent 965db7f commit 33e8f00

File tree

2 files changed

+43
-17
lines changed

2 files changed

+43
-17
lines changed

src/Module.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,6 @@ THE SOFTWARE.
3232

3333
namespace unjit {
3434

35-
struct FileDescriptor {
36-
private:
37-
int fd_;
38-
public:
39-
explicit FileDescriptor(int fd) : fd_(fd) {}
40-
~FileDescriptor()
41-
{
42-
close(fd_);
43-
}
44-
FileDescriptor(FileDescriptor&) = delete;
45-
FileDescriptor& operator=(FileDescriptor&) = delete;
46-
operator int() const
47-
{
48-
return fd_;
49-
}
50-
};
51-
5235
class elf_deleter {
5336
public:
5437
void operator()(Elf* elf) const

src/unjit.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,54 @@ THE SOFTWARE.
3333
#include <iostream>
3434
#include <vector>
3535

36+
#include <unistd.h>
37+
3638
#include <llvm-c/Target.h>
3739
#include <llvm-c/Disassembler.h>
3840

3941
namespace unjit {
4042

43+
struct FileDescriptor {
44+
private:
45+
int fd_;
46+
public:
47+
FileDescriptor() : fd_(-1) {}
48+
explicit FileDescriptor(int fd) : fd_(fd) {}
49+
~FileDescriptor()
50+
{
51+
this->close();
52+
}
53+
54+
FileDescriptor(FileDescriptor&) = delete;
55+
FileDescriptor& operator=(FileDescriptor&) = delete;
56+
57+
FileDescriptor(FileDescriptor&& that)
58+
{
59+
this->close();
60+
this->fd_ = that.fd_;
61+
that.fd_ = -1;
62+
}
63+
FileDescriptor& operator=(FileDescriptor&& that)
64+
{
65+
this->close();
66+
this->fd_ = that.fd_;
67+
that.fd_ = -1;
68+
return *this;
69+
}
70+
71+
operator int() const
72+
{
73+
return fd_;
74+
}
75+
void close()
76+
{
77+
if (fd_ >= 0) {
78+
::close(fd_);
79+
fd_ = -1;
80+
}
81+
}
82+
};
83+
4184
struct Symbol {
4285
std::uint64_t value;
4386
std::uint64_t size;

0 commit comments

Comments
 (0)
0