Exemple #1
0
axis2_char_t *
wsclient_content_type (const axutil_env_t *env,
					   axis2_char_t *content_type)
{
	axis2_char_t *valid_type;
	int i = 0;
	for (i = 0; i < array_sizeof (content_type_array); i++)
	{
		if (!strncmp (content_type_array [i], content_type, 
					  (strchr (content_type, '/') - content_type)))
			break;
	}

	if (i == array_sizeof (content_type_array))
	{
		if ((content_type [0] == 'x' ||
			 content_type [0] == 'X') && content_type [1] == '-')
			valid_type = content_type;
		else
			valid_type = "application/octet-stream";		
	}
	else
		valid_type = content_type;

	return valid_type;
}
static void
get_type_str(char *dst, size_t dstsize, int type)
{
	static struct flag_definition defs[] = {
		DEFINE_FLAG(SOCK_CLOEXEC),
		DEFINE_FLAG(SOCK_NONBLOCK)
	};
	static const char *types[] = {
		UNKNOWN,
		"SOCK_STREAM",
		"SOCK_DGRAM",
		"SOCK_RAW",
		"SOCK_RDM",
		"SOCK_SEQPACKET"
	};
	static int ntypes = array_sizeof(types);
	int flags = SOCK_CLOEXEC | SOCK_NONBLOCK;
	const char *fmt, *s;
	char t[256];

	s = get_array_element(types, ntypes, ~flags & type);
	fmaster_chain_flags(t, sizeof(t), flags & type, defs,
			    array_sizeof(defs));
	fmt = t[0] == '\0' ? "%s" : "%s|%s";

	snprintf(dst, dstsize, fmt, s, t);
}
Exemple #3
0
static void
vdiec(int eval, int code, const char *fmt, va_list ap)
{
	char buf[4096], msg[4096];

	vsnprintf(buf, array_sizeof(buf), fmt, ap);
	snprintf(msg, array_sizeof(msg), "%s: %s", buf, strerror(code));
	die_with_message(eval, msg);
	/* NOTREACHED */
}
Exemple #4
0
int luaC_array__newindex(lua_State *L)
{
  struct Array *A = lunum_checkarray1(L, 1);
  const int m = _get_index(L, A);

  const enum ArrayType T = A->dtype;

  void *val = lunum_tovalue(L, T);
  memcpy((char*)A->data + array_sizeof(T)*m, val, array_sizeof(T));
  free(val);

  return 0;
}
Exemple #5
0
void _lunum_register_array(lua_State *L, struct Array *B)
{
  lua_newtable(L);

  lua_pushcfunction(L, luaC_array_dtype);
  lua_setfield(L, -2, "dtype");

  lua_pushcfunction(L, luaC_array_shape);
  lua_setfield(L, -2, "shape");

  lua_pushcfunction(L, luaC_array_size);
  lua_setfield(L, -2, "size");

  lua_pushcfunction(L, luaC_array_astable);
  lua_setfield(L, -2, "astable");

  lua_pushcfunction(L, luaC_array_astype);
  lua_setfield(L, -2, "astype");

  lua_pushcfunction(L, luaC_array_tofile);
  lua_setfield(L, -2, "tofile");


  // Calls code written in Lua: lunum.__register_array(new_array) to add
  // additional methods to the new array.
  // ---------------------------------------------------------------------------
  lua_getglobal(L, "lunum");
  lua_getfield(L, -1, "__register_array");
  lua_pushvalue(L, -3);
  lua_call(L, 1, 0);
  lua_pop(L, 1);


  void *data = lua_newuserdata(L, B->size * array_sizeof(B->dtype));
  lua_setfield(L, -2, "__buffer");

  memcpy(data, B->data, B->size * array_sizeof(B->dtype));
  free(B->data);
  B->owns = 0;
  B->data = data;

  struct Array *A = (struct Array*) lua_newuserdata(L, sizeof(struct Array));
  lua_setfield(L, -2, "__cstruct");
  *A = *B;

  luaL_getmetatable(L, "array");
  lua_setmetatable(L, -2);
}
Exemple #6
0
static int luaC_lunum_fromfile(lua_State *L)
// -----------------------------------------------------------------------------
// Opens the binary file 'fname' for reading, and returns a 1d array from the
// data. The file size must be a multiple of the data type 'T'.
// -----------------------------------------------------------------------------
{
  const char *fname = luaL_checkstring(L, 1);
  const ArrayType T = luaL_optinteger(L, 2, ARRAY_TYPE_DOUBLE);
  const int sizeof_T = array_sizeof(T);

  FILE *input = fopen(fname, "rb");

  if (input == NULL) {
    return luaL_error(L, "no such file %s", fname);
  }
  fseek(input, 0L, SEEK_END); const size_t sz = ftell(input);
  fseek(input, 0L, SEEK_SET);

  if (sz % sizeof_T != 0) {
    return luaL_error(L, "file size must be a multiple of the data type size");
  }
  const size_t N = sz / sizeof_T;
  Array A = array_new_zeros(N, T);

  if (fread(A.data, N, sizeof_T, input) != sizeof_T) {
    fclose(input);
    return luaL_error(L, "Error while reading file %s", fname);
  }
  fclose(input);
  lunum_pusharray1(L, &A);

  return 1;
}
Exemple #7
0
int luaC_array__call(lua_State *L)
{
  struct Array *A = lunum_checkarray1(L, 1);
  int nind = lua_gettop(L) - 1;

  if (nind != A->ndims) {
    luaL_error(L, "wrong number of indices (%d) for array of dimension %d",
               nind, A->ndims);
    return 0;
  }
  const int Nd = A->ndims;
  int *stride = (int*) malloc(A->ndims * sizeof(int));
  stride[Nd-1] = 1;

  for (int d=Nd-2; d>=0; --d) {
    stride[d] = stride[d+1] * A->shape[d+1];
  }

  int m = 0;
  for (int d=0; d<A->ndims; ++d) {
    int i = lua_tointeger(L, d+2);
    m += i*stride[d];
  }

  _push_value(L, A->dtype, (char*)A->data + m*array_sizeof(A->dtype));
  free(stride);

  return 1;
}
int
sys_fmaster_recvmsg(struct thread *td, struct fmaster_recvmsg_args *uap)
{
	struct flag_definition defs[] = {
		DEFINE_FLAG(MSG_OOB),
		DEFINE_FLAG(MSG_PEEK),
		DEFINE_FLAG(MSG_WAITALL),
		DEFINE_FLAG(MSG_DONTWAIT),
		DEFINE_FLAG(MSG_CMSG_CLOEXEC)
	};
	struct timeval time_start;
	int error, flags;
	char flagsstr[256];

	flags = uap->flags;
	fmaster_chain_flags(flagsstr, sizeof(flagsstr), flags, defs,
			    array_sizeof(defs));
	fmaster_log(td, LOG_DEBUG,
		    "%s: started: s=%d, msg=%p, flags=0x%x (%s)",
		    sysname, uap->s, uap->msg, flags, flagsstr);
	microtime(&time_start);

	error = fmaster_recvmsg_main(td, uap);

	fmaster_log_syscall_end(td, sysname, &time_start, error);

	return (error);
}
int helper_collation_str(const char *src, char *dest, int dest_size)
{
	HELPER_FN_CALL;
	int32_t size = 0;
	UErrorCode status = 0;
	UChar tmp_result[CTS_SQL_MAX_LEN];
	UCollator *collator;
	const char *region;

	region = vconf_get_str(VCONFKEY_REGIONFORMAT);
	HELPER_DBG("region %s", region);
	collator = ucol_open(region, &status);
	h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED,
			"ucol_open() Failed(%s)", u_errorName(status));

	if (U_FAILURE(status)){
		ERR("ucol_setAttribute Failed(%s)", u_errorName(status));
		ucol_close(collator);
		return CTS_ERR_ICU_FAILED;
	}

	u_strFromUTF8(tmp_result, array_sizeof(tmp_result), NULL, src, -1, &status);
	if (U_FAILURE(status)){
		ERR("u_strFromUTF8 Failed(%s)", u_errorName(status));
		ucol_close(collator);
		return CTS_ERR_ICU_FAILED;
	}
	size = ucol_getSortKey(collator, tmp_result, -1, (uint8_t *)dest, dest_size);
	ucol_close(collator);
	dest[size]='\0';

	return CTS_SUCCESS;
}
Exemple #10
0
AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
wsf_create_client_data(
        const axutil_env_t *env)
{

    axutil_hash_t *client_data = NULL;

    axis2_char_t *ssn [] =
            {("11"),("22"),("33"),("44")};

    axis2_char_t *name [] =
            {("manjula"),("kau"),("samisa"),("dimuthu")};

    int i = 0;
    
    client_data = axutil_hash_make(env);

    for(i=0; i<array_sizeof(ssn); i++)
    {
        wsf_client_details_t *client_details = NULL;
        client_details = wsf_client_details_create(env, ssn[i], name[i], name[i]); /*password is same as the username*/

        axutil_hash_set(client_data, name[i], AXIS2_HASH_KEY_STRING, client_details);
    }

    return client_data;
}
Exemple #11
0
    void
    VM::display_opcode_profile()
    {
        for (int i = 0; i < VMOP_INSTRUCTION_COUNT; i++) m_opcode_profile[i].opcode = i;

        qsort(m_opcode_profile, array_sizeof(m_opcode_profile), sizeof(m_opcode_profile[0]), comp_profile_rec);
        for (int i = 0; i < VMOP_INSTRUCTION_COUNT; i++) {
            uint64_t m = 0;
            int prevcode = 0;
            for (int n = 0; n < VMOP_INSTRUCTION_COUNT; n++) {
                if (m < m_opcode_profile[i].prev[n]) {
                    m = m_opcode_profile[i].prev[n];
                    prevcode = n;
                }
            }
            if (m) {
                printf("%24s: %10llu    |%24s: %10llu (%.2f%%) \n",
                        m_heap->inherent_symbol(m_opcode_profile[i].opcode)->name,
                        m_opcode_profile[i].count,
                        m_heap->inherent_symbol(prevcode)->name,
                        m,
                        m * 100.0 / m_opcode_profile[i].count);
            } else {
                printf("%24s: %10llu  \n",
                        m_heap->inherent_symbol(m_opcode_profile[i].opcode)->name,
                        m_opcode_profile[i].count);
            }
        }
    }
