From 3bb8964ec23100d521a09e0868994f9596865070 Mon Sep 17 00:00:00 2001 From: Emanuele Aliberti Date: Tue, 8 Mar 2005 14:28:04 +0000 Subject: [PATCH] Win32 utility to bootstrap the PSX subsystem (it is an optional subsystem, therefore the SM does not bootstrap it on system startup). svn path=/trunk/; revision=13875 --- posix/apps/bootpsx/bootpsx.c | 121 ++++++++++++++++++++++++++++++++++ posix/apps/bootpsx/bootpsx.rc | 4 ++ posix/apps/bootpsx/makefile | 21 ++++++ 3 files changed, 146 insertions(+) create mode 100644 posix/apps/bootpsx/bootpsx.c create mode 100644 posix/apps/bootpsx/bootpsx.rc create mode 100644 posix/apps/bootpsx/makefile diff --git a/posix/apps/bootpsx/bootpsx.c b/posix/apps/bootpsx/bootpsx.c new file mode 100644 index 00000000000..20515a26b93 --- /dev/null +++ b/posix/apps/bootpsx/bootpsx.c @@ -0,0 +1,121 @@ +/* $Id$ + * + * PROJECT: ReactOS Operating System / POSIX Environment Subsystem + * + * -------------------------------------------------------------------- + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write + * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, + * MA 02139, USA. + * + * -------------------------------------------------------------------- + */ +#include +#include +#include + +#define NTOS_MODE_USER +#include +#include + +#define RETRY_COUNT 3 + +/********************************************************************** + * PsxCheckSubSystem/1 + */ +NTSTATUS STDCALL +PsxCheckSubSystem (LPCSTR argv0) +{ + NTSTATUS Status = STATUS_SUCCESS; + UNICODE_STRING DirectoryName = {0, 0, NULL}; + OBJECT_ATTRIBUTES DirectoryAttributes = {0}; + HANDLE hDir = (HANDLE) 0; + + RtlInitUnicodeString (& DirectoryName, L"\\POSIX"); + InitializeObjectAttributes (& DirectoryAttributes, + & DirectoryName, + 0,0,0); + Status = NtOpenDirectoryObject (& hDir, + DIRECTORY_TRAVERSE, + & DirectoryAttributes); + if(NT_SUCCESS(Status)) + { + NtClose (hDir); + } + + return Status; +} + +/********************************************************************** + * PsxBootstrap/1 + */ +NTSTATUS STDCALL +PsxBootstrap (LPCSTR argv0) +{ + NTSTATUS Status = STATUS_SUCCESS; + UNICODE_STRING Program = {0, 0, NULL}; + HANDLE SmApiPort = (HANDLE) 0; + + + printf("Connecting to the SM: "); + Status = SmConnectApiPort (NULL, + (HANDLE) 0, + IMAGE_SUBSYSTEM_UNKNOWN, + & SmApiPort); + if(!NT_SUCCESS(Status)) + { + fprintf(stderr,"\n%s: SmConnectApiPort failed with 0x%08lx\n", + argv0, Status); + return Status; + } + RtlInitUnicodeString (& Program, L"POSIX"); + Status = SmExecuteProgram (SmApiPort, & Program); + if(STATUS_SUCCESS != Status) + { + fprintf(stderr, "%s: SmExecuteProgram = %08lx\n", argv0, Status); + } + NtClose (SmApiPort); + return Status; +} + +/********************************************************************** + * + * ENTRY POINT PUBLIC + * + *********************************************************************/ +int main (int argc, char * argv []) +{ + NTSTATUS Status = STATUS_SUCCESS; + INT RetryCount = RETRY_COUNT; + + while(RetryCount > 0) + { + Status = PsxCheckSubSystem (argv[0]); + if(STATUS_SUCCESS == Status) + { + if (RETRY_COUNT == RetryCount) + { + fprintf(stderr,"POSIX already booted.\n"); + }else{ + fprintf(stderr,"POSIX booted.\n"); + } + break; + }else{ + Status = PsxBootstrap (argv[0]); + } + -- RetryCount; + } + return NT_SUCCESS(Status) ? EXIT_SUCCESS : EXIT_FAILURE; +} +/* EOF */ diff --git a/posix/apps/bootpsx/bootpsx.rc b/posix/apps/bootpsx/bootpsx.rc new file mode 100644 index 00000000000..7ad1217f084 --- /dev/null +++ b/posix/apps/bootpsx/bootpsx.rc @@ -0,0 +1,4 @@ +#define REACTOS_STR_FILE_DESCRIPTION "W32 Utility to boot the POSIX Subsystem\0" +#define REACTOS_STR_INTERNAL_NAME "bootpsx\0" +#define REACTOS_STR_ORIGINAL_FILENAME "bootpsx.exe\0" +#include diff --git a/posix/apps/bootpsx/makefile b/posix/apps/bootpsx/makefile new file mode 100644 index 00000000000..a83343f10e6 --- /dev/null +++ b/posix/apps/bootpsx/makefile @@ -0,0 +1,21 @@ +# $Id: Makefile 13504 2005-02-12 14:33:41Z ea $ + +PATH_TO_TOP = ../../../reactos + +TARGET_TYPE = program + +TARGET_APPTYPE = console + +TARGET_NAME = bootpsx + +TARGET_SDKLIBS = ntdll.a smdll.a kernel32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +TARGET_CFLAGS = -Wall -Werror + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF -- 2.17.1