Skip to content

Commit dfc76de

Browse files
authored
Adding initial support for Linux (#609)
1 parent 6fd3bfa commit dfc76de

File tree

73 files changed

+15912
-252
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+15912
-252
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ imgui.ini
88
*.vcxproj*
99
*.sln
1010
*.vcxitems*
11-
/Releases/
11+
/Releases/
12+
Makefile

Dependencies/glfw/premake5.lua

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,19 @@ project "glfw"
1717
"include"
1818
}
1919

20-
defines {
21-
"_GLFW_WIN32"
22-
}
20+
filter { "system:window" }
21+
defines { "_GLFW_WIN32" }
22+
23+
filter { "system:linux" }
24+
defines { "_GLFW_X11", "_GNU_SOURCE" }
25+
removefiles {
26+
"src/win32_*",
27+
"src/cocoa_*",
28+
"src/posix_time.h",
29+
"src/wgl_*",
30+
"src/nsgl_*"
31+
}
32+
2333

2434
filter { "configurations:Debug" }
2535
defines { "DEBUG" }

Dependencies/tracy/client/TracyFastVector.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define __TRACYFASTVECTOR_HPP__
33

44
#include <assert.h>
5+
#include <cstring>
56
#include <stddef.h>
67

78
#include "../common/TracyAlloc.hpp"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright (C) 2012-2016 Free Software Foundation, Inc.
2+
3+
# Redistribution and use in source and binary forms, with or without
4+
# modification, are permitted provided that the following conditions are
5+
# met:
6+
7+
# (1) Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
10+
# (2) Redistributions in binary form must reproduce the above copyright
11+
# notice, this list of conditions and the following disclaimer in
12+
# the documentation and/or other materials provided with the
13+
# distribution.
14+
15+
# (3) The name of the author may not be used to
16+
# endorse or promote products derived from this software without
17+
# specific prior written permission.
18+
19+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29+
# POSSIBILITY OF SUCH DAMAGE.
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/* alloc.c -- Memory allocation without mmap.
2+
Copyright (C) 2012-2021 Free Software Foundation, Inc.
3+
Written by Ian Lance Taylor, Google.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
(1) Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
12+
(2) Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in
14+
the documentation and/or other materials provided with the
15+
distribution.
16+
17+
(3) The name of the author may not be used to
18+
endorse or promote products derived from this software without
19+
specific prior written permission.
20+
21+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
POSSIBILITY OF SUCH DAMAGE. */
32+
33+
#include "config.h"
34+
35+
#include <errno.h>
36+
#include <stdlib.h>
37+
#include <sys/types.h>
38+
39+
#include "backtrace.hpp"
40+
#include "internal.hpp"
41+
42+
#include "../common/TracyAlloc.hpp"
43+
44+
namespace tracy
45+
{
46+
47+
/* Allocation routines to use on systems that do not support anonymous
48+
mmap. This implementation just uses malloc, which means that the
49+
backtrace functions may not be safely invoked from a signal
50+
handler. */
51+
52+
/* Allocate memory like malloc. If ERROR_CALLBACK is NULL, don't
53+
report an error. */
54+
55+
void *
56+
backtrace_alloc (struct backtrace_state *state ATTRIBUTE_UNUSED,
57+
size_t size, backtrace_error_callback error_callback,
58+
void *data)
59+
{
60+
void *ret;
61+
62+
ret = tracy_malloc (size);
63+
if (ret == NULL)
64+
{
65+
if (error_callback)
66+
error_callback (data, "malloc", errno);
67+
}
68+
return ret;
69+
}
70+
71+
/* Free memory. */
72+
73+
void
74+
backtrace_free (struct backtrace_state *state ATTRIBUTE_UNUSED,
75+
void *p, size_t size ATTRIBUTE_UNUSED,
76+
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
77+
void *data ATTRIBUTE_UNUSED)
78+
{
79+
tracy_free (p);
80+
}
81+
82+
/* Grow VEC by SIZE bytes. */
83+
84+
void *
85+
backtrace_vector_grow (struct backtrace_state *state ATTRIBUTE_UNUSED,
86+
size_t size, backtrace_error_callback error_callback,
87+
void *data, struct backtrace_vector *vec)
88+
{
89+
void *ret;
90+
91+
if (size > vec->alc)
92+
{
93+
size_t alc;
94+
void *base;
95+
96+
if (vec->size == 0)
97+
alc = 32 * size;
98+
else if (vec->size >= 4096)
99+
alc = vec->size + 4096;
100+
else
101+
alc = 2 * vec->size;
102+
103+
if (alc < vec->size + size)
104+
alc = vec->size + size;
105+
106+
base = tracy_realloc (vec->base, alc);
107+
if (base == NULL)
108+
{
109+
error_callback (data, "realloc", errno);
110+
return NULL;
111+
}
112+
113+
vec->base = base;
114+
vec->alc = alc - vec->size;
115+
}
116+
117+
ret = (char *) vec->base + vec->size;
118+
vec->size += size;
119+
vec->alc -= size;
120+
return ret;
121+
}
122+
123+
/* Finish the current allocation on VEC. */
124+
125+
void *
126+
backtrace_vector_finish (struct backtrace_state *state,
127+
struct backtrace_vector *vec,
128+
backtrace_error_callback error_callback,
129+
void *data)
130+
{
131+
void *ret;
132+
133+
/* With this allocator we call realloc in backtrace_vector_grow,
134+
which means we can't easily reuse the memory here. So just
135+
release it. */
136+
if (!backtrace_vector_release (state, vec, error_callback, data))
137+
return NULL;
138+
ret = vec->base;
139+
vec->base = NULL;
140+
vec->size = 0;
141+
vec->alc = 0;
142+
return ret;
143+
}
144+
145+
/* Release any extra space allocated for VEC. */
146+
147+
int
148+
backtrace_vector_release (struct backtrace_state *state ATTRIBUTE_UNUSED,
149+
struct backtrace_vector *vec,
150+
backtrace_error_callback error_callback,
151+
void *data)
152+
{
153+
vec->alc = 0;
154+
155+
if (vec->size == 0)
156+
{
157+
/* As of C17, realloc with size 0 is marked as an obsolescent feature, use
158+
free instead. */
159+
tracy_free (vec->base);
160+
vec->base = NULL;
161+
return 1;
162+
}
163+
164+
vec->base = tracy_realloc (vec->base, vec->size);
165+
if (vec->base == NULL)
166+
{
167+
error_callback (data, "realloc", errno);
168+
return 0;
169+
}
170+
171+
return 1;
172+
}
173+
174+
}

0 commit comments

Comments
 (0)