Exemple #12
0
AXIS2_EXTERN axutil_hash_t *AXIS2_CALL
wsf_create_stock_market(
        const axutil_env_t *env)
{

    axutil_hash_t *market = NULL;

    axis2_char_t *symbol [] =
            {("aa"),("bb"),("cc"),("dd")};

    axis2_char_t *symbol_name [] =
            {("IBM"),("WSO2"),("MICROSOFT"),("SUN")};

    int i = 0;
    
    market = axutil_hash_make(env);

    for(i=0; i<array_sizeof(symbol); i++)
    {
        axis2_StockQuote_t *stock_quote = NULL;
        stock_quote = axis2_StockQuote_create(env);

        axis2_StockQuote_set_name(stock_quote, env, symbol_name[i]);
        axis2_StockQuote_set_symbol(stock_quote, env, symbol[i]);
        axis2_StockQuote_set_price(stock_quote, env, i*100);

        axutil_hash_set(market, symbol[i], AXIS2_HASH_KEY_STRING, stock_quote);
    }

    return market;
}
Exemple #13
0
static void
exec_set_descr(YogEnv* env, YogVal attr, YogVal obj, YogVal val)
{
    SAVE_ARGS3(env, attr, obj, val);
    YogVal setter = YUNDEF;
    YogVal class_of_setter = YUNDEF;
    YogVal method = YUNDEF;
    YogVal class_of_method = YUNDEF;
    YogVal class_of_obj = YUNDEF;
    PUSH_LOCALS5(env, setter, class_of_setter, method, class_of_method, class_of_obj);
    YogHandle* args[] = { YogHandle_REGISTER(env, val) };

    setter = PTR_AS(YogProperty, attr)->setter;
    class_of_setter = YogVal_get_class(env, setter);
    if (!IS_PTR(setter)) {
        ID id = PTR_AS(YogClass, class_of_setter)->name;
        YogError_raise_TypeError(env, "\"%I\" object is not callable", id);
    }
    class_of_obj = YogVal_get_class(env, obj);
    YOG_ASSERT(env, PTR_AS(YogClass, class_of_setter)->call_get_descr != NULL, "can't make instance method");
    method = PTR_AS(YogClass, class_of_setter)->call_get_descr(env, setter, obj, class_of_obj);
    YOG_ASSERT(env, IS_PTR(method), "method isn't pointer");
    class_of_method = YogVal_get_class(env, method);
    Executor exec = PTR_AS(YogClass, class_of_method)->exec;
    YOG_ASSERT(env, exec != NULL, "method isn't callable");

    YogHandle* h_method = YogHandle_REGISTER(env, method);
    exec(env, h_method, array_sizeof(args), args, 0, NULL, NULL, NULL, NULL);

    RETURN_VOID(env);
}
Exemple #14
0
struct Array array_new_from_mask(const struct Array *B1, struct Array *M)
// -----------------------------------------------------------------------------
// Extracts the indices of B1 for which M is true, and returns a 1d-array
// -----------------------------------------------------------------------------
// @M : Array of bool's, must have the same size as B1
// -----------------------------------------------------------------------------
{
  int sizeof_T = array_sizeof(B1->dtype);

  char *b0 = (char*) malloc(sizeof_T);
  char *b1 = (char*) B1->data;

  int m = 0;

  for (int n=0; n<B1->size; ++n) {
    if (((Bool*)M->data)[n]) {
      b0 = (char*) realloc(b0, (++m)*sizeof(double));
      memcpy(b0 + (m-1)*sizeof_T, b1 + n*sizeof_T, sizeof_T);
    }
  }

  struct Array B0 = array_new_zeros(m, B1->dtype);
  memcpy(B0.data, b0, m*sizeof_T);
  free(b0);

  return B0;
}
Exemple #15
0
struct Array array_new_zeros(int N, enum ArrayType T)
{
  struct Array A;

