vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / accelerants / intel_extreme / memory.cpp
blob731b972b72fb867569e076b71bc6381cdd0381cc
1 /*
2 * Copyright 2006-2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include "accelerant.h"
11 #include "intel_extreme.h"
13 #include <errno.h>
14 #include <unistd.h>
17 #undef TRACE
18 //#define TRACE_MEMORY
19 #ifdef TRACE_MEMORY
20 # define TRACE(x...) _sPrintf("intel_extreme accelerant:" x)
21 #else
22 # define TRACE(x...)
23 #endif
25 #define ERROR(x...) _sPrintf("intel_extreme accelerant: " x)
26 #define CALLED(x...) TRACE("CALLED %s\n", __PRETTY_FUNCTION__)
29 void
30 intel_free_memory(addr_t base)
32 if (base == 0)
33 return;
35 intel_free_graphics_memory freeMemory;
36 freeMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
37 freeMemory.buffer_base = base;
39 ioctl(gInfo->device, INTEL_FREE_GRAPHICS_MEMORY, &freeMemory,
40 sizeof(freeMemory));
44 status_t
45 intel_allocate_memory(size_t size, uint32 flags, addr_t &base)
47 intel_allocate_graphics_memory allocMemory;
48 allocMemory.magic = INTEL_PRIVATE_DATA_MAGIC;
49 allocMemory.size = size;
50 allocMemory.alignment = 0;
51 allocMemory.flags = flags;
53 if (ioctl(gInfo->device, INTEL_ALLOCATE_GRAPHICS_MEMORY, &allocMemory,
54 sizeof(allocMemory)) < 0)
55 return errno;
57 base = allocMemory.buffer_base;
58 return B_OK;