#include <sys/statvfs.h>
#endif
-#include "qemu-common.h"
-#include "sysemu.h"
+/* FIXME: This file should be target independent. However it has kqemu
+ hacks, so must be built for every target. */
+
+/* Needed early for HOST_BSD etc. */
+#include "config-host.h"
#ifdef _WIN32
-#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-#elif defined(_BSD)
+#elif defined(HOST_BSD)
#include <stdlib.h>
#else
#include <malloc.h>
#endif
+#include "qemu-common.h"
+#include "sysemu.h"
+#include "qemu_socket.h"
+
#if defined(_WIN32)
void *qemu_memalign(size_t alignment, size_t size)
{
#else
-#if defined(USE_KQEMU)
+#if defined(CONFIG_KQEMU)
+#ifdef __OpenBSD__
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#else
+#ifndef __FreeBSD__
#include <sys/vfs.h>
+#endif
+#endif
+
#include <sys/mman.h>
#include <fcntl.h>
{
static int phys_ram_fd = -1;
static int phys_ram_size = 0;
+ void *ptr;
+
+/* no need (?) for a dummy file on OpenBSD/FreeBSD */
+#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+ int map_anon = MAP_ANON;
+#else
+ int map_anon = 0;
const char *tmpdir;
char phys_ram_file[1024];
- void *ptr;
#ifdef HOST_SOLARIS
struct statvfs stfs;
#else
int64_t free_space;
int ram_mb;
- extern int ram_size;
free_space = (int64_t)stfs.f_bavail * stfs.f_bsize;
if ((ram_size + 8192 * 1024) >= free_space) {
ram_mb = (ram_size / (1024 * 1024));
}
size = (size + 4095) & ~4095;
ftruncate(phys_ram_fd, phys_ram_size + size);
+#endif /* !(__OpenBSD__ || __FreeBSD__ || __DragonFly__) */
ptr = mmap(NULL,
size,
- PROT_WRITE | PROT_READ, MAP_SHARED,
+ PROT_WRITE | PROT_READ, map_anon | MAP_SHARED,
phys_ram_fd, phys_ram_size);
if (ptr == MAP_FAILED) {
fprintf(stderr, "Could not map physical memory\n");
if (ret != 0)
return NULL;
return ptr;
-#elif defined(_BSD)
+#elif defined(HOST_BSD)
return valloc(size);
#else
return memalign(alignment, size);
/* alloc shared memory pages */
void *qemu_vmalloc(size_t size)
{
-#if defined(USE_KQEMU)
+#if defined(CONFIG_KQEMU)
if (kqemu_allowed)
return kqemu_vmalloc(size);
#endif
-#ifdef _BSD
- return valloc(size);
-#else
- return memalign(4096, size);
-#endif
+ return qemu_memalign(getpagesize(), size);
}
void qemu_vfree(void *ptr)
{
-#if defined(USE_KQEMU)
+#if defined(CONFIG_KQEMU)
if (kqemu_allowed)
kqemu_vfree(ptr);
#endif
return 0;
}
#endif /* _WIN32 */
+
+
+#ifdef _WIN32
+void socket_set_nonblock(int fd)
+{
+ unsigned long opt = 1;
+ ioctlsocket(fd, FIONBIO, &opt);
+}
+
+int inet_aton(const char *cp, struct in_addr *ia)
+{
+ uint32_t addr = inet_addr(cp);
+ if (addr == 0xffffffff)
+ return 0;
+ ia->s_addr = addr;
+ return 1;
+}
+#else
+void socket_set_nonblock(int fd)
+{
+ int f;
+ f = fcntl(fd, F_GETFL);
+ fcntl(fd, F_SETFL, f | O_NONBLOCK);
+}
+#endif