  A.data  = malloc(N*array_sizeof(T));
  A.owns  = 1;
  A.size  = N;
  A.dtype = T;
  A.shape = (int*) malloc(sizeof(int));
  A.ndims = 1;

  A.shape[0] = N;
  void *a = A.data;

  switch (T) {
  case ARRAY_TYPE_BOOL    : EXPR_ASSIGN0(Bool   ,0) ; break;
  case ARRAY_TYPE_CHAR    : EXPR_ASSIGN0(char   ,0) ; break;
  case ARRAY_TYPE_SHORT   : EXPR_ASSIGN0(short  ,0) ; break;
  case ARRAY_TYPE_INT     : EXPR_ASSIGN0(int    ,0) ; break;
  case ARRAY_TYPE_LONG    : EXPR_ASSIGN0(long   ,0) ; break;
  case ARRAY_TYPE_FLOAT   : EXPR_ASSIGN0(float  ,0) ; break;
  case ARRAY_TYPE_DOUBLE  : EXPR_ASSIGN0(double ,0) ; break;
  case ARRAY_TYPE_COMPLEX : EXPR_ASSIGN0(Complex,0) ; break;
  }

  return A;
}
Exemple #16
0
static void
print_dlopen_error(YogEnv* env, YogHandle* filename)
{
    SAVE_LOCALS(env);
    if (!env->vm->debug_import) {
        RETURN_VOID(env);
    }
    const char* msg;
#if defined(__MINGW32__) || defined(_MSC_VER)
    TCHAR buf[1024];
    if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buf, array_sizeof(buf), NULL) != 0) {
        RETURN_VOID(env);
    }
    msg = (const char*)buf;
