Aquamarine headers for no pch build and a heap use after free (#6892)

* build: add includes for no precompiled headers

missing includes for no precompiled headers/lto usage.

* math: avoid heap use after free

on destruction of hyprland transforms gets double freed in aquamarine
and hyprland, instead of a global use a function-local static variable
which avoids any issues related to initialization order across
different translation units.
This commit is contained in:
Tom Englund 2024-07-15 20:01:48 +02:00 committed by Vaxry
parent 648b7b3b6d
commit c4913662e1
20 changed files with 44 additions and 100 deletions

View File

@ -9,6 +9,7 @@
#include <aquamarine/output/Output.hpp>
#include <random>
#include <cstring>
#include <filesystem>
#include <unordered_set>
#include "debug/HyprCtl.hpp"
#include "debug/CrashReporter.hpp"
@ -24,6 +25,7 @@
#include "protocols/core/Compositor.hpp"
#include "protocols/core/Subcompositor.hpp"
#include "desktop/LayerSurface.hpp"
#include "render/Renderer.hpp"
#include "xwayland/XWayland.hpp"
#include <hyprutils/string/String.hpp>

View File

@ -24,6 +24,7 @@
#include <ranges>
#include <unordered_set>
#include <hyprutils/string/String.hpp>
#include <filesystem>
using namespace Hyprutils::String;
extern "C" char** environ;

View File

@ -5,6 +5,7 @@
#include <time.h>
#include <errno.h>
#include <sys/stat.h>
#include <filesystem>
#include "../plugins/PluginSystem.hpp"
#include "../signal-safe.hpp"

View File

@ -12,6 +12,8 @@
#include <sys/un.h>
#include <unistd.h>
#include <sys/poll.h>
#include <filesystem>
#include <ranges>
#include <sstream>
#include <string>

View File

@ -3,6 +3,7 @@
#include "../helpers/varlist/VarList.hpp"
#include "../managers/input/InputManager.hpp"
#include "../managers/SeatManager.hpp"
#include "../config/ConfigManager.hpp"
#include <sys/mman.h>
#include <aquamarine/input/Input.hpp>
#include <cstring>

View File

@ -4,6 +4,7 @@
#include "debug/Log.hpp"
#include "../macros.hpp"
#include <xf86drm.h>
#include <drm_fourcc.h>
/*
DRM formats are LE, while OGL is BE. The two primary formats

View File

@ -70,113 +70,28 @@ void matrixRotate(float mat[9], float rad) {
matrixMultiply(mat, mat, rotate);
}
std::unordered_map<eTransform, std::array<float, 9>> transforms = {
{HYPRUTILS_TRANSFORM_NORMAL,
{
1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_90,
{
0.0f,
1.0f,
0.0f,
-1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_180,
{
-1.0f,
0.0f,
0.0f,
0.0f,
-1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_270,
{
0.0f,
-1.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_FLIPPED,
{
-1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_FLIPPED_90,
{
0.0f,
1.0f,
0.0f,
1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_FLIPPED_180,
{
1.0f,
0.0f,
0.0f,
0.0f,
-1.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
{HYPRUTILS_TRANSFORM_FLIPPED_270,
{
0.0f,
-1.0f,
0.0f,
-1.0f,
0.0f,
0.0f,
0.0f,
0.0f,
1.0f,
}},
};
const std::unordered_map<eTransform, std::array<float, 9>>& getTransforms() {
static std::unordered_map<eTransform, std::array<float, 9>> transforms = {
{HYPRUTILS_TRANSFORM_NORMAL, {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_90, {0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_180, {-1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_270, {0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_FLIPPED, {-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_FLIPPED_90, {0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_FLIPPED_180, {1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
{HYPRUTILS_TRANSFORM_FLIPPED_270, {0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}},
};
return transforms;
}
void matrixTransform(float mat[9], eTransform transform) {
matrixMultiply(mat, mat, transforms.at(transform).data());
matrixMultiply(mat, mat, getTransforms().at(transform).data());
}
void matrixProjection(float mat[9], int width, int height, eTransform transform) {
memset(mat, 0, sizeof(*mat) * 9);
const float* t = transforms.at(transform).data();
const float* t = getTransforms().at(transform).data();
float x = 2.0f / width;
float y = 2.0f / height;

View File

@ -4,6 +4,7 @@
#include <optional>
#include <vector>
#include <functional>
#include "../memory/Memory.hpp"
/*
Hyprland synchronization timelines are based on the wlroots' ones, which

View File

@ -6,6 +6,8 @@
#include "../includes.hpp"
#include "../helpers/math/Math.hpp"
#include "../helpers/memory/Memory.hpp"
#include "../macros.hpp"
#include <aquamarine/buffer/Buffer.hpp>
class CWLSurface;

View File

@ -6,6 +6,7 @@
#include "../helpers/math/Math.hpp"
#include "../helpers/math/Math.hpp"
#include "../desktop/WLSurface.hpp"
#include "../helpers/sync/SyncTimeline.hpp"
#include <tuple>
class CMonitor;

View File

@ -49,6 +49,10 @@
#include "../helpers/Monitor.hpp"
#include "../render/Renderer.hpp"
#include "../Compositor.hpp"
#include <aquamarine/buffer/Buffer.hpp>
#include <aquamarine/backend/Backend.hpp>
void CProtocolManager::onMonitorModeChange(CMonitor* pMonitor) {
const bool ISMIRROR = pMonitor->isMirror();

View File

@ -2,6 +2,7 @@
#include "../Compositor.hpp"
#include "../debug/HyprCtl.hpp"
#include <dlfcn.h>
#include <filesystem>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__)
#include <sys/sysctl.h>

View File

@ -7,6 +7,8 @@
#include "wayland.hpp"
#include "linux-dmabuf-v1.hpp"
#include "../helpers/signal/Signal.hpp"
#include "../helpers/Format.hpp"
#include "../helpers/Monitor.hpp"
#include <aquamarine/buffer/Buffer.hpp>
class CDMABuffer;

View File

@ -8,6 +8,7 @@
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Timer.hpp"
#include "../managers/eventLoop/EventLoopTimer.hpp"
#include <aquamarine/buffer/Buffer.hpp>
class CMonitor;
class IHLBuffer;

View File

@ -8,6 +8,7 @@
#include "../../helpers/Monitor.hpp"
#include "../PresentationTime.hpp"
#include "../DRMSyncobj.hpp"
#include "../../render/Renderer.hpp"
#define LOGM PROTO::compositor->protoLog

View File

@ -3,6 +3,7 @@
#include "../core/Compositor.hpp"
#include "../DRMSyncobj.hpp"
#include "../../helpers/sync/SyncTimeline.hpp"
#include "../../Compositor.hpp"
#include <xf86drm.h>
CWLBufferResource::CWLBufferResource(SP<CWlBuffer> resource_) : resource(resource_) {

View File

@ -11,6 +11,7 @@
#include <xf86drm.h>
#include <fcntl.h>
#include <gbm.h>
#include <filesystem>
inline void loadGLProc(void* pProc, const char* name) {
void* proc = (void*)eglGetProcAddress(name);

View File

@ -2,6 +2,8 @@
#include "OpenGL.hpp"
#include "../Compositor.hpp"
#include "../protocols/types/Buffer.hpp"
#include <hyprutils/signal/Listener.hpp>
#include <hyprutils/signal/Signal.hpp>
#include <dlfcn.h>

View File

@ -1,5 +1,8 @@
#pragma once
#include "../helpers/signal/Signal.hpp"
#include "../helpers/memory/Memory.hpp"
#include "../helpers/WLListener.hpp"
#include "Framebuffer.hpp"
#include <aquamarine/buffer/Buffer.hpp>

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
#include <filesystem>
// TODO: cleanup
static bool set_cloexec(int fd, bool cloexec) {