Skip to content

Commit

Permalink
Add forgotten changes
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Nov 19, 2023
1 parent 58d7036 commit f83c413
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 151 deletions.
84 changes: 0 additions & 84 deletions src/util/os_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
# define LOG_TAG "MESA"
# include <unistd.h>
# include <log/log.h>
# include <cutils/properties.h>
#elif DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS || DETECT_OS_HURD
# include <unistd.h>
#elif DETECT_OS_OPENBSD || DETECT_OS_FREEBSD
Expand Down Expand Up @@ -123,93 +122,10 @@ os_log_message(const char *message)
#endif
}

#if DETECT_OS_ANDROID
# include <ctype.h>
# include "hash_table.h"
# include "ralloc.h"
# include "simple_mtx.h"

static struct hash_table *options_tbl;

static void
options_tbl_fini(void)
{
_mesa_hash_table_destroy(options_tbl, NULL);
}

/**
* Get an option value from android's property system, as a fallback to
* getenv() (which is generally less useful on android due to processes
* typically being forked from the zygote.
*
* The option name used for getenv is translated into a property name
* by:
*
* 1) convert to lowercase
* 2) replace '_' with '.'
* 3) if necessary, prepend "mesa."
*
* For example:
* - MESA_EXTENSION_OVERRIDE -> mesa.extension.override
* - GALLIUM_HUD -> mesa.gallium.hud
*
* Note that we use a hashtable for two purposes:
* 1) Avoid re-translating the option name on subsequent lookups
* 2) Avoid leaking memory. Because property_get() returns the
* property value into a user allocated buffer, we cannot return
* that directly to the caller, so we need to strdup(). With the
* hashtable, subsquent lookups can return the existing string.
*/
static const char *
os_get_android_option(const char *name)
{
if (!options_tbl) {
options_tbl = _mesa_hash_table_create(NULL, _mesa_hash_string,
_mesa_key_string_equal);
atexit(options_tbl_fini);
}

struct hash_entry *entry = _mesa_hash_table_search(options_tbl, name);
if (entry) {
return entry->data;
}

char value[PROPERTY_VALUE_MAX];
char key[PROPERTY_KEY_MAX];
char *p = key, *end = key + PROPERTY_KEY_MAX;
/* add "mesa." prefix if necessary: */
if (strstr(name, "MESA_") != name)
p += strlcpy(p, "mesa.", end - p);
p += strlcpy(p, name, end - p);
for (int i = 0; key[i]; i++) {
if (key[i] == '_') {
key[i] = '.';
} else {
key[i] = tolower(key[i]);
}
}

const char *opt = NULL;
int len = property_get(key, value, NULL);
if (len > 1) {
opt = ralloc_strdup(options_tbl, value);
}

_mesa_hash_table_insert(options_tbl, name, (void *)opt);

return opt;
}
#endif

const char *
os_get_option(const char *name)
{
const char *opt = getenv(name);
#if DETECT_OS_ANDROID
if (!opt) {
opt = os_get_android_option(name);
}
#endif
return opt;
}

Expand Down
13 changes: 0 additions & 13 deletions src/util/perf/cpu_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@
util_perfetto_trace_end(category); \
} while (0)

/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering
* between stdatomic.h and atomic.h. See:
*
* https://github.com/android/ndk/issues/1178
*/
#elif defined(ANDROID) && !defined(__cplusplus)

#include <cutils/trace.h>

#define _MESA_TRACE_BEGIN(category, name) \
atrace_begin(ATRACE_TAG_GRAPHICS, name)
#define _MESA_TRACE_END(category) atrace_end(ATRACE_TAG_GRAPHICS)

#else

#define _MESA_TRACE_BEGIN(category, name)
Expand Down
56 changes: 2 additions & 54 deletions src/util/u_debug_stack_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* IN THE SOFTWARE.
*/

#include <backtrace/Backtrace.h>

#include "util/simple_mtx.h"
#include "util/u_debug.h"
Expand Down Expand Up @@ -52,71 +51,20 @@ debug_backtrace_capture(debug_stack_frame *backtrace,
unsigned start_frame,
unsigned nr_frames)
{
Backtrace *bt;

if (!nr_frames)
return;

bt = Backtrace::Create(BACKTRACE_CURRENT_PROCESS,
BACKTRACE_CURRENT_THREAD);
if (bt == NULL) {
for (unsigned i = 0; i < nr_frames; i++)
backtrace[i].procname = NULL;
return;
}

/* Add one to exclude this call. Unwind already ignores itself. */
bt->Unwind(start_frame + 1);

simple_mtx_lock(&table_mutex);

for (unsigned i = 0; i < nr_frames; i++) {
const backtrace_frame_data_t* frame = bt->GetFrame(i);
if (frame) {
backtrace[i].procname = intern_symbol(frame->func_name.c_str());
backtrace[i].start_ip = frame->pc;
backtrace[i].off = frame->func_offset;
backtrace[i].map = intern_symbol(frame->map.Name().c_str());
backtrace[i].map_off = frame->rel_pc;
} else {
backtrace[i].procname = NULL;
}
}

simple_mtx_unlock(&table_mutex);

delete bt;
}

void
debug_backtrace_dump(const debug_stack_frame *backtrace,
unsigned nr_frames)
{
for (unsigned i = 0; i < nr_frames; i++) {
if (backtrace[i].procname)
debug_printf(
"%s(+0x%x)\t%012" PRIx64 ": %s+0x%x\n",
backtrace[i].map,
backtrace[i].map_off,
backtrace[i].start_ip,
backtrace[i].procname,
backtrace[i].off);
}

}

void
debug_backtrace_print(FILE *f,
const debug_stack_frame *backtrace,
unsigned nr_frames)
{
for (unsigned i = 0; i < nr_frames; i++) {
if (backtrace[i].procname)
fprintf(f,
"%s(+0x%x)\t%012" PRIx64 ": %s+0x%x\n",
backtrace[i].map,
backtrace[i].map_off,
backtrace[i].start_ip,
backtrace[i].procname,
backtrace[i].off);
}

}

0 comments on commit f83c413

Please sign in to comment.