1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
63 | /******************************************************************************/ |
63 | /******************************************************************************/ |
64 | |
64 | |
65 | /* Checks a player-provided string which will become the msg property of |
65 | /* Checks a player-provided string which will become the msg property of |
66 | * an object for dangerous input. |
66 | * an object for dangerous input. |
67 | */ |
67 | */ |
68 | bool |
68 | bool |
69 | msg_is_safe (const char *msg) |
69 | msg_is_safe (const char *msg) |
70 | { |
70 | { |
71 | bool safe = true; |
71 | bool safe = true; |
72 | |
72 | |
73 | /* Trying to cheat by getting data into the object */ |
73 | /* Trying to cheat by getting data into the object */ |
… | |
… | |
92 | signal (SIGINT , SIG_IGN); |
92 | signal (SIGINT , SIG_IGN); |
93 | signal (SIGTERM, SIG_IGN); |
93 | signal (SIGTERM, SIG_IGN); |
94 | signal (SIGABRT, SIG_IGN); |
94 | signal (SIGABRT, SIG_IGN); |
95 | |
95 | |
96 | signal (SIGSEGV, SIG_DFL); |
96 | signal (SIGSEGV, SIG_DFL); |
|
|
97 | signal (SIGFPE , SIG_DFL); |
|
|
98 | #ifdef SIGBUS |
97 | signal (SIGBUS , SIG_DFL); |
99 | signal (SIGBUS , SIG_DFL); |
|
|
100 | #endif |
98 | signal (SIGILL , SIG_DFL); |
101 | signal (SIGILL , SIG_DFL); |
99 | signal (SIGTRAP, SIG_DFL); |
102 | signal (SIGTRAP, SIG_DFL); |
100 | |
103 | |
101 | // try to put corefiles into a subdirectory, if existing, to allow |
104 | // try to put corefiles into a subdirectory, if existing, to allow |
102 | // an administrator to reduce the I/O load. |
105 | // an administrator to reduce the I/O load. |
… | |
… | |
127 | |
130 | |
128 | LOG (llevError, "fork abort: %s\n", msg); |
131 | LOG (llevError, "fork abort: %s\n", msg); |
129 | } |
132 | } |
130 | |
133 | |
131 | void * |
134 | void * |
132 | salloc_ (int n) throw (std::bad_alloc) |
135 | salloc_ (int n) |
133 | { |
136 | { |
134 | void *ptr = g_slice_alloc (n); |
137 | void *ptr = g_slice_alloc (n); |
135 | |
138 | |
136 | if (!ptr) |
139 | if (!ptr) |
137 | throw std::bad_alloc (); |
140 | throw std::bad_alloc (); |
… | |
… | |
139 | slice_alloc += n; |
142 | slice_alloc += n; |
140 | return ptr; |
143 | return ptr; |
141 | } |
144 | } |
142 | |
145 | |
143 | void * |
146 | void * |
144 | salloc_ (int n, void *src) throw (std::bad_alloc) |
147 | salloc_ (int n, void *src) |
145 | { |
148 | { |
146 | void *ptr = salloc_ (n); |
149 | void *ptr = salloc_ (n); |
147 | |
150 | |
148 | if (src) |
151 | if (src) |
149 | memcpy (ptr, src, n); |
152 | memcpy (ptr, src, n); |
… | |
… | |
199 | |
202 | |
200 | /******************************************************************************/ |
203 | /******************************************************************************/ |
201 | |
204 | |
202 | refcnt_buf::refcnt_buf (size_t size) |
205 | refcnt_buf::refcnt_buf (size_t size) |
203 | { |
206 | { |
204 | _alloc (size); |
207 | static uint32_t empty_buf [2] = { 0, 1 }; // 2 == never deallocated |
|
|
208 | data = (char *)empty_buf + overhead; |
|
|
209 | assert (overhead == sizeof (empty_buf)); |
|
|
210 | inc (); |
205 | } |
211 | } |
206 | |
212 | |
207 | refcnt_buf::refcnt_buf (void *data, size_t size) |
213 | refcnt_buf::refcnt_buf (void *data, size_t size) |
208 | { |
214 | { |
209 | _alloc (size); |
215 | _alloc (size); |
… | |
… | |
213 | refcnt_buf::~refcnt_buf () |
219 | refcnt_buf::~refcnt_buf () |
214 | { |
220 | { |
215 | dec (); |
221 | dec (); |
216 | } |
222 | } |
217 | |
223 | |
|
|
224 | void |
|
|
225 | refcnt_buf::_dealloc () |
|
|
226 | { |
|
|
227 | sfree<char> (data - overhead, size () + overhead); |
|
|
228 | } |
|
|
229 | |
218 | refcnt_buf & |
230 | refcnt_buf & |
219 | refcnt_buf::operator =(const refcnt_buf &src) |
231 | refcnt_buf::operator =(const refcnt_buf &src) |
220 | { |
232 | { |
221 | dec (); |
233 | dec (); |
222 | data = src.data; |
234 | data = src.data; |
223 | ++_refcnt (); |
235 | inc (); |
224 | return *this; |
236 | return *this; |
225 | } |
237 | } |
226 | |
238 | |
227 | /******************************************************************************/ |
239 | /******************************************************************************/ |
228 | |
240 | |