101e04c3fSmrg/**************************************************************************
201e04c3fSmrg *
37ec681f3Smrg * Copyright 2010 VMware, Inc.
401e04c3fSmrg * All Rights Reserved.
501e04c3fSmrg *
601e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
701e04c3fSmrg * copy of this software and associated documentation files (the
801e04c3fSmrg * "Software"), to deal in the Software without restriction, including
901e04c3fSmrg * without limitation the rights to use, copy, modify, merge, publish,
1001e04c3fSmrg * distribute, sub license, and/or sell copies of the Software, and to
1101e04c3fSmrg * permit persons to whom the Software is furnished to do so, subject to
1201e04c3fSmrg * the following conditions:
1301e04c3fSmrg *
1401e04c3fSmrg * The above copyright notice and this permission notice (including the
1501e04c3fSmrg * next paragraph) shall be included in all copies or substantial portions
1601e04c3fSmrg * of the Software.
1701e04c3fSmrg *
1801e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1901e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2001e04c3fSmrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
2101e04c3fSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
2201e04c3fSmrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2301e04c3fSmrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2401e04c3fSmrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2501e04c3fSmrg *
2601e04c3fSmrg **************************************************************************/
2701e04c3fSmrg
2801e04c3fSmrg
2901e04c3fSmrg/*
3001e04c3fSmrg * Miscellaneous OS services.
3101e04c3fSmrg */
3201e04c3fSmrg
3301e04c3fSmrg
3401e04c3fSmrg#ifndef _OS_MISC_H_
3501e04c3fSmrg#define _OS_MISC_H_
3601e04c3fSmrg
377ec681f3Smrg#include <stdint.h>
387ec681f3Smrg#include <stdbool.h>
3901e04c3fSmrg
407ec681f3Smrg#include "detect_os.h"
4101e04c3fSmrg
4201e04c3fSmrg
437ec681f3Smrg#if DETECT_OS_UNIX
4401e04c3fSmrg#  include <signal.h> /* for kill() */
4501e04c3fSmrg#  include <unistd.h> /* getpid() */
4601e04c3fSmrg#endif
4701e04c3fSmrg
4801e04c3fSmrg
4901e04c3fSmrg#ifdef  __cplusplus
5001e04c3fSmrgextern "C" {
5101e04c3fSmrg#endif
5201e04c3fSmrg
5301e04c3fSmrg
5401e04c3fSmrg/*
5501e04c3fSmrg * Trap into the debugger.
5601e04c3fSmrg */
5701e04c3fSmrg#if (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) && defined(PIPE_CC_GCC)
5801e04c3fSmrg#  define os_break() __asm("int3")
5901e04c3fSmrg#elif defined(PIPE_CC_MSVC)
6001e04c3fSmrg#  define os_break()  __debugbreak()
617ec681f3Smrg#elif DETECT_OS_UNIX
6201e04c3fSmrg#  define os_break() kill(getpid(), SIGTRAP)
6301e04c3fSmrg#else
6401e04c3fSmrg#  define os_break() abort()
6501e04c3fSmrg#endif
6601e04c3fSmrg
6701e04c3fSmrg
6801e04c3fSmrg/*
6901e04c3fSmrg * Abort the program.
7001e04c3fSmrg */
7101e04c3fSmrg#if defined(DEBUG)
7201e04c3fSmrg#  define os_abort() do { os_break(); abort(); } while(0)
7301e04c3fSmrg#else
7401e04c3fSmrg#  define os_abort() abort()
7501e04c3fSmrg#endif
7601e04c3fSmrg
7701e04c3fSmrg
7801e04c3fSmrg/*
7901e04c3fSmrg * Output a message. Message should preferably end in a newline.
8001e04c3fSmrg */
8101e04c3fSmrgvoid
8201e04c3fSmrgos_log_message(const char *message);
8301e04c3fSmrg
8401e04c3fSmrg
8501e04c3fSmrg/*
8601e04c3fSmrg * Get an option. Should return NULL if specified option is not set.
8701e04c3fSmrg */
8801e04c3fSmrgconst char *
8901e04c3fSmrgos_get_option(const char *name);
9001e04c3fSmrg
9101e04c3fSmrg
9201e04c3fSmrg/*
9301e04c3fSmrg * Get the total amount of physical memory available on the system.
9401e04c3fSmrg */
9501e04c3fSmrgbool
9601e04c3fSmrgos_get_total_physical_memory(uint64_t *size);
9701e04c3fSmrg
987ec681f3Smrg/*
997ec681f3Smrg * Amount of physical memory available to a process
1007ec681f3Smrg */
1017ec681f3Smrgbool
1027ec681f3Smrgos_get_available_system_memory(uint64_t *size);
1037ec681f3Smrg
1047ec681f3Smrg/*
1057ec681f3Smrg * Size of a page
1067ec681f3Smrg */
1077ec681f3Smrgbool
1087ec681f3Smrgos_get_page_size(uint64_t *size);
1097ec681f3Smrg
11001e04c3fSmrg
11101e04c3fSmrg#ifdef	__cplusplus
11201e04c3fSmrg}
11301e04c3fSmrg#endif
11401e04c3fSmrg
11501e04c3fSmrg
11601e04c3fSmrg#endif /* _OS_MISC_H_ */
117