xref: /openbmc/qemu/include/sysemu/os-posix.h (revision 8737d9e0c4017aaa5ab1fcf1356c8ee4f7caf1df)
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 
379c17d615SPaolo Bonzini void os_set_line_buffering(void);
389c17d615SPaolo Bonzini void os_set_proc_name(const char *s);
399c17d615SPaolo Bonzini void os_setup_signal_handling(void);
409c17d615SPaolo Bonzini void os_daemonize(void);
419c17d615SPaolo Bonzini void os_setup_post(void);
42888a6bc6SSatoru Moriya int os_mlock(void);
439c17d615SPaolo Bonzini 
44a2d96af4SDaniel P. Berrange #define closesocket(s) close(s)
45a2d96af4SDaniel P. Berrange #define ioctlsocket(s, r, v) ioctl(s, r, v)
46a2d96af4SDaniel P. Berrange 
479c17d615SPaolo Bonzini typedef struct timeval qemu_timeval;
489c17d615SPaolo Bonzini #define qemu_gettimeofday(tp) gettimeofday(tp, NULL)
499c17d615SPaolo Bonzini 
509c17d615SPaolo Bonzini #ifndef CONFIG_UTIMENSAT
519c17d615SPaolo Bonzini #ifndef UTIME_NOW
529c17d615SPaolo Bonzini # define UTIME_NOW     ((1l << 30) - 1l)
539c17d615SPaolo Bonzini #endif
549c17d615SPaolo Bonzini #ifndef UTIME_OMIT
559c17d615SPaolo Bonzini # define UTIME_OMIT    ((1l << 30) - 2l)
569c17d615SPaolo Bonzini #endif
579c17d615SPaolo Bonzini #endif
589c17d615SPaolo Bonzini typedef struct timespec qemu_timespec;
599c17d615SPaolo Bonzini int qemu_utimens(const char *path, const qemu_timespec *times);
609c17d615SPaolo Bonzini 
619c17d615SPaolo Bonzini bool is_daemonized(void);
629c17d615SPaolo Bonzini 
63*8737d9e0SPeter Lieven /**
64*8737d9e0SPeter Lieven  * qemu_alloc_stack:
65*8737d9e0SPeter Lieven  * @sz: pointer to a size_t holding the requested usable stack size
66*8737d9e0SPeter Lieven  *
67*8737d9e0SPeter Lieven  * Allocate memory that can be used as a stack, for instance for
68*8737d9e0SPeter Lieven  * coroutines. If the memory cannot be allocated, this function
69*8737d9e0SPeter Lieven  * will abort (like g_malloc()). This function also inserts an
70*8737d9e0SPeter Lieven  * additional guard page to catch a potential stack overflow.
71*8737d9e0SPeter Lieven  * Note that the memory required for the guard page and alignment
72*8737d9e0SPeter Lieven  * and minimal stack size restrictions will increase the value of sz.
73*8737d9e0SPeter Lieven  *
74*8737d9e0SPeter Lieven  * The allocated stack must be freed with qemu_free_stack().
75*8737d9e0SPeter Lieven  *
76*8737d9e0SPeter Lieven  * Returns: pointer to (the lowest address of) the stack memory.
77*8737d9e0SPeter Lieven  */
78*8737d9e0SPeter Lieven void *qemu_alloc_stack(size_t *sz);
79*8737d9e0SPeter Lieven 
80*8737d9e0SPeter Lieven /**
81*8737d9e0SPeter Lieven  * qemu_free_stack:
82*8737d9e0SPeter Lieven  * @stack: stack to free
83*8737d9e0SPeter Lieven  * @sz: size of stack in bytes
84*8737d9e0SPeter Lieven  *
85*8737d9e0SPeter Lieven  * Free a stack allocated via qemu_alloc_stack(). Note that sz must
86*8737d9e0SPeter Lieven  * be exactly the adjusted stack size returned by qemu_alloc_stack.
87*8737d9e0SPeter Lieven  */
88*8737d9e0SPeter Lieven void qemu_free_stack(void *stack, size_t sz);
89*8737d9e0SPeter Lieven 
909c17d615SPaolo Bonzini #endif
91