Changes in / [73a3be5:98168b9]
- Files:
-
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/main.cfa
r73a3be5 r98168b9 75 75 address.sin_port = htons( options.socket.port ); 76 76 77 int waited = 0; 78 for() { 79 ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) ); 80 if(ret < 0) { 81 if(errno == 98) { 82 if(waited == 0) { 83 printf("Waiting for port\n"); 84 } else { 85 printf("\r%d", waited); 86 fflush(stdout); 87 } 88 waited ++; 89 sleep( 1`s ); 90 continue; 91 } 92 abort( "bind error: (%d) %s\n", (int)errno, strerror(errno) ); 93 } 94 break; 77 ret = bind( server_fd, (struct sockaddr *)&address, sizeof(address) ); 78 if(ret < 0) { 79 abort( "bind error: (%d) %s\n", (int)errno, strerror(errno) ); 95 80 } 96 81 -
libcfa/src/concurrency/coroutine.cfa
r73a3be5 r98168b9 28 28 #include "kernel_private.hfa" 29 29 #include "exception.hfa" 30 #include "math.hfa"31 30 32 31 #define __CFA_INVOKE_PRIVATE__ … … 88 87 89 88 void __stack_prepare( __stack_info_t * this, size_t create_size ); 90 void __stack_clean ( __stack_info_t * this );91 89 92 90 //----------------------------------------------------------------------------- … … 109 107 bool userStack = ((intptr_t)this.storage & 0x1) != 0; 110 108 if ( ! userStack && this.storage ) { 111 __stack_clean( &this ); 112 // __attribute__((may_alias)) intptr_t * istorage = (intptr_t *)&this.storage; 113 // *istorage &= (intptr_t)-1; 114 115 // void * storage = this.storage->limit; 116 // __cfaabi_dbg_debug_do( 117 // storage = (char*)(storage) - __page_size; 118 // if ( mprotect( storage, __page_size, PROT_READ | PROT_WRITE ) == -1 ) { 119 // abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 120 // } 121 // ); 122 // __cfaabi_dbg_print_safe("Kernel : Deleting stack %p\n", storage); 123 // free( storage ); 109 __attribute__((may_alias)) intptr_t * istorage = (intptr_t *)&this.storage; 110 *istorage &= (intptr_t)-1; 111 112 void * storage = this.storage->limit; 113 __cfaabi_dbg_debug_do( 114 storage = (char*)(storage) - __page_size; 115 if ( mprotect( storage, __page_size, PROT_READ | PROT_WRITE ) == -1 ) { 116 abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) ); 117 } 118 ); 119 __cfaabi_dbg_print_safe("Kernel : Deleting stack %p\n", storage); 120 free( storage ); 124 121 } 125 122 } … … 170 167 assert(__page_size != 0l); 171 168 size_t size = libCeiling( storageSize, 16 ) + stack_data_size; 172 size = ceiling(size, __page_size);173 169 174 170 // If we are running debug, we also need to allocate a guardpage to catch stack overflows. 175 171 void * storage; 176 // __cfaabi_dbg_debug_do( 177 // storage = memalign( __page_size, size + __page_size ); 178 // ); 179 // __cfaabi_dbg_no_debug_do( 180 // storage = (void*)malloc(size); 181 // ); 182 183 // __cfaabi_dbg_print_safe("Kernel : Created stack %p of size %zu\n", storage, size); 184 // __cfaabi_dbg_debug_do( 185 // if ( mprotect( storage, __page_size, PROT_NONE ) == -1 ) { 186 // abort( "__stack_alloc : internal error, mprotect failure, error(%d) %s.", (int)errno, strerror( (int)errno ) ); 187 // } 188 // storage = (void *)(((intptr_t)storage) + __page_size); 189 // ); 190 storage = mmap(0p, size + __page_size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 191 if(storage == ((void*)-1)) { 192 abort( "coroutine stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) ); 193 } 194 if ( mprotect( storage, __page_size, PROT_NONE ) == -1 ) { 195 abort( "coroutine stack creation : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) ); 196 } // if 197 storage = (void *)(((intptr_t)storage) + __page_size); 172 __cfaabi_dbg_debug_do( 173 storage = memalign( __page_size, size + __page_size ); 174 ); 175 __cfaabi_dbg_no_debug_do( 176 storage = (void*)malloc(size); 177 ); 178 179 __cfaabi_dbg_print_safe("Kernel : Created stack %p of size %zu\n", storage, size); 180 __cfaabi_dbg_debug_do( 181 if ( mprotect( storage, __page_size, PROT_NONE ) == -1 ) { 182 abort( "__stack_alloc : internal error, mprotect failure, error(%d) %s.", (int)errno, strerror( (int)errno ) ); 183 } 184 storage = (void *)(((intptr_t)storage) + __page_size); 185 ); 198 186 199 187 verify( ((intptr_t)storage & (libAlign() - 1)) == 0ul ); 200 188 return [storage, size]; 201 }202 203 void __stack_clean ( __stack_info_t * this ) {204 size_t size = ((intptr_t)this->storage->base) - ((intptr_t)this->storage->limit) + sizeof(__stack_t);205 void * storage = this->storage->limit;206 207 storage = (void *)(((intptr_t)storage) - __page_size);208 if(munmap(storage, size + __page_size) == -1) {209 abort( "coroutine stack destruction : internal error, munmap failure, error(%d) %s.", errno, strerror( errno ) );210 }211 189 } 212 190 … … 232 210 assertf( size >= MinStackSize, "Stack size %zd provides less than minimum of %zd bytes for a stack.", size, MinStackSize ); 233 211 234 this->storage = (__stack_t *)((intptr_t)storage + size - sizeof(__stack_t));212 this->storage = (__stack_t *)((intptr_t)storage + size); 235 213 this->storage->limit = storage; 236 this->storage->base = (void*)((intptr_t)storage + size - sizeof(__stack_t));214 this->storage->base = (void*)((intptr_t)storage + size); 237 215 this->storage->exception_context.top_resume = 0p; 238 216 this->storage->exception_context.current_exception = 0p; -
libcfa/src/concurrency/coroutine.hfa
r73a3be5 r98168b9 102 102 } 103 103 104 extern void __stack_prepare( __stack_info_t * this, size_t size /* ignored if storage already allocated */); 105 extern void __stack_clean ( __stack_info_t * this ); 106 104 extern void __stack_prepare ( __stack_info_t * this, size_t size /* ignored if storage already allocated */); 107 105 108 106 // Suspend implementation inlined for performance -
libcfa/src/concurrency/io/setup.cfa
r73a3be5 r98168b9 17 17 #define _GNU_SOURCE /* See feature_test_macros(7) */ 18 18 19 #if defined(__CFA_DEBUG__)20 // #define __CFA_DEBUG_PRINT_IO__21 // #define __CFA_DEBUG_PRINT_IO_CORE__22 #endif23 24 19 #include "io/types.hfa" 25 20 #include "kernel.hfa" … … 116 111 117 112 void __kernel_io_startup(void) { 118 __cfa dbg_print_safe(io_core,"Kernel : Creating EPOLL instance\n" );113 __cfaabi_dbg_print_safe( "Kernel : Creating EPOLL instance\n" ); 119 114 120 115 iopoll.epollfd = epoll_create1(0); … … 123 118 } 124 119 125 __cfa dbg_print_safe(io_core,"Kernel : Starting io poller thread\n" );120 __cfaabi_dbg_print_safe( "Kernel : Starting io poller thread\n" ); 126 121 127 122 iopoll.run = true; … … 137 132 // Wait for the io poller thread to finish 138 133 139 __destroy_pthread( iopoll.thrd, iopoll.stack, 0p ); 134 pthread_join( iopoll.thrd, 0p ); 135 free( iopoll.stack ); 140 136 141 137 int ret = close(iopoll.epollfd); … … 146 142 // Io polling is now fully stopped 147 143 148 __cfa dbg_print_safe(io_core,"Kernel : IO poller stopped\n" );144 __cfaabi_dbg_print_safe( "Kernel : IO poller stopped\n" ); 149 145 } 150 146 … … 154 150 id.id = doregister(&id); 155 151 __cfaabi_tls.this_proc_id = &id; 156 __cfa dbg_print_safe(io_core,"Kernel : IO poller thread starting\n" );152 __cfaabi_dbg_print_safe( "Kernel : IO poller thread starting\n" ); 157 153 158 154 // Block signals to control when they arrive … … 189 185 } 190 186 191 __cfa dbg_print_safe(io_core,"Kernel : IO poller thread stopping\n" );187 __cfaabi_dbg_print_safe( "Kernel : IO poller thread stopping\n" ); 192 188 unregister(&id); 193 189 return 0p; -
libcfa/src/concurrency/kernel/startup.cfa
r73a3be5 r98168b9 29 29 #include "kernel_private.hfa" 30 30 #include "startup.hfa" // STARTUP_PRIORITY_XXX 31 #include "math.hfa"32 31 33 32 //----------------------------------------------------------------------------- … … 540 539 } 541 540 542 extern size_t __page_size;543 541 void ^?{}(processor & this) with( this ){ 544 542 if( ! __atomic_load_n(&do_terminate, __ATOMIC_ACQUIRE) ) { … … 552 550 } 553 551 554 __destroy_pthread( kernel_thread, this.stack, 0p ); 552 int err = pthread_join( kernel_thread, 0p ); 553 if( err != 0 ) abort("KERNEL ERROR: joining processor %p caused error %s\n", &this, strerror(err)); 554 555 free( this.stack ); 555 556 556 557 disable_interrupts(); … … 677 678 678 679 void * stack; 679 #warning due to the thunk problem, stack creation uses mmap, revert to malloc once this goes away 680 // __cfaabi_dbg_debug_do( 681 // stack = memalign( __page_size, stacksize + __page_size ); 682 // // pthread has no mechanism to create the guard page in user supplied stack. 683 // if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) { 684 // abort( "mprotect : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) ); 685 // } // if 686 // ); 687 // __cfaabi_dbg_no_debug_do( 688 // stack = malloc( stacksize ); 689 // ); 690 stacksize = ceiling( stacksize, __page_size ) + __page_size; 691 stack = mmap(0p, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); 692 if(stack == ((void*)-1)) { 693 abort( "pthread stack creation : internal error, mmap failure, error(%d) %s.", errno, strerror( errno ) ); 694 } 695 if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) { 696 abort( "pthread stack creation : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) ); 697 } // if 680 __cfaabi_dbg_debug_do( 681 stack = memalign( __page_size, stacksize + __page_size ); 682 // pthread has no mechanism to create the guard page in user supplied stack. 683 if ( mprotect( stack, __page_size, PROT_NONE ) == -1 ) { 684 abort( "mprotect : internal error, mprotect failure, error(%d) %s.", errno, strerror( errno ) ); 685 } // if 686 ); 687 __cfaabi_dbg_no_debug_do( 688 stack = malloc( stacksize ); 689 ); 698 690 699 691 check( pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" ); … … 702 694 return stack; 703 695 } 704 705 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) {706 int err = pthread_join( pthread, retval );707 if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err));708 709 pthread_attr_t attr;710 711 check( pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute712 713 size_t stacksize;714 // default stack size, normally defined by shell limit715 check( pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );716 assert( stacksize >= PTHREAD_STACK_MIN );717 stacksize += __page_size;718 719 if(munmap(stack, stacksize) == -1) {720 abort( "pthread stack destruction : internal error, munmap failure, error(%d) %s.", errno, strerror( errno ) );721 }722 }723 724 696 725 697 #if defined(__CFA_WITH_VERIFY__) -
libcfa/src/concurrency/kernel_private.hfa
r73a3be5 r98168b9 49 49 50 50 void * __create_pthread( pthread_t *, void * (*)(void *), void * ); 51 void __destroy_pthread( pthread_t pthread, void * stack, void ** retval );52 51 53 52 -
libcfa/src/concurrency/preemption.cfa
r73a3be5 r98168b9 575 575 // Wait for the preemption thread to finish 576 576 577 __destroy_pthread( alarm_thread, alarm_stack, 0p ); 577 pthread_join( alarm_thread, 0p ); 578 free( alarm_stack ); 578 579 579 580 // Preemption is now fully stopped -
libcfa/src/heap.cfa
r73a3be5 r98168b9 10 10 // Created On : Tue Dec 19 21:58:35 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 11 07:36:34202013 // Update Count : 9 7012 // Last Modified On : Mon Sep 7 22:17:46 2020 13 // Update Count : 957 14 14 // 15 15 … … 464 464 } // headers 465 465 466 #ifdef __CFA_DEBUG__467 #if __SIZEOF_POINTER__ == 4468 #define MASK 0xdeadbeef469 #else470 #define MASK 0xdeadbeefdeadbeef471 #endif472 #define STRIDE size_t473 474 static void * Memset( void * addr, STRIDE size ) { // debug only475 if ( size % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, size %zd not multiple of %zd.", size, sizeof(STRIDE) );476 if ( (STRIDE)addr % sizeof(STRIDE) != 0 ) abort( "Memset() : internal error, addr %p not multiple of %zd.", addr, sizeof(STRIDE) );477 478 STRIDE * end = (STRIDE *)addr + size / sizeof(STRIDE);479 for ( STRIDE * p = (STRIDE *)addr; p < end; p += 1 ) *p = MASK;480 return addr;481 } // Memset482 #endif // __CFA_DEBUG__483 484 466 #define NO_MEMORY_MSG "insufficient heap memory available for allocating %zd new bytes." 485 467 … … 501 483 #ifdef __CFA_DEBUG__ 502 484 // Set new memory to garbage so subsequent uninitialized usages might fail. 503 //memset( (char *)heapEnd + heapRemaining, '\377', increase ); 504 Memset( (char *)heapEnd + heapRemaining, increase ); 485 memset( (char *)heapEnd + heapRemaining, '\377', increase ); 505 486 #endif // __CFA_DEBUG__ 506 487 rem = heapRemaining + increase - size; … … 576 557 #ifdef __CFA_DEBUG__ 577 558 // Set new memory to garbage so subsequent uninitialized usages might fail. 578 //memset( block, '\377', tsize ); 579 Memset( block, tsize ); 559 memset( block, '\377', tsize ); 580 560 #endif // __CFA_DEBUG__ 581 561 block->header.kind.real.blockSize = tsize; // storage size for munmap … … 626 606 #ifdef __CFA_DEBUG__ 627 607 // Set free memory to garbage so subsequent usages might fail. 628 //memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) ); 629 Memset( ((HeapManager.Storage *)header)->data, freeElem->blockSize - sizeof( HeapManager.Storage ) ); 608 memset( ((HeapManager.Storage *)header)->data, '\377', freeElem->blockSize - sizeof( HeapManager.Storage ) ); 630 609 #endif // __CFA_DEBUG__ 631 610 … … 956 935 header->kind.real.size = size; // reset allocation size 957 936 if ( unlikely( ozfill ) && size > osize ) { // previous request zero fill and larger ? 958 memset( (char *)oaddr + osize, '\0', size - osize ); // initialize added storage937 memset( (char *)oaddr + osize, (int)'\0', size - osize ); // initialize added storage 959 938 } // if 960 939 return oaddr; … … 981 960 header->kind.real.blockSize |= 2; // mark new request as zero filled 982 961 if ( size > osize ) { // previous request larger ? 983 memset( (char *)naddr + osize, '\0', size - osize ); // initialize added storage962 memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage 984 963 } // if 985 964 } // if … … 1348 1327 header->kind.real.blockSize |= 2; // mark new request as zero filled 1349 1328 if ( size > osize ) { // previous request larger ? 1350 memset( (char *)naddr + osize, '\0', size - osize ); // initialize added storage1329 memset( (char *)naddr + osize, (int)'\0', size - osize ); // initialize added storage 1351 1330 } // if 1352 1331 } // if -
src/AST/Convert.cpp
r73a3be5 r98168b9 233 233 const ast::Decl * namedTypePostamble( NamedTypeDecl * decl, const ast::NamedTypeDecl * node ) { 234 234 // base comes from constructor 235 decl->parameters = get<TypeDecl>().acceptL( node->params ); 235 236 decl->assertions = get<DeclarationWithType>().acceptL( node->assertions ); 236 237 declPostamble( decl, node ); … … 1703 1704 cache.emplace( old, decl ); 1704 1705 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1706 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1705 1707 decl->extension = old->extension; 1706 1708 decl->uniqueId = old->uniqueId; … … 1718 1720 ); 1719 1721 decl->assertions = GET_ACCEPT_V(assertions, DeclWithType); 1722 decl->params = GET_ACCEPT_V(parameters, TypeDecl); 1720 1723 decl->extension = old->extension; 1721 1724 decl->uniqueId = old->uniqueId; -
src/AST/Decl.hpp
r73a3be5 r98168b9 154 154 public: 155 155 ptr<Type> base; 156 std::vector<ptr<TypeDecl>> params; 156 157 std::vector<ptr<DeclWithType>> assertions; 157 158 … … 159 160 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 160 161 const Type * b, Linkage::Spec spec = Linkage::Cforall ) 161 : Decl( loc, name, storage, spec ), base( b ), assertions() {}162 : Decl( loc, name, storage, spec ), base( b ), params(), assertions() {} 162 163 163 164 /// Produces a name for the kind of alias -
src/AST/Pass.impl.hpp
r73a3be5 r98168b9 609 609 VISIT({ 610 610 guard_symtab guard { *this }; 611 maybe_accept( node, &TypeDecl::params ); 611 612 maybe_accept( node, &TypeDecl::base ); 612 613 }) … … 637 638 VISIT({ 638 639 guard_symtab guard { *this }; 640 maybe_accept( node, &TypedefDecl::params ); 639 641 maybe_accept( node, &TypedefDecl::base ); 640 642 }) -
src/AST/Print.cpp
r73a3be5 r98168b9 221 221 ++indent; 222 222 node->base->accept( *this ); 223 --indent; 224 } 225 226 if ( ! node->params.empty() ) { 227 os << endl << indent << "... with parameters" << endl; 228 ++indent; 229 printAll( node->params ); 223 230 --indent; 224 231 } -
src/Common/PassVisitor.impl.h
r73a3be5 r98168b9 835 835 { 836 836 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 837 maybeAccept_impl( node->parameters, *this ); 837 838 maybeAccept_impl( node->base , *this ); 838 839 } … … 857 858 { 858 859 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 860 maybeAccept_impl( node->parameters, *this ); 859 861 maybeAccept_impl( node->base , *this ); 860 862 } … … 878 880 { 879 881 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 882 maybeMutate_impl( node->parameters, *this ); 880 883 maybeMutate_impl( node->base , *this ); 881 884 } … … 901 904 { 902 905 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 906 maybeAccept_impl( node->parameters, *this ); 903 907 maybeAccept_impl( node->base , *this ); 904 908 } … … 917 921 { 918 922 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 923 maybeAccept_impl( node->parameters, *this ); 919 924 maybeAccept_impl( node->base , *this ); 920 925 } … … 933 938 { 934 939 auto guard = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 940 maybeMutate_impl( node->parameters, *this ); 935 941 maybeMutate_impl( node->base , *this ); 936 942 } -
src/Parser/TypeData.cc
r73a3be5 r98168b9 900 900 ret = new TypeDecl( name, scs, typebuild( td->base ), TypeDecl::Dtype, true ); 901 901 } // if 902 buildList( td->symbolic.params, ret->get_parameters() ); 902 903 buildList( td->symbolic.assertions, ret->get_assertions() ); 903 904 ret->base->attributes.splice( ret->base->attributes.end(), attributes ); -
src/SynTree/Declaration.h
r73a3be5 r98168b9 181 181 public: 182 182 Type * base; 183 std::list< TypeDecl * > parameters; 183 184 std::list< DeclarationWithType * > assertions; 184 185 … … 189 190 Type * get_base() const { return base; } 190 191 void set_base( Type * newValue ) { base = newValue; } 192 std::list< TypeDecl* > & get_parameters() { return parameters; } 191 193 std::list< DeclarationWithType * >& get_assertions() { return assertions; } 192 194 -
src/SynTree/NamedTypeDecl.cc
r73a3be5 r98168b9 29 29 NamedTypeDecl::NamedTypeDecl( const NamedTypeDecl &other ) 30 30 : Parent( other ), base( maybeClone( other.base ) ) { 31 cloneAll( other.parameters, parameters ); 31 32 cloneAll( other.assertions, assertions ); 32 33 } … … 34 35 NamedTypeDecl::~NamedTypeDecl() { 35 36 delete base; 37 deleteAll( parameters ); 36 38 deleteAll( assertions ); 37 39 } … … 54 56 base->print( os, indent+1 ); 55 57 } // if 58 if ( ! parameters.empty() ) { 59 os << endl << indent << "... with parameters" << endl; 60 printAll( parameters, os, indent+1 ); 61 } // if 56 62 if ( ! assertions.empty() ) { 57 63 os << endl << indent << "... with assertions" << endl; … … 70 76 base->print( os, indent+1 ); 71 77 } // if 78 if ( ! parameters.empty() ) { 79 os << endl << indent << "... with parameters" << endl; 80 printAll( parameters, os, indent+1 ); 81 } // if 72 82 } 73 83
Note: See TracChangeset
for help on using the changeset viewer.