Ejemplo n.º 1
0
void pm_mangle_name(com32sys_t *regs)
{
    const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
    char       *dst = MK_PTR(regs->es, regs->edi.w[0]);

    mangle_name(dst, src);
}
Ejemplo n.º 2
0
/*
 * Convert a relative pathname to an absolute pathname
 * In the future this might also resolve symlinks...
 */
void pm_realpath(com32sys_t *regs)
{
    const char *src = MK_PTR(regs->ds, regs->esi.w[0]);
    char       *dst = MK_PTR(regs->es, regs->edi.w[0]);

    realpath(dst, src, FILENAME_MAX);
}
Ejemplo n.º 3
0
void __constructor __syslinux_get_derivative_info(void)
{
    com32sys_t *const r = &__syslinux_derivative_info.rr.r;

    r->eax.w[0] = 0x000A;
    __intcall(0x22, r, r);

    __syslinux_derivative_info.r.esbx = MK_PTR(r->es, r->ebx.w[0]);
    __syslinux_derivative_info.r.fssi = MK_PTR(r->fs, r->esi.w[0]);
    __syslinux_derivative_info.r.gsdi = MK_PTR(r->gs, r->edi.w[0]);
}
Ejemplo n.º 4
0
void __constructor __syslinux_get_version(void)
{
  static com32sys_t reg;

  reg.eax.w[0] = 0x0001;
  __intcall(0x22, &reg, &reg);

  __syslinux_version.version = reg.ecx.w[0];
  __syslinux_version.max_api = reg.eax.w[0];
  __syslinux_version.filesystem = reg.edx.b[0];
  __syslinux_version.version_string = MK_PTR(reg.es, reg.esi.w[0]);
  __syslinux_version.copyright_string = MK_PTR(reg.es, reg.edi.w[0]);
}
Ejemplo n.º 5
0
void getfsbytes(com32sys_t *regs)
{
    int sectors;
    bool have_more;
    uint32_t bytes_read;
    char *buf;
    struct file *file;
    uint16_t handle;

    handle = regs->esi.w[0];
    file = handle_to_file(handle);

    sectors = regs->ecx.w[0] >> SECTOR_SHIFT(file->fs);

    buf = MK_PTR(regs->es, regs->ebx.w[0]);
    bytes_read = file->fs->fs_ops->getfssec(file, buf, sectors, &have_more);

    /*
     * If we reach EOF, the filesystem driver will have already closed
     * the underlying file... this really should be cleaner.
     */
    if (!have_more) {
	_close_file(file);
        regs->esi.w[0] = 0;
    }

    regs->ecx.l = bytes_read;
}
Ejemplo n.º 6
0
void __constructor __syslinux_get_ipappend_strings(void)
{
    static com32sys_t reg;
    int i;

    reg.eax.w[0] = 0x000f;
    __intcall(0x22, &reg, &reg);

    if (!(reg.eflags.l & EFLAGS_CF)) {
        __syslinux_ipappend_strings.count = reg.ecx.w[0];
        __syslinux_ipappend_strings.ptr =
            syslinux_ipappend_string_list;
        for (i = 0; i < reg.ecx.w[0]; i++) {
            syslinux_ipappend_string_list[i] =
                MK_PTR(reg.es, *(uint16_t *)MK_PTR(reg.es, reg.ebx.w[0]+i*2));
        }
    }
}
Ejemplo n.º 7
0
void __constructor __syslinux_get_keyboard_map(void)
{
    static com32sys_t reg;

    reg.eax.w[0] = 0x001e;
    __intcall(0x22, &reg, &reg);
    if (!(reg.eflags.l & EFLAGS_CF)) {
	__syslinux_keyboard_map.version = reg.eax.w[0];
	__syslinux_keyboard_map.length = reg.ecx.w[0];
	__syslinux_keyboard_map.map = MK_PTR(reg.es, reg.ebx.w[0]);
    }
}
Ejemplo n.º 8
0
void
test_pre()
{
/*	char tmp_buf[256]; */

	DBUG_ENTER("test_pre");

	DBUG_PRINT("", ("sizeof(int)=%d", sizeof(int)));
	DBUG_PRINT("", ("sizeof(CONS*)=%d", sizeof(CONS*)));
	DBUG_PRINT("", ("sizeof(BEH)=%d", sizeof(BEH)));
	assert(sizeof(int) == sizeof(CONS*));
	assert(sizeof(BEH) == sizeof(CONS*));

	DBUG_PRINT("", ("NIL=16#%08lx (%p)", NIL, NIL));
	assert(nilp(NIL));
	assert(nilp(NIL) == _nilp(NIL));

	DBUG_PRINT("", ("sizeof(BOOL)=%d", sizeof(BOOL)));
	assert(sizeof(BOOL) == sizeof(CONS*));
	DBUG_PRINT("", ("TRUE=16#%08lx (%p)", TRUE, TRUE));
	DBUG_PRINT("", ("FALSE=16#%08lx (%p)", FALSE, FALSE));
	assert(TRUE);
	assert(!FALSE);
	assert(TRUE == ((BOOL)(0 == 0)));
	assert(FALSE == ((BOOL)(0 != 0)));

#if TYPETAG_USES_3MSB
	DBUG_PRINT("", ("Type tag in MSB[31:29]"));
#endif /* TYPETAG_USES_3MSB */
#if TYPETAG_USES_2LSB
	DBUG_PRINT("", ("Type tag in LSB[1:0]"));
#endif /* TYPETAG_USES_2LSB */
#if TYPETAG_USES_3LSB
	DBUG_PRINT("", ("Type tag in LSB[2/1:0]"));
#endif /* TYPETAG_USES_3LSB */
#if TYPETAG_USES_1LSB_2MSB
	DBUG_PRINT("", ("Type tag in LSB[0]+MSB[31:30]"));
#endif /* TYPETAG_USES_1LSB_2MSB */
	DBUG_PRINT("", ("_Program[]=16#%08lx (%p)", _Program, _Program));
	assert(_Program == MK_PTR(MK_REF(_Program)));

/* FIXME: enable this test when stack allocation is allowed
	DBUG_PRINT("", ("tmp_buf[]=%p", tmp_buf));
	assert(tmp_buf == MK_PTR(MK_REF(tmp_buf)));
*/

	DBUG_PRINT("", ("test_pre()=16#%08lx (%p)", test_pre, test_pre));
	assert(test_pre == MK_BEH(MK_FUNC(test_pre)));

	DBUG_RETURN;
}
Ejemplo n.º 9
0
void pm_searchdir(com32sys_t *regs)
{
    char *name = MK_PTR(regs->ds, regs->edi.w[0]);
    int rv;

    rv = searchdir(name);
    if (rv < 0) {
	regs->esi.w[0]  = 0;
	regs->eax.l     = 0;
	regs->eflags.l |= EFLAGS_ZF;
    } else {
	regs->esi.w[0]  = rv;
	regs->eax.l     = handle_to_file(rv)->inode->size;
	regs->eflags.l &= ~EFLAGS_ZF;
    }
}
Ejemplo n.º 10
0
void pm_open_file(com32sys_t *regs)
{
    int rv;
    struct file *file;
    const char *name = MK_PTR(regs->es, regs->esi.w[0]);
    char mangled_name[FILENAME_MAX];

    dprintf("pm_open_file %s\n", name);

    mangle_name(mangled_name, name);
    rv = searchdir(mangled_name);
    if (rv < 0) {
	regs->eflags.l |= EFLAGS_CF;
    } else {
	file = handle_to_file(rv);
	regs->eflags.l &= ~EFLAGS_CF;
	regs->eax.l = file->inode->size;
	regs->ecx.w[0] = SECTOR_SIZE(file->fs);
	regs->esi.w[0] = rv;
    }
}
Ejemplo n.º 11
0
/* Copy the data stored in a Cache struct into a continuously allocated memory block in *p.
 * All sub structure status are either uninitialized or compressed, which meaning that they are not allocated separately and therefore should not be deallocated.
 * Only coreRuleSet and coreFuncDescIndex are copied.
 * Starting from *p+size backwards, a list of pointers to pointers in the copied data structures are stored.
 * There pointers are used to quickly access all pointers in the stored data structures so that they can be offset when they are copied to a new memory address.
 * This function returns NULL if it runs out of memory allocated between in *p and *p+size.
 * The rule engine status is also set to uninitialized. */
