| 1 | /* $Id: backend.h 2298 2005-08-22 00:14:50Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | *
|
|---|
| 4 | * LIBC - Backend header.
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright (c) 2004 knut st. osmundsen <[email protected]>
|
|---|
| 7 | *
|
|---|
| 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 | * Resolves the path into an canonicalized absolute path.
|
|---|
| 162 | *
|
|---|
| 163 | * @returns 0 on success.
|
|---|
| 164 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 165 | * @param pszPath The path to resolve.
|
|---|
| 166 | * @param pszBuf Where to store the resolved path.
|
|---|
| 167 | * @param cchBuf Size of the buffer.
|
|---|
| 168 | * @param fFlags Combination of __LIBC_BACKFS_FLAGS_RESOLVE_* defines.
|
|---|
| 169 | */
|
|---|
| 170 | int __libc_Back_fsPathResolve(const char *pszPath, char *pszBuf, size_t cchBuf, unsigned fFlags);
|
|---|
| 171 | /** Flags for __libc_Back_fsPathResolve().
|
|---|
| 172 | * @{ */
|
|---|
| 173 | #define __LIBC_BACKFS_FLAGS_RESOLVE_FULL 0
|
|---|
| 174 | /** Get the native path instead, no unix root translations. */
|
|---|
| 175 | #define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE 0x10
|
|---|
| 176 | /** @} */
|
|---|
| 177 |
|
|---|
| 178 |
|
|---|
| 179 | /**
|
|---|
| 180 | * Changes the default drive of the process.
|
|---|
| 181 | *
|
|---|
| 182 | * @returns 0 on success.
|
|---|
| 183 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 184 | * @param chDrive New default drive.
|
|---|
| 185 | */
|
|---|
| 186 | int __libc_Back_fsDriveDefaultSet(char chDrive);
|
|---|
| 187 |
|
|---|
| 188 | /**
|
|---|
| 189 | * Gets the default drive of the process.
|
|---|
| 190 | *
|
|---|
| 191 | * @returns 0 on success.
|
|---|
| 192 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 193 | * @param pchDrive Where to store the default drive.
|
|---|
| 194 | */
|
|---|
| 195 | int __libc_Back_fsDriveDefaultGet(char *pchDrive);
|
|---|
| 196 |
|
|---|
| 197 | /**
|
|---|
| 198 | * Sets or change the unixroot of the current process.
|
|---|
| 199 | *
|
|---|
| 200 | * @returns 0 on success.
|
|---|
| 201 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 202 | * @param pszNewRoot The new root.
|
|---|
| 203 | */
|
|---|
| 204 | int __libc_Back_fsDirChangeRoot(const char *pszNewRoot);
|
|---|
| 205 |
|
|---|
| 206 | /**
|
|---|
| 207 | * Gets the current directory of the process on a
|
|---|
| 208 | * specific drive or on the current one.
|
|---|
| 209 | *
|
|---|
| 210 | * @returns 0 on success.
|
|---|
| 211 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 212 | * @param pszPath Where to store the path to the current directory.
|
|---|
| 213 | * This will be prefixed with a drive letter if we're
|
|---|
| 214 | * not in the unix tree.
|
|---|
| 215 | * @param cchPath The size of the path buffer.
|
|---|
| 216 | * @param chDrive The drive letter of the drive to get it for.
|
|---|
| 217 | * If '\0' the current dir for the current drive is returned.
|
|---|
| 218 | * @param fFlags Flags for skipping drive letter and slash.
|
|---|
| 219 | */
|
|---|
| 220 | int __libc_Back_fsDirCurrentGet(char *pszPath, size_t cchPath, char chDrive, int fFlags);
|
|---|
| 221 |
|
|---|
| 222 | /** Flags for __libc_Back_fsDirCurrentGet().
|
|---|
| 223 | * @{ */
|
|---|
| 224 | #define __LIBC_BACK_FSCWD_NO_DRIVE 1
|
|---|
| 225 | #define __LIBC_BACK_FSCWD_NO_ROOT_SLASH 2
|
|---|
| 226 | /** @} */
|
|---|
| 227 |
|
|---|
| 228 | /**
|
|---|
| 229 | * Changes the current directory of the process.
|
|---|
| 230 | *
|
|---|
| 231 | * @returns 0 on success.
|
|---|
| 232 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 233 | * @param pszPath Path to the new current directory of the process.
|
|---|
| 234 | * @param fDrive Force a change of the current drive too.
|
|---|
| 235 | */
|
|---|
| 236 | int __libc_Back_fsDirCurrentSet(const char *pszPath, int fDrive);
|
|---|
| 237 |
|
|---|
| 238 | /**
|
|---|
| 239 | * Creates a new directory.
|
|---|
| 240 | *
|
|---|
| 241 | * @returns 0 on success.
|
|---|
| 242 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 243 | * @param pszPath Path of the new directory.
|
|---|
| 244 | * @param Mode Permissions on the created directory.
|
|---|
| 245 | */
|
|---|
| 246 | int __libc_Back_fsDirCreate(const char *pszPath, mode_t Mode);
|
|---|
| 247 |
|
|---|
| 248 | /**
|
|---|
| 249 | * Removes a new directory.
|
|---|
| 250 | *
|
|---|
| 251 | * @returns 0 on success.
|
|---|
| 252 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 253 | * @param pszPath Path to the directory which is to be removed.
|
|---|
| 254 | */
|
|---|
| 255 | int __libc_Back_fsDirRemove(const char *pszPath);
|
|---|
| 256 |
|
|---|
| 257 | /**
|
|---|
| 258 | * Creates a symbolic link.
|
|---|
| 259 | *
|
|---|
| 260 | * @returns 0 on success.
|
|---|
| 261 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 262 | * @param pszTarget The target of the symlink link.
|
|---|
| 263 | * @param pszSymlink The path to the symbolic link to create.
|
|---|
| 264 | */
|
|---|
| 265 | int __libc_Back_fsSymlinkCreate(const char *pszTarget, const char *pszSymlink);
|
|---|
| 266 |
|
|---|
| 267 | /**
|
|---|
| 268 | * Reads the content of a symbolic link.
|
|---|
| 269 | *
|
|---|
| 270 | * This is weird interface as it will return a truncated result if not
|
|---|
| 271 | * enough buffer space. It is also weird in that there is no string
|
|---|
| 272 | * terminator.
|
|---|
| 273 | *
|
|---|
| 274 | * @returns Number of bytes returned in pachBuf.
|
|---|
| 275 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 276 | * @param pszPath The path to the symlink directory.
|
|---|
| 277 | * @param pachBuf Where to store the symlink value.
|
|---|
| 278 | * @param cchBuf Size of buffer.
|
|---|
| 279 | */
|
|---|
| 280 | int __libc_Back_fsSymlinkRead(const char *pszPath, char *pachBuf, size_t cchBuf);
|
|---|
| 281 |
|
|---|
| 282 | /**
|
|---|
| 283 | * Stats a symbolic link.
|
|---|
| 284 | *
|
|---|
| 285 | * @returns 0 on success.
|
|---|
| 286 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 287 | * @param pszPath Path to the file to stat. If this is a symbolic link
|
|---|
| 288 | * the link it self will be stat'ed.
|
|---|
| 289 | * @param pStat Where to store the file stats.
|
|---|
| 290 | */
|
|---|
| 291 | int __libc_Back_fsSymlinkStat(const char *pszPath, struct stat *pStat);
|
|---|
| 292 |
|
|---|
| 293 | /**
|
|---|
| 294 | * Sets the file access mode of a symlink.
|
|---|
| 295 | *
|
|---|
| 296 | * @returns 0 on success.
|
|---|
| 297 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 298 | * @param pszPath The path to the file to set the mode of.
|
|---|
| 299 | * @param Mode The filemode.
|
|---|
| 300 | */
|
|---|
| 301 | int __libc_Back_fsSymlinkModeSet(const char *pszPath, mode_t Mode);
|
|---|
| 302 |
|
|---|
| 303 | /**
|
|---|
| 304 | * Sets the file times of a symlink.
|
|---|
| 305 | *
|
|---|
| 306 | * @returns 0 on success.
|
|---|
| 307 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 308 | * @param pszPath The path to the file to set the mode of.
|
|---|
| 309 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
|---|
| 310 | */
|
|---|
| 311 | int __libc_Back_fsSymlinkTimesSet(const char *pszPath, const struct timeval *paTimes);
|
|---|
| 312 |
|
|---|
| 313 | /**
|
|---|
| 314 | * Stats a file.
|
|---|
| 315 | *
|
|---|
| 316 | * @returns 0 on success.
|
|---|
| 317 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 318 | * @param pszPath Path to the file to stat.
|
|---|
| 319 | * @param pStat Where to store the file stats.
|
|---|
| 320 | */
|
|---|
| 321 | int __libc_Back_fsFileStat(const char *pszPath, struct stat *pStat);
|
|---|
| 322 |
|
|---|
| 323 | /**
|
|---|
| 324 | * Gets the file stats for a file by filehandle.
|
|---|
| 325 | *
|
|---|
| 326 | * @returns 0 on success.
|
|---|
| 327 | * @returns Negative error code (errno.h) on failure. The content
|
|---|
| 328 | * of *pStat is undefined.
|
|---|
| 329 | * @param fh Handle to file.
|
|---|
| 330 | * @param pStat Where to store the stats.
|
|---|
| 331 | */
|
|---|
| 332 | int __libc_Back_fsFileStatFH(int fh, struct stat *pStat);
|
|---|
| 333 |
|
|---|
| 334 | /**
|
|---|
| 335 | * Sets the file access mode of a file.
|
|---|
| 336 | *
|
|---|
| 337 | * @returns 0 on success.
|
|---|
| 338 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 339 | * @param pszPath The path to the file to set the mode of.
|
|---|
| 340 | * @param Mode The filemode.
|
|---|
| 341 | */
|
|---|
| 342 | int __libc_Back_fsFileModeSet(const char *pszPath, mode_t Mode);
|
|---|
| 343 |
|
|---|
| 344 | /**
|
|---|
| 345 | * Sets the file access mode of a file by filehandle.
|
|---|
| 346 | *
|
|---|
| 347 | * @returns 0 on success.
|
|---|
| 348 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 349 | * @param fh Handle to file.
|
|---|
| 350 | * @param Mode The filemode.
|
|---|
| 351 | */
|
|---|
| 352 | int __libc_Back_fsFileModeSetFH(int fh, mode_t Mode);
|
|---|
| 353 |
|
|---|
| 354 | /**
|
|---|
| 355 | * Sets the file the times of a file.
|
|---|
| 356 | *
|
|---|
| 357 | * @returns 0 on success.
|
|---|
| 358 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 359 | * @param pszPath The path to the file to set the times of.
|
|---|
| 360 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
|---|
| 361 | */
|
|---|
| 362 | int __libc_Back_fsFileTimesSet(const char *pszPath, const struct timeval *paTimes);
|
|---|
| 363 |
|
|---|
| 364 | /**
|
|---|
| 365 | * Sets the file the times of a file by filehandle.
|
|---|
| 366 | *
|
|---|
| 367 | * @returns 0 on success.
|
|---|
| 368 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 369 | * @param fh Handle to file.
|
|---|
| 370 | * @param paTimes Two timevalue structures. If NULL the current time is used.
|
|---|
| 371 | */
|
|---|
| 372 | int __libc_Back_fsFileTimesSetFH(int fh, const struct timeval *paTimes);
|
|---|
| 373 |
|
|---|
| 374 | /**
|
|---|
| 375 | * Renames a file or directory.
|
|---|
| 376 | *
|
|---|
| 377 | * @returns 0 on success.
|
|---|
| 378 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 379 | * @param pszPathOld Old file path.
|
|---|
| 380 | * @param pszPathNew New file path.
|
|---|
| 381 | *
|
|---|
| 382 | * @remark OS/2 doesn't preform the deletion of the pszPathNew atomically.
|
|---|
| 383 | */
|
|---|
| 384 | int __libc_Back_fsRename(const char *pszPathOld, const char *pszPathNew);
|
|---|
| 385 |
|
|---|
| 386 | /**
|
|---|
| 387 | * Unlinks a file, directory, symlink, dev, pipe or socket.
|
|---|
| 388 | *
|
|---|
| 389 | * @returns 0 on success.
|
|---|
| 390 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 391 | * @param pszPath Path to the filesystem file/dir/symlink/whatever to remove.
|
|---|
| 392 | */
|
|---|
| 393 | int __libc_Back_fsUnlink(const char *pszPath);
|
|---|
| 394 |
|
|---|
| 395 |
|
|---|
| 396 | /** @defgroup __libc_Back_io LIBC Backend - I/O and File Management.
|
|---|
| 397 | * @{ */
|
|---|
| 398 |
|
|---|
| 399 | /**
|
|---|
| 400 | * Opens a file.
|
|---|
| 401 | *
|
|---|
| 402 | * @returns Filehandle to the opened file on success.
|
|---|
| 403 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 404 | * @param pszFile Path to the file.
|
|---|
| 405 | * @param fFlags Open flags.
|
|---|
| 406 | * @param cbInitial Initial filesize.
|
|---|
| 407 | * @param Mode The specified permission mask.
|
|---|
| 408 | * @param fLibc LIBC filehandle flags.
|
|---|
| 409 | * @param ppFH Where to store the LIBC filehandle structure which was created
|
|---|
| 410 | * for the opened file.
|
|---|
| 411 | */
|
|---|
| 412 | int __libc_Back_ioFileOpen(const char *pszFile, int fFlags, off_t cbInitial, mode_t Mode, unsigned fLibc, PLIBCFH *ppFH);
|
|---|
| 413 |
|
|---|
| 414 | /**
|
|---|
| 415 | * Change the current position of a file stream and get the new position.
|
|---|
| 416 | *
|
|---|
| 417 | * @returns new file offset on success.
|
|---|
| 418 | * @returns Negative error code (errno) on failure.
|
|---|
| 419 | * @param hFile File handle to preform seek operation on.
|
|---|
| 420 | * @param off Offset to seek to.
|
|---|
| 421 | * @param iMethod The seek method. SEEK_CUR, SEEK_SET or SEEK_END.
|
|---|
| 422 | */
|
|---|
| 423 | off_t __libc_Back_ioSeek(int hFile, off_t off, int iMethod);
|
|---|
| 424 |
|
|---|
| 425 | /**
|
|---|
| 426 | * Sets the size of an open file.
|
|---|
| 427 | *
|
|---|
| 428 | * When expanding a file the contents of the allocated
|
|---|
| 429 | * space is undefined.
|
|---|
| 430 | *
|
|---|
| 431 | * @returns 0 on success.
|
|---|
| 432 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 433 | * @param fh Handle to the file which size should be changed.
|
|---|
| 434 | * @param cbFile The new filesize.
|
|---|
| 435 | * @param fZero If set any new allocated file space will be
|
|---|
| 436 | * initialized to zero.
|
|---|
| 437 | */
|
|---|
| 438 | int __libc_Back_ioFileSizeSet(int fh, __off_t cbFile, int fZero);
|
|---|
| 439 |
|
|---|
| 440 | /**
|
|---|
| 441 | * Try resolve a filehandle to a path.
|
|---|
| 442 | *
|
|---|
| 443 | * @returns 0 on success.
|
|---|
| 444 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 445 | * @param fh The file handle.
|
|---|
| 446 | * @param pszPath Where to store the path.
|
|---|
| 447 | * @param cchPath The size of he buffer pointed to by pszPath.
|
|---|
| 448 | */
|
|---|
| 449 | int __libc_Back_ioFHToPath(int fh, char *pszPath, size_t cchPath);
|
|---|
| 450 |
|
|---|
| 451 | /** @} */
|
|---|
| 452 |
|
|---|
| 453 | /** @} */
|
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 | /** @defgroup __libc_Back_ldr LIBC Backend - Loader
|
|---|
| 457 | * @{ */
|
|---|
| 458 |
|
|---|
| 459 | /**
|
|---|
| 460 | * Opens a shared library.
|
|---|
| 461 | *
|
|---|
| 462 | * @returns 0 on success.
|
|---|
| 463 | * @returns Native error number.
|
|---|
| 464 | * @param pszLibrary Name of library to load.
|
|---|
| 465 | * @param fFlags Flags - ignored.
|
|---|
| 466 | * @param ppvModule Where to store the handle.
|
|---|
| 467 | * @param pszError Where to store error information.
|
|---|
| 468 | * @param cchError Size of error buffer.
|
|---|
| 469 | */
|
|---|
| 470 | int __libc_Back_ldrOpen(const char *pszLibrary, int fFlags, void **ppvModule, char *pszError, size_t cchError);
|
|---|
| 471 |
|
|---|
| 472 | /**
|
|---|
| 473 | * Finds a symbol in an open shared library.
|
|---|
| 474 | *
|
|---|
| 475 | * @returns 0 on success.
|
|---|
| 476 | * @returns Native error number.
|
|---|
| 477 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
|---|
| 478 | * @param pszSymbol Name of the symbol we're to find in pvModule.
|
|---|
| 479 | * @param ppfn Where to store the symbol address.
|
|---|
| 480 | */
|
|---|
| 481 | int __libc_Back_ldrSymbol(void *pvHandle, const char *pszSymbol, void **ppfn);
|
|---|
| 482 |
|
|---|
| 483 | /**
|
|---|
| 484 | * Closes a shared library.
|
|---|
| 485 | *
|
|---|
| 486 | * @returns 0 on success.
|
|---|
| 487 | * @returns Native error number.
|
|---|
| 488 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
|---|
| 489 | */
|
|---|
| 490 | int __libc_Back_ldrClose(void *pvModule);
|
|---|
| 491 |
|
|---|
| 492 |
|
|---|
| 493 | /** @} */
|
|---|
| 494 |
|
|---|
| 495 |
|
|---|
| 496 |
|
|---|
| 497 |
|
|---|
| 498 |
|
|---|
| 499 | /** @defgroup __libc_Back_misc LIBC Backend - Miscellaneous
|
|---|
| 500 | * @{ */
|
|---|
| 501 |
|
|---|
| 502 | /**
|
|---|
| 503 | * Gets the system load averages.
|
|---|
| 504 | * The load is the average values of ready and running threads(/processes)
|
|---|
| 505 | * over the last 1, 5 and 15 minuttes.
|
|---|
| 506 | *
|
|---|
| 507 | * @returns 0 on success.
|
|---|
| 508 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 509 | * @param pardAvgs Where to store the samples.
|
|---|
| 510 | * @param cAvgs Number of samples to get. Max is 3.
|
|---|
| 511 | * @remark See OS/2 limitations in getloadavg().
|
|---|
| 512 | */
|
|---|
| 513 | int __libc_Back_miscLoadAvg(double *pardAvgs, unsigned cAvgs);
|
|---|
| 514 |
|
|---|
| 515 | /** @} */
|
|---|
| 516 |
|
|---|
| 517 |
|
|---|
| 518 | /** @defgroup __libc_Back_Signals LIBC Backend - Signals and Exceptions
|
|---|
| 519 | * @{ */
|
|---|
| 520 |
|
|---|
| 521 | #if defined(END_OF_CHAIN) && defined(INCL_DOSEXCEPTIONS)
|
|---|
| 522 | /**
|
|---|
| 523 | * The LIBC Sys Backend exception handler.
|
|---|
| 524 | *
|
|---|
| 525 | * @returns XCPT_CONTINUE_SEARCH or XCPT_CONTINUE_EXECUTION.
|
|---|
| 526 | * @param pXcptRepRec Report record.
|
|---|
| 527 | * @param pXcptRegRec Registration record.
|
|---|
| 528 | * @param pCtx Context record.
|
|---|
| 529 | * @param pvWhatEver Not quite sure what this is...
|
|---|
| 530 | */
|
|---|
| 531 | ULONG _System __libc_Back_exceptionHandler(PEXCEPTIONREPORTRECORD pXcptRepRec,
|
|---|
| 532 | PEXCEPTIONREGISTRATIONRECORD pXcptRegRec,
|
|---|
| 533 | PCONTEXTRECORD pCtx,
|
|---|
| 534 | PVOID pvWhatEver);
|
|---|
| 535 | #endif
|
|---|
| 536 |
|
|---|
| 537 | /** @} */
|
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 | /** @defgroup __libc_Back_MMan LIBC Backend - Memory Management
|
|---|
| 541 | * @{ */
|
|---|
| 542 |
|
|---|
| 543 | /**
|
|---|
| 544 | * Change the memory protection attributes of a range of pages.
|
|---|
| 545 | * This function supports the crossing of object boundaries and works
|
|---|
| 546 | * on any memory the native apis works on.
|
|---|
| 547 | *
|
|---|
| 548 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 549 | * @param pv Pointer to first page - page aligned!
|
|---|
| 550 | * @param cb Size of the ranage - page aligned!
|
|---|
| 551 | * @param fFlags The PROT_* flags to replace the current flags with.
|
|---|
| 552 | */
|
|---|
| 553 | int __libc_Back_mmanProtect(void *pv, size_t cb, unsigned fFlags);
|
|---|
| 554 |
|
|---|
| 555 | /** @} */
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 | /** @defgroup __libc_Back_signal LIBC Backend - Signals
|
|---|
| 559 | * @{
|
|---|
| 560 | */
|
|---|
| 561 |
|
|---|
| 562 | /** @defgroup __libc_Back_signalRaise_return __libc_back_signalRaise() returns.
|
|---|
| 563 | * These are only valid for positive return values.
|
|---|
| 564 | * @{ */
|
|---|
| 565 | /** Try restart any interrupted system call. */
|
|---|
| 566 | #define __LIBC_BSRR_RESTART 0x01
|
|---|
| 567 | /** Go ahead interrupt system call in progress. */
|
|---|
| 568 | #define __LIBC_BSRR_INTERRUPT 0x02
|
|---|
| 569 | /** If set execution should be resumed. */
|
|---|
| 570 | #define __LIBC_BSRR_CONTINUE 0x10
|
|---|
| 571 | /** If set execution should not be resumed but the signal should be passed
|
|---|
| 572 | * on to the system. */
|
|---|
| 573 | #define __LIBC_BSRR_PASSITON 0x20
|
|---|
| 574 | /** If set the passed in SIGQUEUED structure was used. */
|
|---|
| 575 | #define __LIBC_BSRR_USED_QUEUED 0x40
|
|---|
| 576 | /** @} */
|
|---|
| 577 |
|
|---|
| 578 | /** @defgroup __libc_back_signalRaise_flags __libc_back_signalRaise() flags.
|
|---|
| 579 | * @{ */
|
|---|
| 580 | /** The signal is thread specific and must be delivered to the current thread. */
|
|---|
| 581 | #define __LIBC_BSRF_THREAD 0x01
|
|---|
| 582 | /** The signal was send from an unknown process. */
|
|---|
| 583 | #define __LIBC_BSRF_EXTERNAL 0x02
|
|---|
| 584 | /** The signal was generated by the hardware (i.e. CPUs and such). */
|
|---|
| 585 | #define __LIBC_BSRF_HARDWARE 0x04
|
|---|
| 586 | /** The signal should be queued. */
|
|---|
| 587 | #define __LIBC_BSRF_QUEUED 0x08
|
|---|
| 588 | /** @} */
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 | /**
|
|---|
| 592 | * Raises a signal in the current process.
|
|---|
| 593 | *
|
|---|
| 594 | * @returns On success a flag mask out of the __LIBC_BSRR_* #defines is returned.
|
|---|
| 595 | * @returns On failure a negative error code (errno.h) is returned.
|
|---|
| 596 | * @param iSignalNo Signal to raise.
|
|---|
| 597 | * @param pSigInfo Pointer to signal info for this signal.
|
|---|
| 598 | * NULL is allowed.
|
|---|
| 599 | * @param pvXcptOrQueued Exception handler parameter list.
|
|---|
| 600 | * Or if __LIBC_BSRF_QUEUED is set, a pointer to locally malloced
|
|---|
| 601 | * SIGQUEUED node.
|
|---|
| 602 | * @param fFlags Flags of the #defines __LIBC_BSRF_* describing how to
|
|---|
| 603 | * deliver the signal.
|
|---|
| 604 | */
|
|---|
| 605 | int __libc_Back_signalRaise(int iSignalNo, const siginfo_t *pSigInfo, void *pvXcptOrQueued, unsigned fFlags);
|
|---|
| 606 |
|
|---|
| 607 | /**
|
|---|
| 608 | * Queue a signal.
|
|---|
| 609 | *
|
|---|
| 610 | * @returns 0 on success.
|
|---|
| 611 | * @returns -1 on failure, errno set.
|
|---|
| 612 | * @param pid The target process id.
|
|---|
| 613 | * @param iSignalNo Signal to queue.
|
|---|
| 614 | * @param SigVal The value to associate with the signal.
|
|---|
| 615 | */
|
|---|
| 616 | int __libc_Back_signalQueue(pid_t pid, int iSignalNo, const union sigval SigVal);
|
|---|
| 617 |
|
|---|
| 618 | /**
|
|---|
| 619 | * Send a signal to a process.
|
|---|
| 620 | *
|
|---|
| 621 | * Special case for iSignalNo equal to 0, where no signal is sent but permissions to
|
|---|
| 622 | * do so is checked.
|
|---|
| 623 | *
|
|---|
| 624 | * @returns 0 on if signal sent.
|
|---|
| 625 | * @returns -errno on failure.
|
|---|
| 626 | *
|
|---|
| 627 | * @param pid Process Id of the process which the signal is to be sent to.
|
|---|
| 628 | * @param iSignalNo The signal to send.
|
|---|
| 629 | * If 0 no signal is sent, but error handling is done as if.
|
|---|
| 630 | */
|
|---|
| 631 | int __libc_Back_signalSendPid(pid_t pid, int iSignalNo);
|
|---|
| 632 |
|
|---|
| 633 | /**
|
|---|
| 634 | * Sends a signal to a process group.
|
|---|
| 635 | *
|
|---|
| 636 | * Special case for iSignalNo equal to 0, where no signal is sent but permissions to
|
|---|
| 637 | * do so is checked.
|
|---|
| 638 | *
|
|---|
| 639 | * @returns 0 on if signal sent.
|
|---|
| 640 | * @returns -errno on failure.
|
|---|
| 641 | *
|
|---|
| 642 | * @param pgrp Process group (positive).
|
|---|
| 643 | * 0 means the process group of this process.
|
|---|
| 644 | * 1 means all process in the system. (not implemented!)
|
|---|
| 645 | * @param iSignalNo Signal to send to all the processes in the group.
|
|---|
| 646 | * If 0 no signal is sent, but error handling is done as if.
|
|---|
| 647 | */
|
|---|
| 648 | int __libc_Back_signalSendPGrp(pid_t pgrp, int iSignalNo);
|
|---|
| 649 |
|
|---|
| 650 | /**
|
|---|
| 651 | * sigaction worker; queries and/or sets the action for a signal.
|
|---|
| 652 | *
|
|---|
| 653 | * @returns 0 on success.
|
|---|
| 654 | * @returns Negative error code (errno) on failure.
|
|---|
| 655 | * @param iSignalNo Signal number.
|
|---|
| 656 | * @param pSigAct Pointer to new signal action.
|
|---|
| 657 | * If NULL no update is done.
|
|---|
| 658 | * @param pSigActOld Where to store the old signal action.
|
|---|
| 659 | * If NULL nothing is attempted stored.
|
|---|
| 660 | */
|
|---|
| 661 | int __libc_Back_signalAction(int iSignalNo, const struct sigaction *pSigAct, struct sigaction *pSigActOld);
|
|---|
| 662 |
|
|---|
| 663 | /**
|
|---|
| 664 | * Change interrupt/restart system call properties for a signal.
|
|---|
| 665 | *
|
|---|
| 666 | * @returns 0 on success.
|
|---|
| 667 | * @returns Negative error code (errno) on failure.
|
|---|
| 668 | * @param iSignalNo Signal number to change interrupt/restart
|
|---|
| 669 | * properties for.
|
|---|
| 670 | * @param fFlag If set Then clear the SA_RESTART from the handler action.
|
|---|
| 671 | * If clear Then set the SA_RESTART from the handler action.
|
|---|
| 672 | * @remark The SA_RESTART flag is inherited when using signal().
|
|---|
| 673 | */
|
|---|
| 674 | int __libc_Back_signalInterrupt(int iSignalNo, int fFlag);
|
|---|
| 675 |
|
|---|
| 676 | /**
|
|---|
| 677 | * Changes and/or queries the alternative signal stack settings of a thread.
|
|---|
| 678 | *
|
|---|
| 679 | * @returns 0 on success.
|
|---|
| 680 | * @returns Negative error number (errno.h) on failure.
|
|---|
| 681 | * @param pThrd Thread which signal stack to change and/or query.
|
|---|
| 682 | * @param pStack New stack settings. (Optional)
|
|---|
| 683 | * @param pOldStack Old stack settings. (Optional)
|
|---|
| 684 | */
|
|---|
| 685 | int __libc_Back_signalStack(__LIBC_PTHREAD pThrd, const stack_t *pStack, stack_t *pOldStack);
|
|---|
| 686 |
|
|---|
| 687 | /**
|
|---|
| 688 | * Block or unblock signal deliveries of a thread.
|
|---|
| 689 | *
|
|---|
| 690 | * @returns 0 on success.
|
|---|
| 691 | * @returns Negative error code (errno) on failure.
|
|---|
| 692 | * @param pThrd Thread to apply this to.
|
|---|
| 693 | * @param iHow Describes the action taken if pSigSetNew not NULL. Recognized
|
|---|
| 694 | * values are SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
|
|---|
| 695 | *
|
|---|
| 696 | * SIG_BLOCK means to or the sigset pointed to by pSigSetNew with
|
|---|
| 697 | * the signal mask for the current thread.
|
|---|
| 698 | * SIG_UNBLOCK means to and the 0 complement of the sigset pointed
|
|---|
| 699 | * to by pSigSetNew with the signal mask of the current thread.
|
|---|
| 700 | * SIG_SETMASK means to set the signal mask of the current thread
|
|---|
| 701 | * to the sigset pointed to by pSigSetNew.
|
|---|
| 702 | *
|
|---|
| 703 | * @param pSigSetNew Pointer to signal set which will be applied to the current
|
|---|
| 704 | * threads signal mask according to iHow. If NULL no change
|
|---|
| 705 | * will be made the the current threads signal mask.
|
|---|
| 706 | * @param pSigSetOld Where to store the current threads signal mask prior to applying
|
|---|
| 707 | * pSigSetNew to it. This parameter can be NULL.
|
|---|
| 708 | */
|
|---|
| 709 | int __libc_Back_signalMask(__LIBC_PTHREAD pThrd, int iHow, const sigset_t * __restrict pSigSetNew, sigset_t * __restrict pSigSetOld);
|
|---|
| 710 |
|
|---|
| 711 | /**
|
|---|
| 712 | * Wait for one or more signals and remove and return the first of them
|
|---|
| 713 | * to occur.
|
|---|
| 714 | *
|
|---|
| 715 | * Will return immediately if one of the signals is already pending. If more than
|
|---|
| 716 | * one signal is pending the signal with highest priority will be returned.
|
|---|
| 717 | *
|
|---|
| 718 | * @returns Signal number on success.
|
|---|
| 719 | * @returns Negative error code (errno) on failure.
|
|---|
| 720 | * @param pSigSet Signals to wait for.
|
|---|
| 721 | * @param pSigInfo Where to store the signal info for the signal
|
|---|
| 722 | * that we accepted.
|
|---|
| 723 | * @param pTimeout Timeout specification. If NULL wait for ever.
|
|---|
| 724 | */
|
|---|
| 725 | int __libc_Back_signalWait(const sigset_t *pSigSet, siginfo_t *pSigInfo, const struct timespec *pTimeout);
|
|---|
| 726 |
|
|---|
| 727 | /**
|
|---|
| 728 | * Suspends the current thread till a signal have been handled.
|
|---|
| 729 | *
|
|---|
| 730 | * @returns Negative error code (errno) on failure. (always fails)
|
|---|
| 731 | * @param pSigSet Temporary signal mask for the thread.
|
|---|
| 732 | */
|
|---|
| 733 | int __libc_Back_signalSuspend(const sigset_t *pSigSet);
|
|---|
| 734 |
|
|---|
| 735 | /**
|
|---|
| 736 | * Gets the set of signals which are blocked by the current thread and are
|
|---|
| 737 | * pending on the process or the calling thread.
|
|---|
| 738 | *
|
|---|
| 739 | * @returns 0 indicating success.
|
|---|
| 740 | * @returns Negative error code (errno) on failure.
|
|---|
| 741 | * @param pSigSet Pointer to signal set where the result is to be stored.
|
|---|
| 742 | */
|
|---|
| 743 | int __libc_Back_signalPending(sigset_t *pSigSet);
|
|---|
| 744 |
|
|---|
| 745 | /**
|
|---|
| 746 | * Queries and/or starts/stops a timer.
|
|---|
| 747 | *
|
|---|
| 748 | * @returns 0 on success.
|
|---|
| 749 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 750 | * @param iWhich Which timer to get, any of the ITIMER_* #defines.
|
|---|
| 751 | * OS/2 only supports ITIMER_REAL.
|
|---|
| 752 | * @param pValue Where to store the value.
|
|---|
| 753 | * Optional. If NULL pOldValue must not be NULL.
|
|---|
| 754 | * @param pOldValue Where to store the old value.
|
|---|
| 755 | * Optional. If NULL pValue must not be NULL.
|
|---|
| 756 | */
|
|---|
| 757 | int __libc_Back_signalTimer(int iWhich, const struct itimerval *pValue, struct itimerval *pOldValue);
|
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
|
|---|
| 761 | /** @} */
|
|---|
| 762 |
|
|---|
| 763 |
|
|---|
| 764 |
|
|---|
| 765 | /** @defgroup grp_Back_process LIBC Backend - Process Management
|
|---|
| 766 | * @{ */
|
|---|
| 767 |
|
|---|
| 768 | /**
|
|---|
| 769 | * Fork a child process pretty much identical to the calling process.
|
|---|
| 770 | * See SuS for full description of what fork() does and doesn't.
|
|---|
| 771 | *
|
|---|
| 772 | * @returns 0 in the child process.
|
|---|
| 773 | * @returns process identifier of the new child in the parent process. (positive, non-zero)
|
|---|
| 774 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 775 | */
|
|---|
| 776 | pid_t __libc_Back_processFork(void);
|
|---|
| 777 |
|
|---|
| 778 | /**
|
|---|
| 779 | * Waits/polls for on one or more processes to change it's running status.
|
|---|
| 780 | *
|
|---|
| 781 | * @returns 0 on success, pSigInfo containing status info.
|
|---|
| 782 | * @returns Negated error code (errno.h) on failure.
|
|---|
| 783 | * @param enmIdType What kind of process specification Id contains.
|
|---|
| 784 | * @param Id Process specification of the enmIdType sort.
|
|---|
| 785 | * @param pSigInfo Where to store the result.
|
|---|
| 786 | * @param fOptions The WEXITED, WUNTRACED, WSTOPPED and WCONTINUED flags are used to
|
|---|
| 787 | * select the events to report. WNOHANG is used for preventing the api
|
|---|
| 788 | * from blocking. And WNOWAIT is used for peeking.
|
|---|
| 789 | * @param pResUsage Where to store the reported resources usage for the child.
|
|---|
| 790 | * Optional and not implemented on OS/2.
|
|---|
| 791 | */
|
|---|
| 792 | int __libc_Back_processWait(idtype_t enmIdType, id_t Id, siginfo_t *pSigInfo, unsigned fOptions, struct rusage *pUsage);
|
|---|
| 793 |
|
|---|
| 794 | /**
|
|---|
| 795 | * Gets the real user id of the current process.
|
|---|
| 796 | * @returns Real user id.
|
|---|
| 797 | */
|
|---|
| 798 | uid_t __libc_Back_processGetUid(void);
|
|---|
| 799 |
|
|---|
| 800 | /**
|
|---|
| 801 | * Gets the effective user id of the current process.
|
|---|
| 802 | * @returns Effective user id.
|
|---|
| 803 | */
|
|---|
| 804 | uid_t __libc_Back_processGetEffUid(void);
|
|---|
| 805 |
|
|---|
| 806 | /**
|
|---|
| 807 | * Sets the effective user id of the current process.
|
|---|
| 808 | * If the caller is superuser real and saved user id are also set.
|
|---|
| 809 | *
|
|---|
| 810 | * @returns 0 on success.
|
|---|
| 811 | * @returns Negative error code (errno) on failure.
|
|---|
| 812 | * @param uid New effective user id.
|
|---|
| 813 | * For superusers this is also the new real and saved user id.
|
|---|
| 814 | */
|
|---|
| 815 | int __libc_Back_processSetUid(uid_t uid);
|
|---|
| 816 |
|
|---|
| 817 | /**
|
|---|
| 818 | * Sets the real, effective and saved user ids of the current process.
|
|---|
| 819 | * Unprivilegde users can only set them to the real user id, the
|
|---|
| 820 | * effective user id or the saved user id.
|
|---|
| 821 | *
|
|---|
| 822 | * @returns 0 on success.
|
|---|
| 823 | * @returns Negative error code (errno) on failure.
|
|---|
| 824 | * @param ruid New real user id. Ignore if -1.
|
|---|
| 825 | * @param euid New effective user id. Ignore if -1.
|
|---|
| 826 | * @param svuid New Saved user id. Ignore if -1.
|
|---|
| 827 | */
|
|---|
| 828 | int __libc_Back_processSetUidAll(uid_t ruid, uid_t euid, uid_t svuid);
|
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 | /**
|
|---|
| 832 | * Gets the real group id of the current process.
|
|---|
| 833 | * @returns Real group id.
|
|---|
| 834 | */
|
|---|
| 835 | gid_t __libc_Back_processGetGid(void);
|
|---|
| 836 |
|
|---|
| 837 | /**
|
|---|
| 838 | * Gets the effective group id of the current process.
|
|---|
| 839 | * @returns Effective group id.
|
|---|
| 840 | */
|
|---|
| 841 | gid_t __libc_Back_processGetEffGid(void);
|
|---|
| 842 |
|
|---|
| 843 | /**
|
|---|
| 844 | * Sets the effective group id of the current process.
|
|---|
| 845 | * If the caller is superuser real and saved group id are also set.
|
|---|
| 846 | *
|
|---|
| 847 | * @returns 0 on success.
|
|---|
| 848 | * @returns Negative error code (errno) on failure.
|
|---|
| 849 | */
|
|---|
| 850 | int __libc_Back_processSetGid(gid_t gid);
|
|---|
| 851 |
|
|---|
| 852 | /**
|
|---|
| 853 | * Sets the real, effective and saved group ids of the current process.
|
|---|
| 854 | * Unprivilegde users can only set them to the real group id, the
|
|---|
| 855 | * effective group id or the saved group id.
|
|---|
| 856 | *
|
|---|
| 857 | * @returns 0 on success.
|
|---|
| 858 | * @returns Negative error code (errno) on failure.
|
|---|
| 859 | * @param rgid New real group id. Ignore if -1.
|
|---|
| 860 | * @param egid New effective group id. Ignore if -1.
|
|---|
| 861 | * @param svgid New Saved group id. Ignore if -1.
|
|---|
| 862 | */
|
|---|
| 863 | int __libc_Back_processSetGidAll(gid_t rgid, gid_t egid, gid_t svgid);
|
|---|
| 864 |
|
|---|
| 865 | /**
|
|---|
| 866 | * Gets the session id of the current process.
|
|---|
| 867 | * @returns Session id.
|
|---|
| 868 | * @returns Negated errno on failure.
|
|---|
| 869 | * @param pid Process to get the process group for.
|
|---|
| 870 | * Use 0 for the current process.
|
|---|
| 871 | */
|
|---|
| 872 | pid_t __libc_Back_processGetSid(pid_t pid);
|
|---|
| 873 |
|
|---|
| 874 | /**
|
|---|
| 875 | * Gets the process group of the specfied process.
|
|---|
| 876 | * @returns Process group.
|
|---|
| 877 | * @returns Negated errno on failure.
|
|---|
| 878 | * @param pid Process to get the process group for.
|
|---|
| 879 | * Use 0 for the current process.
|
|---|
| 880 | */
|
|---|
| 881 | pid_t __libc_Back_processGetPGrp(pid_t pid);
|
|---|
| 882 |
|
|---|
| 883 | /**
|
|---|
| 884 | * Gets the most favourable priority of a process, group of processes
|
|---|
| 885 | * or all processed owned by a user.
|
|---|
| 886 | *
|
|---|
| 887 | * @returns 0 on success.
|
|---|
| 888 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 889 | * @param iWhich PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
|
|---|
| 890 | * @param idWho Id of the type specified by iWhich. 0 means the current process/pgrp/user.
|
|---|
| 891 | * @param piPrio Where to store the priority.
|
|---|
| 892 | */
|
|---|
| 893 | int __libc_Back_processGetPriority(int iWhich, id_t idWho, int *piPrio);
|
|---|
| 894 |
|
|---|
| 895 | /**
|
|---|
| 896 | * Sets the priority of a process, a group of processes
|
|---|
| 897 | * or all processed owned by a user.
|
|---|
| 898 | *
|
|---|
| 899 | * @returns 0 on success.
|
|---|
| 900 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 901 | * @param iWhich PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
|
|---|
| 902 | * @param idWho Id of the type specified by iWhich. 0 means the current process/pgrp/user.
|
|---|
| 903 | * @param iPrio The new priority.
|
|---|
| 904 | */
|
|---|
| 905 | int __libc_Back_processSetPriority(int iWhich, id_t idWho, int iPrio);
|
|---|
| 906 |
|
|---|
| 907 |
|
|---|
| 908 | /** @} */
|
|---|
| 909 |
|
|---|
| 910 |
|
|---|
| 911 | /** @defgroup grp_Back_time LIBC Backend - Time Management
|
|---|
| 912 | * @{ */
|
|---|
| 913 |
|
|---|
| 914 | /**
|
|---|
| 915 | * Gets the current high-resolution timestamp as nanoseconds.
|
|---|
| 916 | *
|
|---|
| 917 | * @returns nanosecond timestamp.
|
|---|
| 918 | */
|
|---|
| 919 | hrtime_t __libc_Back_timeHighResNano(void);
|
|---|
| 920 |
|
|---|
| 921 | /** @} */
|
|---|
| 922 |
|
|---|
| 923 |
|
|---|
| 924 | /** @defgroup grp_Back_sysvipc LIBC Backend - SysV IPC
|
|---|
| 925 | * @{ */
|
|---|
| 926 |
|
|---|
| 927 | /**
|
|---|
| 928 | * sysget syscall.
|
|---|
| 929 | */
|
|---|
| 930 | int __libc_Back_sysvSemGet(key_t key, int nsems, int semflg);
|
|---|
| 931 |
|
|---|
| 932 | /**
|
|---|
| 933 | * semop syscall.
|
|---|
| 934 | */
|
|---|
| 935 | int __libc_Back_sysvSemOp(int semid, struct sembuf *sops_user, size_t nsops);
|
|---|
| 936 |
|
|---|
| 937 | /**
|
|---|
| 938 | * semctl syscall
|
|---|
| 939 | */
|
|---|
| 940 | int __libc_Back_sysvSemCtl(int semid, int semnum, int cmd, union semun real_arg);
|
|---|
| 941 |
|
|---|
| 942 |
|
|---|
| 943 | /**
|
|---|
| 944 | * shmget.
|
|---|
| 945 | */
|
|---|
| 946 | int __libc_Back_sysvShmGet(key_t key, size_t size, int shmflg);
|
|---|
| 947 |
|
|---|
| 948 | /**
|
|---|
| 949 | * shmat.
|
|---|
| 950 | */
|
|---|
| 951 | int __libc_Back_sysvShmAt(int shmid, const void *shmaddr, int shmflg, void **ppvActual);
|
|---|
| 952 |
|
|---|
| 953 | /**
|
|---|
| 954 | * shmdt.
|
|---|
| 955 | */
|
|---|
| 956 | int __libc_Back_sysvShmDt(const void *shmaddr);
|
|---|
| 957 |
|
|---|
| 958 | /**
|
|---|
| 959 | * shmctl.
|
|---|
| 960 | */
|
|---|
| 961 | int __libc_Back_sysvShmCtl(int shmid, int cmd, struct shmid_ds *bufptr);
|
|---|
| 962 |
|
|---|
| 963 | /** @} */
|
|---|
| 964 |
|
|---|
| 965 |
|
|---|
| 966 | /** @defgroup grp_Back_safesem LIBC Backend - Internal Signal-Safe Semaphores.
|
|---|
| 967 | * @{ */
|
|---|
| 968 |
|
|---|
| 969 | /**
|
|---|
| 970 | * Safe Mutex Semaphore structure.
|
|---|
| 971 | *
|
|---|
| 972 | * For shared semaphores this structure must be in shared memory so all users
|
|---|
| 973 | * actually use the very same structure.
|
|---|
| 974 | */
|
|---|
| 975 | typedef struct __LIBC_SAFESEMMTX
|
|---|
| 976 | {
|
|---|
| 977 | #ifdef __OS2__
|
|---|
| 978 | /** Mutex handle. */
|
|---|
| 979 | unsigned long hmtx;
|
|---|
| 980 | #endif
|
|---|
| 981 | } __LIBC_SAFESEMMTX;
|
|---|
| 982 | /** Pointer to a SAFESEM Mutex structure. */
|
|---|
| 983 | typedef __LIBC_SAFESEMMTX *__LIBC_PSAFESEMMTX;
|
|---|
| 984 |
|
|---|
| 985 | /**
|
|---|
| 986 | * Creates a safe mutex sem.
|
|---|
| 987 | *
|
|---|
| 988 | * @returns 0 on success.
|
|---|
| 989 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 990 | * @param pmtx Pointer to the semaphore structure to initialize.
|
|---|
| 991 | * @param fShared Set if the semaphore should be sharable between processes.
|
|---|
| 992 | */
|
|---|
| 993 | int __libc_Back_safesemMtxCreate(__LIBC_PSAFESEMMTX pmtx, int fShared);
|
|---|
| 994 |
|
|---|
| 995 | /**
|
|---|
| 996 | * Opens a shared safe mutex sem.
|
|---|
| 997 | *
|
|---|
| 998 | * @returns 0 on success.
|
|---|
| 999 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1000 | * @param pmtx Pointer to the semaphore structure.
|
|---|
| 1001 | */
|
|---|
| 1002 | int __libc_Back_safesemMtxOpen(__LIBC_PSAFESEMMTX pmtx);
|
|---|
| 1003 |
|
|---|
| 1004 | /**
|
|---|
| 1005 | * Closes a shared safe mutex sem.
|
|---|
| 1006 | *
|
|---|
| 1007 | * @returns 0 on success.
|
|---|
| 1008 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1009 | * @param pmtx Pointer to the semaphore structure.
|
|---|
| 1010 | */
|
|---|
| 1011 | int __libc_Back_safesemMtxClose(__LIBC_PSAFESEMMTX pmtx);
|
|---|
| 1012 |
|
|---|
| 1013 | /**
|
|---|
| 1014 | * Locks a mutex semaphore.
|
|---|
| 1015 | *
|
|---|
| 1016 | * @returns 0 on success.
|
|---|
| 1017 | * @returns Negative errno on failure.
|
|---|
| 1018 | * @param pmtx Pointer to the semaphore structure.
|
|---|
| 1019 | */
|
|---|
| 1020 | int __libc_Back_safesemMtxLock(__LIBC_PSAFESEMMTX pmtx);
|
|---|
| 1021 |
|
|---|
| 1022 | /**
|
|---|
| 1023 | * Unlocks a mutex semaphore.
|
|---|
| 1024 | *
|
|---|
| 1025 | * @returns 0 on success.
|
|---|
| 1026 | * @returns Negative errno on failure.
|
|---|
| 1027 | * @param pmtx Pointer to the semaphore structure.
|
|---|
| 1028 | */
|
|---|
| 1029 | int __libc_Back_safesemMtxUnlock(__LIBC_PSAFESEMMTX pmtx);
|
|---|
| 1030 |
|
|---|
| 1031 |
|
|---|
| 1032 | /**
|
|---|
| 1033 | * Safe Event Semaphore structure.
|
|---|
| 1034 | *
|
|---|
| 1035 | * For shared semaphores this structure must be in shared memory so all users
|
|---|
| 1036 | * actually use the very same structure.
|
|---|
| 1037 | *
|
|---|
| 1038 | * @remark The event semaphore business is difficult because the lack of
|
|---|
| 1039 | * atomic mutex release + event wait apis in OS/2. We have to
|
|---|
| 1040 | * jump around the place to get this working nearly safly...
|
|---|
| 1041 | */
|
|---|
| 1042 | typedef struct __LIBC_SAFESEMEV
|
|---|
| 1043 | {
|
|---|
| 1044 | #ifdef __OS2__
|
|---|
| 1045 | /** The event semaphore. */
|
|---|
| 1046 | unsigned long hev;
|
|---|
| 1047 | #endif
|
|---|
| 1048 | /** Number of threads which are supposed to be blocking on the above event semaphore. */
|
|---|
| 1049 | uint32_t volatile cWaiters;
|
|---|
| 1050 | /** The mutex semaphore used to protect the event semaphore. */
|
|---|
| 1051 | __LIBC_PSAFESEMMTX pmtx;
|
|---|
| 1052 | /** Set if the semaphore is shared.
|
|---|
| 1053 | * If shared this structure is allocated from SPM, else it's from the heap. */
|
|---|
| 1054 | unsigned fShared;
|
|---|
| 1055 | } __LIBC_SAFESEMEV;
|
|---|
| 1056 | /** Pointer to a SAFESEM Event structure. */
|
|---|
| 1057 | typedef __LIBC_SAFESEMEV *__LIBC_PSAFESEMEV;
|
|---|
| 1058 |
|
|---|
| 1059 | /**
|
|---|
| 1060 | * Creates a safe event sem.
|
|---|
| 1061 | *
|
|---|
| 1062 | * @returns 0 on success.
|
|---|
| 1063 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1064 | * @param pev Pointer to the semaphore structure to initialize.
|
|---|
| 1065 | * @param pmtx Pointer to the mutex semaphore which protects the event semaphore.
|
|---|
| 1066 | * @param fShared Set if the semaphore should be sharable between processes.
|
|---|
| 1067 | */
|
|---|
| 1068 | int __libc_Back_safesemEvCreate(__LIBC_PSAFESEMEV pev, __LIBC_PSAFESEMMTX pmtx, int fShared);
|
|---|
| 1069 |
|
|---|
| 1070 | /**
|
|---|
| 1071 | * Opens a shared safe event sem.
|
|---|
| 1072 | *
|
|---|
| 1073 | * The caller is responsible for opening the associated mutex
|
|---|
| 1074 | * semaphore before calling this function.
|
|---|
| 1075 | *
|
|---|
| 1076 | * @returns 0 on success.
|
|---|
| 1077 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1078 | * @param pev Pointer to the semaphore structure to open.
|
|---|
| 1079 | */
|
|---|
| 1080 | int __libc_Back_safesemEvOpen(__LIBC_PSAFESEMEV pev);
|
|---|
| 1081 |
|
|---|
| 1082 | /**
|
|---|
| 1083 | * Closes a shared safe mutex sem.
|
|---|
| 1084 | *
|
|---|
| 1085 | * @returns 0 on success.
|
|---|
| 1086 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1087 | * @param pev Pointer to the semaphore structure to close.
|
|---|
| 1088 | */
|
|---|
| 1089 | int __libc_Back_safesemEvClose(__LIBC_PSAFESEMEV pev);
|
|---|
| 1090 |
|
|---|
| 1091 | /**
|
|---|
| 1092 | * Sleep on a semaphore.
|
|---|
| 1093 | *
|
|---|
| 1094 | * The caller must own the associated mutex semaphore. The mutex semaphore will
|
|---|
| 1095 | * be released as we go to sleep and reclaimed when we wake up.
|
|---|
| 1096 | *
|
|---|
| 1097 | * The pfnComplete callback is used to correct state before signals are handled.
|
|---|
| 1098 | * It will always be called be for this function returns, and it'll either be under
|
|---|
| 1099 | * the protection of the signal mutex or the associated mutex (both safe sems).
|
|---|
| 1100 | *
|
|---|
| 1101 | * This is the most difficult thing we're doing in this API. On OS/2 we have
|
|---|
| 1102 | * potential (at least theoretically) race conditions...
|
|---|
| 1103 | *
|
|---|
| 1104 | * @returns 0 on success.
|
|---|
| 1105 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1106 | *
|
|---|
| 1107 | * @param pev Pointer to the semaphore structure to sleep on.
|
|---|
| 1108 | * @param pfnComplete Function to execute on signal or on wait completion.
|
|---|
| 1109 | * @param pvUser User argument to pfnComplete.
|
|---|
| 1110 | */
|
|---|
| 1111 | int __libc_Back_safesemEvSleep(__LIBC_PSAFESEMEV pev, void (*pfnComplete)(void *pvUser), void *pvUser);
|
|---|
| 1112 |
|
|---|
| 1113 | /**
|
|---|
| 1114 | * Wakes up all threads sleeping on a given event semaphore.
|
|---|
| 1115 | *
|
|---|
| 1116 | * @returns 0 on success.
|
|---|
| 1117 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 1118 | * @param pev Pointer to the semaphore structure to post.
|
|---|
| 1119 | */
|
|---|
| 1120 | int __libc_Back_safesemEvWakeup(__LIBC_PSAFESEMEV pev);
|
|---|
| 1121 |
|
|---|
| 1122 |
|
|---|
| 1123 | /** @} */
|
|---|
| 1124 |
|
|---|
| 1125 |
|
|---|
| 1126 | /** @defgroup grp_Back_panic LIBC Backend - Panic Routines
|
|---|
| 1127 | * @{ */
|
|---|
| 1128 |
|
|---|
| 1129 | /** The panic was caused by a signal. Drop the LIBC PANIC line. */
|
|---|
| 1130 | #define __LIBC_PANIC_SIGNAL 1
|
|---|
| 1131 | /** Don't set the SPM termination code / status. When set the caller is
|
|---|
| 1132 | * responsible for doing this. */
|
|---|
| 1133 | #define __LIBC_PANIC_NO_SPM_TERM 2
|
|---|
| 1134 |
|
|---|
| 1135 | /**
|
|---|
| 1136 | * Print a panic message and dump/kill the process.
|
|---|
| 1137 | *
|
|---|
| 1138 | * @param fFlags A combination of the __LIBC_PANIC_* defines.
|
|---|
| 1139 | * @param pvCtx Pointer to a context record if available. This is a PCONTEXTRECORD.
|
|---|
| 1140 | * @param pszFormat User message which may contain %s and %x.
|
|---|
| 1141 | * @param ... String pointers and unsigned intergers as specified by the %s and %x in pszFormat.
|
|---|
| 1142 | */
|
|---|
| 1143 | void __libc_Back_panic(unsigned fFlags, void *pvCtx, const char *pszFormat, ...) __attribute__((__noreturn__));
|
|---|
| 1144 |
|
|---|
| 1145 | /**
|
|---|
| 1146 | * Print a panic message and dump/kill the process.
|
|---|
| 1147 | *
|
|---|
| 1148 | * @param fFlags A combination of the __LIBC_PANIC_* defines.
|
|---|
| 1149 | * @param pvCtx Pointer to a context record if available. This is a PCONTEXTRECORD.
|
|---|
| 1150 | * @param pszFormat User message which may contain %s and %x.
|
|---|
| 1151 | * @param args String pointers and unsigned intergers as specified by the %s and %x in pszFormat.
|
|---|
| 1152 | */
|
|---|
| 1153 | void __libc_Back_panicV(unsigned fFlags, void *pvCtx, const char *pszFormat, va_list args) __attribute__((__noreturn__));
|
|---|
| 1154 |
|
|---|
| 1155 | /* @} */
|
|---|
| 1156 |
|
|---|
| 1157 | __END_DECLS
|
|---|
| 1158 |
|
|---|
| 1159 | #endif
|
|---|