File: clb_os_wrapper.h

package info (click to toggle)
eprover 2.6%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 21,288 kB
  • sloc: ansic: 331,111; csh: 12,026; python: 10,178; awk: 5,825; makefile: 461; sh: 389
file content (122 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*-----------------------------------------------------------------------

File  : clb_os_wrapper.h

Author: Stephan Schulz (schulz@eprover.org)

Contents

  Functions wrapping some OS functions in a convenient manner.

  Copyright 2007 by the author.
  This code is released under the GNU General Public Licence and
  the GNU Lesser General Public License.
  See the file COPYING in the main E directory for details..
  Run "eprover -h" for contact information.

Changes

<1>     New

-----------------------------------------------------------------------*/

#ifndef CLB_OS_WRAPPERS

#define CLB_OS_WRAPPERS

#include <assert.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>

#include "clb_error.h"


/*---------------------------------------------------------------------*/
/*                    Data type declarations                           */
/*---------------------------------------------------------------------*/

typedef enum
{
   RLimFailed,
   RLimReduced,
   RLimSuccess
}RLimResult;


/*---------------------------------------------------------------------*/
/*                Exported Functions and Variables                     */
/*---------------------------------------------------------------------*/

#ifdef PROFILE_WALL_CLOCK
#define GETTIME GetUSecTime
#else
#define GETTIME GetUSecClock
#endif

#define INCREASE_STACK_SIZE \
   {\
      struct rlimit rlim;\
      int res;\
      rlim.rlim_cur = 0;\
      rlim.rlim_max = 0;\
      \
      if(getrlimit(RLIMIT_STACK, &rlim)==-1)\
      {\
         TmpErrno = errno;\
         fprintf(stderr, "%s: Warning: Cannot get stack limit", argv[0]);\
      }\
      else\
      {\
         rlim.rlim_cur=rlim.rlim_max;\
         res = setrlimit(RLIMIT_STACK, &rlim);\
         if(res ==-1)\
         {\
            fprintf(stderr, "%s: Warning: Cannot set stack limit", argv[0]);\
            fprintf(stderr, "%s: Warning: Continuing with default stack size", argv[0]);\
         }\
      }\
   }



#ifdef INSTRUMENT_PERF_CTR
#define PERF_CTR_DEFINE(name)  long long name = 0; long long name##_store = 0
#define PERF_CTR_DECL(name)    extern long long name; extern long long name##_store
#define PERF_CTR_RESET(name)   name = 0
#define PERF_CTR_ENTRY(name)   name##_store = GETTIME()
#define PERF_CTR_EXIT(name)    name+=(GETTIME()-(name##_store));name##_store=0
#define PERF_CTR_PRINT(out, name) fprintf((out), "# PC%-34s : %f\n", "(" #name ")", ((float)name)/1000000.0)
#else
#define PERF_CTR_DEFINE(name)  enum { name##_store } // Used to silence compiler warnings
#define PERF_CTR_DECL(name)    enum { name }         // about extra semicolons.
#define PERF_CTR_RESET(name)
#define PERF_CTR_ENTRY(name)
#define PERF_CTR_EXIT(name)
#define PERF_CTR_PRINT(out, name)
#endif

RLimResult SetSoftRlimit(int resource, rlim_t limit);
void       SetSoftRlimitErr(int resource, rlim_t limit, char* desc);
void       SetMemoryLimit(rlim_t mem_limit);
rlim_t     GetSoftRlimit(int resource);
// void       IncreaseMaxStackSize(char *argv[], rlim_t stacksize);
long long  GetUSecTime(void);
long long  GetUSecClock(void);
#define    GetMSecTime() (GetUSecTime()/1000)
#define    GetSecTime() (GetUSecTime()/1000000)
#define    GetSecTimeMod() (GetSecTime()%1000)

FILE*      SecureFOpen(char* name, char* mode);
void       SecureFClose(FILE* fp);

#endif

/*---------------------------------------------------------------------*/
/*                        End of File                                  */
/*---------------------------------------------------------------------*/