Cache *copyCache( unsigned char **p, size_t size, Cache *ptr ) {
    /* size should be large enough and divisible by ALIGNMENT */
    if (size < DEFAULT_BLOCK_SIZE || 0 != size % REGION_ALIGNMENT) {
        return NULL;
    }

    unsigned char *buf = *p;
    unsigned char *pointers0 = buf + size;

    /* shared objects */
    unsigned char **pointers = &pointers0;
    int generatePtrDesc = 1;

    allocateInBuffer( Cache, ecopy, ptr );

    MK_POINTER( &( ecopy->address ) );
    MK_POINTER( &( ecopy->pointers ) );

    // objectMap will use a hash table size that is twice the number of objects being held (to favor speed).
    // Example: The shared memory region has a size of SHMMAX (see shared_memory.hpp). SHMMAX == 30000000.
    // The upper bound of the passed-in size is the shared memory region size.
    // With an average compiled object size of 75 bytes (taken over sample of 9000 lines of rule code), SHMMAX / 75 = 400000 objects.
    // The maximum size of the hash table should be twice the objects that can fit in shared memory (400000 * 2 = 800000).
    // The ratio of the shared memory region size to the maximum hash table size is 30000000 / 800000 = 37.5
    // Since the calculations are based on an average size, the ratio is rounded to 40 to avoid imbuing too much significance.
    // The size of the hash table for a cache of the passed-in size, then, should be the size of the cache divided by the ratio.
    // hashtable size upper limit == cache size upper limit / 40 == 30000000 / 40 < 800000
    const int SHMEM_TO_MAX_HASHTABLE_SIZE_RATIO{40};
    Hashtable *objectMap = newHashTable(size / SHMEM_TO_MAX_HASHTABLE_SIZE_RATIO);

    MK_PTR( RuleSet, coreRuleSet );
    ecopy->coreRuleSetStatus = COMPRESSED;
    ecopy->appRuleSet = NULL;
    ecopy->appRuleSetStatus = UNINITIALIZED;
    ecopy->extRuleSet = NULL;
    ecopy->extRuleSetStatus = UNINITIALIZED;
    MK_PTR_TAPP( Env, coreFuncDescIndex, PARAM( Node ) );
    ecopy->coreFuncDescIndexStatus = COMPRESSED; /* The coreFuncDescIndex is stored in a continuously allocated memory block in *buf */
    ecopy->appFuncDescIndex = NULL;
    ecopy->appFuncDescIndexStatus = UNINITIALIZED;
    ecopy->extFuncDescIndex = NULL;
    ecopy->extFuncDescIndexStatus = UNINITIALIZED;
    ecopy->dataSize = ( *p - buf );
    ecopy->address = buf;
    ecopy->pointers = pointers0;
    ecopy->cacheSize = size;
    ecopy->cacheStatus = INITIALIZED;
    ecopy->appRegion = NULL;
    ecopy->appRegionStatus = UNINITIALIZED;
    ecopy->coreRegion = NULL;
    ecopy->coreRegionStatus = UNINITIALIZED;
    ecopy->extRegion = NULL;
    ecopy->extRegionStatus = UNINITIALIZED;
    ecopy->sysRegion = NULL;
    ecopy->sysRegionStatus = UNINITIALIZED;
    ecopy->sysFuncDescIndex = NULL;
    ecopy->sysFuncDescIndexStatus = UNINITIALIZED;
    ecopy->ruleEngineStatus = UNINITIALIZED;
    MK_VAR_ARRAY_IN_STRUCT( char, ruleBase );

    deleteHashTable( objectMap, nop );

    return ecopy;
}