xref: /qemu/include/system/os-posix.h (revision e76fadf93e4d64492206b34fd3d434b515450d2c)
10d93ca7cSJes Sorensen /*
20d93ca7cSJes Sorensen  * posix specific declarations
30d93ca7cSJes Sorensen  *
40d93ca7cSJes Sorensen  * Copyright (c) 2003-2008 Fabrice Bellard
50d93ca7cSJes Sorensen  * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com>
60d93ca7cSJes Sorensen  *
70d93ca7cSJes Sorensen  * Permission is hereby granted, free of charge, to any person obtaining a copy
80d93ca7cSJes Sorensen  * of this software and associated documentation files (the "Software"), to deal
90d93ca7cSJes Sorensen  * in the Software without restriction, including without limitation the rights
100d93ca7cSJes Sorensen  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
110d93ca7cSJes Sorensen  * copies of the Software, and to permit persons to whom the Software is
120d93ca7cSJes Sorensen  * furnished to do so, subject to the following conditions:
130d93ca7cSJes Sorensen  *
140d93ca7cSJes Sorensen  * The above copyright notice and this permission notice shall be included in
150d93ca7cSJes Sorensen  * all copies or substantial portions of the Software.
160d93ca7cSJes Sorensen  *
170d93ca7cSJes Sorensen  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180d93ca7cSJes Sorensen  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
190d93ca7cSJes Sorensen  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
200d93ca7cSJes Sorensen  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
210d93ca7cSJes Sorensen  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
220d93ca7cSJes Sorensen  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
230d93ca7cSJes Sorensen  * THE SOFTWARE.
240d93ca7cSJes Sorensen  */
250d93ca7cSJes Sorensen 
260d93ca7cSJes Sorensen #ifndef QEMU_OS_POSIX_H
270d93ca7cSJes Sorensen #define QEMU_OS_POSIX_H
280d93ca7cSJes Sorensen 
2902d0e095SPaolo Bonzini #include <sys/mman.h>
30a2d96af4SDaniel P. Berrange #include <sys/socket.h>
31a2d96af4SDaniel P. Berrange #include <netinet/in.h>
32a2d96af4SDaniel P. Berrange #include <netinet/tcp.h>
33a2d96af4SDaniel P. Berrange #include <arpa/inet.h>
34a2d96af4SDaniel P. Berrange #include <netdb.h>
35a2d96af4SDaniel P. Berrange #include <sys/un.h>
36506f40ffSWenchao Xia 
374d04351fSChristopher Covington #ifdef CONFIG_SYSMACROS
384d04351fSChristopher Covington #include <sys/sysmacros.h>
394d04351fSChristopher Covington #endif
404d04351fSChristopher Covington 
41415a9fb8SPeter Maydell #ifdef __cplusplus
42415a9fb8SPeter Maydell extern "C" {
43415a9fb8SPeter Maydell #endif
44415a9fb8SPeter Maydell 
459156d763SJes Sorensen void os_set_line_buffering(void);
46327adeecSMarc-André Lureau void os_setup_early_signal_handling(void);
47ce798cf2SJes Sorensen void os_set_proc_name(const char *s);
488d963e6aSJes Sorensen void os_setup_signal_handling(void);
49b21bdbb5SMichael Tokarev int os_set_daemonize(bool d);
50b21bdbb5SMichael Tokarev bool is_daemonized(void);
51eb505be1SJes Sorensen void os_daemonize(void);
52d2803376SPhilippe Mathieu-Daudé bool os_set_runas(const char *user_id);
53d2803376SPhilippe Mathieu-Daudé void os_set_chroot(const char *path);
5403e471c4SFiona Ebner void os_setup_limits(void);
55eb505be1SJes Sorensen void os_setup_post(void);
56*e76fadf9SDaniil Tatianin int os_mlock(bool on_fault);
578d963e6aSJes Sorensen 
588737d9e0SPeter Lieven /**
598737d9e0SPeter Lieven  * qemu_alloc_stack:
608737d9e0SPeter Lieven  * @sz: pointer to a size_t holding the requested usable stack size
618737d9e0SPeter Lieven  *
628737d9e0SPeter Lieven  * Allocate memory that can be used as a stack, for instance for
638737d9e0SPeter Lieven  * coroutines. If the memory cannot be allocated, this function
648737d9e0SPeter Lieven  * will abort (like g_malloc()). This function also inserts an
658737d9e0SPeter Lieven  * additional guard page to catch a potential stack overflow.
668737d9e0SPeter Lieven  * Note that the memory required for the guard page and alignment
678737d9e0SPeter Lieven  * and minimal stack size restrictions will increase the value of sz.
688737d9e0SPeter Lieven  *
698737d9e0SPeter Lieven  * The allocated stack must be freed with qemu_free_stack().
708737d9e0SPeter Lieven  *
718737d9e0SPeter Lieven  * Returns: pointer to (the lowest address of) the stack memory.
728737d9e0SPeter Lieven  */
738737d9e0SPeter Lieven void *qemu_alloc_stack(size_t *sz);
748737d9e0SPeter Lieven 
758737d9e0SPeter Lieven /**
768737d9e0SPeter Lieven  * qemu_free_stack:
778737d9e0SPeter Lieven  * @stack: stack to free
788737d9e0SPeter Lieven  * @sz: size of stack in bytes
798737d9e0SPeter Lieven  *
808737d9e0SPeter Lieven  * Free a stack allocated via qemu_alloc_stack(). Note that sz must
818737d9e0SPeter Lieven  * be exactly the adjusted stack size returned by qemu_alloc_stack.
828737d9e0SPeter Lieven  */
838737d9e0SPeter Lieven void qemu_free_stack(void *stack, size_t sz);
848737d9e0SPeter Lieven 
851ee73216SRichard Henderson /* POSIX and Mingw32 differ in the name of the stdio lock functions.  */
861ee73216SRichard Henderson 
qemu_flockfile(FILE * f)871ee73216SRichard Henderson static inline void qemu_flockfile(FILE *f)
881ee73216SRichard Henderson {
891ee73216SRichard Henderson     flockfile(f);
901ee73216SRichard Henderson }
911ee73216SRichard Henderson 
qemu_funlockfile(FILE * f)921ee73216SRichard Henderson static inline void qemu_funlockfile(FILE *f)
931ee73216SRichard Henderson {
941ee73216SRichard Henderson     funlockfile(f);
951ee73216SRichard Henderson }
961ee73216SRichard Henderson 
97415a9fb8SPeter Maydell #ifdef __cplusplus
98415a9fb8SPeter Maydell }
99415a9fb8SPeter Maydell #endif
100415a9fb8SPeter Maydell 
1010d93ca7cSJes Sorensen #endif
102