#else
    msg = dlerror();
    if (msg == NULL) {
        RETURN_VOID(env);
    }
#endif
#if defined(__linux__)
    fprintf(stderr, "%s\n", msg);
#else
    YogVal bin = YogString_to_bin_in_default_encoding(env, filename);
    fprintf(stderr, "%s: %s\n", BINARY_CSTR(bin), msg);
#endif
    RETURN_VOID(env);
}
Exemple #17
0
void *lunum_tovalue(lua_State *L, enum ArrayType T)
{
  Complex x=0.0;

  if (lua_isnumber(L, -1)) {
    x = lua_tonumber(L, -1);
  }
  else if (lua_isboolean(L, -1)) {
    x = lua_toboolean(L, -1);
  }
  else if (lunum_hasmetatable(L, -1, "complex")) {
    x = *((Complex*) lua_touserdata(L, -1));
  }
  else {
    luaL_error(L, "unkown data type");
  }

  void *y = malloc(array_sizeof(T));

  switch (T) {
  case ARRAY_TYPE_BOOL    : *((Bool   *)y) = x; break;
  case ARRAY_TYPE_CHAR    : *((char   *)y) = x; break;
  case ARRAY_TYPE_SHORT   : *((short  *)y) = x; break;
  case ARRAY_TYPE_INT     : *((int    *)y) = x; break;
  case ARRAY_TYPE_LONG    : *((long   *)y) = x; break;
  case ARRAY_TYPE_FLOAT   : *((float  *)y) = x; break;
  case ARRAY_TYPE_DOUBLE  : *((double *)y) = x; break;
  case ARRAY_TYPE_COMPLEX : *((Complex*)y) = x; break;
  }

  return y;
}
int
sys_fmaster_accept4(struct thread *td, struct fmaster_accept4_args *uap)
{
	struct sockaddr *name;
	struct timeval time_start;
	socklen_t *anamelen;
	int error, flags, s;
	const char *fmt = "%s: started: s=%d, name=%p, anamelen=%p, flags=0x%x "
			  "(%s)";
	char buf[256];

	s = uap->s;
	name = uap->name;
	anamelen = uap->anamelen;
	flags = uap->flags;
	fmaster_chain_flags(buf, sizeof(buf), flags, flag_defs,
			    array_sizeof(flag_defs));
	fmaster_log(td, LOG_DEBUG, fmt, sysname, s, name, anamelen, flags, buf);
	microtime(&time_start);

	error = accept4_main(td, s, name, anamelen, flags);

	fmaster_log_syscall_end(td, sysname, &time_start, error);

	return (error);
}
Exemple #19
0
static int luaC_array__newindex(lua_State *L)
{
  Array *A = lunum_checkarray1(L, 1);

  int success;
  const size_t m = _get_index(L, A, &success);

  if (success) {
    const ArrayType T = A->dtype;
    ArrayAllNum val;

    lunum_tovalue(L, T, &val);
    memcpy((char*)A->data + array_sizeof(T)*m, &val, array_sizeof(T));
  }

  return 0;
}
int helper_normalize_str(const char *src, char *dest, int dest_size)
{
	int type = CTS_LANG_OTHERS;
	int32_t size;
	UErrorCode status = 0;
	UChar tmp_result[CTS_SQL_MAX_LEN*2];
	UChar result[CTS_SQL_MAX_LEN*2];
	int i = 0;
	int j = 0;
	int str_len = strlen(src);
	int char_len = 0;

	for (i=0;i<str_len;i+=char_len) {
		char char_src[10];
		char_len = check_utf8(src[i]);
		memcpy(char_src, &src[i], char_len);
		char_src[char_len] = '\0';

		u_strFromUTF8(tmp_result, array_sizeof(tmp_result), NULL, char_src, -1, &status);
		h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED,
				"u_strFromUTF8() Failed(%s)", u_errorName(status));

		u_strToLower(tmp_result, array_sizeof(tmp_result), tmp_result, -1, NULL, &status);
		h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED,
				"u_strToLower() Failed(%s)", u_errorName(status));

		size = unorm_normalize(tmp_result, -1, UNORM_NFD, 0,
				(UChar *)result, array_sizeof(result), &status);
		h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED,
				"unorm_normalize(%s) Failed(%s)", char_src, u_errorName(status));

		if (0 == i)
			type = helper_check_language(result);
		helper_extra_normalize(result, size);

		u_strToUTF8(&dest[j], dest_size-j, &size, result, -1, &status);
		h_retvm_if(U_FAILURE(status), CTS_ERR_ICU_FAILED,
				"u_strToUTF8() Failed(%s)", u_errorName(status));
		j += size;
		dest[j++] = 0x01;
	}
	dest[j]='\0';
	HELPER_DBG("src(%s) is transformed(%s)", src, dest);
	return type;
}
Exemple #21
0
ErrorCode Thread::readCPUState(Architecture::CPUState &state) {
  CONTEXT context;

  memset(&context, 0, sizeof(context));
  context.ContextFlags = CONTEXT_INTEGER |        // GP registers.
                         CONTEXT_CONTROL |        // Some more GP + CPSR.
                         CONTEXT_FLOATING_POINT | // FP registers.
                         CONTEXT_DEBUG_REGISTERS; // Debug registers.

  BOOL result = GetThreadContext(_handle, &context);
  if (!result) {
    return Platform::TranslateError();
  }

  // GP registers + CPSR.
  state.gp.r0 = context.R0;
  state.gp.r1 = context.R1;
  state.gp.r2 = context.R2;
  state.gp.r3 = context.R3;
  state.gp.r4 = context.R4;
  state.gp.r5 = context.R5;
  state.gp.r6 = context.R6;
  state.gp.r7 = context.R7;
  state.gp.r8 = context.R8;
  state.gp.r9 = context.R9;
  state.gp.r10 = context.R10;
  state.gp.r11 = context.R11;
  state.gp.ip = context.R12;
  state.gp.sp = context.Sp;
  state.gp.lr = context.Lr;
  state.gp.pc = context.Pc;
  state.gp.cpsr = context.Cpsr;

  // Floating point registers.
  static_assert(sizeof(context.D) == sizeof(state.vfp.dbl),
                "floating point register count mismatch");
  for (size_t i = 0; i < array_sizeof(context.D); ++i) {
    state.vfp.dbl[i].value = context.D[i];
  }
  state.vfp.fpscr = context.Fpscr;

  if (state.isThumb()) {
    if (state.gp.pc & 1ULL) {
      DS2LOG(Debug, "removing thumb bit from pc and lr");
      state.gp.pc &= ~1ULL;
    } else {
      DS2LOG(Warning,
             "CPU is in thumb mode but doesn't have thumb bit set in pc");
    }
  }

  // TODO(sas): Handle debug registers.

  return kSuccess;
}
Exemple #22
0
void
diex(int eval, const char *fmt, ...)
{
	va_list ap;
	char buf[4096];

	va_start(ap, fmt);
	vsnprintf(buf, array_sizeof(buf), fmt, ap);
	va_end(ap);
	die_with_message(eval, buf);
}
static void bvector_print(SgObject obj, SgPort *port, SgWriteContext *ctx)
{
  SgByteVector *b = SG_BVECTOR(obj);
  size_t i, size = b->size;
  uint8_t *u8 = b->elements;
  char buf[32];
  
  if (SG_VM_IS_SET_FLAG(Sg_VM(), SG_R7RS_MODE)) {
    Sg_PutuzUnsafe(port, UC("#u8("));
  } else {
    Sg_PutuzUnsafe(port, UC("#vu8("));
  }
  if (size != 0) {
    for (i = 0; i < size - 1; i++) {
      snprintf(buf, array_sizeof(buf), "%u", u8[i]);
      Sg_PutzUnsafe(port, buf);
      Sg_PutcUnsafe(port, ' ');
    }
    snprintf(buf, array_sizeof(buf), "%u", u8[i]);
    Sg_PutzUnsafe(port, buf);
  }
  Sg_PutcUnsafe(port, ')');
}
Exemple #24
0
static struct zip*
open_zip(YogEnv* env, YogVal pkg, YogVal path, int flags)
{
    SAVE_ARGS2(env, pkg, path);

    int error;
    YogVal bin = YogString_to_bin_in_default_encoding(env, VAL2HDL(env, path));
    struct zip* archive = zip_open(BINARY_CSTR(bin), flags, &error);
    if (archive == NULL) {
        char buf[256];
        zip_error_to_str(buf, array_sizeof(buf), error, errno);
        raise_ZipError(env, pkg, buf);
    }

    RETURN(env, archive);
}
static const char *
get_domain_str(int domain)
{
	static const char *domains[] = {
		"PF_UNSPEC",
		"PF_LOCAL",
		"PF_INET",
		"PF_IMPLINK",
		"PF_PUP",
		"PF_CHAOS",
		"PF_NETBIOS",
		"PF_ISO",
		"PF_ECMA",
		"PF_DATAKIT",
		"PF_CCITT",
		"PF_SNA",
		"PF_DECnet",
		"PF_DLI",
		"PF_LAT",
		"PF_HYLINK",
		"PF_APPLETALK",
		"PF_ROUTE",
		"PF_LINK",
		"pseudo_PF_XTP",
		"PF_COIP",
		"PF_CNT",
		"pseudo_PF_RTIP",
		"PF_IPX",
		"PF_SIP",
		"pseudo_PF_PIP",
		"PF_ISDN",
		"pseudo_PF_KEY",
		"PF_INET6",
		"PF_NATM",
		"PF_ATM",
		"pseudo_PF_HDRCMPLT",
		"PF_NETGRAPH",
		"PF_SLOW",
		"PF_SCLUSTER",
		"PF_ARP",
		"PF_BLUETOOTH",
		"PF_IEEE80211"
	};
	static int ndomains = array_sizeof(domains);

	return (get_array_element(domains, ndomains, domain));
}
Exemple #26
0
ErrorCode Thread::writeCPUState(Architecture::CPUState const &state) {
  CONTEXT context;

  memset(&context, 0, sizeof(context));
  // TODO(sas): Handle debug registers.
  context.ContextFlags = CONTEXT_INTEGER |       // GP registers.
                         CONTEXT_CONTROL |       // Some more GP + CPSR.
                         CONTEXT_FLOATING_POINT; // FP registers.

  // GP registers + CPSR.
  context.R0 = state.gp.r0;
  context.R1 = state.gp.r1;
  context.R2 = state.gp.r2;
  context.R3 = state.gp.r3;
  context.R4 = state.gp.r4;
  context.R5 = state.gp.r5;
  context.R6 = state.gp.r6;
  context.R7 = state.gp.r7;
  context.R8 = state.gp.r8;
  context.R9 = state.gp.r9;
  context.R10 = state.gp.r10;
  context.R11 = state.gp.r11;
  context.R12 = state.gp.ip;
  context.Sp = state.gp.sp;
  context.Lr = state.gp.lr;
  context.Pc = state.gp.pc;
  context.Cpsr = state.gp.cpsr;

  // Floating point registers.
  for (size_t i = 0; i < array_sizeof(context.D); ++i) {
    context.D[i] = state.vfp.dbl[i].value;
  }
  context.Fpscr = state.vfp.fpscr;

  if (state.isThumb()) {
    DS2ASSERT(!(state.gp.pc & 1ULL));
    DS2LOG(Debug, "setting back thumb bit on pc and lr");
    context.Pc |= 1ULL;
  }

  BOOL result = SetThreadContext(_handle, &context);
  if (!result) {
    return Platform::TranslateError();
  }

  return kSuccess;
}
Exemple #27
0
int luaC_array_tofile(lua_State *L)
// -----------------------------------------------------------------------------
// Writes the array 'A' as binary data to the file named 'fname'.
// -----------------------------------------------------------------------------
{
  struct Array *A = lunum_checkarray1(L, 1);
  const char *fname = luaL_checkstring(L, 2);
  FILE *output = fopen(fname, "wb");

  if (output == NULL) {
    luaL_error(L, "could not create file %s", fname);
  }
  fwrite(A->data, A->size, array_sizeof(A->dtype), output);
  fclose(output);

  return 0;
}
Exemple #28
0
static int luaC_array__call(lua_State *L)
{
  Array *A = lunum_checkarray1(L, 1);

  /* slicing done here to split concerns between indexing and slicing */
  if (lua_type(L, 2) == LUA_TTABLE || lua_type(L, 2) == LUA_TSTRING) {
    /* make slice */
    lua_getglobal(L, "lunum");
    lua_getfield(L, -1, "__build_slice");
    lua_insert(L, 1);
    lua_settop(L, 3);
    lua_call(L, 2, 1);

    return 1;
  }
  /* index */
  const int nind = lua_gettop(L) - 1;

  if (nind != A->ndims) {
    return luaL_error(L, "wrong number of indices (%d) for array of dimension %d",
               nind, A->ndims);
    return 0;
  }

  int isnum;
  size_t m = 0;
  for (int d=0; d < nind; ++d) {
    const size_t i = lua_tointegerx(L, d+2, &isnum);
    if (i >= A->shape[d]) {
      return luaL_error(L, "array indexed out of bounds (%d) on dimension %d of size %d",
                 i, d, A->shape[d]);
    } else if (!isnum) {
      return luaL_error(L, "non-integer index encountered");
    }
    m = m * A->shape[d] + i;
  }
  _push_value(L, A->dtype, (char*)A->data + m*array_sizeof(A->dtype));

  return 1;
}
int
main(int argc, const char *argv[])
{
	struct pollfd fds[3];
	int masterfd, slavefd;
	const char *path;

	if (argc < 2)
		return (1);
	path = argv[1];

	masterfd = open("/dev/null", O_RDONLY);
	if (masterfd == -1)
		return (2);
	slavefd = open(path, O_RDONLY);
	if (slavefd == -1)
		return (3);

	fds[0].fd = -1;
	fds[0].events = POLLSTANDARD;
	fds[0].revents = 0;
	fds[1].fd = masterfd;
	fds[1].events = POLLIN;
	fds[1].revents = 0;
	fds[2].fd = slavefd;
	fds[2].events = POLLIN;
	fds[2].revents = 0;
	if (poll(fds, array_sizeof(fds), 0) != 2)
		return (4);
	if (fds[0].revents != 0)
		return (5);
	if (fds[1].revents != POLLIN)
		return (6);
	if (fds[2].revents != POLLIN)
		return (7);

	return (0);
}
int
main(int argc, const char *argv[])
{
	struct pollfd fds[1];
	int d;
	const char *path;

	if (argc < 2)
		return (1);
	path = argv[1];

	d = open(path, O_RDONLY);
	if (d == -1)
		return (2);
	fds[0].fd = d;
	fds[0].events = POLLIN;
	fds[0].revents = 0;
	if (poll(fds, array_sizeof(fds), 0) != 1)
		return (3);
	if (fds[0].revents != POLLIN)
		return (4);

	return (0);
}