core/linux/os.c
/* returns -1 if all indices are in use */
1 if all indices are in use
1 if all indices are in use
static int
find_unused_ldt_index()
{
    int i, bytes;
    raw_ldt_entry_t ldt[LDT_ENTRIES_TO_CHECK];
    ASSERT(LDT_ENTRIES_TO_CHECK < LDT_ENTRIES);
    ASSERT(sizeof(raw_ldt_entry_t) == LDT_ENTRY_SIZE);
    memset(ldt, 0, sizeof(ldt));
    bytes = modify_ldt_syscall(0, (void *)ldt, sizeof(ldt));
    if (bytes == 0) {
        return 0;
    }
    ASSERT(bytes == sizeof(ldt));
    for (i = 0; i < bytes/sizeof(raw_ldt_entry_t); i++) {
        if (((ldt[i].base3124<<24) | (ldt[i].base2316<<16) | ldt[i].base1500) == 0) {
            return i;
        }
    }
    return -1;
}
static int find_unused_ldt_index ( ) { int i , bytes ; raw_ldt_entry_t ldt [ LDT_ENTRIES_TO_CHECK ] ; ASSERT ( LDT_ENTRIES_TO_CHECK < LDT_ENTRIES ) ; ASSERT ( sizeof ( raw_ldt_entry_t ) == LDT_ENTRY_SIZE ) ; memset ( ldt , 0 , sizeof ( ldt ) ) ; bytes = modify_ldt_syscall ( 0 , ( void * ) ldt , sizeof ( ldt ) ) ; if ( bytes == 0 ) { return 0 ; } ASSERT ( bytes == sizeof ( ldt ) ) ; for ( i = 0 ; i < bytes / sizeof ( raw_ldt_entry_t ) ; i ++ ) { if ( ( ( ldt [ i ] . base3124 << 24 ) | ( ldt [ i ] . base2316 << 16 ) | ldt [ i ] . base1500 ) == 0 ) { return i ; } } return -1 ; }
returns -1 if all indices are in use
returns - 1 if all indices are in use
/* N.B.: we don't have 64K of stack for the full LDT_ENTRIES
     * array, and I don't want to allocate a big array on the heap
     * when it's very doubtful any more than a handful of these
     * descriptors are actually in use
     */ /* make sure our struct size jives w/ ldt.h */ /* no indices are taken yet */