os_misc.h revision 01e04c3f
101e04c3fSmrg/**************************************************************************
201e04c3fSmrg *
301e04c3fSmrg * 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
3701e04c3fSmrg
3801e04c3fSmrg#include "pipe/p_compiler.h"
3901e04c3fSmrg
4001e04c3fSmrg
4101e04c3fSmrg#if defined(PIPE_OS_UNIX)
4201e04c3fSmrg#  include <signal.h> /* for kill() */
4301e04c3fSmrg#  include <unistd.h> /* getpid() */
4401e04c3fSmrg#endif
4501e04c3fSmrg
4601e04c3fSmrg
4701e04c3fSmrg#ifdef  __cplusplus
4801e04c3fSmrgextern "C" {
4901e04c3fSmrg#endif
5001e04c3fSmrg
5101e04c3fSmrg
5201e04c3fSmrg/*
5301e04c3fSmrg * Trap into the debugger.
5401e04c3fSmrg */
5501e04c3fSmrg#if (defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64)) && defined(PIPE_CC_GCC)
5601e04c3fSmrg#  define os_break() __asm("int3")
5701e04c3fSmrg#elif defined(PIPE_CC_MSVC)
5801e04c3fSmrg#  define os_break()  __debugbreak()
5901e04c3fSmrg#elif defined(PIPE_OS_UNIX)
6001e04c3fSmrg#  define os_break() kill(getpid(), SIGTRAP)
6101e04c3fSmrg#else
6201e04c3fSmrg#  define os_break() abort()
6301e04c3fSmrg#endif
6401e04c3fSmrg
6501e04c3fSmrg
6601e04c3fSmrg/*
6701e04c3fSmrg * Abort the program.
6801e04c3fSmrg */
6901e04c3fSmrg#if defined(DEBUG)
7001e04c3fSmrg#  define os_abort() do { os_break(); abort(); } while(0)
7101e04c3fSmrg#else
7201e04c3fSmrg#  define os_abort() abort()
7301e04c3fSmrg#endif
7401e04c3fSmrg
7501e04c3fSmrg
7601e04c3fSmrg/*
7701e04c3fSmrg * Output a message. Message should preferably end in a newline.
7801e04c3fSmrg */
7901e04c3fSmrgvoid
8001e04c3fSmrgos_log_message(const char *message);
8101e04c3fSmrg
8201e04c3fSmrg
8301e04c3fSmrg/*
8401e04c3fSmrg * Get an option. Should return NULL if specified option is not set.
8501e04c3fSmrg */
8601e04c3fSmrgconst char *
8701e04c3fSmrgos_get_option(const char *name);
8801e04c3fSmrg
8901e04c3fSmrg
9001e04c3fSmrg/*
9101e04c3fSmrg * Get the total amount of physical memory available on the system.
9201e04c3fSmrg */
9301e04c3fSmrgbool
9401e04c3fSmrgos_get_total_physical_memory(uint64_t *size);
9501e04c3fSmrg
9601e04c3fSmrg
9701e04c3fSmrg#ifdef	__cplusplus
9801e04c3fSmrg}
9901e04c3fSmrg#endif
10001e04c3fSmrg
10101e04c3fSmrg
10201e04c3fSmrg#endif /* _OS_MISC_H_ */
103