43
43
#include <sys/types.h>
47
#include <IOKit/IOTypes.h>
48
#include <CoreFoundation/CFData.h>
49
#include <CoreFoundation/CFNumber.h>
50
#include <CoreFoundation/CFDictionary.h>
51
#include <CoreFoundation/CFArray.h>
52
#include <CoreFoundation/CFString.h>
55
46
#include "vm_assert.h"
56
47
#include "unicodeTypes.h"
59
#define SYSTEM_VOL_DIR "/Volumes"
63
51
* Define the Util_ThreadID type.
72
60
typedef pid_t Util_ThreadID;
76
EXTERN char *Util_CFStringToUTF8CString(CFStringRef s);
77
EXTERN char *Util_IORegCopyStringProperty(io_object_t entry, CFStringRef property);
78
EXTERN Bool Util_IORegGetNumberProperty(io_object_t entry, CFStringRef property,
79
CFNumberType type, void *val);
80
EXTERN Bool Util_IORegGetBooleanProperty(io_object_t entry, CFStringRef property,
82
EXTERN CFDataRef Util_IORegCopyDataProperty(io_object_t entry, CFStringRef property);
83
EXTERN CFDictionaryRef Util_IORegCopyDictionaryProperty(io_object_t entry,
84
CFStringRef property);
85
EXTERN CFMutableDictionaryRef UtilMacos_CreateCFDictionary(
86
unsigned int numPairs, ...);
87
EXTERN io_service_t Util_IORegGetDeviceObjectByName(const char *deviceName);
88
EXTERN char *Util_GetBSDName(const char *deviceName);
89
EXTERN char *Util_IORegGetDriveType(const char *deviceName);
90
EXTERN uint64 Util_GetPartitionOffset(const char *bsdDev);
91
EXTERN char *Util_GetMacOSDefaultVMPath();
94
* Mac laptops without a cdrom drive (currently only the Air, but maybe
95
* more in the future) provide a way to use a desktop's cdrom drive
96
* remotely over the network. These functions enumerate all such
97
* remote disks currently mounted as volumes, and return a list of
98
* volume to bsd name mappings. The bsd device can be considered a
99
* flat-file representation of the disk contents and can be connected
100
* to our cdrom image backend. We also include the size, since we must
101
* get that from the IO registry as well, and it doesn't change while
102
* the disk is mounted.
104
* FYI, Apple calls this "Remote Disc" not "Remote Disk", so we follow
105
* that convention here too.
107
typedef struct RemoteDiscList {
110
uint64 size; // In bytes
111
struct RemoteDiscList *next;
114
EXTERN RemoteDiscList *Util_GetRemoteDiscList(void);
115
EXTERN void Util_FreeRemoteDiscList(RemoteDiscList *list);
118
* Additional keys for disk/partition device properties.
120
EXTERN const CFStringRef kUtilMacosDeviceSerialNumberKey;
121
EXTERN const CFStringRef kUtilMacosVolumeOffsetKey;
123
EXTERN CFDictionaryRef UtilMacos_CopyDiskDeviceProperties(const char *bsdDev);
124
EXTERN CFArrayRef UtilMacos_CopyDiskDeviceBSDNames(const char *parentDisk);
128
64
EXTERN uint32 CRC_Compute(const uint8 *buf, int len);
129
65
EXTERN uint32 Util_Checksum32(const uint32 *buf, int len);
130
66
EXTERN uint32 Util_Checksum(const uint8 *buf, int len);
131
67
EXTERN uint32 Util_Checksumv(void *iov, int numEntries);
68
EXTERN uint32 Util_HashString(const char *str);
132
69
EXTERN Unicode Util_ExpandString(ConstUnicode fileName);
133
70
EXTERN void Util_ExitThread(int);
134
71
EXTERN NORETURN void Util_ExitProcessAbruptly(int);
192
129
int Util_CompareDotted(const char *s1, const char *s2);
132
* This enum defines how Util_GetOpt should handle non-option arguments:
134
* UTIL_NONOPT_PERMUTE: Permute argv so that all non-options are at the end.
135
* UTIL_NONOPT_STOP: Stop when first non-option argument is seen.
136
* UTIL_NONOPT_ALL: Return each non-option argument as if it were
137
* an option with character code 1.
139
typedef enum { UTIL_NONOPT_PERMUTE, UTIL_NONOPT_STOP, UTIL_NONOPT_ALL } Util_NonOptMode;
141
int Util_GetOpt(int argc, char * const *argv, const struct option *opts,
142
Util_NonOptMode mode);
194
145
#if defined(VMX86_STATS)
195
146
Bool Util_QueryCStResidency(uint32 *numCpus, uint32 *numCStates,
196
147
uint64 **transitns, uint64 **residency,
203
154
EXTERN Bool Util_Throttle(uint32 count);
204
155
EXTERN uint32 Util_FastRand(uint32 seed);
159
*-----------------------------------------------------------------------------
161
* Util_ValidateBytes --
163
* Check that memory is filled with the specified value.
167
* !NULL First address that doesn't have the proper value
172
*-----------------------------------------------------------------------------
176
Util_ValidateBytes(const void *ptr, // IN: ptr to check
177
size_t size, // IN: size of ptr
178
uint8 byteValue) // IN: memory must be filled with this
193
/* Compare bytes until a "nice" boundary is achieved. */
194
while ((uintptr_t) p % sizeof bigValue) {
195
if (*p != byteValue) {
206
/* Compare using a "nice sized" chunk for a long as possible. */
207
memset(&bigValue, (int) byteValue, sizeof bigValue);
209
while (p + sizeof bigValue <= end) {
210
if (*((uint64 *) p) != bigValue) {
211
/* That's not right... let the loop below report the exact address. */
215
size -= sizeof bigValue;
216
p += sizeof bigValue;
219
/* Handle any trailing bytes. */
221
if (*p != byteValue) {
207
233
*----------------------------------------------------------------------
209
235
* Util_BufferIsEmpty --
211
* Determine wether or not the buffer of 'len' bytes starting at 'base' is
212
* empty (i.e. full of zeroes)
237
* Determine if the specified buffer of 'len' bytes starting at 'base'
238
* is empty (i.e. full of zeroes).
221
247
*----------------------------------------------------------------------
224
static INLINE Bool Util_BufferIsEmpty(void const *base, // IN
251
Util_BufferIsEmpty(void const *base, // IN:
231
ASSERT_ON_COMPILE(sizeof(uint32) == 4);
233
p32 = (uint32 const *)base;
235
for (; p32 < e32; p32++) {
242
p16 = (uint16 const *)p32;
253
&& *(uint8 const *)p16) {
254
return Util_ValidateBytes(base, len, '\0') == NULL;
261
258
EXTERN Bool Util_MakeSureDirExistsAndAccessible(char const *path,
264
261
#ifdef N_PLAT_NLM
265
262
# define DIRSEPS "\\"