1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | #include <fcntl.h> |
22 | #include <hurd.h> |
23 | #include <mach.h> |
24 | #include <device/device.h> |
25 | |
26 | #include "maptime.h" |
27 |
|
28 | |
29 | |
30 | |
31 | |
32 | |
33 | error_t |
34 | maptime_map (int use_mach_dev, char *dev_name, |
35 | volatile struct mapped_time_value **mtime) |
36 | { |
37 | error_t err; |
38 | mach_port_t memobj; |
39 | |
40 | if (use_mach_dev) |
| 1 | Assuming 'use_mach_dev' is not equal to 0 | |
|
| |
41 | { |
42 | device_t device; |
| 3 | | Variable 'device' declared without an initial value | |
|
43 | mach_port_t device_master; |
44 | |
45 | err = get_privileged_ports (0, &device_master); |
46 | if (! err) |
| 4 | | Assuming 'err' is not equal to 0 | |
|
| |
47 | { |
48 | err = device_open (device_master, 0, dev_name ?: "time", &device); |
49 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), device_master); |
50 | if (err) |
51 | return err; |
52 | } |
53 | |
54 | err = device_map (device, VM_PROT_READ((vm_prot_t) 0x01), 0, sizeof *mtime, &memobj, 0); |
| 6 | | Function call argument is an uninitialized value |
|
55 | } |
56 | else |
57 | { |
58 | mach_port_t wr_memobj; |
59 | file_t node = file_name_lookup (dev_name ?: "/dev/time", O_RDONLY0x0001, 0); |
60 | |
61 | if (node == MACH_PORT_NULL((mach_port_t) 0)) |
62 | return errno(*__errno_location ()); |
63 | |
64 | err = io_map (node, &memobj, &wr_memobj); |
65 | if (!err && wr_memobj != MACH_PORT_NULL((mach_port_t) 0)) |
66 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), wr_memobj); |
67 | |
68 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), node); |
69 | } |
70 | |
71 | if (! err) |
72 | { |
73 | *mtime = 0; |
74 | err = |
75 | vm_map (mach_task_self ()((__mach_task_self_ + 0)), (vm_address_t *)mtime, sizeof *mtime, 0, 1, |
76 | memobj, 0, 0, VM_PROT_READ((vm_prot_t) 0x01), VM_PROT_READ((vm_prot_t) 0x01), VM_INHERIT_NONE((vm_inherit_t) 2)); |
77 | mach_port_deallocate (mach_task_self ()((__mach_task_self_ + 0)), memobj); |
78 | } |
79 | |
80 | return err; |
81 | } |