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