1 | /* $Id: backend.h 3914 2014-10-24 14:01:38Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * LIBC - Backend header.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2004-2014 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
8 | *
|
---|
9 | * This file is part of InnoTek LIBC.
|
---|
10 | *
|
---|
11 | * InnoTek LIBC is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * InnoTek LIBC is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with InnoTek LIBC; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef __InnoTekLIBC_backend_h__
|
---|
28 | #define __InnoTekLIBC_backend_h__
|
---|
29 |
|
---|
30 | #include <sys/cdefs.h>
|
---|
31 | #include <sys/types.h>
|
---|
32 | #include <sys/_timeval.h>
|
---|
33 | #include <sys/resource.h>
|
---|
34 | #include <sys/time.h>
|
---|
35 | #include <sys/wait.h>
|
---|
36 | #include <sys/sem.h>
|
---|
37 | #include <sys/shm.h>
|
---|
38 | #include <signal.h>
|
---|
39 | #include <emx/io.h>
|
---|
40 | #include <stdarg.h>
|
---|
41 |
|
---|
42 |
|
---|
43 | __BEGIN_DECLS
|
---|
44 |
|
---|
45 | #ifndef __LIBC_THREAD_DECLARED
|
---|
46 | #define __LIBC_THREAD_DECLARED
|
---|
47 | typedef struct __libc_thread *__LIBC_PTHREAD, **__LIBC_PPTHREAD;
|
---|
48 | #endif
|
---|
49 | struct statfs;
|
---|
50 | struct stat;
|
---|
51 |
|
---|
52 |
|
---|
53 | /** @defgroup __libc_Back_thread LIBC Backend - Threads
|
---|
54 | * @{ */
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Initiatlize a new thread structure.
|
---|
58 | *
|
---|
59 | * @param pThrd Pointer to the thread structure.
|
---|
60 | * @param pParentThrd Pointer to the thread structure for the parent thread.
|
---|
61 | * If NULL and thread id is 1 then inherit from parent process.
|
---|
62 | * If NULL and thread is not null or no record of parent then
|
---|
63 | * use defaults.
|
---|
64 | */
|
---|
65 | void __libc_Back_threadInit(__LIBC_PTHREAD pThrd, const __LIBC_PTHREAD pParentThrd);
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Called before the thread structure is freed so the backend
|
---|
69 | * can cleanup its members.
|
---|
70 | *
|
---|
71 | * @param pThrd Pointer to the thread in question.
|
---|
72 | */
|
---|
73 | void __libc_Back_threadCleanup(__LIBC_PTHREAD pThrd);
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Called in the context of the newly started thread to register
|
---|
77 | * exception handler and to do other init stuff.
|
---|
78 | *
|
---|
79 | * @param pExpRegRec Exception handler registration record on the stack.
|
---|
80 | * To be used for any exception handler registration.
|
---|
81 | */
|
---|
82 | void __libc_Back_threadStartup(void *pExpRegRec);
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * Called in the context of the thread which is to be terminated to
|
---|
86 | * unregister exception handler and to do other final term stuff.
|
---|
87 | *
|
---|
88 | * @param pExpRegRec Exception handler registration record on the stack.
|
---|
89 | * To be used for any exception handler registration.
|
---|
90 | * @remark This is called after __libc_Back_threadCleanup().
|
---|
91 | * @remark It is not called by thread which calls _endthread(), nor for the
|
---|
92 | * main thread.
|
---|
93 | */
|
---|
94 | void __libc_Back_threadEnd(void *pExpRegRec);
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Suspend execution of the current thread for a given number of nanoseconds
|
---|
98 | * or till a signal is received.
|
---|
99 | *
|
---|
100 | * @returns 0 on success.
|
---|
101 | * @returns -EINVAL if the pReqTS is invalid.
|
---|
102 | * @returns -EINTR if the interrupted by signal.
|
---|
103 |
|
---|
104 | * @param ullNanoReq Time to sleep, in nano seconds.
|
---|
105 | * @param pullNanoRem Where to store remaining time (also nano seconds).
|
---|
106 |
|
---|
107 | * @remark For relativly small sleeps this api temporarily changes the thread
|
---|
108 | * priority to timecritical (that is, if it's in the normal or idle priority
|
---|
109 | * classes) to increase precision. This means that if a signal or other
|
---|
110 | * asyncronous event is executed, it will be executed at wrong priority.
|
---|
111 | * It also means that if such code changes the priority it will be undone.
|
---|
112 | */
|
---|
113 | int __libc_Back_threadSleep(unsigned long long ullNanoReq, unsigned long long *pullNanoRem);
|
---|
114 |
|
---|
115 | /** @} */
|
---|
116 |
|
---|
117 |
|
---|
118 | /** @defgroup __libc_Back_fs LIBC Backend - File System
|
---|
119 | * @{ */
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Get the statistics for the filesystem which pszPath is located on.
|
---|
123 | *
|
---|
124 | * @returns 0 on success.
|
---|
125 | * @returns Negative error code (errno.h) on failure.
|
---|
126 | * @param pszPath The path to somewhere in the filesystem.
|
---|
127 | * @param pStatFs Where to store the obtained information.
|
---|
128 | */
|
---|
129 | int __libc_Back_fsStat(const char *pszPath, struct statfs *pStatFs);
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Get file system statistics
|
---|
133 | *
|
---|
134 | * @returns 0 on success.
|
---|
135 | * @returns Negative error code (errno.h) on failure.
|
---|
136 | * @param fh The filehandle of any file within the mounted file system.
|
---|
137 | * @param pStatFs Where to store the statistics.
|
---|
138 | */
|
---|
139 | int __libc_Back_fsStatFH(int fh, struct statfs *pStatFs);
|
---|
140 |
|
---|
141 | /**
|
---|
142 | * Get the statistics for all the mounted filesystems.
|
---|
143 | *
|
---|
144 | * @returns Number of returned statfs structs on success.
|
---|
145 | * @returns Number of mounted filesystems on success if paStatFS is NULL
|
---|
146 | * @returns Negative error code (errno.h) on failure.
|
---|
147 | * @param paStatFs Where to to store the statistics.
|
---|
148 | * @param cStatFS Number of structures the array pointed to by paStatFs can hold.
|
---|
149 | * @param fFlags Flags, currently ignored.
|
---|
150 | */
|
---|
151 | int __libc_Back_fsStats(struct statfs *paStatFs, unsigned cStatFs, unsigned fFlags);
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Schedules all file system buffers for writing.
|
---|
155 | *
|
---|
156 | * See sync() for OS/2 limitations.
|
---|
157 | */
|
---|
158 | void __libc_Back_fsSync(void);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Query filesystem configuration information by path.
|
---|
162 | *
|
---|
163 | * @returns 0 on success.
|
---|
164 | * @returns Negative error code (errno.h) on failure.
|
---|
165 | * @param pszPath Path to query info about.
|
---|
166 | * @param iName Which path config variable to query.
|
---|
167 | * @param plValue Where to return the value.
|
---|
168 | * @sa __libc_Back_ioPathConf, fpathconf, pathconf, sysconf.
|
---|
169 | */
|
---|
170 | int __libc_Back_fsPathConf(const char *pszPath, int iName, long *plValue);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Resolves the path into an canonicalized absolute path.
|
---|
174 | *
|
---|
175 | * @returns 0 on success.
|
---|
176 | * @returns Negative error code (errno.h) on failure.
|
---|
177 | * @param pszPath The path to resolve.
|
---|
178 | * @param pszBuf Where to store the resolved path.
|
---|
179 | * @param cchBuf Size of the buffer.
|
---|
180 | * @param fFlags Combination of __LIBC_BACKFS_FLAGS_RESOLVE_* defines.
|
---|
181 | */
|
---|
182 | int __libc_Back_fsPathResolve(const char *pszPath, char *pszBuf, size_t cchBuf, unsigned fFlags);
|
---|
183 | /** Flags for __libc_Back_fsPathResolve().
|
---|
184 | * @{ */
|
---|
185 | #define __LIBC_BACKFS_FLAGS_RESOLVE_FULL 0
|
---|
186 | /** Resolves and verfies the entire path, but it's ok if the last component
|
---|
187 | * does not exist. */
|
---|
188 | #define __LIBC_BACKFS_FLAGS_RESOLVE_FULL_MAYBE 0x01
|
---|
189 | /** Get the native path instead, no unix root translations. */
|
---|
190 | #define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE 0x10
|
---|
191 | /** Direct buffer mode for testing purposes. */
|
---|
192 | #define __LIBC_BACKFS_FLAGS_RESOLVE_DIRECT_BUF 0x8000
|
---|
193 | /** @} */
|
---|
194 |
|
---|
195 |
|
---|
196 | /**
|
---|
197 | * Changes the default drive of the process.
|
---|
198 | *
|
---|
199 | * @returns 0 on success.
|
---|
200 | * @returns Negative error code (errno.h) on failure.
|
---|
201 | * @param chDrive New default drive.
|
---|
202 | */
|
---|
203 | int __libc_Back_fsDriveDefaultSet(char chDrive);
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Gets the default drive of the process.
|
---|
207 | *
|
---|
208 | * @returns 0 on success.
|
---|
209 | * @returns Negative error code (errno.h) on failure.
|
---|
210 | * @param pchDrive Where to store the default drive.
|
---|
211 | */
|
---|
212 | int __libc_Back_fsDriveDefaultGet(char *pchDrive);
|
---|
213 |
|
---|
214 | /**
|
---|
215 | * Sets or change the unixroot of the current process.
|
---|
216 | *
|
---|
217 | * @returns 0 on success.
|
---|
218 | * @returns Negative error code (errno.h) on failure.
|
---|
219 | * @param pszNewRoot The new root.
|
---|
220 | */
|
---|
221 | int __libc_Back_fsDirChangeRoot(const char *pszNewRoot);
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Gets the current directory of the process on a
|
---|
225 | * specific drive or on the current one.
|
---|
226 | *
|
---|
227 | * @returns 0 on success.
|
---|
228 | * @returns Negative error code (errno.h) on failure.
|
---|
229 | * @param pszPath Where to store the path to the current directory.
|
---|
230 | * This will be prefixed with a drive letter if we're
|
---|
231 | * not in the unix tree.
|
---|
232 | * @param cchPath The size of the path buffer.
|
---|
233 | * @param chDrive The drive letter of the drive to get it for.
|
---|
234 | * If '\0' the current dir for the current drive is returned.
|
---|
235 | * @param fFlags Flags for skipping drive letter and slash.
|
---|
236 | */
|
---|
237 | int __libc_Back_fsDirCurrentGet(char *pszPath, size_t cchPath, char chDrive, int fFlags);
|
---|
238 |
|
---|
239 | /** Flags for __libc_Back_fsDirCurrentGet().
|
---|
240 | * @{ */
|
---|
241 | #define __LIBC_BACK_FSCWD_NO_DRIVE 1
|
---|
242 | #define __LIBC_BACK_FSCWD_NO_ROOT_SLASH 2
|
---|
243 | /** @} */
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Changes the current directory of the process.
|
---|
247 | *
|
---|
248 | * @returns 0 on success.
|
---|
249 | * @returns Negative error code (errno.h) on failure.
|
---|
250 | * @param pszPath Path to the new current directory of the process.
|
---|
251 | * @param fDrive Force a change of the current drive too.
|
---|
252 | */
|
---|
253 | int __libc_Back_fsDirCurrentSet(const char *pszPath, int fDrive);
|
---|
254 |
|
---|
255 | /**
|
---|
256 | * Changes the current directory of the process.
|
---|
257 | *
|
---|
258 | * @returns 0 on success.
|
---|
259 | * @returns Negative error code (errno.h) on failure.
|
---|
260 | * @param fh The handle of an open directory.
|
---|
261 | * @param fDrive Force a change of the current drive too.
|
---|
262 | */
|
---|
263 | int __libc_Back_fsDirCurrentSetFH(int fh, int fDrive);
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Creates a new directory.
|
---|
267 | *
|
---|
268 | * @returns 0 on success.
|
---|
269 | * @returns Negative error code (errno.h) on failure.
|
---|
270 | * @param pszPath Path of the new directory.
|
---|
271 | * @param Mode Permissions on the created directory.
|
---|
272 | */
|
---|
273 | int __libc_Back_fsDirCreate(const char *pszPath, mode_t Mode);
|
---|
274 |
|
---|
275 | /**
|
---|
276 | * Removes a new directory.
|
---|
277 | *
|
---|
278 | * @returns 0 on success.
|
---|
279 | * @returns Negative error code (errno.h) on failure.
|
---|
280 | * @param pszPath Path to the directory which is to be removed.
|
---|
281 | */
|
---|
282 | int __libc_Back_fsDirRemove(const char *pszPath);
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Creates a symbolic link.
|
---|
286 | *
|
---|
287 | * @returns 0 on success.
|
---|
288 | * @returns Negative error code (errno.h) on failure.
|
---|
289 | * @param pszTarget The target of the symlink link.
|
---|
290 | * @param pszSymlink The path to the symbolic link to create.
|
---|
291 | */
|
---|
292 | int __libc_Back_fsSymlinkCreate(const char *pszTarget, const char *pszSymlink);
|
---|
293 |
|
---|
294 | /**
|
---|
295 | * Reads the content of a symbolic link.
|
---|
296 | *
|
---|
297 | * This is weird interface as it will return a truncated result if not
|
---|
298 | * enough buffer space. It is also weird in that there is no string
|
---|
299 | * terminator.
|
---|
300 | *
|
---|
301 | * @returns Number of bytes returned in pachBuf.
|
---|
302 | * @returns Negative error code (errno.h) on failure.
|
---|
303 | * @param pszPath The path to the symlink directory.
|
---|
304 | * @param pachBuf Where to store the symlink value.
|
---|
305 | * @param cchBuf Size of buffer.
|
---|
306 | */
|
---|
307 | int __libc_Back_fsSymlinkRead(const char *pszPath, char *pachBuf, size_t cchBuf);
|
---|
308 |
|
---|
309 | /**
|
---|
310 | * Stats a symbolic link.
|
---|
311 | *
|
---|
312 | * @returns 0 on success.
|
---|
313 | * @returns Negative error code (errno.h) on failure.
|
---|
314 | * @param pszPath Path to the file to stat. If this is a symbolic link
|
---|
315 | * the link it self will be stat'ed.
|
---|
316 | * @param pStat Where to store the file stats.
|
---|
317 | */
|
---|
318 | int __libc_Back_fsSymlinkStat(const char *pszPath, struct stat *pStat);
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Sets the file access mode of a symlink.
|
---|
322 | *
|
---|
323 | * @returns 0 on success.
|
---|
324 | * @returns Negative error code (errno.h) on failure.
|
---|
325 | * @param pszPath The path to the file to set the mode of.
|
---|
326 | * @param Mode The filemode.
|
---|
327 | */
|
---|
328 | int __libc_Back_fsSymlinkModeSet(const char *pszPath, mode_t Mode);
|
---|
329 |
|
---|
330 | /**
|
---|
331 | * Sets the file times of a symlink.
|
---|
332 | *
|
---|
333 | * @returns 0 on success.
|
---|
334 | * @returns Negative error code (errno.h) on failure.
|
---|
335 | * @param pszPath The path to the file to set the mode of.
|
---|
336 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
---|
337 | */
|
---|
338 | int __libc_Back_fsSymlinkTimesSet(const char *pszPath, const struct timeval *paTimes);
|
---|
339 |
|
---|
340 | /**
|
---|
341 | * Changes the ownership and/or group, without following any final symlink.
|
---|
342 | *
|
---|
343 | * @returns 0 on success.
|
---|
344 | * @returns Negative error code (errno.h) on failure.
|
---|
345 | * @param pszPath Path to the file to modify ownership of. If this is a
|
---|
346 | * symbolic link, the link it self will modified.
|
---|
347 | * @param uid The user id of the new owner, pass -1 to not change it.
|
---|
348 | * @param gid The group id of the new group, pass -1 to not change it.
|
---|
349 | */
|
---|
350 | int __libc_Back_fsSymlinkOwnerSet(const char *pszPath, uid_t uid, gid_t gid);
|
---|
351 |
|
---|
352 | /**
|
---|
353 | * Stats a file.
|
---|
354 | *
|
---|
355 | * @returns 0 on success.
|
---|
356 | * @returns Negative error code (errno.h) on failure.
|
---|
357 | * @param pszPath Path to the file to stat.
|
---|
358 | * @param pStat Where to store the file stats.
|
---|
359 | */
|
---|
360 | int __libc_Back_fsFileStat(const char *pszPath, struct stat *pStat);
|
---|
361 |
|
---|
362 | /**
|
---|
363 | * Gets the file stats for a file by filehandle.
|
---|
364 | *
|
---|
365 | * @returns 0 on success.
|
---|
366 | * @returns Negative error code (errno.h) on failure. The content
|
---|
367 | * of *pStat is undefined.
|
---|
368 | * @param fh Handle to file.
|
---|
369 | * @param pStat Where to store the stats.
|
---|
370 | */
|
---|
371 | int __libc_Back_fsFileStatFH(int fh, struct stat *pStat);
|
---|
372 |
|
---|
373 | /**
|
---|
374 | * Sets the file access mode of a file.
|
---|
375 | *
|
---|
376 | * @returns 0 on success.
|
---|
377 | * @returns Negative error code (errno.h) on failure.
|
---|
378 | * @param pszPath The path to the file to set the mode of.
|
---|
379 | * @param Mode The filemode.
|
---|
380 | */
|
---|
381 | int __libc_Back_fsFileModeSet(const char *pszPath, mode_t Mode);
|
---|
382 |
|
---|
383 | /**
|
---|
384 | * Sets the file access mode of a file by filehandle.
|
---|
385 | *
|
---|
386 | * @returns 0 on success.
|
---|
387 | * @returns Negative error code (errno.h) on failure.
|
---|
388 | * @param fh Handle to file.
|
---|
389 | * @param Mode The filemode.
|
---|
390 | */
|
---|
391 | int __libc_Back_fsFileModeSetFH(int fh, mode_t Mode);
|
---|
392 |
|
---|
393 | /**
|
---|
394 | * Sets the file the times of a file.
|
---|
395 | *
|
---|
396 | * @returns 0 on success.
|
---|
397 | * @returns Negative error code (errno.h) on failure.
|
---|
398 | * @param pszPath The path to the file to set the times of.
|
---|
399 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
---|
400 | */
|
---|
401 | int __libc_Back_fsFileTimesSet(const char *pszPath, const struct timeval *paTimes);
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * Sets the file the times of a file by filehandle.
|
---|
405 | *
|
---|
406 | * @returns 0 on success.
|
---|
407 | * @returns Negative error code (errno.h) on failure.
|
---|
408 | * @param fh Handle to file.
|
---|
409 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
---|
410 | */
|
---|
411 | int __libc_Back_fsFileTimesSetFH(int fh, const struct timeval *paTimes);
|
---|
412 |
|
---|
413 | /**
|
---|
414 | * Changes the ownership and/or group, following all symbolic links.
|
---|
415 | *
|
---|
416 | * @returns 0 on success.
|
---|
417 | * @returns Negative error code (errno.h) on failure.
|
---|
418 | * @param pszPath Path to the file to modify ownership of.
|
---|
419 | * @param uid The user id of the new owner, pass -1 to not change it.
|
---|
420 | * @param gid The group id of the new group, pass -1 to not change it.
|
---|
421 | */
|
---|
422 | int __libc_Back_fsFileOwnerSet(const char *pszPath, uid_t uid, gid_t gid);
|
---|
423 |
|
---|
424 | /**
|
---|
425 | * Changes the ownership and/or group.
|
---|
426 | *
|
---|
427 | * @returns 0 on success.
|
---|
428 | * @returns Negative error code (errno.h) on failure.
|
---|
429 | * @param fh Handle to file.
|
---|
430 | * @param uid The user id of the new owner, pass -1 to not change it.
|
---|
431 | * @param gid The group id of the new group, pass -1 to not change it.
|
---|
432 | */
|
---|
433 | int __libc_Back_fsFileOwnerSetFH(int fh, uid_t uid, gid_t gid);
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * Renames a file or directory.
|
---|
437 | *
|
---|
438 | * @returns 0 on success.
|
---|
439 | * @returns Negative error code (errno.h) on failure.
|
---|
440 | * @param pszPathOld Old file path.
|
---|
441 | * @param pszPathNew New file path.
|
---|
442 | *
|
---|
443 | * @remark OS/2 doesn't preform the deletion of the pszPathNew atomically.
|
---|
444 | */
|
---|
445 | int __libc_Back_fsRename(const char *pszPathOld, const char *pszPathNew);
|
---|
446 |
|
---|
447 | /**
|
---|
448 | * Unlinks a file, directory, symlink, dev, pipe or socket.
|
---|
449 | *
|
---|
450 | * @returns 0 on success.
|
---|
451 | * @returns Negative error code (errno.h) on failure.
|
---|
452 | * @param pszPath Path to the filesystem file/dir/symlink/whatever to remove.
|
---|
453 | */
|
---|
454 | int __libc_Back_fsUnlink(const char *pszPath);
|
---|
455 |
|
---|
456 |
|
---|
457 | /** @defgroup __libc_Back_io LIBC Backend - I/O and File Management.
|
---|
458 | * @{ */
|
---|
459 |
|
---|
460 | /**
|
---|
461 | * Opens or creates a file.
|
---|
462 | *
|
---|
463 | * @returns Filehandle to the opened file on success.
|
---|
464 | * @returns Negative error code (errno.h) on failure.
|
---|
465 | * @param pszFile Path to the file.
|
---|
466 | * @param fLibc The LIBC open flags (O_*).
|
---|
467 | * @param fShare The share flags (SH_*).
|
---|
468 | * @param cbInitial Initial filesize.
|
---|
469 | * @param Mode The specified permission mask.
|
---|
470 | * @param ppFH Where to store the LIBC filehandle structure which was created
|
---|
471 | * for the opened file.
|
---|
472 | */
|
---|
473 | int __libc_Back_ioFileOpen(const char *pszFile, unsigned fLibc, int fShare, off_t cbInitial, mode_t Mode, PLIBCFH *ppFH);
|
---|
474 |
|
---|
475 | /**
|
---|
476 | * Change the current position of a file stream and get the new position.
|
---|
477 | *
|
---|
478 | * @returns new file offset on success.
|
---|
479 | * @returns Negative error code (errno) on failure.
|
---|
480 | * @param hFile File handle to preform seek operation on.
|
---|
481 | * @param off Offset to seek to.
|
---|
482 | * @param iMethod The seek method. SEEK_CUR, SEEK_SET or SEEK_END.
|
---|
483 | */
|
---|
484 | off_t __libc_Back_ioSeek(int hFile, off_t off, int iMethod);
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * Sets the size of an open file.
|
---|
488 | *
|
---|
489 | * When expanding a file the contents of the allocated
|
---|
490 | * space is undefined.
|
---|
491 | *
|
---|
492 | * @returns 0 on success.
|
---|
493 | * @returns Negative error code (errno.h) on failure.
|
---|
494 | * @param fh Handle to the file which size should be changed.
|
---|
495 | * @param cbFile The new filesize.
|
---|
496 | * @param fZero If set any new allocated file space will be
|
---|
497 | * initialized to zero.
|
---|
498 | */
|
---|
499 | int __libc_Back_ioFileSizeSet(int fh, __off_t cbFile, int fZero);
|
---|
500 |
|
---|
501 | /**
|
---|
502 | * Reads directory entries from an open directory.
|
---|
503 | *
|
---|
504 | * @returns Number of bytes read.
|
---|
505 | * @returns Negative error code (errno.h) on failure.
|
---|
506 | *
|
---|
507 | * @param fh The file handle of an open directory.
|
---|
508 | * @param pvBuf Where to store the directory entries.
|
---|
509 | * The returned data is a series of dirent structs with
|
---|
510 | * variable name size. d_reclen must be used the offset
|
---|
511 | * to the next struct (from the start of the current one).
|
---|
512 | * @param cbBuf Size of the buffer.
|
---|
513 | * @param poff Where to store the lseek offset of the first entry.
|
---|
514 | *
|
---|
515 | */
|
---|
516 | ssize_t __libc_Back_ioDirGetEntries(int fh, void *pvBuf, size_t cbBuf, __off_t *poff);
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * File Control.
|
---|
520 | *
|
---|
521 | * Deals with file descriptor flags, file descriptor duplication and locking.
|
---|
522 | *
|
---|
523 | * @returns 0 on success and *piRet set.
|
---|
524 | * @returns Negated errno on failure and *piRet set to -1.
|
---|
525 | * @param fh File handle (descriptor).
|
---|
526 | * @param iRequest Which file file descriptior request to perform.
|
---|
527 | * @param iArg Argument which content is specific to each
|
---|
528 | * iRequest operation.
|
---|
529 | * @param prc Where to store the value which upon success is
|
---|
530 | * returned to the caller.
|
---|
531 | */
|
---|
532 | int __libc_Back_ioFileControl(int fh, int iRequest, intptr_t iArg, int *prc);
|
---|
533 |
|
---|
534 | /**
|
---|
535 | * File Control operation - OS/2 standard handle.
|
---|
536 | *
|
---|
537 | * @returns 0 on success.
|
---|
538 | * @returns OS/2 error code or negated errno on failure.
|
---|
539 | *
|
---|
540 | * @param pFH Pointer to the handle structure to operate on.
|
---|
541 | * @param fh It's associated filehandle.
|
---|
542 | * @param iRequest Which file file descriptior request to perform.
|
---|
543 | * @param iArg Argument which content is specific to each
|
---|
544 | * iRequest operation.
|
---|
545 | * @param prc Where to store the value which upon success is
|
---|
546 | * returned to the caller.
|
---|
547 | */
|
---|
548 | int __libc_Back_ioFileControlStandard(__LIBC_PFH pFH, int fh, int iRequest, intptr_t iArg, int *prc);
|
---|
549 |
|
---|
550 | /**
|
---|
551 | * Try resolve a filehandle to a path.
|
---|
552 | *
|
---|
553 | * @returns 0 on success.
|
---|
554 | * @returns Negative error code (errno.h) on failure.
|
---|
555 | * @param fh The file handle.
|
---|
556 | * @param pszPath Where to store the native path.
|
---|
557 | * @param cchPath The size of he buffer pointed to by pszPath.
|
---|
558 | */
|
---|
559 | int __libc_Back_ioFHToPath(int fh, char *pszPath, size_t cchPath);
|
---|
560 |
|
---|
561 | /**
|
---|
562 | * Query filesystem configuration information by file handle.
|
---|
563 | *
|
---|
564 | * @returns 0 on success.
|
---|
565 | * @returns Negative error code (errno.h) on failure.
|
---|
566 | * @param fh The handle to query config info about.
|
---|
567 | * @param iName Which path config variable to query.
|
---|
568 | * @param plValue Where to return the configuration value.
|
---|
569 | * @sa __libc_Back_fsPathConf, fpathconf, pathconf, sysconf.
|
---|
570 | */
|
---|
571 | int __libc_Back_ioPathConf(int fh, int iName, long *plValue);
|
---|
572 |
|
---|
573 | /** @} */
|
---|
574 |
|
---|
575 | /** @} */
|
---|
576 |
|
---|
577 |
|
---|
578 | /** @defgroup __libc_Back_ldr LIBC Backend - Loader
|
---|
579 | * @{ */
|
---|
580 |
|
---|
581 | /** Special handle that's returned when passing NULL as library name to
|
---|
582 | * __libc_Back_ldrOpen. */
|
---|
583 | #define __LIBC_BACK_LDR_GLOBAL ((void *)(intptr_t)-2)
|
---|
584 |
|
---|
585 | /**
|
---|
586 | * Opens a shared library.
|
---|
587 | *
|
---|
588 | * @returns 0 on success.
|
---|
589 | * @returns Native error number.
|
---|
590 | * @param pszLibrary Name of library to load.
|
---|
591 | * @param fFlags Flags - ignored.
|
---|
592 | * @param ppvModule Where to store the handle.
|
---|
593 | * @param pszError Where to store error information.
|
---|
594 | * @param cchError Size of error buffer.
|
---|
595 | */
|
---|
596 | int __libc_Back_ldrOpen(const char *pszLibrary, int fFlags, void **ppvModule, char *pszError, size_t cchError);
|
---|
597 |
|
---|
598 | /**
|
---|
599 | * Finds a symbol in an open shared library.
|
---|
600 | *
|
---|
601 | * @returns 0 on success.
|
---|
602 | * @returns Native error number.
|
---|
603 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
---|
604 | * @param pszSymbol Name of the symbol we're to find in pvModule.
|
---|
605 | * @param ppfn Where to store the symbol address.
|
---|
606 | */
|
---|
607 | int __libc_Back_ldrSymbol(void *pvHandle, const char *pszSymbol, void **ppfn);
|
---|
608 |
|
---|
609 | /**
|
---|
610 | * Closes a shared library.
|
---|
611 | *
|
---|
612 | * @returns 0 on success.
|
---|
613 | * @returns Native error number.
|
---|
614 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
---|
615 | */
|
---|
616 | int __libc_Back_ldrClose(void *pvModule);
|
---|
617 |
|
---|
618 |
|
---|
619 | /** @} */
|
---|
620 |
|
---|
621 |
|
---|
622 |
|
---|
623 |
|
---|
624 |
|
---|
625 | /** @defgroup __libc_Back_misc LIBC Backend - Miscellaneous
|
---|
626 | * @{ */
|
---|
627 |
|
---|
628 | /**
|
---|
629 | * Gets the system load averages.
|
---|
630 | * The load is the average values of ready and running threads(/processes)
|
---|
631 | * over the last 1, 5 and 15 minuttes.
|
---|
632 | *
|
---|
633 | * @returns 0 on success.
|
---|
634 | * @returns Negative error code (errno.h) on failure.
|
---|
635 | * @param pardAvgs Where to store the samples.
|
---|
636 | * @param cAvgs Number of samples to get. Max is 3.
|
---|
637 | * @remark See OS/2 limitations in getloadavg().
|
---|
638 | */
|
---|
639 | int __libc_Back_miscLoadAvg(double *pardAvgs, unsigned cAvgs);
|
---|
640 |
|
---|
641 | /** @} */
|
---|
642 |
|
---|
643 |
|
---|
644 | /** @defgroup __libc_Back_Signals LIBC Backend - Signals and Exceptions
|
---|
645 | * @{ */
|
---|
646 |
|
---|
647 | #if defined(END_OF_CHAIN) && defined(INCL_DOSEXCEPTIONS)
|
---|
648 | /**
|
---|
649 | * The LIBC Sys Backend exception handler.
|
---|
650 | *
|
---|
651 | * @returns XCPT_CONTINUE_SEARCH or XCPT_CONTINUE_EXECUTION.
|
---|
652 | * @param pXcptRepRec Report record.
|
---|
653 | * @param pXcptRegRec Registration record.
|
---|
654 | * @param pCtx Context record.
|
---|
655 | * @param pvWhatEver Not quite sure what this is...
|
---|
656 | */
|
---|
657 | ULONG _System __libc_Back_exceptionHandler(PEXCEPTIONREPORTRECORD pXcptRepRec,
|
---|
658 | PEXCEPTIONREGISTRATIONRECORD pXcptRegRec,
|
---|
659 | PCONTEXTRECORD pCtx,
|
---|
660 | PVOID pvWhatEver);
|
---|
661 | #endif
|
---|
662 |
|
---|
663 | /** @} */
|
---|
664 |
|
---|
665 |
|
---|
666 | /** @defgroup __libc_Back_MMan LIBC Backend - Memory Management
|
---|
667 | * @{ */
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * Change the memory protection attributes of a range of pages.
|
---|
671 | * This function supports the crossing of object boundaries and works
|
---|
672 | * on any memory the native apis works on.
|
---|
673 | *
|
---|
674 | * @returns Negative error code (errno.h) on failure.
|
---|
675 | * @param pv Pointer to first page - page aligned!
|
---|
676 | * @param cb Size of the ranage - page aligned!
|
---|
677 | * @param fFlags The PROT_* flags to replace the current flags with.
|
---|
678 | */
|
---|
679 | int __libc_Back_mmanProtect(void *pv, size_t cb, unsigned fFlags);
|
---|
680 |
|
---|
681 | /** @} */
|
---|
682 |
|
---|
683 |
|
---|
684 | /** @defgroup __libc_Back_signal LIBC Backend - Signals
|
---|
685 | * @{
|
---|
686 | */
|
---|
687 |
|
---|
688 | /** @defgroup __libc_Back_signalRaise_return __libc_back_signalRaise() returns.
|
---|
689 | * These are only valid for positive return values.
|
---|
690 | * @{ */
|
---|
691 | /** Try restart any interrupted system call. */
|
---|
692 | #define __LIBC_BSRR_RESTART 0x01
|
---|
693 | /** Go ahead interrupt system call in progress. */
|
---|
694 | #define __LIBC_BSRR_INTERRUPT 0x02
|
---|
695 | /** If set execution should be resumed. */
|
---|
696 | #define __LIBC_BSRR_CONTINUE 0x10
|
---|
697 | /** If set execution should not be resumed but the signal should be passed
|
---|
698 | * on to the system. */
|
---|
699 | #define __LIBC_BSRR_PASSITON 0x20
|
---|
700 | /** If set the passed in SIGQUEUED structure was used. */
|
---|
701 | #define __LIBC_BSRR_USED_QUEUED 0x40
|
---|
702 | /** @} */
|
---|
703 |
|
---|
704 | /** @defgroup __libc_back_signalRaise_flags __libc_back_signalRaise() flags.
|
---|
705 | * @{ */
|
---|
706 | /** The signal is thread specific and must be delivered to the current thread. */
|
---|
707 | #define __LIBC_BSRF_THREAD 0x01
|
---|
708 | /** The signal was send from an unknown process. */
|
---|
709 | #define __LIBC_BSRF_EXTERNAL 0x02
|
---|
710 | /** The signal was generated by the hardware (i.e. CPUs and such). */
|
---|
711 | #define __LIBC_BSRF_HARDWARE 0x04
|
---|
712 | /** The signal should be queued. */
|
---|
713 | #define __LIBC_BSRF_QUEUED 0x08
|
---|
714 | /** @} */
|
---|
715 |
|
---|
716 |
|
---|
717 | /**
|
---|
718 | * Raises a signal in the current process.
|
---|
719 | *
|
---|
720 | * @returns On success a flag mask out of the __LIBC_BSRR_* #defines is returned.
|
---|
721 | * @returns On failure a negative error code (errno.h) is returned.
|
---|
722 | * @param iSignalNo Signal to raise.
|
---|
723 | * @param pSigInfo Pointer to signal info for this signal.
|
---|
724 | * NULL is allowed.
|
---|
725 | * @param pvXcptOrQueued Exception handler parameter list.
|
---|
726 | * Or if __LIBC_BSRF_QUEUED is set, a pointer to locally malloced
|
---|
727 | * SIGQUEUED node.
|
---|
728 | * @param fFlags Flags of the #defines __LIBC_BSRF_* describing how to
|
---|
729 | * deliver the signal.
|
---|
730 | */
|
---|
731 | int __libc_Back_signalRaise(int iSignalNo, const siginfo_t *pSigInfo, void *pvXcptOrQueued, unsigned fFlags);
|
---|
732 |
|
---|
733 | /**
|
---|
734 | * Queue a signal.
|
---|
735 | *
|
---|
736 | * @returns 0 on success.
|
---|
737 | * @returns -1 on failure, errno set.
|
---|
738 | * @param pid The target process id.
|
---|
739 | * @param iSignalNo Signal to queue.
|
---|
740 | * @param SigVal The value to associate with the signal.
|
---|
741 | */
|
---|
742 | int __libc_Back_signalQueue(pid_t pid, int iSignalNo, const union sigval SigVal);
|
---|
743 |
|
---|
744 | /**
|
---|
745 | * Send a signal to a process.
|
---|
746 | *
|
---|
747 | * Special case for iSignalNo equal to 0, where no signal is sent but permissions to
|
---|
748 | * do so is checked.
|
---|
749 | *
|
---|
750 | * @returns 0 on if signal sent.
|
---|
751 | * @returns -errno on failure.
|
---|
752 | *
|
---|
753 | * @param pid Process Id of the process which the signal is to be sent to.
|
---|
754 | * @param iSignalNo The signal to send.
|
---|
755 | * If 0 no signal is sent, but error handling is done as if.
|
---|
756 | */
|
---|
757 | int __libc_Back_signalSendPid(pid_t pid, int iSignalNo);
|
---|
758 |
|
---|
759 | /**
|
---|
760 | * Sends a signal to a process group.
|
---|
761 | *
|
---|
762 | * Special case for iSignalNo equal to 0, where no signal is sent but permissions to
|
---|
763 | * do so is checked.
|
---|
764 | *
|
---|
765 | * @returns 0 on if signal sent.
|
---|
766 | * @returns -errno on failure.
|
---|
767 | *
|
---|
768 | * @param pgrp Process group (positive).
|
---|
769 | * 0 means the process group of this process.
|
---|
770 | * 1 means all process in the system. (not implemented!)
|
---|
771 | * @param iSignalNo Signal to send to all the processes in the group.
|
---|
772 | * If 0 no signal is sent, but error handling is done as if.
|
---|
773 | */
|
---|
774 | int __libc_Back_signalSendPGrp(pid_t pgrp, int iSignalNo);
|
---|
775 |
|
---|
776 | /**
|
---|
777 | * sigaction worker; queries and/or sets the action for a signal.
|
---|
778 | *
|
---|
779 | * @returns 0 on success.
|
---|
780 | * @returns Negative error code (errno) on failure.
|
---|
781 | * @param iSignalNo Signal number.
|
---|
782 | * @param pSigAct Pointer to new signal action.
|
---|
783 | * If NULL no update is done.
|
---|
784 | * @param pSigActOld Where to store the old signal action.
|
---|
785 | * If NULL nothing is attempted stored.
|
---|
786 | */
|
---|
787 | int __libc_Back_signalAction(int iSignalNo, const struct sigaction *pSigAct, struct sigaction *pSigActOld);
|
---|
788 |
|
---|
789 | /**
|
---|
790 | * Change interrupt/restart system call properties for a signal.
|
---|
791 | *
|
---|
792 | * @returns 0 on success.
|
---|
793 | * @returns Negative error code (errno) on failure.
|
---|
794 | * @param iSignalNo Signal number to change interrupt/restart
|
---|
795 | * properties for.
|
---|
796 | * @param fFlag If set Then clear the SA_RESTART from the handler action.
|
---|
797 | * If clear Then set the SA_RESTART from the handler action.
|
---|
798 | * @remark The SA_RESTART flag is inherited when using signal().
|
---|
799 | */
|
---|
800 | int __libc_Back_signalInterrupt(int iSignalNo, int fFlag);
|
---|
801 |
|
---|
802 | /**
|
---|
803 | * Changes and/or queries the alternative signal stack settings of a thread.
|
---|
804 | *
|
---|
805 | * @returns 0 on success.
|
---|
806 | * @returns Negative error number (errno.h) on failure.
|
---|
807 | * @param pThrd Thread which signal stack to change and/or query.
|
---|
808 | * @param pStack New stack settings. (Optional)
|
---|
809 | * @param pOldStack Old stack settings. (Optional)
|
---|
810 | */
|
---|
811 | int __libc_Back_signalStack(__LIBC_PTHREAD pThrd, const stack_t *pStack, stack_t *pOldStack);
|
---|
812 |
|
---|
813 | /**
|
---|
814 | * Block or unblock signal deliveries of a thread.
|
---|
815 | *
|
---|
816 | * @returns 0 on success.
|
---|
817 | * @returns Negative error code (errno) on failure.
|
---|
818 | * @param pThrd Thread to apply this to.
|
---|
819 | * @param iHow Describes the action taken if pSigSetNew not NULL. Recognized
|
---|
820 | * values are SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
|
---|
821 | *
|
---|
822 | * SIG_BLOCK means to or the sigset pointed to by pSigSetNew with
|
---|
823 | * the signal mask for the current thread.
|
---|
824 | * SIG_UNBLOCK means to and the 0 complement of the sigset pointed
|
---|
825 | * to by pSigSetNew with the signal mask of the current thread.
|
---|
826 | * SIG_SETMASK means to set the signal mask of the current thread
|
---|
827 | * to the sigset pointed to by pSigSetNew.
|
---|
828 | *
|
---|
829 | * @param pSigSetNew Pointer to signal set which will be applied to the current
|
---|
830 | * threads signal mask according to iHow. If NULL no change
|
---|
831 | * will be made the the current threads signal mask.
|
---|
832 | * @param pSigSetOld Where to store the current threads signal mask prior to applying
|
---|
833 | * pSigSetNew to it. This parameter can be NULL.
|
---|
834 | */
|
---|
835 | int __libc_Back_signalMask(__LIBC_PTHREAD pThrd, int iHow, const sigset_t * __restrict pSigSetNew, sigset_t * __restrict pSigSetOld);
|
---|
836 |
|
---|
837 | /**
|
---|
838 | * Wait for one or more signals and remove and return the first of them
|
---|
839 | * to occur.
|
---|
840 | *
|
---|
841 | * Will return immediately if one of the signals is already pending. If more than
|
---|
842 | * one signal is pending the signal with highest priority will be returned.
|
---|
843 | *
|
---|
844 | * @returns Signal number on success.
|
---|
845 | * @returns Negative error code (errno) on failure.
|
---|
846 | * @param pSigSet Signals to wait for.
|
---|
847 | * @param pSigInfo Where to store the signal info for the signal
|
---|
848 | * that we accepted.
|
---|
849 | * @param pTimeout Timeout specification. If NULL wait for ever.
|
---|
850 | */
|
---|
851 | int __libc_Back_signalWait(const sigset_t *pSigSet, siginfo_t *pSigInfo, const struct timespec *pTimeout);
|
---|
852 |
|
---|
853 | /**
|
---|
854 | * Suspends the current thread till a signal have been handled.
|
---|
855 | *
|
---|
856 | * @returns Negative error code (errno) on failure. (always fails)
|
---|
857 | * @param pSigSet Temporary signal mask for the thread.
|
---|
858 | */
|
---|
859 | int __libc_Back_signalSuspend(const sigset_t *pSigSet);
|
---|
860 |
|
---|
861 | /**
|
---|
862 | * Gets the set of signals which are blocked by the current thread and are
|
---|
863 | * pending on the process or the calling thread.
|
---|
864 | *
|
---|
865 | * @returns 0 indicating success.
|
---|
866 | * @returns Negative error code (errno) on failure.
|
---|
867 | * @param pSigSet Pointer to signal set where the result is to be stored.
|
---|
868 | */
|
---|
869 | int __libc_Back_signalPending(sigset_t *pSigSet);
|
---|
870 |
|
---|
871 | /**
|
---|
872 | * Queries and/or starts/stops a timer.
|
---|
873 | *
|
---|
874 | * @returns 0 on success.
|
---|
875 | * @returns Negative error code (errno.h) on failure.
|
---|
876 | * @param iWhich Which timer to get, any of the ITIMER_* #defines.
|
---|
877 | * OS/2 only supports ITIMER_REAL.
|
---|
878 | * @param pValue Where to store the value.
|
---|
879 | * Optional. If NULL pOldValue must not be NULL.
|
---|
880 | * @param pOldValue Where to store the old value.
|
---|
881 | * Optional. If NULL pValue must not be NULL.
|
---|
882 | */
|
---|
883 | int __libc_Back_signalTimer(int iWhich, const struct itimerval *pValue, struct itimerval *pOldValue);
|
---|
884 |
|
---|
885 | /**
|
---|
886 | * This is a hack to deal with potentially lost thread pokes.
|
---|
887 | *
|
---|
888 | * For some reason or another we loose the async signal in some situations. It's
|
---|
889 | * been observed happening after/when opening files (fopen), but it's not known
|
---|
890 | * whether this is really related or not.
|
---|
891 | */
|
---|
892 | void __libc_Back_signalLostPoke(void);
|
---|
893 |
|
---|
894 |
|
---|
895 | /** @} */
|
---|
896 |
|
---|
897 |
|
---|
898 |
|
---|
899 | /** @defgroup grp_Back_process LIBC Backend - Process Management
|
---|
900 | * @{ */
|
---|
901 |
|
---|
902 | /**
|
---|
903 | * Fork a child process pretty much identical to the calling process.
|
---|
904 | * See SuS for full description of what fork() does and doesn't.
|
---|
905 | *
|
---|
906 | * @returns 0 in the child process.
|
---|
907 | * @returns process identifier of the new child in the parent process. (positive, non-zero)
|
---|
908 | * @returns Negative error code (errno.h) on failure.
|
---|
909 | */
|
---|
910 | pid_t __libc_Back_processFork(void);
|
---|
911 |
|
---|
912 | /**
|
---|
913 | * Waits/polls for on one or more processes to change it's running status.
|
---|
914 | *
|
---|
915 | * @returns 0 on success, pSigInfo containing status info.
|
---|
916 | * @returns Negated error code (errno.h) on failure.
|
---|
917 | * @param enmIdType What kind of process specification Id contains.
|
---|
918 | * @param Id Process specification of the enmIdType sort.
|
---|
919 | * @param pSigInfo Where to store the result.
|
---|
920 | * @param fOptions The WEXITED, WUNTRACED, WSTOPPED and WCONTINUED flags are used to
|
---|
921 | * select the events to report. WNOHANG is used for preventing the api
|
---|
922 | * from blocking. And WNOWAIT is used for peeking.
|
---|
923 | * @param pResUsage Where to store the reported resources usage for the child.
|
---|
924 | * Optional and not implemented on OS/2.
|
---|
925 | */
|
---|
926 | int __libc_Back_processWait(idtype_t enmIdType, id_t Id, siginfo_t *pSigInfo, unsigned fOptions, struct rusage *pUsage);
|
---|
927 |
|
---|
928 | /**
|
---|
929 | * Gets the real user id of the current process.
|
---|
930 | * @returns Real user id.
|
---|
931 | */
|
---|
932 | uid_t __libc_Back_processGetUid(void);
|
---|
933 |
|
---|
934 | /**
|
---|
935 | * Gets the effective user id of the current process.
|
---|
936 | * @returns Effective user id.
|
---|
937 | */
|
---|
938 | uid_t __libc_Back_processGetEffUid(void);
|
---|
939 |
|
---|
940 | /**
|
---|
941 | * Sets the effective user id of the current process.
|
---|
942 | * If the caller is superuser real and saved user id are also set.
|
---|
943 | *
|
---|
944 | * @returns 0 on success.
|
---|
945 | * @returns Negative error code (errno) on failure.
|
---|
946 | * @param uid New effective user id.
|
---|
947 | * For superusers this is also the new real and saved user id.
|
---|
948 | */
|
---|
949 | int __libc_Back_processSetUid(uid_t uid);
|
---|
950 |
|
---|
951 | /**
|
---|
952 | * Sets the real, effective and saved user ids of the current process.
|
---|
953 | * Unprivilegde users can only set them to the real user id, the
|
---|
954 | * effective user id or the saved user id.
|
---|
955 | *
|
---|
956 | * @returns 0 on success.
|
---|
957 | * @returns Negative error code (errno) on failure.
|
---|
958 | * @param ruid New real user id. Ignore if -1.
|
---|
959 | * @param euid New effective user id. Ignore if -1.
|
---|
960 | * @param svuid New Saved user id. Ignore if -1.
|
---|
961 | */
|
---|
962 | int __libc_Back_processSetUidAll(uid_t ruid, uid_t euid, uid_t svuid);
|
---|
963 |
|
---|
964 |
|
---|
965 | /**
|
---|
966 | * Gets the real group id of the current process.
|
---|
967 | * @returns Real group id.
|
---|
968 | */
|
---|
969 | gid_t __libc_Back_processGetGid(void);
|
---|
970 |
|
---|
971 | /**
|
---|
972 | * Gets the effective group id of the current process.
|
---|
973 | * @returns Effective group id.
|
---|
974 | */
|
---|
975 | gid_t __libc_Back_processGetEffGid(void);
|
---|
976 |
|
---|
977 | /**
|
---|
978 | * Sets the effective group id of the current process.
|
---|
979 | * If the caller is superuser real and saved group id are also set.
|
---|
980 | *
|
---|
981 | * @returns 0 on success.
|
---|
982 | * @returns Negative error code (errno) on failure.
|
---|
983 | */
|
---|
984 | int __libc_Back_processSetGid(gid_t gid);
|
---|
985 |
|
---|
986 | /**
|
---|
987 | * Sets the real, effective and saved group ids of the current process.
|
---|
988 | * Unprivilegde users can only set them to the real group id, the
|
---|
989 | * effective group id or the saved group id.
|
---|
990 | *
|
---|
991 | * @returns 0 on success.
|
---|
992 | * @returns Negative error code (errno) on failure.
|
---|
993 | * @param rgid New real group id. Ignore if -1.
|
---|
994 | * @param egid New effective group id. Ignore if -1.
|
---|
995 | * @param svgid New Saved group id. Ignore if -1.
|
---|
996 | */
|
---|
997 | int __libc_Back_processSetGidAll(gid_t rgid, gid_t egid, gid_t svgid);
|
---|
998 |
|
---|
999 | /**
|
---|
1000 | * Gets the session id of the current process.
|
---|
1001 | * @returns Session id.
|
---|
1002 | * @returns Negated errno on failure.
|
---|
1003 | * @param pid Process to get the process group for.
|
---|
1004 | * Use 0 for the current process.
|
---|
1005 | */
|
---|
1006 | pid_t __libc_Back_processGetSid(pid_t pid);
|
---|
1007 |
|
---|
1008 | /**
|
---|
1009 | * Gets the process group of the specfied process.
|
---|
1010 | * @returns Process group.
|
---|
1011 | * @returns Negated errno on failure.
|
---|
1012 | * @param pid Process to get the process group for.
|
---|
1013 | * Use 0 for the current process.
|
---|
1014 | */
|
---|
1015 | pid_t __libc_Back_processGetPGrp(pid_t pid);
|
---|
1016 |
|
---|
1017 | /**
|
---|
1018 | * Gets the most favourable priority of a process, group of processes
|
---|
1019 | * or all processed owned by a user.
|
---|
1020 | *
|
---|
1021 | * @returns 0 on success.
|
---|
1022 | * @returns Negative error code (errno.h) on failure.
|
---|
1023 | * @param iWhich PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
|
---|
1024 | * @param idWho Id of the type specified by iWhich. 0 means the current process/pgrp/user.
|
---|
1025 | * @param piPrio Where to store the priority.
|
---|
1026 | */
|
---|
1027 | int __libc_Back_processGetPriority(int iWhich, id_t idWho, int *piPrio);
|
---|
1028 |
|
---|
1029 | /**
|
---|
1030 | * Sets the priority of a process, a group of processes
|
---|
1031 | * or all processed owned by a user.
|
---|
1032 | *
|
---|
1033 | * @returns 0 on success.
|
---|
1034 | * @returns Negative error code (errno.h) on failure.
|
---|
1035 | * @param iWhich PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
|
---|
1036 | * @param idWho Id of the type specified by iWhich. 0 means the current process/pgrp/user.
|
---|
1037 | * @param iPrio The new priority.
|
---|
1038 | */
|
---|
1039 | int __libc_Back_processSetPriority(int iWhich, id_t idWho, int iPrio);
|
---|
1040 |
|
---|
1041 |
|
---|
1042 | /** When this flag is set, the exec / spawn backend will handle hash bang scripts. */
|
---|
1043 | extern int __libc_Back_gfProcessHandleHashBangScripts;
|
---|
1044 | /** When this flag is set, the exec / spawn backend will handle PC batch scripts. */
|
---|
1045 | extern int __libc_Back_gfProcessHandlePCBatchScripts;
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * Gets the default shell for functions like system() and popen().
|
---|
1049 | *
|
---|
1050 | * @returns 0 on success, negative error number on failure.
|
---|
1051 | * @param pszShell Where to put the path to the shell.
|
---|
1052 | * @param cbShell The size of the buffer @a pszShell points to.
|
---|
1053 | * @param poffShellArg Where to return the offset into @a pszShell of the
|
---|
1054 | * first argument. The system() and popen() calls has
|
---|
1055 | * traditionally not included the path to /bin/sh.
|
---|
1056 | * @param pszCmdLineOpt Where to put the shell option for specifying a
|
---|
1057 | * command line it should execute.
|
---|
1058 | * @param cbCmdLineOpt The size of the buffer @a pszCmdLineOpt points to.
|
---|
1059 | */
|
---|
1060 | int __libc_Back_processGetDefaultShell(char *pszShell, size_t cbShell, size_t *poffShellArg,
|
---|
1061 | char *pszCmdLineOpt, size_t cbCmdLineOpt);
|
---|
1062 |
|
---|
1063 | /** @} */
|
---|
1064 |
|
---|
1065 |
|
---|
1066 | /** @defgroup grp_Back_time LIBC Backend - Time Management
|
---|
1067 | * @{ */
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Gets the current high-resolution timestamp as nanoseconds.
|
---|
1071 | *
|
---|
1072 | * @returns nanosecond timestamp.
|
---|
1073 | */
|
---|
1074 | hrtime_t __libc_Back_timeHighResNano(void);
|
---|
1075 |
|
---|
1076 | /** @} */
|
---|
1077 |
|
---|
1078 |
|
---|
1079 | /** @defgroup grp_Back_sysvipc LIBC Backend - SysV IPC
|
---|
1080 | * @{ */
|
---|
1081 |
|
---|
1082 | /**
|
---|
1083 | * sysget syscall.
|
---|
1084 | */
|
---|
1085 | int __libc_Back_sysvSemGet(key_t key, int nsems, int semflg);
|
---|
1086 |
|
---|
1087 | /**
|
---|
1088 | * semop syscall.
|
---|
1089 | */
|
---|
1090 | int __libc_Back_sysvSemOp(int semid, struct sembuf *sops_user, size_t nsops);
|
---|
1091 |
|
---|
1092 | /**
|
---|
1093 | * semctl syscall
|
---|
1094 | */
|
---|
1095 | int __libc_Back_sysvSemCtl(int semid, int semnum, int cmd, union semun real_arg);
|
---|
1096 |
|
---|
1097 |
|
---|
1098 | /**
|
---|
1099 | * shmget.
|
---|
1100 | */
|
---|
1101 | int __libc_Back_sysvShmGet(key_t key, size_t size, int shmflg);
|
---|
1102 |
|
---|
1103 | /**
|
---|
1104 | * shmat.
|
---|
1105 | */
|
---|
1106 | int __libc_Back_sysvShmAt(int shmid, const void *shmaddr, int shmflg, void **ppvActual);
|
---|
1107 |
|
---|
1108 | /**
|
---|
1109 | * shmdt.
|
---|
1110 | */
|
---|
1111 | int __libc_Back_sysvShmDt(const void *shmaddr);
|
---|
1112 |
|
---|
1113 | /**
|
---|
1114 | * shmctl.
|
---|
1115 | */
|
---|
1116 | int __libc_Back_sysvShmCtl(int shmid, int cmd, struct shmid_ds *bufptr);
|
---|
1117 |
|
---|
1118 | /** @} */
|
---|
1119 |
|
---|
1120 |
|
---|
1121 | /** @defgroup grp_Back_safesem LIBC Backend - Internal Signal-Safe Semaphores.
|
---|
1122 | * @{ */
|
---|
1123 |
|
---|
1124 | /**
|
---|
1125 | * Safe Mutex Semaphore structure.
|
---|
1126 | *
|
---|
1127 | * For shared semaphores this structure must be in shared memory so all users
|
---|
1128 | * actually use the very same structure.
|
---|
1129 | */
|
---|
1130 | typedef struct __LIBC_SAFESEMMTX
|
---|
1131 | {
|
---|
1132 | #ifdef __OS2__
|
---|
1133 | /** Mutex handle. */
|
---|
1134 | unsigned long hmtx;
|
---|
1135 | #endif
|
---|
1136 | /** Set if the semaphore is shared. */
|
---|
1137 | unsigned fShared;
|
---|
1138 | } __LIBC_SAFESEMMTX;
|
---|
1139 | /** Pointer to a SAFESEM Mutex structure. */
|
---|
1140 | typedef __LIBC_SAFESEMMTX *__LIBC_PSAFESEMMTX;
|
---|
1141 |
|
---|
1142 | /**
|
---|
1143 | * Creates a safe mutex sem.
|
---|
1144 | *
|
---|
1145 | * @returns 0 on success.
|
---|
1146 | * @returns Negative error code (errno.h) on failure.
|
---|
1147 | * @param pmtx Pointer to the semaphore structure to initialize.
|
---|
1148 | * @param fShared Set if the semaphore should be sharable between processes.
|
---|
1149 | */
|
---|
1150 | int __libc_Back_safesemMtxCreate(__LIBC_PSAFESEMMTX pmtx, int fShared);
|
---|
1151 |
|
---|
1152 | /**
|
---|
1153 | * Opens a shared safe mutex sem.
|
---|
1154 | *
|
---|
1155 | * @returns 0 on success.
|
---|
1156 | * @returns Negative error code (errno.h) on failure.
|
---|
1157 | * @param pmtx Pointer to the semaphore structure.
|
---|
1158 | */
|
---|
1159 | int __libc_Back_safesemMtxOpen(__LIBC_PSAFESEMMTX pmtx);
|
---|
1160 |
|
---|
1161 | /**
|
---|
1162 | * Closes a shared safe mutex sem.
|
---|
1163 | *
|
---|
1164 | * @returns 0 on success.
|
---|
1165 | * @returns Negative error code (errno.h) on failure.
|
---|
1166 | * @param pmtx Pointer to the semaphore structure.
|
---|
1167 | */
|
---|
1168 | int __libc_Back_safesemMtxClose(__LIBC_PSAFESEMMTX pmtx);
|
---|
1169 |
|
---|
1170 | /**
|
---|
1171 | * Locks a mutex semaphore.
|
---|
1172 | *
|
---|
1173 | * @returns 0 on success.
|
---|
1174 | * @returns Negative errno on failure.
|
---|
1175 | * @param pmtx Pointer to the semaphore structure.
|
---|
1176 | */
|
---|
1177 | int __libc_Back_safesemMtxLock(__LIBC_PSAFESEMMTX pmtx);
|
---|
1178 |
|
---|
1179 | /**
|
---|
1180 | * Unlocks a mutex semaphore.
|
---|
1181 | *
|
---|
1182 | * @returns 0 on success.
|
---|
1183 | * @returns Negative errno on failure.
|
---|
1184 | * @param pmtx Pointer to the semaphore structure.
|
---|
1185 | */
|
---|
1186 | int __libc_Back_safesemMtxUnlock(__LIBC_PSAFESEMMTX pmtx);
|
---|
1187 |
|
---|
1188 |
|
---|
1189 | /**
|
---|
1190 | * Safe Event Semaphore structure.
|
---|
1191 | *
|
---|
1192 | * For shared semaphores this structure must be in shared memory so all users
|
---|
1193 | * actually use the very same structure.
|
---|
1194 | *
|
---|
1195 | * @remark The event semaphore business is difficult because the lack of
|
---|
1196 | * atomic mutex release + event wait apis in OS/2. We have to
|
---|
1197 | * jump around the place to get this working nearly safly...
|
---|
1198 | */
|
---|
1199 | typedef struct __LIBC_SAFESEMEV
|
---|
1200 | {
|
---|
1201 | #ifdef __OS2__
|
---|
1202 | /** The event semaphore. */
|
---|
1203 | unsigned long hev;
|
---|
1204 | #endif
|
---|
1205 | /** Number of threads which are supposed to be blocking on the above event semaphore. */
|
---|
1206 | uint32_t volatile cWaiters;
|
---|
1207 | /** The mutex semaphore used to protect the event semaphore. */
|
---|
1208 | __LIBC_PSAFESEMMTX pmtx;
|
---|
1209 | /** Set if the semaphore is shared. */
|
---|
1210 | unsigned fShared;
|
---|
1211 | } __LIBC_SAFESEMEV;
|
---|
1212 | /** Pointer to a SAFESEM Event structure. */
|
---|
1213 | typedef __LIBC_SAFESEMEV *__LIBC_PSAFESEMEV;
|
---|
1214 |
|
---|
1215 | /**
|
---|
1216 | * Creates a safe event sem.
|
---|
1217 | *
|
---|
1218 | * @returns 0 on success.
|
---|
1219 | * @returns Negative error code (errno.h) on failure.
|
---|
1220 | * @param pev Pointer to the semaphore structure to initialize.
|
---|
1221 | * @param pmtx Pointer to the mutex semaphore which protects the event semaphore.
|
---|
1222 | * @param fShared Set if the semaphore should be sharable between processes.
|
---|
1223 | */
|
---|
1224 | int __libc_Back_safesemEvCreate(__LIBC_PSAFESEMEV pev, __LIBC_PSAFESEMMTX pmtx, int fShared);
|
---|
1225 |
|
---|
1226 | /**
|
---|
1227 | * Opens a shared safe event sem.
|
---|
1228 | *
|
---|
1229 | * The caller is responsible for opening the associated mutex
|
---|
1230 | * semaphore before calling this function.
|
---|
1231 | *
|
---|
1232 | * @returns 0 on success.
|
---|
1233 | * @returns Negative error code (errno.h) on failure.
|
---|
1234 | * @param pev Pointer to the semaphore structure to open.
|
---|
1235 | */
|
---|
1236 | int __libc_Back_safesemEvOpen(__LIBC_PSAFESEMEV pev);
|
---|
1237 |
|
---|
1238 | /**
|
---|
1239 | * Closes a shared safe mutex sem.
|
---|
1240 | *
|
---|
1241 | * @returns 0 on success.
|
---|
1242 | * @returns Negative error code (errno.h) on failure.
|
---|
1243 | * @param pev Pointer to the semaphore structure to close.
|
---|
1244 | */
|
---|
1245 | int __libc_Back_safesemEvClose(__LIBC_PSAFESEMEV pev);
|
---|
1246 |
|
---|
1247 | /**
|
---|
1248 | * Sleep on a semaphore.
|
---|
1249 | *
|
---|
1250 | * The caller must own the associated mutex semaphore. The mutex semaphore will
|
---|
1251 | * be released as we go to sleep and reclaimed when we wake up.
|
---|
1252 | *
|
---|
1253 | * The pfnComplete callback is used to correct state before signals are handled.
|
---|
1254 | * It will always be called be for this function returns, and it'll either be under
|
---|
1255 | * the protection of the signal mutex or the associated mutex (both safe sems).
|
---|
1256 | *
|
---|
1257 | * This is the most difficult thing we're doing in this API. On OS/2 we have
|
---|
1258 | * potential (at least theoretically) race conditions...
|
---|
1259 | *
|
---|
1260 | * @returns 0 on success.
|
---|
1261 | * @returns Negative error code (errno.h) on failure.
|
---|
1262 | *
|
---|
1263 | * @param pev Pointer to the semaphore structure to sleep on.
|
---|
1264 | * @param pfnComplete Function to execute on signal or on wait completion.
|
---|
1265 | * @param pvUser User argument to pfnComplete.
|
---|
1266 | */
|
---|
1267 | int __libc_Back_safesemEvSleep(__LIBC_PSAFESEMEV pev, void (*pfnComplete)(void *pvUser), void *pvUser);
|
---|
1268 |
|
---|
1269 | /**
|
---|
1270 | * Wakes up all threads sleeping on a given event semaphore.
|
---|
1271 | *
|
---|
1272 | * @returns 0 on success.
|
---|
1273 | * @returns Negative error code (errno.h) on failure.
|
---|
1274 | * @param pev Pointer to the semaphore structure to post.
|
---|
1275 | */
|
---|
1276 | int __libc_Back_safesemEvWakeup(__LIBC_PSAFESEMEV pev);
|
---|
1277 |
|
---|
1278 |
|
---|
1279 | /** @} */
|
---|
1280 |
|
---|
1281 |
|
---|
1282 | /** @defgroup grp_Back_panic LIBC Backend - Panic Routines
|
---|
1283 | * @{ */
|
---|
1284 |
|
---|
1285 | /** The panic was caused by a signal. Drop the LIBC PANIC line. */
|
---|
1286 | #define __LIBC_PANIC_SIGNAL 1
|
---|
1287 | /** Don't set the SPM termination code / status. When set the caller is
|
---|
1288 | * responsible for doing this. */
|
---|
1289 | #define __LIBC_PANIC_NO_SPM_TERM 2
|
---|
1290 |
|
---|
1291 | /**
|
---|
1292 | * Print a panic message and dump/kill the process.
|
---|
1293 | *
|
---|
1294 | * @param fFlags A combination of the __LIBC_PANIC_* defines.
|
---|
1295 | * @param pvCtx Pointer to a context record if available. This is a PCONTEXTRECORD.
|
---|
1296 | * @param pszFormat User message which may contain %s and %x.
|
---|
1297 | * @param ... String pointers and unsigned intergers as specified by the %s and %x in pszFormat.
|
---|
1298 | */
|
---|
1299 | void __libc_Back_panic(unsigned fFlags, void *pvCtx, const char *pszFormat, ...) __attribute__((__noreturn__));
|
---|
1300 |
|
---|
1301 | /**
|
---|
1302 | * Print a panic message and dump/kill the process.
|
---|
1303 | *
|
---|
1304 | * @param fFlags A combination of the __LIBC_PANIC_* defines.
|
---|
1305 | * @param pvCtx Pointer to a context record if available. This is a PCONTEXTRECORD.
|
---|
1306 | * @param pszFormat User message which may contain %s and %x.
|
---|
1307 | * @param args String pointers and unsigned intergers as specified by the %s and %x in pszFormat.
|
---|
1308 | */
|
---|
1309 | void __libc_Back_panicV(unsigned fFlags, void *pvCtx, const char *pszFormat, va_list args) __attribute__((__noreturn__));
|
---|
1310 |
|
---|
1311 | /* @} */
|
---|
1312 |
|
---|
1313 | __END_DECLS
|
---|
1314 |
|
---|
1315 | #endif
|
---|