blob: 2f2ddc1c07eeec1793c5e01f7bdc7ff2cb5b87da [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Shuzhen Wangc502c872014-01-28 16:10:42 -08003 * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <limits.h>
19#include <errno.h>
20#include <pthread.h>
21#include <unistd.h>
22#include <string.h>
23#include <stdarg.h>
24
25#include <sys/mman.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <sys/ioctl.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070029
30#include <cutils/log.h>
31#include <cutils/atomic.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070032
33#include <hardware/hardware.h>
34#include <hardware/gralloc.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070035
36#include "gralloc_priv.h"
37#include "gr.h"
38#include "alloc_controller.h"
39#include "memalloc.h"
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080040#include <qdMetaData.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070041
42using namespace gralloc;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070043/*****************************************************************************/
44
45// Return the type of allocator -
46// these are used for mapping/unmapping
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070047static IMemAlloc* getAllocator(int flags)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070048{
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070049 IMemAlloc* memalloc;
50 IAllocController* alloc_ctrl = IAllocController::getInstance();
Iliyan Malchev202a77d2012-06-11 14:41:12 -070051 memalloc = alloc_ctrl->getAllocator(flags);
52 return memalloc;
53}
54
55static int gralloc_map(gralloc_module_t const* module,
Naseer Ahmed34d33bc2013-05-08 12:28:37 -040056 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070057{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080058 if(!module)
59 return -EINVAL;
60
Iliyan Malchev202a77d2012-06-11 14:41:12 -070061 private_handle_t* hnd = (private_handle_t*)handle;
62 void *mappedAddress;
63 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) &&
64 !(hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER)) {
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070065 unsigned int size = hnd->size;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -070066 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070067 int err = memalloc->map_buffer(&mappedAddress, size,
Naseer Ahmed29a26812012-06-14 00:56:20 -070068 hnd->offset, hnd->fd);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080069 if(err || mappedAddress == MAP_FAILED) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070070 ALOGE("Could not mmap handle %p, fd=%d (%s)",
Naseer Ahmed29a26812012-06-14 00:56:20 -070071 handle, hnd->fd, strerror(errno));
Iliyan Malchev202a77d2012-06-11 14:41:12 -070072 hnd->base = 0;
73 return -errno;
74 }
75
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070076 hnd->base = uint64_t(mappedAddress) + hnd->offset;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -080077 mappedAddress = MAP_FAILED;
78 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
79 err = memalloc->map_buffer(&mappedAddress, size,
80 hnd->offset_metadata, hnd->fd_metadata);
81 if(err || mappedAddress == MAP_FAILED) {
82 ALOGE("Could not mmap handle %p, fd=%d (%s)",
83 handle, hnd->fd_metadata, strerror(errno));
84 hnd->base_metadata = 0;
85 return -errno;
86 }
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070087 hnd->base_metadata = uint64_t(mappedAddress) + hnd->offset_metadata;
Iliyan Malchev202a77d2012-06-11 14:41:12 -070088 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070089 return 0;
90}
91
92static int gralloc_unmap(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -070093 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -070094{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080095 if(!module)
96 return -EINVAL;
97
Iliyan Malchev202a77d2012-06-11 14:41:12 -070098 private_handle_t* hnd = (private_handle_t*)handle;
99 if (!(hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)) {
100 int err = -EINVAL;
101 void* base = (void*)hnd->base;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700102 unsigned int size = hnd->size;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700103 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800104 if(memalloc != NULL) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700105 err = memalloc->unmap_buffer(base, size, hnd->offset);
Ramkumar Radhakrishnan47573e22012-11-07 11:36:41 -0800106 if (err) {
107 ALOGE("Could not unmap memory at address %p", base);
108 }
109 base = (void*)hnd->base_metadata;
110 size = ROUND_UP_PAGESIZE(sizeof(MetaData_t));
111 err = memalloc->unmap_buffer(base, size, hnd->offset_metadata);
112 if (err) {
113 ALOGE("Could not unmap memory at address %p", base);
114 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700115 }
116 }
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800117 /* need to initialize the pointer to NULL otherwise unmapping for that
118 * buffer happens twice which leads to crash */
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700119 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800120 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700121 return 0;
122}
123
124/*****************************************************************************/
125
126static pthread_mutex_t sMapLock = PTHREAD_MUTEX_INITIALIZER;
127
128/*****************************************************************************/
129
130int gralloc_register_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700131 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700132{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800133 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700134 return -EINVAL;
135
136 // In this implementation, we don't need to do anything here
137
138 /* NOTE: we need to initialize the buffer as not mapped/not locked
139 * because it shouldn't when this function is called the first time
140 * in a new process. Ideally these flags shouldn't be part of the
141 * handle, but instead maintained in the kernel or at least
142 * out-of-line
143 */
144
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700145 private_handle_t* hnd = (private_handle_t*)handle;
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700146 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800147 hnd->base_metadata = 0;
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400148 int err = gralloc_map(module, handle);
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700149 if (err) {
150 ALOGE("%s: gralloc_map failed", __FUNCTION__);
151 return err;
152 }
153
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700154 return 0;
155}
156
157int gralloc_unregister_buffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700158 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700159{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800160 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700161 return -EINVAL;
162
163 /*
164 * If the buffer has been mapped during a lock operation, it's time
165 * to un-map it. It's an error to be here with a locked buffer.
166 * NOTE: the framebuffer is handled differently and is never unmapped.
167 */
168
169 private_handle_t* hnd = (private_handle_t*)handle;
170
Kinjal Bhavsar139e1622012-09-10 12:35:11 -0700171 if (hnd->base != 0) {
172 gralloc_unmap(module, handle);
173 }
174 hnd->base = 0;
Ramkumar Radhakrishnan7bf31c32013-01-28 22:51:51 -0800175 hnd->base_metadata = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700176 return 0;
177}
178
179int terminateBuffer(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700180 private_handle_t* hnd)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700181{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800182 if(!module)
183 return -EINVAL;
184
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700185 /*
186 * If the buffer has been mapped during a lock operation, it's time
187 * to un-map it. It's an error to be here with a locked buffer.
188 */
189
190 if (hnd->base != 0) {
191 // this buffer was mapped, unmap it now
192 if (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_PMEM |
193 private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP |
194 private_handle_t::PRIV_FLAGS_USES_ASHMEM |
195 private_handle_t::PRIV_FLAGS_USES_ION)) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700196 gralloc_unmap(module, hnd);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700197 } else {
Naseer Ahmed29a26812012-06-14 00:56:20 -0700198 ALOGE("terminateBuffer: unmapping a non pmem/ashmem buffer flags = 0x%x",
199 hnd->flags);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700200 gralloc_unmap(module, hnd);
201 }
202 }
203
204 return 0;
205}
206
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400207static int gralloc_map_and_invalidate (gralloc_module_t const* module,
208 buffer_handle_t handle, int usage)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700209{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800210 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700211 return -EINVAL;
212
213 int err = 0;
214 private_handle_t* hnd = (private_handle_t*)handle;
215 if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK)) {
216 if (hnd->base == 0) {
217 // we need to map for real
218 pthread_mutex_t* const lock = &sMapLock;
219 pthread_mutex_lock(lock);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400220 err = gralloc_map(module, handle);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700221 pthread_mutex_unlock(lock);
222 }
Naseer Ahmedec147982013-06-14 17:06:46 -0400223 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
224 //Invalidate if reading in software. No need to do this for the
225 //metadata buffer as it is only read/written in software.
226 IMemAlloc* memalloc = getAllocator(hnd->flags) ;
227 err = memalloc->clean_buffer((void*)hnd->base,
228 hnd->size, hnd->offset, hnd->fd,
229 CACHE_INVALIDATE);
230 if (usage & GRALLOC_USAGE_SW_WRITE_MASK) {
231 // Mark the buffer to be flushed after cpu read/write
232 hnd->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
233 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700234 }
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400235 } else {
236 hnd->flags |= private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700237 }
238 return err;
239}
240
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400241int gralloc_lock(gralloc_module_t const* module,
242 buffer_handle_t handle, int usage,
243 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
244 void** vaddr)
245{
246 private_handle_t* hnd = (private_handle_t*)handle;
247 int err = gralloc_map_and_invalidate(module, handle, usage);
248 if(!err)
249 *vaddr = (void*)hnd->base;
250 return err;
251}
252
253int gralloc_lock_ycbcr(gralloc_module_t const* module,
254 buffer_handle_t handle, int usage,
255 int /*l*/, int /*t*/, int /*w*/, int /*h*/,
256 struct android_ycbcr *ycbcr)
257{
258 private_handle_t* hnd = (private_handle_t*)handle;
259 int err = gralloc_map_and_invalidate(module, handle, usage);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400260 if(!err)
261 err = getYUVPlaneInfo(hnd, ycbcr);
Naseer Ahmed34d33bc2013-05-08 12:28:37 -0400262 return err;
263}
264
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700265int gralloc_unlock(gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700266 buffer_handle_t handle)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700267{
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800268 if (!module || private_handle_t::validate(handle) < 0)
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700269 return -EINVAL;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800270
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400271 int err = 0;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700272 private_handle_t* hnd = (private_handle_t*)handle;
273
Naseer Ahmedec147982013-06-14 17:06:46 -0400274 if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) {
Naseer Ahmed69662ac2013-08-28 13:16:48 -0400275 IMemAlloc* memalloc = getAllocator(hnd->flags);
Naseer Ahmedec147982013-06-14 17:06:46 -0400276 if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) {
277 err = memalloc->clean_buffer((void*)hnd->base,
278 hnd->size, hnd->offset, hnd->fd,
279 CACHE_CLEAN_AND_INVALIDATE);
280 hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH;
281 } else if(hnd->flags & private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH) {
282 hnd->flags &= ~private_handle_t::PRIV_FLAGS_DO_NOT_FLUSH;
283 } else {
284 //Probably a round about way to do this, but this avoids adding new
285 //flags
286 err = memalloc->clean_buffer((void*)hnd->base,
287 hnd->size, hnd->offset, hnd->fd,
288 CACHE_INVALIDATE);
289 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700290 }
291
Naseer Ahmedaeab91f2013-03-20 21:01:19 -0400292 return err;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700293}
294
295/*****************************************************************************/
296
297int gralloc_perform(struct gralloc_module_t const* module,
Naseer Ahmed29a26812012-06-14 00:56:20 -0700298 int operation, ... )
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700299{
300 int res = -EINVAL;
301 va_list args;
Arun Kumar K.R6c85f052014-01-21 21:47:41 -0800302 if(!module)
303 return res;
304
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700305 va_start(args, operation);
306 switch (operation) {
307 case GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER:
308 {
309 int fd = va_arg(args, int);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700310 unsigned int size = va_arg(args, unsigned int);
311 unsigned int offset = va_arg(args, unsigned int);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700312 void* base = va_arg(args, void*);
313 int width = va_arg(args, int);
314 int height = va_arg(args, int);
315 int format = va_arg(args, int);
316
317 native_handle_t** handle = va_arg(args, native_handle_t**);
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700318 private_handle_t* hnd = (private_handle_t*)native_handle_create(
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700319 private_handle_t::sNumFds, private_handle_t::sNumInts());
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700320 hnd->magic = private_handle_t::sMagic;
321 hnd->fd = fd;
Naseer Ahmed01d3fd32012-07-14 21:08:13 -0700322 hnd->flags = private_handle_t::PRIV_FLAGS_USES_ION;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700323 hnd->size = size;
324 hnd->offset = offset;
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -0700325 hnd->base = uint64_t(base) + offset;
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700326 hnd->gpuaddr = 0;
327 hnd->width = width;
328 hnd->height = height;
329 hnd->format = format;
330 *handle = (native_handle_t *)hnd;
331 res = 0;
332 break;
333
334 }
Naomi Luisa44100c2013-02-08 12:42:03 -0800335 case GRALLOC_MODULE_PERFORM_GET_STRIDE:
336 {
337 int width = va_arg(args, int);
338 int format = va_arg(args, int);
339 int *stride = va_arg(args, int *);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800340 int alignedw = 0, alignedh = 0;
341 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700342 0, format, false, alignedw, alignedh);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800343 *stride = alignedw;
Naomi Luisa44100c2013-02-08 12:42:03 -0800344 res = 0;
345 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700346
Naseer Ahmeda978f952013-09-26 14:36:28 -0400347 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE:
348 {
349 private_handle_t* hnd = va_arg(args, private_handle_t*);
350 int *stride = va_arg(args, int *);
351 if (private_handle_t::validate(hnd)) {
352 return res;
353 }
354 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
355 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
356 *stride = metadata->bufferDim.sliceWidth;
357 } else {
358 *stride = hnd->width;
359 }
360 res = 0;
361 } break;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700362
Raj Kamal3d01d8d2014-03-04 05:25:33 +0530363 case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE:
364 {
365 private_handle_t* hnd = va_arg(args, private_handle_t*);
366 int *stride = va_arg(args, int *);
367 int *height = va_arg(args, int *);
368 if (private_handle_t::validate(hnd)) {
369 return res;
370 }
371 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
372 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
373 *stride = metadata->bufferDim.sliceWidth;
374 *height = metadata->bufferDim.sliceHeight;
375 } else {
376 *stride = hnd->width;
377 *height = hnd->height;
378 }
379 res = 0;
380 } break;
381
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700382 case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES:
383 {
384 int width = va_arg(args, int);
385 int height = va_arg(args, int);
386 int format = va_arg(args, int);
387 int usage = va_arg(args, int);
388 int *alignedWidth = va_arg(args, int *);
389 int *alignedHeight = va_arg(args, int *);
390 int *tileEnabled = va_arg(args,int *);
391 *tileEnabled = isMacroTileEnabled(format, usage);
392 AdrenoMemInfo::getInstance().getAlignedWidthAndHeight(width,
393 height, format, *tileEnabled, *alignedWidth,
394 *alignedHeight);
395 res = 0;
396 } break;
397
Shuzhen Wangc502c872014-01-28 16:10:42 -0800398 case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE:
399 {
400 private_handle_t* hnd = va_arg(args, private_handle_t*);
401 int *color_space = va_arg(args, int *);
402 if (private_handle_t::validate(hnd)) {
403 return res;
404 }
405 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
406 if(metadata && metadata->operation & UPDATE_COLOR_SPACE) {
407 *color_space = metadata->colorSpace;
408 res = 0;
409 }
410 } break;
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400411 case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO:
412 {
413 private_handle_t* hnd = va_arg(args, private_handle_t*);
414 android_ycbcr* ycbcr = va_arg(args, struct android_ycbcr *);
Naseer Ahmedf5ff33a2014-04-30 15:30:39 -0400415 if (!private_handle_t::validate(hnd)) {
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -0400416 res = getYUVPlaneInfo(hnd, ycbcr);
417 }
418 } break;
419
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700420 default:
421 break;
422 }
423 va_end(args);
424 return res;
425}