/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <ctype.h> /* ask for Annex K for memset_s. will set the appropriate #define
* if Annex K is supported */ #define __STDC_WANT_LIB_EXT1__ 1 #include <string.h> #include <stddef.h> #include <stdlib.h> #include <stdint.h> #include"prtypes.h" #include"prlog.h"/* for PR_ASSERT */ #include"plarena.h" #include"plstr.h"
/* These functions are for use with PORTArenaPools. */ extern PLArenaPool *PORT_NewArena(unsignedlong chunksize); externvoid PORT_FreeArena(PLArenaPool *arena, PRBool zero);
/* These functions are for use with PORTCheapArenaPools. */ externvoid PORT_InitCheapArena(PORTCheapArenaPool *arena, unsignedlong chunksize); externvoid PORT_DestroyCheapArena(PORTCheapArenaPool *arena);
/* These functions work with both kinds of arena pool. */ externvoid *PORT_ArenaAlloc(PLArenaPool *arena, size_t size); externvoid *PORT_ArenaZAlloc(PLArenaPool *arena, size_t size); externvoid *PORT_ArenaGrow(PLArenaPool *arena, void *ptr,
size_t oldsize, size_t newsize); externvoid *PORT_ArenaMark(PLArenaPool *arena); externvoid PORT_ArenaRelease(PLArenaPool *arena, void *mark); externvoid PORT_ArenaZRelease(PLArenaPool *arena, void *mark); externvoid PORT_ArenaUnmark(PLArenaPool *arena, void *mark); externchar *PORT_ArenaStrdup(PLArenaPool *arena, constchar *str);
SEC_END_PROTOS
#define PORT_Assert PR_ASSERT /* This is a variation of PORT_Assert where the arguments will be always *usedeitherinDebugornot.But,inoptimizedmodetheresultwillbe
* ignored. See more details in Bug 1588015. */ #define PORT_AssertArg PR_ASSERT_ARG
/* Assert the current location can't be reached, passing a reason-string. */ #define PORT_AssertNotReached(reasonStr) PR_NOT_REACHED(reasonStr)
/* *Constanttimemacros
*/ /* These macros use the fact that arithmetic shift shifts-in the sign bit. *However,thisisnotensuredbytheCstandardsoyoumayneedtoreplace *themwithsomethingelseforoddcompilers.Thesemacrosworkforobject *sizesupto32bits.Theinequalitieswillproduceincorrectresultsif *abs(a-b)>=PR_UINT32_MAX/2.Thiscanbeavoidedifunsignedvaluesstay *withintherange0-PRUINT32_MAX/2andsignedvaluesstaywithintherange *-PRINT32_MAX/2-PRINT32_MAX/2.Iftheseareinsufficient,wecanfix *thisbyeitherexpandingthePORT_CT_DUPLICATE_MSB_TO_ALLtoPRUint64 *orbycreatingthefollowingnewmacrosforinequality: * *PORT_CT_OVERFLOWpreventstheoverflowconditionbyhandlingthecase *wherethehighbitsinaandbaredifferentspecially.Basicallyif *thehighbitinaandbdifferswecanjust *copythehighbitofoneoftheparameterstodeterminetheresultas *follows: *GxUifahasthehighbiton,a>b,sod=a *LxUifbhasthehighbiton,a<b,sod=b *GxSifbhasthehighbiton,it'snegativea>bsod=b *LxSifahasthehighbiton,it'snegativea<bsod=a *wherePORT_CT_xxU()macrosdounsignedcomparesandPORT_CT_xxS()dosigned *compares. * *#definePORT_CT_OVERFLOW(a,b,c,d)\ *PORT_CT_SEL(PORT_CT_DUPLICATE_MSB_TO_ALL((a)^(b)),\ *(PORT_CT_DUPLICATE_MSB_TO_ALL(d)),c) *#definePORT_CT_GTU(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_GT(a,b),a) *#definePORT_CT_LTU(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_LT(a,b),b) *#definePORT_CT_GEU(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_GE(a,b),a) *#definePORT_CT_LEU(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_LE(a,b),b) *#definePORT_CT_GTS(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_GT(a,b),b) *#definePORT_CT_LTS(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_LT(a,b),a) *#definePORT_CT_GES(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_GE(a,b),b) *#definePORT_CT_LES(a,b)PORT_CT_OVERFLOW(a,b,PORT_CT_LE(a,b),a) * *
* */ /* Constant-time helper macro that copies the MSB of x to all other bits. */ #define PORT_CT_DUPLICATE_MSB_TO_ALL(x) ((PRUint32)((PRInt32)(x) >> (sizeof(PRInt32) * 8- 1)))
/* Constant-time helper macro that selects l or r depending on all-1 or all-0
* mask m */ #define PORT_CT_SEL(m, l, r) (((m) & (l)) | (~(m) & (r)))
/* Constant-time helper macro that returns all-1s if x is not 0; and all-0s
* otherwise. */ #define PORT_CT_NOT_ZERO(x) (PORT_CT_DUPLICATE_MSB_TO_ALL(((x) | (0 - (x)))))
/* Constant-time helper macro that returns all-1s if x is 0; and all-0s
* otherwise. */ #define PORT_CT_ZERO(x) (~PORT_CT_DUPLICATE_MSB_TO_ALL(((x) | (0 - (x)))))
/* Constant-time helper macro for equalities and inequalities.
* returns all-1's for true and all-0's for false */ #define PORT_CT_EQ(a, b) PORT_CT_ZERO(((a) - (b))) #define PORT_CT_NE(a, b) PORT_CT_NOT_ZERO(((a) - (b))) #define PORT_CT_GT(a, b) PORT_CT_DUPLICATE_MSB_TO_ALL((b) - (a)) #define PORT_CT_LT(a, b) PORT_CT_DUPLICATE_MSB_TO_ALL((a) - (b)) #define PORT_CT_GE(a, b) (~PORT_CT_LT(a, b)) #define PORT_CT_LE(a, b) (~PORT_CT_GT(a, b)) #define PORT_CT_TRUE (~0) #define PORT_CT_FALSE 0
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.