// init_unit_tester_messenger static status_t init_unit_tester_messenger() { // Unfortunately BeOS R5 doesn't update the roster-side information about // the app looper's port ID once a BApplication has been created, and // thus we can't construct a BMessenger targeting a BApplication created // after the first one using the signature/team ID constructor. // We need to do some hacking. struct fake_messenger { port_id fPort; int32 fHandlerToken; team_id fTeam; int32 extra0; int32 extra1; bool fPreferredTarget; bool extra2; bool extra3; bool extra4; } &fake = *(fake_messenger*)&unitTesterMessenger; // get team status_t error = B_OK; fake.fTeam = BRoster().TeamFor(kUnitTesterSignature); if (fake.fTeam < 0) error = fake.fTeam; // find app looper port bool found = false; int32 cookie = 0; port_info info; while (error == B_OK && !found) { error = get_next_port_info(fake.fTeam, &cookie, &info); found = (error == B_OK && !strcmp("AppLooperPort", info.name)); } // init messenger if (error == B_OK) { fake.fPort = info.port; fake.fHandlerToken = 0; fake.fPreferredTarget = true; } return error; }
status_t _user_get_next_port_info(team_id team, int32 *userCookie, struct port_info *userInfo) { struct port_info info; status_t status; int32 cookie; if (userCookie == NULL || userInfo == NULL) return B_BAD_VALUE; if (!IS_USER_ADDRESS(userCookie) || !IS_USER_ADDRESS(userInfo) || user_memcpy(&cookie, userCookie, sizeof(int32)) < B_OK) return B_BAD_ADDRESS; status = get_next_port_info(team, &cookie, &info); // copy back to user space if (user_memcpy(userCookie, &cookie, sizeof(int32)) < B_OK || (status == B_OK && user_memcpy(userInfo, &info, sizeof(struct port_info)) < B_OK)) return B_BAD_ADDRESS; return status; }
void slowPoll( void ) { RANDOM_STATE randomState; BYTE buffer[ RANDOM_BUFSIZE + 8 ]; key_info keyInfo; team_info teami; thread_info threadi; area_info areai; port_info porti; sem_info semi; image_info imagei; double temperature; int32 devID, cookie; int fd, value; if( ( fd = open( "/dev/urandom", O_RDONLY ) ) >= 0 ) { MESSAGE_DATA msgData; BYTE buffer[ ( DEVRANDOM_BITS / 8 ) + 8 ]; static const int quality = 100; /* Read data from /dev/urandom, which won't block (although the quality of the noise is lesser). */ read( fd, buffer, DEVRANDOM_BITS / 8 ); setMessageData( &msgData, buffer, DEVRANDOM_BITS / 8 ); krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE_S, &msgData, CRYPT_IATTRIBUTE_ENTROPY ); zeroise( buffer, DEVRANDOM_BITS / 8 ); close( fd ); krnlSendMessage( SYSTEM_OBJECT_HANDLE, IMESSAGE_SETATTRIBUTE, ( MESSAGE_CAST ) &quality, CRYPT_IATTRIBUTE_ENTROPY_QUALITY ); return; } initRandomData( randomState, buffer, RANDOM_BUFSIZE ); /* Get the state of all keys on the keyboard and various other system states */ #if 0 /* See comment at start */ if( get_key_info( &keyInfo ) == B_NO_ERROR ) addRandomData( randomState, &keyInfo, sizeof( key_info ) ); #endif /* 0 */ value = is_computer_on(); /* Returns 1 if computer is on */ addRandomValue( randomState, value ); temperature = is_computer_on_fire(); /* MB temp.if on fire */ addRandomData( randomState, &temperature, sizeof( double ) ); /* Get information on all running teams (thread groups, ie applications). This returns the team ID, number of threads, images, and areas, debugger port and thread ID, program args, and uid and gid */ cookie = 0; while( get_next_team_info( &cookie, &teami ) == B_NO_ERROR ) addRandomData( randomState, &teami, sizeof( teami ) ); /* Get information on all running threads. This returns the thread ID, team ID, thread name and state (eg running, suspended, asleep, blocked), the thread priority, elapsed user and kernel time, and thread stack information */ cookie = 0; while( get_next_thread_info( 0, &cookie, &threadi ) == B_NO_ERROR ) { addRandomValue( randomState, has_data( threadi.thread ) ); addRandomData( randomState, &threadi, sizeof( threadi ) ); } /* Get information on all memory areas (chunks of virtual memory). This returns the area ID, name, size, locking scheme and protection bits, ID of the owning team, start address, number of resident bytes, copy- on-write count, an number of pages swapped in and out */ cookie = 0; while( get_next_area_info( 0, &cookie, &areai ) == B_NO_ERROR ) addRandomData( randomState, &areai, sizeof( areai ) ); /* Get information on all message ports. This returns the port ID, ID of the owning team, message queue length, number of messages in the queue, and total number of messages processed */ cookie = 0; while( get_next_port_info( 0, &cookie, &porti ) == B_NO_ERROR ) addRandomData( randomState, &porti, sizeof( porti ) ); /* Get information on all semaphores. This returns the semaphore and owning team ID, the name, thread count, and the ID of the last thread which acquired the semaphore */ cookie = 0; while( get_next_sem_info( 0, &cookie, &semi ) == B_NO_ERROR ) addRandomData( randomState, &semi, sizeof( semi ) ); /* Get information on all images (code blocks, eg applications, shared libraries, and add-on images (DLL's on steroids). This returns the image ID and type (app, library, or add-on), the order in which the image was loaded compared to other images, the address of the init and shutdown routines, the device and node where the image lives, and the image text and data sizes) */ cookie = 0; while( get_next_image_info( 0, &cookie, &imagei ) == B_NO_ERROR ) addRandomData( randomState, &imagei, sizeof( imagei ) ); /* Get information on all storage devices. This returns the device number, root inode, various device parameters such as I/O block size, and the number of free and used blocks and inodes */ devID = 0; while( next_dev( &devID ) >= 0 ) { fs_info fsInfo; if( fs_stat_dev( devID, &fsInfo ) == B_NO_ERROR ) addRandomData( randomState, &fsInfo, sizeof( fs_info ) ); } /* Flush any remaining data through */ endRandomData( randomState, 100 ); }