Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 44359 invoked from network); 8 Jun 2009 07:43:00 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Jun 2009 07:43:00 -0000 Received: (qmail 64531 invoked by uid 500); 8 Jun 2009 07:43:11 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 64390 invoked by uid 500); 8 Jun 2009 07:43:10 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 64381 invoked by uid 99); 8 Jun 2009 07:43:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 07:43:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jun 2009 07:42:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E899C23888D7; Mon, 8 Jun 2009 07:42:37 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r782550 - in /commons/sandbox/runtime/trunk/src/main/native: Makefile.msc.in include/arch/windows/acr_arch.h os/win32/ios.c os/win32/main.c Date: Mon, 08 Jun 2009 07:42:37 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090608074237.E899C23888D7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Mon Jun 8 07:42:36 2009 New Revision: 782550 URL: http://svn.apache.org/viewvc?rev=782550&view=rev Log: Add handle<->int mapping table, so we can use int descriptor type on all platforms Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=782550&r1=782549&r2=782550&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original) +++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Mon Jun 8 07:42:36 2009 @@ -84,6 +84,7 @@ $(SRCDIR)/os/win32/main.$(OBJ) \ $(SRCDIR)/os/win32/platform.$(OBJ) \ $(SRCDIR)/os/win32/os.$(OBJ) \ + $(SRCDIR)/os/win32/ios.$(OBJ) \ $(SRCDIR)/os/win32/syslog.$(OBJ) \ $(SRCDIR)/os/win32/group.$(OBJ) \ $(SRCDIR)/os/win32/user.$(OBJ) \ Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h?rev=782550&r1=782549&r2=782550&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch.h Mon Jun 8 07:42:36 2009 @@ -274,6 +274,22 @@ size_t iov_len; /* Number of bytes */ }; +typedef struct acr_ioh { + void *h; + int type; + unsigned int flags; +} acr_ioh; + +extern acr_ioh *acr_ioh_tab; +extern int acr_ioh_mask; + +/** Default number of IO slots + */ +#define ACR_IOH_SLOTS (64 * 1024) +#define ACR_IOH_TYPE(H) acr_ioh_tab[(H) & acr_ioh_mask].type +#define ACR_IOH_FLAGS(H) acr_ioh_tab[(H) & acr_ioh_mask].flags +#define ACR_IOH(H) acr_ioh_tab[(H) & acr_ioh_mask].h + /* * --------------------------------------------------------------------- * end of POSIX utilities Added: commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c?rev=782550&view=auto ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c (added) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/ios.c Mon Jun 8 07:42:36 2009 @@ -0,0 +1,210 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "acr.h" +#include "acr_private.h" +#include "acr_arch.h" +#include "acr_error.h" +#include "acr_memory.h" +#include "acr_descriptor.h" +#include "acr_vm.h" + +#define _SET_BIT(a, x) ((void)((a)[(x) >> 3] |= __zero_bit_mask[(x) & 0x07])) +#define _CLR_BIT(a, x) ((void)((a)[(x) >> 3] &= __ones_bit_mask[(x) & 0x07])) + +acr_ioh *acr_ioh_tab; +int acr_ioh_mask; + +static CRITICAL_SECTION ios_lock; +static unsigned char *__bitmap; +static int __ioh_size; +static int __bmp_size; + +static unsigned char __zero_bit_mask[] = { + 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 +}; + +static unsigned char __ones_bit_mask[] = { + 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE +}; + +static unsigned char __sbit_mask[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 0 +}; + +int acr_ioh_init(int size) +{ + if (acr_ioh_tab) + return EEXIST; + InitializeCriticalSection(&ios_lock); + + if (size > 0) { + int i, s; + for (i = 10; i < 27; i++) { + s = 1 << i; + if (s > size) { + __ioh_size = s; + break; + } + } + } + else + __ioh_size = ACR_IOH_SLOTS; + if (!__ioh_size) + return EINVAL; + __bmp_size = __ioh_size / 8; + acr_ioh_mask = __ioh_size - 1; + acr_ioh_tab = (acr_ioh *)calloc(sizeof(acr_ioh), __ioh_size); + if (acr_ioh_tab) { + acr_ioh_tab[acr_ioh_mask].h = INVALID_HANDLE_VALUE; + /* XXX: Allocate slots 0, 1 and 2 for stdio? + */ + } + else + return errno; + __bitmap = (unsigned char *)calloc(1, __bmp_size); + if (!__bitmap) { + int rv = errno; + free(acr_ioh_tab); + acr_ioh_tab = NULL; + return rv; + } + return 0; +} + +static int ioh_extend() +{ + int ns; + int nb; + acr_ioh *io; + unsigned char *bm; + if (!acr_ioh_tab) + return EBADF; + + ns = __ioh_size * 2; + /* Hardcode the maximum to 1M + */ + if (ns > (1024 * 1024)) { + return ERANGE; + } + nb = ns / 8; + io = (acr_ioh *)calloc(sizeof(acr_ioh), ns); + if (io) { + memcpy(io, acr_ioh_tab, sizeof(acr_ioh) * acr_ioh_mask); + free(acr_ioh_tab); + acr_ioh_tab = io; + __ioh_size = ns; + acr_ioh_mask = ns - 1; + acr_ioh_tab[acr_ioh_mask].h = INVALID_HANDLE_VALUE; + + } + else + return errno; + bm = (unsigned char *)calloc(1, nb); + if (!bm) { + return errno; + } + memcpy(bm, __bitmap, __bmp_size); + free(__bitmap); + __bitmap = bm; + __bmp_size = nb; + + return 0; +} + +int acr_ioh_alloc(void *h, int type, unsigned int flags) +{ + int i, x; + + EnterCriticalSection(&ios_lock); + + for (i = 0; i < __bmp_size; i++) { + if (__bitmap[i] != 0xFF) { + x = (i << 3) + __sbit_mask[__bitmap[i]]; + acr_ioh_tab[x].h = h; + acr_ioh_tab[x].type = type; + acr_ioh_tab[x].flags = flags; + _SET_BIT(__bitmap, x); + LeaveCriticalSection(&ios_lock); + return x; + } + } + if ((errno = ioh_extend())) { + LeaveCriticalSection(&ios_lock); + return -1; + } + for (; i < __bmp_size; i++) { + if (__bitmap[i] != 0xFF) { + x = (i << 3) + __sbit_mask[__bitmap[i]]; + acr_ioh_tab[x].h = h; + acr_ioh_tab[x].type = type; + acr_ioh_tab[x].flags = flags; + _SET_BIT(__bitmap, x); + LeaveCriticalSection(&ios_lock); + return x; + } + } + LeaveCriticalSection(&ios_lock); + errno = ENOSPC; + return -1; +} + +int acr_ioh_free(int i) +{ + if (i < 0 || i >= acr_ioh_mask) + return EINVAL; + + EnterCriticalSection(&ios_lock); + memset(&acr_ioh_tab[i], 0, sizeof(acr_ioh)); + _CLR_BIT(__bitmap, i); + LeaveCriticalSection(&ios_lock); + + return 0; +} + +void acr_ioh_cleanup() +{ + int i; + + EnterCriticalSection(&ios_lock); + for (i = 0; i < acr_ioh_mask; i++) { + if (acr_ioh_tab[i].h) { + /* TODO: Run the cleanup */ + + } + } + free(acr_ioh_tab); + free(__bitmap); + __bitmap = NULL; + acr_ioh_tab = NULL; + DeleteCriticalSection(&ios_lock); + +} Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c?rev=782550&r1=782549&r2=782550&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/os/win32/main.c Mon Jun 8 07:42:36 2009 @@ -16,7 +16,6 @@ #include "acr.h" #include "acr_private.h" -#include "acr_arch.h" #include "acr_error.h" #include "acr_vm.h"