mirror of
https://github.com/qemu/qemu.git
synced 2024-11-23 10:53:37 +08:00
osdep: Move memalign-related functions to their own header
Move the various memalign-related functions out of osdep.h and into their own header, which we include only where they are used. While we're doing this, add some brief documentation comments. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-id: 20220226180723.1706285-10-peter.maydell@linaro.org
This commit is contained in:
parent
1a11265d7e
commit
5df022cf2e
@ -16,6 +16,7 @@
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
typedef struct {
|
||||
BdrvChild *test_file;
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "qemu/coroutine.h"
|
||||
#include "block/aio_task.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#define BLOCK_COPY_MAX_COPY_RANGE (16 * MiB)
|
||||
#define BLOCK_COPY_MAX_BUFFER (1 * MiB)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qemu/ratelimit.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
|
||||
enum {
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "crypto.h"
|
||||
|
||||
typedef struct BlockCrypto BlockCrypto;
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "dmg.h"
|
||||
|
||||
int (*dmg_uncompress_bz2)(char *next_in, unsigned int avail_in,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define FUSE_USE_VERSION 31
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "block/aio.h"
|
||||
#include "block/block.h"
|
||||
#include "block/export.h"
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/units.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
#include "block/thread-pool.h"
|
||||
#include "qemu/iov.h"
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "block/coroutines.h"
|
||||
#include "block/write-threshold.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qemu/ratelimit.h"
|
||||
#include "qemu/bitmap.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#define MAX_IN_FLIGHT 16
|
||||
#define MAX_IO_BYTES (1 << 20) /* 1 Mb */
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qemu/vfio-helpers.h"
|
||||
#include "block/block_int.h"
|
||||
#include "sysemu/replay.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "parallels.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "qemu/uuid.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#define PARALLELS_FORMAT_EXTENSION_MAGIC 0xAB234CEF23DCEA87ULL
|
||||
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "qapi/qapi-visit-block-core.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/bitmap.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "migration/blocker.h"
|
||||
#include "parallels.h"
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include <zlib.h>
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
|
@ -23,6 +23,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qcow2.h"
|
||||
#include "trace.h"
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qcow2.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
|
||||
int qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t exact_size)
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "qemu/range.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
|
||||
static int64_t alloc_clusters_noref(BlockDriverState *bs, uint64_t size,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
static void qcow2_free_single_snapshot(BlockDriverState *bs, int i)
|
||||
{
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "qemu/option_int.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/qobject-input-visitor.h"
|
||||
#include "qapi/qapi-visit-block-core.h"
|
||||
#include "crypto.h"
|
||||
|
@ -51,6 +51,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
#include "qed.h"
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "qemu/sockets.h" /* for EINPROGRESS on Windows */
|
||||
#include "qed.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
/* Called with table_lock held. */
|
||||
static int coroutine_fn qed_read_table(BDRVQEDState *s, uint64_t offset,
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
#include "qed.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "block/block_int.h"
|
||||
#include "block/coroutines.h"
|
||||
#include "block/qdict.h"
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
typedef struct BDRVRawState {
|
||||
uint64_t offset;
|
||||
|
@ -64,6 +64,7 @@
|
||||
#include "qemu/coroutine.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/uuid.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
/* Code configuration options. */
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "block/block_int.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "vhdx.h"
|
||||
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "qemu/crc32c.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "vhdx.h"
|
||||
#include "migration/blocker.h"
|
||||
#include "qemu/uuid.h"
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "migration/blocker.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include <zlib.h>
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "migration/blocker.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/uuid.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qobject-input-visitor.h"
|
||||
#include "qapi/qapi-visit-block-core.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "block/raw-aio.h"
|
||||
#include "qemu/event_notifier.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/error.h"
|
||||
#include "hw/xen/xen_common.h"
|
||||
#include "hw/block/xen_blkif.h"
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "qapi/error.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "hw/irq.h"
|
||||
#include "hw/isa/isa.h"
|
||||
#include "hw/qdev-properties.h"
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "qemu/hw-version.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "sysemu/blockdev.h"
|
||||
#include "sysemu/dma.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/datadir.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-events-machine.h"
|
||||
#include "qapi/qapi-events-qdev.h"
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "cpu.h"
|
||||
#include "helper_regs.h"
|
||||
#include "hw/ppc/spapr.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/hw-version.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "hw/scsi/scsi.h"
|
||||
#include "migration/qemu-file-types.h"
|
||||
#include "migration/vmstate.h"
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/error.h"
|
||||
#include "sysemu/memory_mapping.h"
|
||||
#include "migration/vmstate.h"
|
||||
|
61
include/qemu/memalign.h
Normal file
61
include/qemu/memalign.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Allocation and free functions for aligned memory
|
||||
*
|
||||
* 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_MEMALIGN_H
|
||||
#define QEMU_MEMALIGN_H
|
||||
|
||||
/**
|
||||
* qemu_try_memalign: Allocate aligned memory
|
||||
* @alignment: required alignment, in bytes
|
||||
* @size: size of allocation, in bytes
|
||||
*
|
||||
* Allocate memory on an aligned boundary (i.e. the returned
|
||||
* address will be an exact multiple of @alignment).
|
||||
* @alignment must be a power of 2, or the function will assert().
|
||||
* On success, returns allocated memory; on failure, returns NULL.
|
||||
*
|
||||
* The memory allocated through this function must be freed via
|
||||
* qemu_vfree() (and not via free()).
|
||||
*/
|
||||
void *qemu_try_memalign(size_t alignment, size_t size);
|
||||
/**
|
||||
* qemu_memalign: Allocate aligned memory, without failing
|
||||
* @alignment: required alignment, in bytes
|
||||
* @size: size of allocation, in bytes
|
||||
*
|
||||
* Allocate memory in the same way as qemu_try_memalign(), but
|
||||
* abort() with an error message if the memory allocation fails.
|
||||
*
|
||||
* The memory allocated through this function must be freed via
|
||||
* qemu_vfree() (and not via free()).
|
||||
*/
|
||||
void *qemu_memalign(size_t alignment, size_t size);
|
||||
/**
|
||||
* qemu_vfree: Free memory allocated through qemu_memalign
|
||||
* @ptr: memory to free
|
||||
*
|
||||
* This function must be used to free memory allocated via qemu_memalign()
|
||||
* or qemu_try_memalign(). (Using the wrong free function will cause
|
||||
* subtle bugs on Windows hosts.)
|
||||
*/
|
||||
void qemu_vfree(void *ptr);
|
||||
/*
|
||||
* It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define
|
||||
* g_autofree macro.
|
||||
*/
|
||||
static inline void qemu_cleanup_generic_vfree(void *p)
|
||||
{
|
||||
void **pp = (void **)p;
|
||||
qemu_vfree(*pp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free.
|
||||
*/
|
||||
#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree)))
|
||||
|
||||
#endif
|
@ -379,28 +379,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
int qemu_daemon(int nochdir, int noclose);
|
||||
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, bool shared,
|
||||
bool noreserve);
|
||||
void qemu_vfree(void *ptr);
|
||||
void qemu_anon_ram_free(void *ptr, size_t size);
|
||||
|
||||
/*
|
||||
* It's an analog of GLIB's g_autoptr_cleanup_generic_gfree(), used to define
|
||||
* g_autofree macro.
|
||||
*/
|
||||
static inline void qemu_cleanup_generic_vfree(void *p)
|
||||
{
|
||||
void **pp = (void **)p;
|
||||
qemu_vfree(*pp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Analog of g_autofree, but qemu_vfree is called on cleanup instead of g_free.
|
||||
*/
|
||||
#define QEMU_AUTO_VFREE __attribute__((cleanup(qemu_cleanup_generic_vfree)))
|
||||
|
||||
#ifdef _WIN32
|
||||
#define HAVE_CHARDEV_SERIAL 1
|
||||
#elif defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) \
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "trace.h"
|
||||
#include "nbd-internal.h"
|
||||
#include "qemu/units.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#define NBD_META_ID_BASE_ALLOCATION 0
|
||||
#define NBD_META_ID_ALLOCATION_DEPTH 1
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include "qemu/sockets.h"
|
||||
#include "qemu/iov.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
/* The buffer size needs to be investigated for optimum numbers and
|
||||
* optimum means of paging in on different systems. This size is
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "qemu/cacheinfo.h"
|
||||
#include "qemu/xxhash.h"
|
||||
#include "qemu/plugin.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "hw/core/cpu.h"
|
||||
#include "exec/exec-all.h"
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "qemu/module.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qemu/units.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qom/object_interfaces.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "block/block_int.h"
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "qemu/option.h"
|
||||
#include "qemu/timer.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#define CMD_NOFILE_OK 0x01
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "qom/object.h"
|
||||
#include "qom/object_interfaces.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qapi/visitor.h"
|
||||
#include "qapi/string-input-visitor.h"
|
||||
#include "qapi/string-output-visitor.h"
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "qemu/config-file.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/qemu-print.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "exec/memory.h"
|
||||
#include "exec/ioport.h"
|
||||
#include "sysemu/dma.h"
|
||||
|
@ -49,6 +49,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#include "sysemu/hvf.h"
|
||||
#include "sysemu/hvf_int.h"
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/config-file.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "hw/i386/x86.h"
|
||||
#include "hw/i386/apic.h"
|
||||
#include "hw/i386/apic_internal.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "qemu/units.h"
|
||||
#include "qemu/madvise.h"
|
||||
#include "qemu/mprotect.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "qemu/cacheinfo.h"
|
||||
#include "qapi/error.h"
|
||||
#include "exec/exec-all.h"
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "qemu/thread.h"
|
||||
#include "qemu/host-utils.h"
|
||||
#include "qemu/processor.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
struct thread_info {
|
||||
uint64_t r;
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "qemu/qht.h"
|
||||
#include "qemu/rcu.h"
|
||||
#include "qemu/xxhash.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
struct thread_stats {
|
||||
size_t rd;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "qemu/atomic.h"
|
||||
#include "qemu/thread.h"
|
||||
#include "qemu/cacheinfo.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
#ifdef CONFIG_ATOMIC64
|
||||
#error This file must only be compiled if !CONFIG_ATOMIC64
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/host-utils.h"
|
||||
#include "qemu/memalign.h"
|
||||
#include "trace.h"
|
||||
|
||||
void *qemu_try_memalign(size_t alignment, size_t size)
|
||||
|
@ -69,6 +69,7 @@
|
||||
#include "qemu/qht.h"
|
||||
#include "qemu/atomic.h"
|
||||
#include "qemu/rcu.h"
|
||||
#include "qemu/memalign.h"
|
||||
|
||||
//#define QHT_DEBUG
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user