mirror of
https://github.com/decompals/wibo.git
synced 2025-12-13 07:06:18 +00:00
Add Handles::clear() and run it on exit
This commit is contained in:
@@ -62,7 +62,6 @@ struct ProcessObject final : WaitableObject {
|
|||||||
explicit ProcessObject(pid_t pid, int pidfd) : WaitableObject(kType), pid(pid), pidfd(pidfd) {}
|
explicit ProcessObject(pid_t pid, int pidfd) : WaitableObject(kType), pid(pid), pidfd(pidfd) {}
|
||||||
|
|
||||||
~ProcessObject() override {
|
~ProcessObject() override {
|
||||||
std::lock_guard lk(m);
|
|
||||||
if (pidfd != -1) {
|
if (pidfd != -1) {
|
||||||
close(pidfd);
|
close(pidfd);
|
||||||
pidfd = -1;
|
pidfd = -1;
|
||||||
@@ -81,7 +80,6 @@ struct ThreadObject final : WaitableObject {
|
|||||||
explicit ThreadObject(pthread_t thread) : WaitableObject(kType), thread(thread) {}
|
explicit ThreadObject(pthread_t thread) : WaitableObject(kType), thread(thread) {}
|
||||||
|
|
||||||
~ThreadObject() override {
|
~ThreadObject() override {
|
||||||
std::lock_guard lk(m);
|
|
||||||
// Threads are detached at creation; we can safely drop
|
// Threads are detached at creation; we can safely drop
|
||||||
if (tib) {
|
if (tib) {
|
||||||
wibo::destroyTib(tib);
|
wibo::destroyTib(tib);
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ struct MappingObject : ObjectBase {
|
|||||||
};
|
};
|
||||||
|
|
||||||
MappingObject::~MappingObject() {
|
MappingObject::~MappingObject() {
|
||||||
std::lock_guard lk(m);
|
|
||||||
if (fd != -1) {
|
if (fd != -1) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = -1;
|
fd = -1;
|
||||||
|
|||||||
@@ -314,8 +314,7 @@ DWORD_PTR WIN_FUNC SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffin
|
|||||||
|
|
||||||
[[noreturn]] void exitInternal(DWORD exitCode) {
|
[[noreturn]] void exitInternal(DWORD exitCode) {
|
||||||
DEBUG_LOG("exitInternal(%u)\n", exitCode);
|
DEBUG_LOG("exitInternal(%u)\n", exitCode);
|
||||||
// We have some problems cleaning up when shutting down with exit;
|
wibo::handles().clear();
|
||||||
// temporarily use _exit to terminate without running cleanup
|
|
||||||
_exit(static_cast<int>(exitCode));
|
_exit(static_cast<int>(exitCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1625,7 +1625,7 @@ namespace msvcrt {
|
|||||||
void WIN_ENTRY _exit(int status) {
|
void WIN_ENTRY _exit(int status) {
|
||||||
HOST_CONTEXT_GUARD();
|
HOST_CONTEXT_GUARD();
|
||||||
DEBUG_LOG("_exit(%d)\n", status);
|
DEBUG_LOG("_exit(%d)\n", status);
|
||||||
_Exit(status);
|
kernel32::exitInternal(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int WIN_ENTRY strcpy_s(char *dest, size_t dest_size, const char *src) {
|
int WIN_ENTRY strcpy_s(char *dest, size_t dest_size, const char *src) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
kernel32::FsObject::~FsObject() {
|
kernel32::FsObject::~FsObject() {
|
||||||
std::lock_guard lk(m);
|
|
||||||
int fd = std::exchange(this->fd, -1);
|
int fd = std::exchange(this->fd, -1);
|
||||||
if (fd >= 0 && closeOnDestroy) {
|
if (fd >= 0 && closeOnDestroy) {
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|||||||
@@ -28,6 +28,20 @@ inline bool isPseudo(HANDLE h) noexcept { return reinterpret_cast<int32_t>(h) <
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
Handles::~Handles() { clear(); }
|
||||||
|
|
||||||
|
void Handles::clear() {
|
||||||
|
for (auto &entry : mSlots) {
|
||||||
|
if (entry.obj) {
|
||||||
|
detail::deref(entry.obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mSlots.clear();
|
||||||
|
mFreeBelow.clear();
|
||||||
|
mFreeAbove.clear();
|
||||||
|
nextIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
HANDLE Handles::alloc(Pin<> obj, uint32_t grantedAccess, uint32_t flags) {
|
HANDLE Handles::alloc(Pin<> obj, uint32_t grantedAccess, uint32_t flags) {
|
||||||
std::unique_lock lk(m);
|
std::unique_lock lk(m);
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,9 @@ class Handles {
|
|||||||
public:
|
public:
|
||||||
using OnHandleZeroFn = void (*)(ObjectBase *);
|
using OnHandleZeroFn = void (*)(ObjectBase *);
|
||||||
explicit Handles(OnHandleZeroFn cb) : mOnHandleZero(cb) {}
|
explicit Handles(OnHandleZeroFn cb) : mOnHandleZero(cb) {}
|
||||||
|
~Handles();
|
||||||
|
|
||||||
|
void clear();
|
||||||
HANDLE alloc(Pin<> obj, uint32_t grantedAccess, uint32_t flags);
|
HANDLE alloc(Pin<> obj, uint32_t grantedAccess, uint32_t flags);
|
||||||
bool release(HANDLE h);
|
bool release(HANDLE h);
|
||||||
Pin<> get(HANDLE h, HandleMeta *metaOut = nullptr);
|
Pin<> get(HANDLE h, HandleMeta *metaOut = nullptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user