Skip to content
Snippets Groups Projects
Commit 6518f469 authored by Martin Pitt's avatar Martin Pitt
Browse files

WIP

parent 9ebb6eca
Branches
No related tags found
No related merge requests found
...@@ -216,6 +216,87 @@ public class IoctlData : GLib.Object { ...@@ -216,6 +216,87 @@ public class IoctlData : GLib.Object {
Posix.memcpy(&data[offset], new_data, new_data.length); Posix.memcpy(&data[offset], new_data, new_data.length);
} }
/**
* umockdev_ioctl_get_int:
* @self: A #UMockdevIoctlData
*
* Return data as integer. This avoids problems with unaligned memory.
*/
public int get_int() {
int value = 0; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
Posix.memcpy(&value, data, sizeof(int));
return value;
}
/**
* umockdev_ioctl_set_int:
* @self: A #UMockdevIoctlData
* @value: Value to set
*
* Set data to given value. This avoids problems with unaligned memory.
*/
public void set_int(int value) {
Posix.memcpy(data, &value, sizeof(int));
}
/**
* umockdev_ioctl_set_uint32:
* @self: A #UMockdevIoctlData
* @value: Value to set
*
* Set data to given value. This avoids problems with unaligned memory.
*/
public void set_uint32(uint32 value) {
Posix.memcpy(data, &value, sizeof(uint32));
}
/**
* umockdev_ioctl_get_ulong:
* @self: A #UMockdevIoctlData
*
* Return data as ulong. This avoids problems with unaligned memory.
*/
public ulong get_ulong() {
ulong value = 0; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
Posix.memcpy(&value, data, sizeof(ulong));
return value;
}
/**
* umockdev_ioctl_set_ulong:
* @self: A #UMockdevIoctlData
* @value: Value to set
*
* Set data to given value. This avoids problems with unaligned memory.
*/
public void set_ulong(ulong value) {
Posix.memcpy(data, &value, sizeof(ulong));
}
/**
* umockdev_ioctl_get_long:
* @self: A #UMockdevIoctlData
*
* Return data as long. This avoids problems with unaligned memory.
*/
public long get_long() {
long value = 0; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
Posix.memcpy(&value, data, sizeof(long));
return value;
}
/**
* umockdev_ioctl_get_pointer:
* @self: A #UMockdevIoctlData
*
* Return data as pointer. This avoids problems with unaligned memory.
*/
public void* get_pointer() {
void* value = null; // unnecessary initialization, avoids "Use of possibly unassigned local variable"
Posix.memcpy(&value, data, sizeof(void*));
return value;
}
/** /**
* umockdev_ioctl_retrieve: * umockdev_ioctl_retrieve:
* @self: A #UMockdevIoctlData * @self: A #UMockdevIoctlData
...@@ -934,7 +1015,7 @@ internal class IoctlTreeHandler : IoctlBase { ...@@ -934,7 +1015,7 @@ internal class IoctlTreeHandler : IoctlBase {
} else { } else {
Posix.errno = Posix.ENOTTY; Posix.errno = Posix.ENOTTY;
} }
last = tree.execute(last, request, *(void**) client.arg.data, ref ret); last = tree.execute(last, request, client.arg.get_pointer(), ref ret);
my_errno = Posix.errno; my_errno = Posix.errno;
Posix.errno = 0; Posix.errno = 0;
if (last != null) if (last != null)
...@@ -955,7 +1036,7 @@ internal class IoctlTreeHandler : IoctlBase { ...@@ -955,7 +1036,7 @@ internal class IoctlTreeHandler : IoctlBase {
* This should only happen for REAPURB, but it does not hurt to * This should only happen for REAPURB, but it does not hurt to
* just always check. * just always check.
*/ */
if (*(void**) data.data == (void*) last_submit_urb.data) { if (data.get_pointer() == (void*) last_submit_urb.data) {
data.set_ptr(0, last_submit_urb); data.set_ptr(0, last_submit_urb);
last_submit_urb = null; last_submit_urb = null;
...@@ -1062,7 +1143,7 @@ internal class IoctlTreeRecorder : IoctlBase { ...@@ -1062,7 +1143,7 @@ internal class IoctlTreeRecorder : IoctlBase {
} }
/* Record */ /* Record */
node = new IoctlTree.Tree.from_bin(request, *(void**) client.arg.data, ret); node = new IoctlTree.Tree.from_bin(request, client.arg.get_pointer(), ret);
if (node != null) { if (node != null) {
tree.insert((owned) node); tree.insert((owned) node);
} }
......
...@@ -93,7 +93,7 @@ internal class IoctlUsbPcapHandler : IoctlBase { ...@@ -93,7 +93,7 @@ internal class IoctlUsbPcapHandler : IoctlBase {
switch (request) { switch (request) {
case USBDEVFS_GET_CAPABILITIES: case USBDEVFS_GET_CAPABILITIES:
*(uint32*) data.data = capabilities; data.set_uint32(capabilities);
client.complete(0, 0); client.complete(0, 0);
return true; return true;
...@@ -108,7 +108,7 @@ internal class IoctlUsbPcapHandler : IoctlBase { ...@@ -108,7 +108,7 @@ internal class IoctlUsbPcapHandler : IoctlBase {
case USBDEVFS_DISCARDURB: case USBDEVFS_DISCARDURB:
for (int i = 0; i < urbs.length; i++) { for (int i = 0; i < urbs.length; i++) {
if (urbs.index(i).urb_data.client_addr == *((ulong*)client.arg.data)) { if (urbs.index(i).urb_data.client_addr == client.arg.get_ulong()) {
/* Found the urb, add to discard array, remove it and return success */ /* Found the urb, add to discard array, remove it and return success */
discarded.prepend_val(urbs.index(i)); discarded.prepend_val(urbs.index(i));
urbs.remove_index(i); urbs.remove_index(i);
......
...@@ -1000,15 +1000,13 @@ static bool ...@@ -1000,15 +1000,13 @@ static bool
ioctl_custom_handle_ioctl_cb(UMockdev.IoctlBase handler, UMockdev.IoctlClient client) ioctl_custom_handle_ioctl_cb(UMockdev.IoctlBase handler, UMockdev.IoctlClient client)
{ {
if (client.request == 1) { if (client.request == 1) {
client.complete(*(long*)client.arg.data, 0); client.complete(client.arg.get_long(), 0);
} else if (client.request == 2) { } else if (client.request == 2) {
client.complete(-1, Posix.ENOMEM); client.complete(-1, Posix.ENOMEM);
} else if (client.request == 3 ) { } else if (client.request == 3 ) {
try { try {
var data = client.arg.resolve(0, sizeof(int)); var data = client.arg.resolve(0, sizeof(int));
data.set_int((int) 0xc00fffee);
*(int*) data.data = (int) 0xc00fffee;
client.complete(0, 0); client.complete(0, 0);
} catch (Error e) { } catch (Error e) {
error ("cannot resolve client arg: %s", e.message); error ("cannot resolve client arg: %s", e.message);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment