mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-12 21:35:37 +00:00
547fabd58e
NEED_CPU_H is the define we use to distinguish per-target object compilation from common object compilation. For the former, we must also include config-target.h so that the .c files see the necessary CONFIG_ constants. Backports commit b1e34d1c3a9059e87719634bfc4db53174d63e14 from qemu
160 lines
3.7 KiB
C
160 lines
3.7 KiB
C
/*
|
|
* OS includes and handling of OS dependencies
|
|
*
|
|
* This header exists to pull in some common system headers that
|
|
* most code in QEMU will want, and to fix up some possible issues with
|
|
* it (missing defines, Windows weirdness, and so on).
|
|
*
|
|
* To avoid getting into possible circular include dependencies, this
|
|
* file should not include any other QEMU headers, with the exceptions
|
|
* of config-host.h, compiler.h, os-posix.h and os-win32.h, all of which
|
|
* are doing a similar job to this file and are under similar constraints.
|
|
*
|
|
* This header also contains prototypes for functions defined in
|
|
* os-*.c and util/oslib-*.c; those would probably be better split
|
|
* out into separate header files.
|
|
*
|
|
* In an ideal world this header would contain only:
|
|
* (1) things which everybody needs
|
|
* (2) things without which code would work on most platforms but
|
|
* fail to compile or misbehave on a minority of host OSes
|
|
*
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
* See the COPYING file in the top-level directory.
|
|
*/
|
|
#ifndef QEMU_OSDEP_H
|
|
#define QEMU_OSDEP_H
|
|
|
|
#include "config-host.h"
|
|
#ifdef NEED_CPU_H
|
|
#include "config-target.h"
|
|
#endif
|
|
#include "qemu/compiler.h"
|
|
|
|
/* Older versions of C++ don't get definitions of various macros from
|
|
* stdlib.h unless we define these macros before first inclusion of
|
|
* that system header.
|
|
*/
|
|
#ifndef __STDC_CONSTANT_MACROS
|
|
#define __STDC_CONSTANT_MACROS
|
|
#endif
|
|
#ifndef __STDC_LIMIT_MACROS
|
|
#define __STDC_LIMIT_MACROS
|
|
#endif
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
#define __STDC_FORMAT_MACROS
|
|
#endif
|
|
|
|
|
|
#include <stdarg.h>
|
|
#include <stddef.h>
|
|
#include "unicorn/platform.h"
|
|
#include <sys/types.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <strings.h>
|
|
#include <inttypes.h>
|
|
#include <limits.h>
|
|
#include <time.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
#include <assert.h>
|
|
#include <signal.h>
|
|
|
|
#ifdef __OpenBSD__
|
|
#include <sys/signal.h>
|
|
#endif
|
|
|
|
#ifndef _WIN32
|
|
#include <sys/wait.h>
|
|
#else
|
|
#define WIFEXITED(x) 1
|
|
#define WEXITSTATUS(x) (x)
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#include "sysemu/os-win32.h"
|
|
#endif
|
|
|
|
#include "glib_compat.h"
|
|
|
|
#ifndef O_LARGEFILE
|
|
#define O_LARGEFILE 0
|
|
#endif
|
|
#ifndef O_BINARY
|
|
#define O_BINARY 0
|
|
#endif
|
|
#ifndef MAP_ANONYMOUS
|
|
#define MAP_ANONYMOUS MAP_ANON
|
|
#endif
|
|
#ifndef ENOMEDIUM
|
|
#define ENOMEDIUM ENODEV
|
|
#endif
|
|
#if !defined(ENOTSUP)
|
|
#define ENOTSUP 4096
|
|
#endif
|
|
#if !defined(ECANCELED)
|
|
#define ECANCELED 4097
|
|
#endif
|
|
#if !defined(EMEDIUMTYPE)
|
|
#define EMEDIUMTYPE 4098
|
|
#endif
|
|
#ifndef TIME_MAX
|
|
#define TIME_MAX LONG_MAX
|
|
#endif
|
|
|
|
#ifndef MIN
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
#endif
|
|
#ifndef MAX
|
|
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
|
#endif
|
|
|
|
/* Minimum function that returns zero only iff both values are zero.
|
|
* Intended for use with unsigned values only. */
|
|
#ifndef MIN_NON_ZERO
|
|
#define MIN_NON_ZERO(a, b) (((a) != 0 && (a) < (b)) ? (a) : (b))
|
|
#endif
|
|
|
|
#ifndef ROUND_UP
|
|
#define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
|
|
#endif
|
|
|
|
#ifndef DIV_ROUND_UP
|
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
|
#endif
|
|
|
|
#ifndef ARRAY_SIZE
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
#endif
|
|
|
|
void *qemu_try_memalign(size_t alignment, size_t size);
|
|
void *qemu_memalign(size_t alignment, size_t size);
|
|
void *qemu_anon_ram_alloc(size_t size, uint64_t *align);
|
|
void qemu_vfree(void *ptr);
|
|
void qemu_anon_ram_free(void *ptr, size_t size);
|
|
|
|
#if defined(__HAIKU__) && defined(__i386__)
|
|
#define FMT_pid "%ld"
|
|
#elif defined(WIN64)
|
|
#define FMT_pid "%" PRId64
|
|
#else
|
|
#define FMT_pid "%d"
|
|
#endif
|
|
|
|
/**
|
|
* qemu_getauxval:
|
|
* @type: the auxiliary vector key to lookup
|
|
*
|
|
* Search the auxiliary vector for @type, returning the value
|
|
* or 0 if @type is not present.
|
|
*/
|
|
unsigned long qemu_getauxval(unsigned long type);
|
|
|
|
#endif
|