| 1 | /* $Id: backend.h 1627 2004-11-08 09:57:37Z 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/wait.h>
|
|---|
| 35 | #include <signal.h>
|
|---|
| 36 | #include <emx/io.h>
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | __BEGIN_DECLS
|
|---|
| 40 |
|
|---|
| 41 | #ifndef __LIBC_THREAD_DECLARED
|
|---|
| 42 | #define __LIBC_THREAD_DECLARED
|
|---|
| 43 | typedef struct __libc_thread *__LIBC_PTHREAD, **__LIBC_PPTHREAD;
|
|---|
| 44 | #endif
|
|---|
| 45 | struct statfs;
|
|---|
| 46 | struct stat;
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | /** @defgroup __libc_Back_thread LIBC Backend - Threads
|
|---|
| 50 | * @{ */
|
|---|
| 51 |
|
|---|
| 52 | /**
|
|---|
| 53 | * Initiatlize a new thread structure.
|
|---|
| 54 | *
|
|---|
| 55 | * @param pThrd Pointer to the thread structure.
|
|---|
| 56 | * @param pParentThrd Pointer to the thread structure for the parent thread.
|
|---|
| 57 | * If NULL and thread id is 1 then inherit from parent process.
|
|---|
| 58 | * If NULL and thread is not null or no record of parent then
|
|---|
| 59 | * use defaults.
|
|---|
| 60 | */
|
|---|
| 61 | void __libc_Back_threadInit(__LIBC_PTHREAD pThrd, const __LIBC_PTHREAD pParentThrd);
|
|---|
| 62 |
|
|---|
| 63 | /**
|
|---|
| 64 | * Called before the thread structure is freed so the backend
|
|---|
| 65 | * can cleanup its members.
|
|---|
| 66 | *
|
|---|
| 67 | * @param pThrd Pointer to the thread in question.
|
|---|
| 68 | */
|
|---|
| 69 | void __libc_Back_threadCleanup(__LIBC_PTHREAD pThrd);
|
|---|
| 70 |
|
|---|
| 71 | /**
|
|---|
| 72 | * Called in the context of the newly started thread to register
|
|---|
| 73 | * exception handler and to do other init stuff.
|
|---|
| 74 | *
|
|---|
| 75 | * @param pExpRegRec Exception handler registration record on the stack.
|
|---|
| 76 | * To be used for any exception handler registration.
|
|---|
| 77 | */
|
|---|
| 78 | void __libc_Back_threadStartup(void *pExpRegRec);
|
|---|
| 79 |
|
|---|
| 80 | /**
|
|---|
| 81 | * Called in the context of the thread which is to be terminated to
|
|---|
| 82 | * unregister exception handler and to do other final term stuff.
|
|---|
| 83 | *
|
|---|
| 84 | * @param pExpRegRec Exception handler registration record on the stack.
|
|---|
| 85 | * To be used for any exception handler registration.
|
|---|
| 86 | * @remark This is called after __libc_Back_threadCleanup().
|
|---|
| 87 | * @remark It is not called by thread which calls _endthread(), nor for the
|
|---|
| 88 | * main thread.
|
|---|
| 89 | */
|
|---|
| 90 | void __libc_Back_threadEnd(void *pExpRegRec);
|
|---|
| 91 |
|
|---|
| 92 | /** @} */
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | /** @defgroup __libc_Back_fs LIBC Backend - File System
|
|---|
| 96 | * @{ */
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * Get the statistics for the filesystem which pszPath is located on.
|
|---|
| 100 | *
|
|---|
| 101 | * @returns 0 on success.
|
|---|
| 102 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 103 | * @param pszPath The path to somewhere in the filesystem.
|
|---|
| 104 | * @param pStatFs Where to store the obtained information.
|
|---|
| 105 | */
|
|---|
| 106 | int __libc_Back_fsStat(const char *pszPath, struct statfs *pStatFs);
|
|---|
| 107 |
|
|---|
| 108 | /**
|
|---|
| 109 | * Get file system statistics
|
|---|
| 110 | *
|
|---|
| 111 | * @returns 0 on success.
|
|---|
| 112 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 113 | * @param fh The filehandle of any file within the mounted file system.
|
|---|
| 114 | * @param pStatFs Where to store the statistics.
|
|---|
| 115 | */
|
|---|
| 116 | int __libc_Back_fsStatFH(int fh, struct statfs *pStatFs);
|
|---|
| 117 |
|
|---|
| 118 | /**
|
|---|
| 119 | * Get the statistics for all the mounted filesystems.
|
|---|
| 120 | *
|
|---|
| 121 | * @returns Number of returned statfs structs on success.
|
|---|
| 122 | * @returns Number of mounted filesystems on success if paStatFS is NULL
|
|---|
| 123 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 124 | * @param paStatFs Where to to store the statistics.
|
|---|
| 125 | * @param cStatFS Number of structures the array pointed to by paStatFs can hold.
|
|---|
| 126 | * @param fFlags Flags, currently ignored.
|
|---|
| 127 | */
|
|---|
| 128 | int __libc_Back_fsStats(struct statfs *paStatFs, unsigned cStatFs, unsigned fFlags);
|
|---|
| 129 |
|
|---|
| 130 | /**
|
|---|
| 131 | * Schedules all file system buffers for writing.
|
|---|
| 132 | *
|
|---|
| 133 | * See sync() for OS/2 limitations.
|
|---|
| 134 | */
|
|---|
| 135 | void __libc_Back_fsSync(void);
|
|---|
| 136 |
|
|---|
| 137 | /**
|
|---|
| 138 | * Resolves the path into an canonicalized absolute path.
|
|---|
| 139 | *
|
|---|
| 140 | * @returns 0 on success.
|
|---|
| 141 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 142 | * @param pszPath The path to resolve.
|
|---|
| 143 | * @param pszBuf Where to store the resolved path.
|
|---|
| 144 | * @param cchBuf Size of the buffer.
|
|---|
| 145 | * @param fFlags Combination of __LIBC_BACKFS_FLAGS_RESOLVE_* defines.
|
|---|
| 146 | */
|
|---|
| 147 | int __libc_Back_fsPathResolve(const char *pszPath, char *pszBuf, size_t cchBuf, unsigned fFlags);
|
|---|
| 148 | /** Flags for __libc_Back_fsPathResolve().
|
|---|
| 149 | * @{ */
|
|---|
| 150 | #define __LIBC_BACKFS_FLAGS_RESOLVE_FULL 0
|
|---|
| 151 | /** Get the native path instead, no unix root translations. */
|
|---|
| 152 | #define __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE 0x10
|
|---|
| 153 | /** @} */
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 | /**
|
|---|
| 157 | * Changes the default drive of the process.
|
|---|
| 158 | *
|
|---|
| 159 | * @returns 0 on success.
|
|---|
| 160 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 161 | * @param chDrive New default drive.
|
|---|
| 162 | */
|
|---|
| 163 | int __libc_Back_fsDriveDefaultSet(char chDrive);
|
|---|
| 164 |
|
|---|
| 165 | /**
|
|---|
| 166 | * Gets the default drive of the process.
|
|---|
| 167 | *
|
|---|
| 168 | * @returns 0 on success.
|
|---|
| 169 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 170 | * @param pchDrive Where to store the default drive.
|
|---|
| 171 | */
|
|---|
| 172 | int __libc_Back_fsDriveDefaultGet(char *pchDrive);
|
|---|
| 173 |
|
|---|
| 174 | /**
|
|---|
| 175 | * Sets or change the unixroot of the current process.
|
|---|
| 176 | *
|
|---|
| 177 | * @returns 0 on success.
|
|---|
| 178 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 179 | * @param pszNewRoot The new root.
|
|---|
| 180 | */
|
|---|
| 181 | int __libc_Back_fsDirChangeRoot(const char *pszNewRoot);
|
|---|
| 182 |
|
|---|
| 183 | /**
|
|---|
| 184 | * Gets the current directory of the process on a
|
|---|
| 185 | * specific drive or on the current one.
|
|---|
| 186 | *
|
|---|
| 187 | * @returns 0 on success.
|
|---|
| 188 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 189 | * @param pszPath Where to store the path to the current directory.
|
|---|
| 190 | * This will be prefixed with a drive letter if we're
|
|---|
| 191 | * not in the unix tree.
|
|---|
| 192 | * @param cchPath The size of the path buffer.
|
|---|
| 193 | * @param chDrive The drive letter of the drive to get it for.
|
|---|
| 194 | * If '\0' the current dir for the current drive is returned.
|
|---|
| 195 | * @param fFlags Flags for skipping drive letter and slash.
|
|---|
| 196 | */
|
|---|
| 197 | int __libc_Back_fsDirCurrentGet(char *pszPath, size_t cchPath, char chDrive, int fFlags);
|
|---|
| 198 |
|
|---|
| 199 | /** Flags for __libc_Back_fsDirCurrentGet().
|
|---|
| 200 | * @{ */
|
|---|
| 201 | #define __LIBC_BACK_FSCWD_NO_DRIVE 1
|
|---|
| 202 | #define __LIBC_BACK_FSCWD_NO_ROOT_SLASH 2
|
|---|
| 203 | /** @} */
|
|---|
| 204 |
|
|---|
| 205 | /**
|
|---|
| 206 | * Changes the current directory of the process.
|
|---|
| 207 | *
|
|---|
| 208 | * @returns 0 on success.
|
|---|
| 209 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 210 | * @param pszPath Path to the new current directory of the process.
|
|---|
| 211 | */
|
|---|
| 212 | int __libc_Back_fsDirCurrentSet(const char *pszPath);
|
|---|
| 213 |
|
|---|
| 214 | /**
|
|---|
| 215 | * Creates a new directory.
|
|---|
| 216 | *
|
|---|
| 217 | * @returns 0 on success.
|
|---|
| 218 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 219 | * @param pszPath Path of the new directory.
|
|---|
| 220 | * @param Mode Permissions on the created directory.
|
|---|
| 221 | */
|
|---|
| 222 | int __libc_Back_fsDirCreate(const char *pszPath, mode_t Mode);
|
|---|
| 223 |
|
|---|
| 224 | /**
|
|---|
| 225 | * Removes a new directory.
|
|---|
| 226 | *
|
|---|
| 227 | * @returns 0 on success.
|
|---|
| 228 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 229 | * @param pszPath Path to the directory which is to be removed.
|
|---|
| 230 | */
|
|---|
| 231 | int __libc_Back_fsDirRemove(const char *pszPath);
|
|---|
| 232 |
|
|---|
| 233 | /**
|
|---|
| 234 | * Creates a symbolic link.
|
|---|
| 235 | *
|
|---|
| 236 | * @returns 0 on success.
|
|---|
| 237 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 238 | * @param pszTarget The target of the symlink link.
|
|---|
| 239 | * @param pszSymlink The path to the symbolic link to create.
|
|---|
| 240 | */
|
|---|
| 241 | int __libc_Back_fsSymlinkCreate(const char *pszTarget, const char *pszSymlink);
|
|---|
| 242 |
|
|---|
| 243 | /**
|
|---|
| 244 | * Reads the content of a symbolic link.
|
|---|
| 245 | *
|
|---|
| 246 | * This is weird interface as it will return a truncated result if not
|
|---|
| 247 | * enough buffer space. It is also weird in that there is no string
|
|---|
| 248 | * terminator.
|
|---|
| 249 | *
|
|---|
| 250 | * @returns Number of bytes returned in pachBuf.
|
|---|
| 251 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 252 | * @param pszPath The path to the symlink directory.
|
|---|
| 253 | * @param pachBuf Where to store the symlink value.
|
|---|
| 254 | * @param cchBuf Size of buffer.
|
|---|
| 255 | */
|
|---|
| 256 | int __libc_Back_fsSymlinkRead(const char *pszPath, char *pachBuf, size_t cchBuf);
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | * Stats a symbolic link.
|
|---|
| 260 | *
|
|---|
| 261 | * @returns 0 on success.
|
|---|
| 262 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 263 | * @param pszPath Path to the file to stat. If this is a symbolic link
|
|---|
| 264 | * the link it self will be stat'ed.
|
|---|
| 265 | * @param pStat Where to store the file stats.
|
|---|
| 266 | */
|
|---|
| 267 | int __libc_Back_fsSymlinkStat(const char *pszPath, struct stat *pStat);
|
|---|
| 268 |
|
|---|
| 269 | /**
|
|---|
| 270 | * Stats a file.
|
|---|
| 271 | *
|
|---|
| 272 | * @returns 0 on success.
|
|---|
| 273 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 274 | * @param pszPath Path to the file to stat.
|
|---|
| 275 | * @param pStat Where to store the file stats.
|
|---|
| 276 | */
|
|---|
| 277 | int __libc_Back_fsFileStat(const char *pszPath, struct stat *pStat);
|
|---|
| 278 |
|
|---|
| 279 | /**
|
|---|
| 280 | * Gets the file stats for a file by filehandle.
|
|---|
| 281 | *
|
|---|
| 282 | * @returns 0 on success.
|
|---|
| 283 | * @returns Negative error code (errno.h) on failure. The content
|
|---|
| 284 | * of *pStat is undefined.
|
|---|
| 285 | * @param fh Handle to file.
|
|---|
| 286 | * @param pStat Where to store the stats.
|
|---|
| 287 | */
|
|---|
| 288 | int __libc_Back_fsFileStatFH(int fh, struct stat *pStat);
|
|---|
| 289 |
|
|---|
| 290 |
|
|---|
| 291 | /** @defgroup __libc_Back_io LIBC Backend - I/O and File Management.
|
|---|
| 292 | * @{ */
|
|---|
| 293 |
|
|---|
| 294 | /**
|
|---|
| 295 | * Opens a file.
|
|---|
| 296 | *
|
|---|
| 297 | * @returns Filehandle to the opened file on success.
|
|---|
| 298 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 299 | * @param pszFile Path to the file.
|
|---|
| 300 | * @param fFlags Open flags.
|
|---|
| 301 | * @param cbInitial Initial filesize.
|
|---|
| 302 | * @param Mode The specified permission mask.
|
|---|
| 303 | * @param fLibc LIBC filehandle flags.
|
|---|
| 304 | * @param ppFH Where to store the LIBC filehandle structure which was created
|
|---|
| 305 | * for the opened file.
|
|---|
| 306 | */
|
|---|
| 307 | int __libc_Back_ioFileOpen(const char *pszFile, int fFlags, off_t cbInitial, mode_t Mode, unsigned fLibc, PLIBCFH *ppFH);
|
|---|
| 308 |
|
|---|
| 309 | /**
|
|---|
| 310 | * Change the current position of a file stream and get the new position.
|
|---|
| 311 | *
|
|---|
| 312 | * @returns new file offset on success.
|
|---|
| 313 | * @returns Negative error code (errno) on failure.
|
|---|
| 314 | * @param hFile File handle to preform seek operation on.
|
|---|
| 315 | * @param off Offset to seek to.
|
|---|
| 316 | * @param iMethod The seek method. SEEK_CUR, SEEK_SET or SEEK_END.
|
|---|
| 317 | */
|
|---|
| 318 | off_t __libc_Back_ioSeek(int hFile, off_t off, int iMethod);
|
|---|
| 319 |
|
|---|
| 320 | /**
|
|---|
| 321 | * Sets the size of an open file.
|
|---|
| 322 | *
|
|---|
| 323 | * When expanding a file the contents of the allocated
|
|---|
| 324 | * space is undefined.
|
|---|
| 325 | *
|
|---|
| 326 | * @returns 0 on success.
|
|---|
| 327 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 328 | * @param fh Handle to the file which size should be changed.
|
|---|
| 329 | * @param cbFile The new filesize.
|
|---|
| 330 | * @param fZero If set any new allocated file space will be
|
|---|
| 331 | * initialized to zero.
|
|---|
| 332 | */
|
|---|
| 333 | int __libc_Back_ioFileSizeSet(int fh, __off_t cbFile, int fZero);
|
|---|
| 334 |
|
|---|
| 335 | /**
|
|---|
| 336 | * Try resolve a filehandle to a path.
|
|---|
| 337 | *
|
|---|
| 338 | * @returns 0 on success.
|
|---|
| 339 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 340 | * @param fh The file handle.
|
|---|
| 341 | * @param pszPath Where to store the path.
|
|---|
| 342 | * @param cchPath The size of he buffer pointed to by pszPath.
|
|---|
| 343 | */
|
|---|
| 344 | int __libc_Back_ioFHToPath(int fh, char *pszPath, size_t cchPath);
|
|---|
| 345 |
|
|---|
| 346 | /** @} */
|
|---|
| 347 |
|
|---|
| 348 | /** @} */
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 | /** @defgroup __libc_Back_ldr LIBC Backend - Loader
|
|---|
| 352 | * @{ */
|
|---|
| 353 |
|
|---|
| 354 | /**
|
|---|
| 355 | * Opens a shared library.
|
|---|
| 356 | *
|
|---|
| 357 | * @returns 0 on success.
|
|---|
| 358 | * @returns Native error number.
|
|---|
| 359 | * @param pszLibrary Name of library to load.
|
|---|
| 360 | * @param fFlags Flags - ignored.
|
|---|
| 361 | * @param ppvModule Where to store the handle.
|
|---|
| 362 | * @param pszError Where to store error information.
|
|---|
| 363 | * @param cchError Size of error buffer.
|
|---|
| 364 | */
|
|---|
| 365 | int __libc_Back_ldrOpen(const char *pszLibrary, int fFlags, void **ppvModule, char *pszError, size_t cchError);
|
|---|
| 366 |
|
|---|
| 367 | /**
|
|---|
| 368 | * Finds a symbol in an open shared library.
|
|---|
| 369 | *
|
|---|
| 370 | * @returns 0 on success.
|
|---|
| 371 | * @returns Native error number.
|
|---|
| 372 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
|---|
| 373 | * @param pszSymbol Name of the symbol we're to find in pvModule.
|
|---|
| 374 | * @param ppfn Where to store the symbol address.
|
|---|
| 375 | */
|
|---|
| 376 | int __libc_Back_ldrSymbol(void *pvHandle, const char *pszSymbol, void **ppfn);
|
|---|
| 377 |
|
|---|
| 378 | /**
|
|---|
| 379 | * Closes a shared library.
|
|---|
| 380 | *
|
|---|
| 381 | * @returns 0 on success.
|
|---|
| 382 | * @returns Native error number.
|
|---|
| 383 | * @param pvModule Module handle returned by __libc_Back_ldrOpen();
|
|---|
| 384 | */
|
|---|
| 385 | int __libc_Back_ldrClose(void *pvModule);
|
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 | /** @} */
|
|---|
| 389 |
|
|---|
| 390 |
|
|---|
| 391 |
|
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 | /** @defgroup __libc_Back_misc LIBC Backend - Miscellaneous
|
|---|
| 395 | * @{ */
|
|---|
| 396 |
|
|---|
| 397 | /**
|
|---|
| 398 | * Gets the system load averages.
|
|---|
| 399 | * The load is the average values of ready and running threads(/processes)
|
|---|
| 400 | * over the last 1, 5 and 15 minuttes.
|
|---|
| 401 | *
|
|---|
| 402 | * @returns 0 on success.
|
|---|
| 403 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 404 | * @param pardAvgs Where to store the samples.
|
|---|
| 405 | * @param cAvgs Number of samples to get. Max is 3.
|
|---|
| 406 | * @remark See OS/2 limitations in getloadavg().
|
|---|
| 407 | */
|
|---|
| 408 | int __libc_Back_miscLoadAvg(double *pardAvgs, unsigned cAvgs);
|
|---|
| 409 |
|
|---|
| 410 | /** @} */
|
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 | /** @defgroup __libc_Back_Signals LIBC Backend - Signals and Exceptions
|
|---|
| 414 | * @{ */
|
|---|
| 415 |
|
|---|
| 416 | #if defined(END_OF_CHAIN) && defined(INCL_DOSEXCEPTIONS)
|
|---|
| 417 | /**
|
|---|
| 418 | * The LIBC Sys Backend exception handler.
|
|---|
| 419 | *
|
|---|
| 420 | * @returns XCPT_CONTINUE_SEARCH or XCPT_CONTINUE_EXECUTION.
|
|---|
| 421 | * @param pXcptRepRec Report record.
|
|---|
| 422 | * @param pXcptRegRec Registration record.
|
|---|
| 423 | * @param pCtx Context record.
|
|---|
| 424 | * @param pvWhatEver Not quite sure what this is...
|
|---|
| 425 | */
|
|---|
| 426 | ULONG _System __libc_Back_exceptionHandler(PEXCEPTIONREPORTRECORD pXcptRepRec,
|
|---|
| 427 | PEXCEPTIONREGISTRATIONRECORD pXcptRegRec,
|
|---|
| 428 | PCONTEXTRECORD pCtx,
|
|---|
| 429 | PVOID pvWhatEver);
|
|---|
| 430 | #endif
|
|---|
| 431 |
|
|---|
| 432 | /** @} */
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 | /** @defgroup __libc_Back_MMan LIBC Backend - Memory Management
|
|---|
| 436 | * @{ */
|
|---|
| 437 |
|
|---|
| 438 | /**
|
|---|
| 439 | * Change the memory protection attributes of a range of pages.
|
|---|
| 440 | * This function supports the crossing of object boundaries and works
|
|---|
| 441 | * on any memory the native apis works on.
|
|---|
| 442 | *
|
|---|
| 443 | * @returns Negative error code (errno.h) on failure.
|
|---|
| 444 | * @param pv Pointer to first page - page aligned!
|
|---|
| 445 | * @param cb Size of the ranage - page aligned!
|
|---|
| 446 | * @param fFlags The PROT_* flags to replace the current flags with.
|
|---|
| 447 | */
|
|---|
| 448 | int __libc_Back_mmanProtect(void *pv, size_t cb, unsigned fFlags);
|
|---|
| 449 |
|
|---|
| 450 | /** @} */
|
|---|
| 451 |
|
|---|
| 452 |
|
|---|
| 453 | /** @defgroup __libc_Back_signal LIBC Backend - Signals
|
|---|
| 454 | * @{
|
|---|
| 455 | */
|
|---|
| 456 |
|
|---|
| 457 | /** @defgroup __libc_Back_signalRaise_return __libc_back_signalRaise() returns.
|
|---|
| 458 | * These are only valid for positive return values.
|
|---|
| 459 | * @{ */
|
|---|
| 460 | /** Try restart any interrupted system call. */
|
|---|
| 461 | #define __LIBC_BSRR_RESTART 0x01
|
|---|
| 462 | /** Go ahead interrupt system call in progress. */
|
|---|
| 463 | #define __LIBC_BSRR_INTERRUPT 0x02
|
|---|
| 464 | /** If set execution should be resumed. */
|
|---|
| 465 | #define __LIBC_BSRR_CONTINUE 0x10
|
|---|
| 466 | /** If set execution should not be resumed but the signal should be passed
|
|---|
| 467 | * on to the system. */
|
|---|
| 468 | #define __LIBC_BSRR_PASSITON 0x20
|
|---|
| 469 | /** If set the passed in SIGQUEUED structure was used. */
|
|---|
| 470 | #define __LIBC_BSRR_USED_QUEUED 0x40
|
|---|
| 471 | /** @} */
|
|---|
| 472 |
|
|---|
| 473 | /** @defgroup __libc_back_signalRaise_flags __libc_back_signalRaise() flags.
|
|---|
| 474 | * @{ */
|
|---|
| 475 | /** The signal is thread specific and must be delivered to the current thread. */
|
|---|
| 476 | #define __LIBC_BSRF_THREAD 0x01
|
|---|
| 477 | /** The signal was send from an unknown process. */
|
|---|
| 478 | #define __LIBC_BSRF_EXTERNAL 0x02
|
|---|
| 479 | /** The signal was generated by the hardware (i.e. CPUs and such). */
|
|---|
| 480 | #define __LIBC_BSRF_HARDWARE 0x04
|
|---|
| 481 | /** The signal should be queued. */
|
|---|
| 482 | #define __LIBC_BSRF_QUEUED 0x08
|
|---|
| 483 | /** @} */
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 | /**
|
|---|
| 487 | * Raises a signal in the current process.
|
|---|
| 488 | *
|
|---|
| 489 | * @returns On success a flag mask out of the __LIBC_BSRR_* #defines is returned.
|
|---|
| 490 | * @returns On failure a negative error code (errno.h) is returned.
|
|---|
| 491 | * @param iSignalNo Signal to raise.
|
|---|
| 492 | * @param pSigInfo Pointer to signal info for this signal.
|
|---|
| 493 | * NULL is allowed.
|
|---|
| 494 | * @param pvXcptOrQueued Exception handler parameter list.
|
|---|
| 495 | * Or if __LIBC_BSRF_QUEUED is set, a pointer to locally malloced
|
|---|
| 496 | * SIGQUEUED node.
|
|---|
| 497 | * @param fFlags Flags of the #defines __LIBC_BSRF_* describing how to
|
|---|
| 498 | * deliver the signal.
|
|---|
| 499 | *
|
|---|
| 500 | * @remark This Backend Signal API does NOT require the caller to own the signal semaphore.
|
|---|
| 501 | */
|
|---|
| 502 | int __libc_Back_signalRaise(int iSignalNo, siginfo_t *pSigInfo, void *pvXcptOrQueued, unsigned fFlags);
|
|---|
| 503 |
|
|---|
| 504 | /**
|
|---|
| 505 | * Queue a signal.
|
|---|
| 506 | *
|
|---|
| 507 | * @returns 0 on success.
|
|---|
| 508 | * @returns -1 on failure, errno set.
|
|---|
| 509 | * @param pid The target process id.
|
|---|
| 510 | * @param iSignalNo Signal to queue.
|
|---|
| 511 | * @param SigVal The value to associate with the signal.
|
|---|
| 512 | */
|
|---|
| 513 | int __libc_Back_signalQueue(pid_t pid, int iSignalNo, const union sigval SigVal);
|
|---|
| 514 |
|
|---|
| 515 | /**
|
|---|
| 516 | * Send a signal to a process.
|
|---|
| 517 | *
|
|---|
| 518 | * @returns 0 on if signal sent.
|
|---|
| 519 | * @returns -errno on failure.
|
|---|
| 520 | *
|
|---|
| 521 | * @param pid Process Id of the process which the signal is to be sent to.
|
|---|
| 522 | * @param iSignalNo The signal to send.
|
|---|
| 523 | * @remark This Backend Signal API does NOT require the caller to own the signal semaphore.
|
|---|
| 524 | */
|
|---|
| 525 | int __libc_Back_signalSendPid(pid_t pid, int iSignalNo);
|
|---|
| 526 |
|
|---|
| 527 | /**
|
|---|
| 528 | * Verify the existance of another process and that the current process
|
|---|
| 529 | * is allowed to signal it.
|
|---|
| 530 | *
|
|---|
| 531 | * @return 0 on success.
|
|---|
| 532 | * @return -ESRCH if pid doesn't exist.
|
|---|
| 533 | * @return -EPERM if we aren't allowed to signal the pid.
|
|---|
| 534 | * @param pid Process Id for the process which we wanna signal.
|
|---|
| 535 | * @todo Do EPERM check, no ideas here yet.
|
|---|
| 536 | * @remark This Backend Signal API does NOT require the caller to own the signal semaphore.
|
|---|
| 537 | */
|
|---|
| 538 | int __libc_Back_signalVerifyPid(pid_t pid);
|
|---|
| 539 |
|
|---|
| 540 | /**
|
|---|
| 541 | * Not implemented.
|
|---|
| 542 | *
|
|---|
| 543 | * @returns -ENOSYS.
|
|---|
| 544 | * @param pgrp Process group (positive).
|
|---|
| 545 | * 0 means the process group of this process.
|
|---|
| 546 | * 1 means all process in the system.
|
|---|
| 547 | * @param iSignalNo Signal to send to all the processes in the group.
|
|---|
| 548 | */
|
|---|
| 549 | int __libc_Back_signalSendPGrp(pid_t pgrp, int iSignalNo);
|
|---|
| 550 |
|
|---|
| 551 | /**
|
|---|
| 552 | * Verify the existance of a process group and that the current process
|
|---|
| 553 | * is allowed to signal it.
|
|---|
| 554 | *
|
|---|
| 555 | * @return 0 on success.
|
|---|
| 556 | * @return -ESRCH if pgid doesn't exist.
|
|---|
| 557 | * @return -EPERM if we aren't allowed to signal the pgid.
|
|---|
| 558 | * @param pgid Process group id which the current process intend to signal.
|
|---|
| 559 | * @todo Do EPERM check, no ideas here yet.
|
|---|
| 560 | * @remark This Backend Signal API does NOT require the caller to own the signal semaphore.
|
|---|
| 561 | */
|
|---|
| 562 | int __libc_Back_signalVerifyPGrp(pid_t pgid);
|
|---|
| 563 |
|
|---|
| 564 | /**
|
|---|
| 565 | * sigaction worker; queries and/or sets the action for a signal.
|
|---|
| 566 | *
|
|---|
| 567 | * @returns 0 on success.
|
|---|
| 568 | * @returns Negative error code (errno) on failure.
|
|---|
| 569 | * @param iSignalNo Signal number.
|
|---|
| 570 | * @param pSigAct Pointer to new signal action.
|
|---|
| 571 | * If NULL no update is done.
|
|---|
| 572 | * @param pSigActOld Where to store the old signal action.
|
|---|
| 573 | * If NULL nothing is attempted stored.
|
|---|
| 574 | */
|
|---|
| 575 | int __libc_Back_signalAction(int iSignalNo, const struct sigaction *pSigAct, struct sigaction *pSigActOld);
|
|---|
| 576 |
|
|---|
| 577 | /**
|
|---|
| 578 | * Change interrupt/restart system call properties for a signal.
|
|---|
| 579 | *
|
|---|
| 580 | * @returns 0 on success.
|
|---|
| 581 | * @returns Negative error code (errno) on failure.
|
|---|
| 582 | * @param iSignalNo Signal number to change interrupt/restart
|
|---|
| 583 | * properties for.
|
|---|
| 584 | * @param fFlag If set Then clear the SA_RESTART from the handler action.
|
|---|
| 585 | * If clear Then set the SA_RESTART from the handler action.
|
|---|
| 586 | * @remark The SA_RESTART flag is inherited when using signal().
|
|---|
| 587 | */
|
|---|
| 588 | int __libc_Back_signalInterrupt(int iSignalNo, int fFlag);
|
|---|
| 589 |
|
|---|
| 590 | /**
|
|---|
| 591 | * Changes and/or queries the alternative signal stack settings of a thread.
|
|---|
| 592 | *
|
|---|
| 593 | * @returns 0 on success.
|
|---|
| 594 | * @returns Negative error number (errno.h) on failure.
|
|---|
| 595 | * @param pThrd Thread which signal stack to change and/or query.
|
|---|
| 596 | * @param pStack New stack settings. (Optional)
|
|---|
| 597 | * @param pOldStack Old stack settings. (Optional)
|
|---|
| 598 | */
|
|---|
| 599 | int __libc_Back_signalStack(__LIBC_PTHREAD pThrd, const stack_t *pStack, stack_t *pOldStack);
|
|---|
| 600 |
|
|---|
| 601 | /**
|
|---|
| 602 | * Block or unblock signal deliveries of a thread.
|
|---|
| 603 | *
|
|---|
| 604 | * @returns 0 on success.
|
|---|
| 605 | * @returns Negative error code (errno) on failure.
|
|---|
| 606 | * @param pThrd Thread to apply this to.
|
|---|
| 607 | * @param iHow Describes the action taken if pSigSetNew not NULL. Recognized
|
|---|
| 608 | * values are SIG_BLOCK, SIG_UNBLOCK or SIG_SETMASK.
|
|---|
| 609 | *
|
|---|
| 610 | * SIG_BLOCK means to or the sigset pointed to by pSigSetNew with
|
|---|
| 611 | * the signal mask for the current thread.
|
|---|
| 612 | * SIG_UNBLOCK means to and the 0 complement of the sigset pointed
|
|---|
| 613 | * to by pSigSetNew with the signal mask of the current thread.
|
|---|
| 614 | * SIG_SETMASK means to set the signal mask of the current thread
|
|---|
| 615 | * to the sigset pointed to by pSigSetNew.
|
|---|
| 616 | *
|
|---|
| 617 | * @param pSigSetNew Pointer to signal set which will be applied to the current
|
|---|
| 618 | * threads signal mask according to iHow. If NULL no change
|
|---|
| 619 | * will be made the the current threads signal mask.
|
|---|
| 620 | * @param pSigSetOld Where to store the current threads signal mask prior to applying
|
|---|
| 621 | * pSigSetNew to it. This parameter can be NULL.
|
|---|
| 622 | */
|
|---|
| 623 | int __libc_Back_signalMask(__LIBC_PTHREAD pThrd, int iHow, const sigset_t * __restrict pSigSetNew, sigset_t * __restrict pSigSetOld);
|
|---|
| 624 |
|
|---|
| 625 | /**
|
|---|
| 626 | * Wait for one or more signals and remove and return the first of them
|
|---|
| 627 | * to occur.
|
|---|
| 628 | *
|
|---|
| 629 | * Will return immediately if one of the signals is already pending. If more than
|
|---|
| 630 | * one signal is pending the signal with highest priority will be returned.
|
|---|
| 631 | *
|
|---|
| 632 | * @returns Signal number on success.
|
|---|
| 633 | * @returns Negative error code (errno) on failure.
|
|---|
| 634 | * @param pSigSet Signals to wait for.
|
|---|
| 635 | * @param pSigInfo Where to store the signal info for the signal
|
|---|
| 636 | * that we accepted.
|
|---|
| 637 | * @param pTimeout Timeout specification. If NULL wait for ever.
|
|---|
| 638 | */
|
|---|
| 639 | int __libc_Back_signalWait(const sigset_t *pSigSet, siginfo_t *pSigInfo, const struct timespec *pTimeout);
|
|---|
| 640 |
|
|---|
| 641 | /**
|
|---|
| 642 | * Suspends the current thread till a signal have been handled.
|
|---|
| 643 | * The signal semaphore is owned.
|
|---|
| 644 | *
|
|---|
| 645 | * @returns Negative error code (errno) on failure. (allways fails)
|
|---|
| 646 | * @param pSigSet Temporary signal mask for the thread.
|
|---|
| 647 | */
|
|---|
| 648 | int __libc_Back_signalSuspend(const sigset_t *pSigSet);
|
|---|
| 649 |
|
|---|
| 650 | /**
|
|---|
| 651 | * Gets the set of signals which are blocked by the current thread and are
|
|---|
| 652 | * pending on the process or the calling thread.
|
|---|
| 653 | *
|
|---|
| 654 | * @returns 0 indicating success.
|
|---|
| 655 | * @returns Negative error code (errno) on failure.
|
|---|
| 656 | * @param pSigSet Pointer to signal set where the result is to be stored.
|
|---|
| 657 | */
|
|---|
| 658 | int __libc_Back_signalPending(sigset_t *pSigSet);
|
|---|
| 659 |
|
|---|
| 660 | /** @} */
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
|
|---|
| 664 | /** @defgroup grp_Back_process LIBC Backend - Process Management
|
|---|
| 665 | * @{ */
|
|---|
| 666 |
|
|---|
| 667 | /**
|
|---|
| 668 | * Waits/polls for on one or more processes to change it's running status.
|
|---|
| 669 | *
|
|---|
| 670 | * @returns 0 on success, pSigInfo containing status info.
|
|---|
| 671 | * @returns -1 and errno on failure.
|
|---|
| 672 | * @param enmIdType What kind of process specification Id contains.
|
|---|
| 673 | * @param Id Process specification of the enmIdType sort.
|
|---|
| 674 | * @param pSigInfo Where to store the result.
|
|---|
| 675 | * @param fOptions The WEXITED, WUNTRACED, WSTOPPED and WCONTINUED flags are used to
|
|---|
| 676 | * select the events to report. WNOHANG is used for preventing the api
|
|---|
| 677 | * from blocking. And WNOWAIT is used for peeking.
|
|---|
| 678 | * @param pResUsage Where to store the reported resources usage for the child.
|
|---|
| 679 | * Optional and not implemented on OS/2.
|
|---|
| 680 | */
|
|---|
| 681 | int __libc_Back_processWait(idtype_t enmIdType, id_t Id, siginfo_t *pSigInfo, unsigned fOptions, struct rusage *pUsage);
|
|---|
| 682 |
|
|---|
| 683 | /** @} */
|
|---|
| 684 |
|
|---|
| 685 | __END_DECLS
|
|---|
| 686 |
|
|---|
| 687 | #endif
|
|---|