Exemple #1
0
static void
timod_error(int fd, int prim, int terr, int uerr)
{
	struct file		*fp;
	struct T_primsg		*it;
	struct T_error_ack	*err;

#if defined(CONFIG_ABI_TRACE)
	abi_trace(ABI_TRACE_STREAMS, "TI: %u error prim=%d, TLI=%d, UNIX=%d\n",
			fd, prim, terr, uerr);
#endif

	fp = fcheck(fd);
	it = timod_mkctl(sizeof(struct T_error_ack));
	if (!it)
		return;

	err = (struct T_error_ack *)&it->type;
	err->PRIM_type = T_ERROR_ACK;
	err->ERROR_prim = prim;
	err->TLI_error = terr;
	err->UNIX_error = iABI_errors(uerr);

	it->pri = MSG_HIPRI;
	it->length = sizeof(struct T_error_ack);
	it->next = Priv(fp)->pfirst;

	Priv(fp)->pfirst = it;
	if (!Priv(fp)->plast)
		Priv(fp)->plast = it;
	timod_socket_wakeup(fp);
}
Exemple #2
0
static void
timod_ok(int fd, int prim)
{
	struct file		*fp;
	struct T_primsg		*it;
	struct T_ok_ack 	*ok;

#if defined(CONFIG_ABI_TRACE)
	abi_trace(ABI_TRACE_STREAMS, "TI: %u ok ack prim=%d\n", fd, prim);
#endif

	fp = fcheck(fd);
	it = timod_mkctl(sizeof(struct T_ok_ack));
	if (!it)
		return;

	ok = (struct T_ok_ack *)&it->type;
	ok->PRIM_type = T_OK_ACK;
	ok->CORRECT_prim = prim;

	it->pri = MSG_HIPRI;
	it->length = sizeof(struct T_ok_ack);
	it->next = Priv(fp)->pfirst;

	Priv(fp)->pfirst = it;
	if (!Priv(fp)->plast)
		Priv(fp)->plast = it;
	timod_socket_wakeup(fp);
}
Exemple #3
0
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// SHUTdown
HRESULT SHUT(PCTSTR ptzCmd)
{
	Priv(SE_SHUTDOWN_NAME);
	BOOL bReboot = ((*ptzCmd) == 'R') || ((*ptzCmd) == 'r');
	if (ExitWindowsEx(bReboot ? EWX_REBOOT : EWX_POWEROFF, 0))
	{
		return S_OK;
	}

	// End session
	DWORD dwResult;
	SendMessageTimeout(HWND_BROADCAST, WM_QUERYENDSESSION, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_ENDSESSION, 0, 0, 0, 2000, &dwResult);
	//SendMessageTimeout(HWND_BROADCAST, WM_CLOSE, 0, 0, 0, 2000, &dwResult);
	SendMessageTimeout(HWND_BROADCAST, WM_DESTROY, 0, 0, 0, 2000, &dwResult);

	// Get function address
	typedef DWORD (NTAPI *PNtShutdownSystem)(DWORD dwAction);
	PNtShutdownSystem NtShutdownSystem = (PNtShutdownSystem) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtShutdownSystem");
	if (!NtShutdownSystem)
	{
		return E_FAIL;
	}

	// Shutdown
	return NtShutdownSystem(bReboot ? 1: 2);
}
Exemple #4
0
static int
i_peek(u_int fd, struct file *fp, struct inode *ip,
		void *data, struct pt_regs *regs)
{
#if !defined(CONFIG_ABI_XTI)
	fput(fp);
	return 0;
#else
	struct T_private	*ti = Priv(fp);
	struct T_primsg		*tp;
	struct strpeek		buf, *uap = data;
	int			error = -EFAULT;

	if (copy_from_user(&buf, uap, sizeof(buf)))
		goto fput;

	error = 0;
	if (!ip->i_sock)
		goto fput;
	
	if (IS_SOCKSYS(ip))
		timod_update_socket(fd, fp, regs);

	if (!ti || !ti->pfirst)
		goto fput;
	tp = ti->pfirst;
			
	error = -EFAULT;
	if (!buf.flags || buf.flags == tp->pri) {
		int	l;
	

			
		if (buf.ctl.maxlen <= tp->length)
			l = buf.ctl.maxlen;
		else
			l = tp->length;

		if (copy_to_user(buf.ctl.buf,
		    ((char *)&tp->type) + ti->offset, l))
			goto fput;

		if (put_user(l, &uap->ctl.len))
			goto fput;

		if (buf.dat.maxlen >= 0 && put_user(0, &uap->dat.len))
			goto fput;

		if (put_user(tp->pri, &uap->flags))
			goto fput;

		error = 1;
	}
fput:
	fput(fp);
	return error;
#endif /* CONFIG_ABI_XTI */
}
Exemple #5
0
static int
i_nread(u_int fd, struct file *fp, struct inode *ip,
        void *data, struct pt_regs *regs)
{
    int error=0;

    if (!access_ok(VERIFY_WRITE, data, sizeof(u_long))) {
        error = -EFAULT;
        goto fput;
    }

#if !defined(CONFIG_ABI_XTI)
    if (S_ISSOCK(ip->i_mode)) {
        struct T_private *ti = Priv(fp);

        if (IS_SOCKSYS(ip))
            timod_update_socket(fd, fp, regs);

        if (ti && ti->pfirst) {
            put_user(ti->pfirst->length, (u_long *)data);
            fput(fp);
            return 1; /* at least 1... (FIXME) */
        }
    }

    fput(fp);
#endif

    error = SYS(ioctl,fd, TIOCINQ, (long)data);
    if (error == -EINVAL)
        return 0;
    else if (error)
        return error;

    __get_user(error, (u_long *)data);
    return !!error;
fput:
    fput(fp);
    return error;
}
Exemple #6
0
static int
i_nread(u_int fd, struct file *fp, struct inode *ip,
		void *data, struct pt_regs *regs)
{
	int			error;

	error = verify_area(VERIFY_WRITE, data, sizeof(u_long));
	if (error)
		goto fput;

#if defined(CONFIG_ABI_XTI)
	if (ip->i_sock) {
		struct T_private *ti = Priv(fp);

		if (IS_SOCKSYS(ip))
			timod_update_socket(fd, fp, regs);

		if (ti && ti->pfirst) {
			put_user(ti->pfirst->length, (u_long *)data);
			fput(fp);
			return 1; /* at least 1... (FIXME) */
		}
	}
#endif
	fput(fp);

	error = sys_ioctl(fd, TIOCINQ, data);
	if (error == -EINVAL)
		return 0;
	else if (error)
		return error;

	__get_user(error, (u_long *)data);
	return !!error;
fput:
	fput(fp);
	return error;
}
void test()
{
  // This function tests C++0x 5.16

  // p1 (contextually convert to bool)
  int i1 = ToBool() ? 0 : 1;

  // p2 (one or both void, and throwing)
  i1 ? throw 0 : throw 1;
  i1 ? test() : throw 1;
  i1 ? throw 0 : test();
  i1 ? test() : test();
  i1 = i1 ? throw 0 : 0;
  i1 = i1 ? 0 : throw 0;
  i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}}
  i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}}
  (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}}
  (i1 ? i1 : throw 0) = 0; // expected-error {{expression is not assignable}}

  // p3 (one or both class type, convert to each other)
  // b1 (lvalues)
  Base base;
  Derived derived;
  Convertible conv;
  Base &bar1 = i1 ? base : derived;
  Base &bar2 = i1 ? derived : base;
  Base &bar3 = i1 ? base : conv;
  Base &bar4 = i1 ? conv : base;
  // these are ambiguous
  BadBase bb;
  BadDerived bd;
  (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}}
  (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}}
  // curiously enough (and a defect?), these are not
  // for rvalues, hierarchy takes precedence over other conversions
  (void)(i1 ? BadBase() : BadDerived());
  (void)(i1 ? BadDerived() : BadBase());

  // b2.1 (hierarchy stuff)
  extern const Base constret();
  extern const Derived constder();
  // should use const overload
  A a1((i1 ? constret() : Base()).trick());
  A a2((i1 ? Base() : constret()).trick());
  A a3((i1 ? constret() : Derived()).trick());
  A a4((i1 ? Derived() : constret()).trick());
  // should use non-const overload
  i1 = (i1 ? Base() : Base()).trick();
  i1 = (i1 ? Base() : Base()).trick();
  i1 = (i1 ? Base() : Derived()).trick();
  i1 = (i1 ? Derived() : Base()).trick();
  // should fail: const lost
  (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}}
  (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}}

  Priv priv;
  Fin fin;
  (void)(i1 ? Base() : Priv()); // expected-error{{private base class}}
  (void)(i1 ? Priv() : Base()); // expected-error{{private base class}}
  (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
  (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
  (void)(i1 ? base : priv); // expected-error {{private base class}}
  (void)(i1 ? priv : base); // expected-error {{private base class}}
  (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}}
  (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}}

  // b2.2 (non-hierarchy)
  i1 = i1 ? I() : i1;
  i1 = i1 ? i1 : I();
  I i2(i1 ? I() : J());
  I i3(i1 ? J() : I());
  // "the type [it] woud have if E2 were converted to an rvalue"
  vfn pfn = i1 ? F() : test;
  pfn = i1 ? test : F();
  (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}}
  (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}}
  (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}}
  (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}}
  // By the way, this isn't an lvalue:
  &(i1 ? i1 : i2); // expected-error {{address expression must be an lvalue or a function designator}}

  // p4 (lvalue, same type)
  Fields flds;
  int &ir1 = i1 ? flds.i1 : flds.i2;
  (i1 ? flds.b1 : flds.i2) = 0;
  (i1 ? flds.i1 : flds.b2) = 0;
  (i1 ? flds.b1 : flds.b2) = 0;

  // p5 (conversion to built-in types)
  // GCC 4.3 fails these
  double d1 = i1 ? I() : K();
  pfn = i1 ? F() : G();
  DFnPtr pfm;
  pfm = i1 ? DFnPtr() : &Base::fn1;
  pfm = i1 ? &Base::fn1 : DFnPtr();

  // p6 (final conversions)
  i1 = i1 ? i1 : ir1;
  int *pi1 = i1 ? &i1 : 0;
  pi1 = i1 ? 0 : &i1;
  i1 = i1 ? i1 : EVal;
  i1 = i1 ? EVal : i1;
  d1 = i1 ? 'c' : 4.0;
  d1 = i1 ? 4.0 : 'c';
  Base *pb = i1 ? (Base*)0 : (Derived*)0;
  pb = i1 ? (Derived*)0 : (Base*)0;
  pfm = i1 ? &Base::fn1 : &Derived::fn2;
  pfm = i1 ? &Derived::fn2 : &Base::fn1;
  pfm = i1 ? &Derived::fn2 : 0;
  pfm = i1 ? 0 : &Derived::fn2;
  const int (MixedFieldsDerived::*mp1) =
    i1 ? &MixedFields::ci : &MixedFieldsDerived::i;
  const volatile int (MixedFields::*mp2) =
    i1 ? &MixedFields::ci : &MixedFields::cvi;
  (void)(i1 ? &MixedFields::ci : &MixedFields::vi);
  // Conversion of primitives does not result in an lvalue.
  &(i1 ? i1 : d1); // expected-error {{address expression must be an lvalue or a function designator}}

  (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}}
  (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}}
  

  unsigned long test0 = 5;
  test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
  test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
  test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
  test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
  test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
  test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
  test0 = test0 ? test0 : (long) 10;
  test0 = test0 ? test0 : (int) 10;
  test0 = test0 ? test0 : (short) 10;
  test0 = test0 ? (long) 10 : test0;
  test0 = test0 ? (int) 10 : test0;
  test0 = test0 ? (short) 10 : test0;

  int test1;
  test0 = test0 ? EVal : test0;
  test1 = test0 ? EVal : (int) test0;

  test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
  test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}

  test1 = test0 ? EVal : (int) test0;
  test1 = test0 ? (int) test0 : EVal;

  // Note the thing that this does not test: since DR446, various situations
  // *must* create a separate temporary copy of class objects. This can only
  // be properly tested at runtime, though.
}
Exemple #8
0
HRESULT PAGE(PTSTR ptzCmd)
{
	// Parse size
	UINT uMin = 0;
	UINT uMax = 0;
	PTSTR p = UStrChr(ptzCmd, ' ');
	if (p)
	{
		*p++ = 0;
		uMin = UStrToInt(p);
		p = UStrChr(p, ' ');
		if (p)
		{
			*p++ = 0;
			uMax = UStrToInt(p);
		}
	}

	if (uMax<uMin)
	{
		uMax=uMin;
	}

	// Get DOS device name for page file
	TCHAR tzDrive[16];
	TCHAR tzDos[MAX_PATH];
	TCHAR tzFile[MAX_PATH];
	tzDrive[0] = ptzCmd[0]; tzDrive[1] = ptzCmd[1]; tzDrive[2] = 0;
	UStrCopy(tzFile, ptzCmd + 2);
	QueryDosDevice(tzDrive, tzDos, MAX_PATH);
	UStrCat(tzDos, tzFile);

	WCHAR wzPath[MAX_PATH];
	UStrToWStr(wzPath, tzDos, MAX_PATH);

	UNICODE_STRING sPath;
	sPath.Length = UWStrLen(wzPath) * sizeof(WCHAR);
	sPath.MaximumLength = sPath.Length + sizeof(WCHAR);
	sPath.Buffer = wzPath;

	// Fill size param
	ULARGE_INTEGER ulMax, ulMin;
	ulMin.QuadPart = uMin * 1024 * 1024;
	ulMax.QuadPart = uMax * 1024 * 1024;

	// Get function address
	typedef NTSTATUS (NTAPI* PNtCreatePagingFile)(PUNICODE_STRING sPath, PULARGE_INTEGER puInitSize, PULARGE_INTEGER puMaxSize, ULONG uPriority);
	PNtCreatePagingFile NtCreatePagingFile = (PNtCreatePagingFile) GetProcAddress(GetModuleHandle(TEXT("NTDLL")), "NtCreatePagingFile");
	if (!NtCreatePagingFile)
	{
		return E_FAIL;
	}

	// Create page file
	Priv(SE_CREATE_PAGEFILE_NAME);
	HRESULT hResult = NtCreatePagingFile(&sPath, &ulMin, &ulMax, 0);
	if (hResult == S_OK)
	{
		// Log to Windows Registry
		TCHAR tzStr[MAX_PATH];
		DWORD i = sizeof(tzStr);
		if (SHGetValue(HKEY_LOCAL_MACHINE, REG_MemMgr, REG_PageFile, NULL, tzStr, &i) != S_OK)
		{
			i = 0;
		}
		else
		{
			i = (i / sizeof(TCHAR)) - 1;
		}

		i += UStrPrint(tzStr + i, TEXT("%s %d %d"), ptzCmd, uMin, uMax);
		tzStr[++i] = 0;
		SHSetValue(HKEY_LOCAL_MACHINE, REG_MemMgr, REG_PageFile, REG_MULTI_SZ, tzStr, i * sizeof(TCHAR));
	}

	return hResult;
}