Landin library reference discuss source

platform/windows/processes.ldn

1--  Processes, pipes, events and waiting on them: kernel32's calls, raw.
2
3fixed if compiler.os == windows then
4    --- `SECURITY_ATTRIBUTES`, given only to make a handle a child may
5    --- inherit: its size, no descriptor, and `inherit` nonzero.
6    public security_attributes: type = struct
7        length: u32
8        descriptor: usize
9        inherit: i32
10    end security_attributes
11
12    --- `STARTUPINFOEXW`: what `create_process` gives the child's first
13    --- thread, its standard handles among them when `flags` holds
14    --- `use_std_handles`, and the attribute list that names the handles it
15    --- inherits.
16    public startup_information: type = struct
17        size: u32
18        reserved: usize
19        desktop: usize
20        title: usize
21        x: u32
22        y: u32
23        x_size: u32
24        y_size: u32
25        x_count: u32
26        y_count: u32
27        fill: u32
28        flags: u32
29        show: u16
30        reserved_count: u16
31        reserved_data: usize
32        input: handle
33        output: handle
34        errors: handle
35        attributes: usize
36    end startup_information
37
38    --- `STARTF_USESTDHANDLES`.
39    public use_std_handles: u32 = 0x100
40
41    --- What `create_process` fills: `PROCESS_INFORMATION`.
42    public process_information: type = struct
43        process: handle
44        thread: handle
45        process_id: u32
46        thread_id: u32
47    end process_information
48
49    --- `create_process`'s flags: `CREATE_UNICODE_ENVIRONMENT`, the block is
50    --- 16-bit units; `EXTENDED_STARTUPINFO_PRESENT`, the information has an
51    --- attribute list.
52    public unicode_environment: u32 = 0x400
53    --- `EXTENDED_STARTUP_INFO_PRESENT`: the information has an attribute list.
54    public extended_startup: u32 = 0x80000
55
56    --- `PROC_THREAD_ATTRIBUTE_HANDLE_LIST`: the handles a child inherits,
57    --- no other.
58    public attribute_handle_list: usize = 0x20002
59
60    --- Start the program `application` with the command line `line`,
61    --- `CreateProcessW`: nonzero with the child's handles in `started`, or
62    --- zero with the reason in `last_error`.  `application` is not looked up
63    --- on a search path and gets no extension; `line` is changed in place.
64    public extern(c) link(symbol: "CreateProcessW") create_process:
65        (application: ptr u16, line: ptr mut u16, process_security: usize,
66         thread_security: usize, inherit: i32, flags: u32,
67         environment: usize, directory: usize,
68         startup: ptr startup_information,
69         started: ptr mut process_information) -> (done: i32)
70
71    --- Make an attribute list for `count` attributes in `list`'s `size`
72    --- bytes, `InitializeProcThreadAttributeList`; with `list` zero it puts
73    --- the size it needs in `size` and fails.
74    public extern(c) link(symbol: "InitializeProcThreadAttributeList") initialize_attributes:
75        (list: usize, count: u32, flags: u32, size: ptr mut usize)
76        -> (done: i32)
77
78    --- Set the attribute `attribute` of `list` to the `size` bytes at
79    --- `value`, `UpdateProcThreadAttribute`, which `value` must outlive.
80    public extern(c) link(symbol: "UpdateProcThreadAttribute") update_attribute:
81        (list: usize, flags: u32, attribute: usize, value: usize, size: usize,
82         previous: usize, returned: usize) -> (done: i32)
83
84    --- Release what an attribute list holds, `DeleteProcThreadAttributeList`.
85    public extern(c) link(symbol: "DeleteProcThreadAttributeList") delete_attributes: (list: usize) -> none
86
87    --- `WaitForSingleObject`'s and `WaitForMultipleObjects`' answers: the
88    --- object, or the first of several, is signalled; the time ran out; the
89    --- wait failed with the reason in `last_error`.
90    public wait_object_0: u32 = 0
91    --- `WAIT_FAILED`: the wait failed, with the reason in `last_error`.
92    public wait_failed: u32 = 0xFFFFFFFF
93
94    --- Wait up to `milliseconds`, or `infinite`, for `object` to be
95    --- signalled, `WaitForSingleObject`.
96    public extern(c) link(symbol: "WaitForSingleObject") wait_for:
97        (object: handle, milliseconds: u32) -> (result: u32)
98
99    --- Wait up to `milliseconds` for any of the `count` objects at `objects`,
100    --- or all of them when `all` is nonzero, `WaitForMultipleObjects`: the
101    --- answer is `wait_object_0` plus the first signalled one's index.
102    public extern(c) link(symbol: "WaitForMultipleObjects") wait_for_any:
103        (count: u32, objects: ptr handle, all: i32, milliseconds: u32)
104        -> (result: u32)
105
106    --- The exit code of `process`, `GetExitCodeProcess`, or `STILL_ACTIVE`,
107    --- 259, while it runs.
108    public extern(c) link(symbol: "GetExitCodeProcess") exit_code_of:
109        (process: handle, code: ptr mut u32) -> (done: i32)
110
111    --- The calling process's ID, `GetCurrentProcessId`.
112    public extern(c) link(symbol: "GetCurrentProcessId") current_process_id:
113        () -> (id: u32)
114
115    --- The process `process`'s ID, `GetProcessId`.
116    public extern(c) link(symbol: "GetProcessId") process_id_of:
117        (process: handle) -> (id: u32)
118
119    --- The calling process as a handle, `GetCurrentProcess`: the pseudo
120    --- handle all ones less one, which needs no closing.
121    public extern(c) link(symbol: "GetCurrentProcess") current_process:
122        () -> (result: handle)
123
124    --- `DUPLICATE_SAME_ACCESS`.
125    public duplicate_same_access: u32 = 2
126
127    --- Duplicate `source` of `source_process` into `target_process` as
128    --- `target`, `DuplicateHandle`, inheritable when `inherit` is nonzero.
129    public extern(c) link(symbol: "DuplicateHandle") duplicate_handle:
130        (source_process: handle, source: handle, target_process: handle,
131         target: ptr mut handle, access: u32, inherit: i32, options: u32)
132        -> (done: i32)
133
134    --- `HANDLE_FLAG_INHERIT`.
135    public handle_flag_inherit: u32 = 1
136
137    --- Set the flags `mask` selects of `object` to `flags`,
138    --- `SetHandleInformation`.
139    public extern(c) link(symbol: "SetHandleInformation") set_handle_information:
140        (object: handle, mask: u32, flags: u32) -> (done: i32)
141
142    --- `CreateNamedPipeW`'s open mode: inbound, outbound or duplex, each
143    --- with `FILE_FLAG_OVERLAPPED` and `FILE_FLAG_FIRST_PIPE_INSTANCE`.
144    public pipe_access_inbound: u32 = 1
145    --- `PIPE_ACCESS_OUTBOUND`: the server end writes.
146    public pipe_access_outbound: u32 = 2
147    --- `FILE_FLAG_FIRST_PIPE_INSTANCE`: fail if the name is taken.
148    public pipe_first_instance: u32 = 0x00080000
149
150    --- `CreateNamedPipeW`'s pipe mode: bytes, waiting, remote clients
151    --- refused.
152    public pipe_byte_wait_local: u32 = 0x8
153
154    --- Make the first instance of the named pipe `name`, `CreateNamedPipeW`:
155    --- its server end, or `invalid_handle` with the reason in `last_error`.
156    public extern(c) link(symbol: "CreateNamedPipeW") create_named_pipe:
157        (name: ptr u16, open_mode: u32, pipe_mode: u32, instances: u32,
158         out_size: u32, in_size: u32, timeout: u32, security: usize)
159        -> (result: handle)
160
161    --- What is waiting in the pipe `pipe`, without reading it,
162    --- `PeekNamedPipe`: the bytes available in `available`.
163    public extern(c) link(symbol: "PeekNamedPipe") peek_named_pipe:
164        (pipe: handle, into: usize, size: u32, read: usize,
165         available: ptr mut u32, left: usize) -> (done: i32)
166
167    --- Make an event, `CreateEventW`: reset by hand when `manual` is
168    --- nonzero, signalled at first when `initial` is; its handle or zero.
169    public extern(c) link(symbol: "CreateEventW") create_event:
170        (security: usize, manual: i32, initial: i32, name: usize)
171        -> (result: handle)
172
173    --- Cancel the overlapped call `record` names on `opened`, or every one
174    --- the process has on it when `record` is zero, `CancelIoEx`.
175    public extern(c) link(symbol: "CancelIoEx") cancel_io:
176        (opened: handle, record: usize) -> (done: i32)
177end if