19c17d615SPaolo Bonzini /* 29c17d615SPaolo Bonzini * posix specific declarations 39c17d615SPaolo Bonzini * 49c17d615SPaolo Bonzini * Copyright (c) 2003-2008 Fabrice Bellard 59c17d615SPaolo Bonzini * Copyright (c) 2010 Jes Sorensen <Jes.Sorensen@redhat.com> 69c17d615SPaolo Bonzini * 79c17d615SPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy 89c17d615SPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal 99c17d615SPaolo Bonzini * in the Software without restriction, including without limitation the rights 109c17d615SPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 119c17d615SPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is 129c17d615SPaolo Bonzini * furnished to do so, subject to the following conditions: 139c17d615SPaolo Bonzini * 149c17d615SPaolo Bonzini * The above copyright notice and this permission notice shall be included in 159c17d615SPaolo Bonzini * all copies or substantial portions of the Software. 169c17d615SPaolo Bonzini * 179c17d615SPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 189c17d615SPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 199c17d615SPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 209c17d615SPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 219c17d615SPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 229c17d615SPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 239c17d615SPaolo Bonzini * THE SOFTWARE. 249c17d615SPaolo Bonzini */ 259c17d615SPaolo Bonzini 269c17d615SPaolo Bonzini #ifndef QEMU_OS_POSIX_H 279c17d615SPaolo Bonzini #define QEMU_OS_POSIX_H 289c17d615SPaolo Bonzini 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 45327adeecSMarc-André Lureau int os_parse_cmd_args(int index, const char *optarg); 469c17d615SPaolo Bonzini void os_set_line_buffering(void); 47327adeecSMarc-André Lureau void os_setup_early_signal_handling(void); 489c17d615SPaolo Bonzini void os_set_proc_name(const char *s); 499c17d615SPaolo Bonzini void os_setup_signal_handling(void); 50*b21bdbb5SMichael Tokarev int os_set_daemonize(bool d); 51*b21bdbb5SMichael Tokarev bool is_daemonized(void); 529c17d615SPaolo Bonzini void os_daemonize(void); 539c17d615SPaolo Bonzini void os_setup_post(void); 54888a6bc6SSatoru Moriya int os_mlock(void); 559c17d615SPaolo Bonzini 568737d9e0SPeter Lieven /** 578737d9e0SPeter Lieven * qemu_alloc_stack: 588737d9e0SPeter Lieven * @sz: pointer to a size_t holding the requested usable stack size 598737d9e0SPeter Lieven * 608737d9e0SPeter Lieven * Allocate memory that can be used as a stack, for instance for 618737d9e0SPeter Lieven * coroutines. If the memory cannot be allocated, this function 628737d9e0SPeter Lieven * will abort (like g_malloc()). This function also inserts an 638737d9e0SPeter Lieven * additional guard page to catch a potential stack overflow. 648737d9e0SPeter Lieven * Note that the memory required for the guard page and alignment 658737d9e0SPeter Lieven * and minimal stack size restrictions will increase the value of sz. 668737d9e0SPeter Lieven * 678737d9e0SPeter Lieven * The allocated stack must be freed with qemu_free_stack(). 688737d9e0SPeter Lieven * 698737d9e0SPeter Lieven * Returns: pointer to (the lowest address of) the stack memory. 708737d9e0SPeter Lieven */ 718737d9e0SPeter Lieven void *qemu_alloc_stack(size_t *sz); 728737d9e0SPeter Lieven 738737d9e0SPeter Lieven /** 748737d9e0SPeter Lieven * qemu_free_stack: 758737d9e0SPeter Lieven * @stack: stack to free 768737d9e0SPeter Lieven * @sz: size of stack in bytes 778737d9e0SPeter Lieven * 788737d9e0SPeter Lieven * Free a stack allocated via qemu_alloc_stack(). Note that sz must 798737d9e0SPeter Lieven * be exactly the adjusted stack size returned by qemu_alloc_stack. 808737d9e0SPeter Lieven */ 818737d9e0SPeter Lieven void qemu_free_stack(void *stack, size_t sz); 828737d9e0SPeter Lieven 831ee73216SRichard Henderson /* POSIX and Mingw32 differ in the name of the stdio lock functions. */ 841ee73216SRichard Henderson 851ee73216SRichard Henderson static inline void qemu_flockfile(FILE *f) 861ee73216SRichard Henderson { 871ee73216SRichard Henderson flockfile(f); 881ee73216SRichard Henderson } 891ee73216SRichard Henderson 901ee73216SRichard Henderson static inline void qemu_funlockfile(FILE *f) 911ee73216SRichard Henderson { 921ee73216SRichard Henderson funlockfile(f); 931ee73216SRichard Henderson } 941ee73216SRichard Henderson 95415a9fb8SPeter Maydell #ifdef __cplusplus 96415a9fb8SPeter Maydell } 97415a9fb8SPeter Maydell #endif 98415a9fb8SPeter Maydell 999c17d615SPaolo Bonzini #endif 100