Win32 port of the userspace tools using MinGW.
Subsystems (3)
RFC 1/1 Win32 port of the userspace tools using MinGW.
OK, I haven't quite gotten around to posting the Windows kernel driver source that goes with this. So I'm not asking that this patch be merged, since nobody else can use it yet. :-) I'd love to get review, though:
Does this look like it's in a mergeable state? I'm happy with it, but do I need to change anything to make it acceptable to you folks?
This patch requires basically all the other patches I've posted.
Makefile.in | 1 + include/byteswap.h | 39 +++++++ kexec/Makefile | 6 + kexec/arch/i386/Makefile | 2 + kexec/arch/i386/kexec-x86.c | 2 + kexec/arch/i386/x86-linux-setup.c | 4 + kexec/kexec-syscall.h | 7 ++ kexec/kexec.c | 4 + kexec/kexec.h | 10 ++ kexec/win32.c | 214 +++++++++++++++++++++++++++++++++++++ 10 files changed, 289 insertions(+), 0 deletions(-) create mode 100644 include/byteswap.h create mode 100644 kexec/win32.c
Makefile.in +1 -0
@@ -24,6 +24,7 @@ ARCH = @ARCH@ OBJDIR = @OBJDIR@ target = @target@ host = @host@ +host_os = @host_os@ # Compiler for building kexec CC = @CC@
include/byteswap.h new file +39 -0
@@ -0,0 +1,39 @@ +/* byteswap.h + +Copyright 2005 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef _BYTESWAP_H +#define _BYTESWAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +static __inlineunsigned short +bswap_16 (unsigned short __x) +{ +return (__x >>8 ) | (__x <<8 ); +} + +static __inlineunsigned int +bswap_32 (unsigned int __x) +{ +return (bswap_16 (__x &0xffff ) <<16 ) | (bswap_16 (__x >>16 )); +} + +static __inlineunsigned long long +bswap_64 (unsigned long long __x) +{ +return (((unsigned long long )bswap_32 (__x &0xffffffffull )) <<32 ) | (bswap_32 (__x >>32 )); +} + +#ifdef __cplusplus +} +#endif +#endif /* _BYTESWAP_H */
kexec/Makefile +6 -0
@@ -11,16 +11,22 @@ KEXEC_SRCS = KEXEC_GENERATED_SRCS = KEXEC_SRCS += kexec/kexec.c +ifneq ($(host_os),mingw32msvc) KEXEC_SRCS += kexec/ifdown.c +endif KEXEC_SRCS += kexec/kexec-elf.c KEXEC_SRCS += kexec/kexec-elf-exec.c KEXEC_SRCS += kexec/kexec-elf-core.c KEXEC_SRCS += kexec/kexec-elf-rel.c KEXEC_SRCS += kexec/kexec-elf-boot.c KEXEC_SRCS += kexec/kexec-iomem.c +ifneq ($(host_os),mingw32msvc) KEXEC_SRCS += kexec/crashdump.c KEXEC_SRCS += kexec/crashdump-xen.c KEXEC_SRCS += kexec/phys_arch.c +else +KEXEC_SRCS += kexec/win32.c +endif KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C)
kexec/arch/i386/Makefile +2 -0
@@ -9,7 +9,9 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c +ifneq ($(host_os),mingw32msvc) i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c +endif dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS) \ kexec/arch/i386/kexec-x86.h kexec/arch/i386/crashdump-x86.h \
kexec/arch/i386/kexec-x86.c +2 -0
@@ -32,6 +32,7 @@#include "crashdump-x86.h" #include <arch/options.h> +#ifndef __MINGW32__static struct memory_range memory_range[MAX_MEMORY_RANGES ];/* Return a sorted list of memory ranges. */
@@ -113,6 +114,7 @@ int get_memory_ranges(struct memory_range **range, int *ranges, *ranges = memory_ranges;return 0 ; } +#endif /* !defined(__MINGW32__) */ struct file_type file_type[] = { {"multiboot-x86" , multiboot_x86_probe, multiboot_x86_load,
kexec/arch/i386/x86-linux-setup.c +4 -0
@@ -23,8 +23,10 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#ifndef __MINGW32__#include <sys/ioctl.h> #include <linux/fb.h> +#endif #include <unistd.h> #include <x86/x86-linux.h> #include "../../kexec.h"
@@ -101,6 +103,7 @@ void setup_linux_bootloader_parameters(int setup_linux_vesafb (struct x86_linux_param_header *real_mode) { +#ifndef __MINGW32__struct fb_fix_screeninfo fix;struct fb_var_screeninfo var;int fd;
@@ -153,6 +156,7 @@ int setup_linux_vesafb(struct x86_linux_param_header *real_mode) out:close (fd); +#endif /* !defined(__MINGW32__) */ return -1 ; }
kexec/kexec-syscall.h +7 -0
@@ -1,6 +1,8 @@#ifndef KEXEC_SYSCALL_H #define KEXEC_SYSCALL_H +#ifndef __MINGW32__ +#define __LIBRARY__#include <syscall.h> #include <sys/syscall.h>
@@ -69,6 +71,11 @@ static inline long kexec_reboot(void) return (long) syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_KEXEC, 0); } +#else /* defined(__MINGW32__) */ +extern long kexec_load (void *entry,unsigned long nr_segments, +struct kexec_segment *segments,unsigned long flags); +extern long kexec_reboot (void ); +#endif /* defined(__MINGW32__) */ #define KEXEC_ON_CRASH 0x00000001#define KEXEC_ARCH_MASK 0xffff0000
kexec/kexec.c +4 -0
@@ -804,6 +804,7 @@ static int kexec_loaded(void)/* check we retained the initrd */ void check_reuse_initrd (void ) { +#ifndef __MINGW32__FILE * fp;char * line =NULL ;size_t len =0 ;
@@ -814,11 +815,14 @@ void check_reuse_initrd(void)die ("unable to open /proc/cmdline\n" ); read =getline (&line, &len, fp); if (strstr(line, "retain_initrd") == NULL) +#endif die ("unrecoverable error: current boot didn't " "retain the initrd for reuse.\n" ); +#ifndef __MINGW32__if (line)free (line);fclose (fp); +#endif }int main (int argc,char *argv[])
kexec/kexec.h +10 -0
@@ -8,7 +8,13 @@#include <stdint.h> #define USE_BSD #include <byteswap.h> +#ifdef __MINGW32__ +#include <sys/param.h> +extern int getpagesize (void ); +#define sync () +#else #include <endian.h> +#endif #define _GNU_SOURCE#include "kexec-elf.h"
@@ -217,7 +223,11 @@ extern unsigned long add_buffer_phys_virt(struct kexec_info *info, int buf_end, int phys);extern void arch_reuse_initrd (void ); +#ifdef __MINGW32__ +#define ifdown () +#else extern int ifdown (void ); +#endif extern unsigned char purgatory[];extern size_t purgatory_size;
kexec/win32.c new file +214 -0
214 lines not on this page · raw message
Signature · 7 lines
1.5.4.1 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines · Jamey Sharp
OK, I haven't quite gotten around to posting the Windows kernel driver source that goes with this.
Do you plan to release the driver sources? Is there a driver binary available for now?
kexec/win32.c line 72
Quoted 7 lines
kexec/win32.c new file +7
-0+ +if (memory_range) + { + *range = memory_range; + *ranges = memory_ranges; +return 0 ; + }
I think you should use the kernel coding style here, i.e. the '{' in the same line as the 'if'.
Bernhard
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 5 lines · Bernhard Walle
Quoted 2 lines · Jamey Sharp
OK, I haven't quite gotten around to posting the Windows kernel driver source that goes with this.
Do you plan to release the driver sources?
Yes, and I've finally done so. The code I wrote is licensed under GPLv2 or later; some Linux kernel source is included verbatim or with modifications, and is licensed accordingly.
http://source.thetovacompany.com/kexec-win/
I've only tried cross-compiling this code from Linux. In principle it should build with MinGW on Windows as well, if anyone cares. :-)
My versions of machine_kexec_32.c and relocate_kernel_32.S have some changes. I've been trying to find time to propose them as patches to Linux kexec, but I've been waiting until I could test them, which hasn't happened yet. I started from Linux v2.6.25 if anyone cares to diff them.
The load_kimage function in kexec.c is roughly equivalent to sys_kexec_load in Linux but with a lot less code. It doesn't handle the possibility of being allocated pages at addresses that won't fit in an unsigned long. But I think it handles everything else that Linux does, with less complexity. I'd really like to get review on that, and see if something like my algorithm should go into the Linux implementation too.
Quoted 10 lines
kexec/win32.c line 72
Quoted 7 lines
kexec/win32.c new file +7
-0+ +if (memory_range) + { + *range = memory_range; + *ranges = memory_ranges; +return 0 ; + }I think you should use the kernel coding style here, i.e. the '{' in the same line as the 'if'.
I assume you mean I should use kernel style throughout, not just in the quoted bit. :-) Sure, I can do that. I was hoping for more feedback than just code style though. :-)
Jamey
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Hi,
Quoted 2 lines · Jamey Sharp
I was hoping for more feedback than just code style though. :-)
Of course. I'll give it a try first. I'm not very familar with Windows programming, though. I'm interested in kexec on Windows because it might be a nice way to start a Linux installation from Windows ...
Bernhard
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 8 lines · Jamey Sharp
Quoted 5 lines · Bernhard Walle
Quoted 2 lines · Jamey Sharp
OK, I haven't quite gotten around to posting the Windows kernel driver source that goes with this.
Do you plan to release the driver sources?
Quoted 7 lines
Yes, and I've finally done so. The code I wrote is licensed under GPLv2 or later; some Linux kernel source is included verbatim or with modifications, and is licensed accordingly.
http://source.thetovacompany.com/kexec-win/I've only tried cross-compiling this code from Linux. In principle it should build with MinGW on Windows as well, if anyone cares. :-)
That was my first approach, because I _thought_ it might be easier than cross-compiling. However, compiling kexec-tools on Windows did not work here because of several reasons. I fixed up everything, but I ended in a problem that I was not able to create a ET_REL binary of purgatory/purgatory.ro. The problem is that -Wl,--oformat didn't work (ld: cannot perform PE operations on non PE output file). Google advised me to use 'objcopy' -- however, that produced a ET_EXEC binary instead of ET_REL. The manual page of objcopy mentions
However, copying a relocatable object file between any two formats may not work as expected.
At that point, I gave up and gave the cross-compiler a try. That worked flawlessly. However, if somebody has an idea how to create a working ELF ET_REL file on Windows with Mingw, I can post the other fixups, so that we have a "clean" Windows port.
I'm also able to _compile_ the driver (also on Windows), but I don't know how to _load_ the driver. Running kexec -l on Windows gave me an error message that loading fails, and it seems that the driver device file is just not there.
Can you please advise me here?
Bernhard
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 7 lines · Jamey Sharp
OK, I haven't quite gotten around to posting the Windows kernel driver source that goes with this. So I'm not asking that this patch be merged, since nobody else can use it yet. :-) I'd love to get review, though:
Does this look like it's in a mergeable state? I'm happy with it, but do I need to change anything to make it acceptable to you folks?This patch requires basically all the other patches I've posted.
Hi Jamey,
Firstly, thanks for your work in not only getting this port up and going, but methodically posted patches relating to it. You have made my job very easy :-)
The patch looks a little invasive, but I guess that is to be expected given the nature of what you re doing. I wonder if there will be other equally different ports (by which I mean its the first time the code has been made to work outside of some Linux environment) and thus whether it is worth abstracting some of these things somehow. Just a thought. I'm not opposed to the patch as it is.
Can you advise if there is any way to cross compile this code on a Linux (i686) box? Its not critical, I'm more curious than anything else. But if it is possible, it would at least allow me to check that the code still compiles as other changes get merged in over time.
The licence in include/byteswap.h. How does that effect the licencing of the rest of the code? Is it going to cause any distributions - I am thinking about Debian - to have a cow?
Lastly, I'm a big fan of <= 80 character wide lines.
Signature · 1 line
Horms
Quoted 455 lines
Makefile.in | 1 + include/byteswap.h | 39 +++++++ kexec/Makefile | 6 + kexec/arch/i386/Makefile | 2 + kexec/arch/i386/kexec-x86.c | 2 + kexec/arch/i386/x86-linux-setup.c | 4 + kexec/kexec-syscall.h | 7 ++ kexec/kexec.c | 4 + kexec/kexec.h | 10 ++ kexec/win32.c | 214 +++++++++++++++++++++++++++++++++++++ 10 files changed, 289 insertions(+), 0 deletions(-) create mode 100644 include/byteswap.h create mode 100644 kexec/win32.cMakefile.in +1
-0@@ -24,6 +24,7 @@ ARCH = @ARCH@ OBJDIR = @OBJDIR@ target = @target@ host = @host@ +host_os = @host_os@ # Compiler for building kexec CC = @CC@include/byteswap.h new file +39
-0@@ -0,0 +1,39 @@ +/* byteswap.h + +Copyright 2005 Red Hat, Inc. + +This file is part of Cygwin. + +This software is a copyrighted work licensed under the terms of the +Cygwin license. Please consult the file "CYGWIN_LICENSE" for +details. */ + +#ifndef _BYTESWAP_H +#define _BYTESWAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +static __inlineunsigned short +bswap_16 (unsigned short __x) +{ +return (__x >>8 ) | (__x <<8 ); +} + +static __inlineunsigned int +bswap_32 (unsigned int __x) +{ +return (bswap_16 (__x &0xffff ) <<16 ) | (bswap_16 (__x >>16 )); +} + +static __inlineunsigned long long +bswap_64 (unsigned long long __x) +{ +return (((unsigned long long )bswap_32 (__x &0xffffffffull )) <<32 ) | (bswap_32 (__x >>32 )); +} + +#ifdef __cplusplus +} +#endif +#endif /* _BYTESWAP_H */ kexec/Makefile +6
-0@@ -11,16 +11,22 @@ KEXEC_SRCS = KEXEC_GENERATED_SRCS = KEXEC_SRCS += kexec/kexec.c +ifneq ($(host_os),mingw32msvc) KEXEC_SRCS += kexec/ifdown.c +endif KEXEC_SRCS += kexec/kexec-elf.c KEXEC_SRCS += kexec/kexec-elf-exec.c KEXEC_SRCS += kexec/kexec-elf-core.c KEXEC_SRCS += kexec/kexec-elf-rel.c KEXEC_SRCS += kexec/kexec-elf-boot.c KEXEC_SRCS += kexec/kexec-iomem.c +ifneq ($(host_os),mingw32msvc) KEXEC_SRCS += kexec/crashdump.c KEXEC_SRCS += kexec/crashdump-xen.c KEXEC_SRCS += kexec/phys_arch.c +else +KEXEC_SRCS += kexec/win32.c +endif KEXEC_GENERATED_SRCS += $(PURGATORY_HEX_C)kexec/arch/i386/Makefile +2
-0@@ -9,7 +9,9 @@ i386_KEXEC_SRCS += kexec/arch/i386/kexec-multiboot-x86.c i386_KEXEC_SRCS += kexec/arch/i386/kexec-beoboot-x86.c i386_KEXEC_SRCS += kexec/arch/i386/kexec-nbi.c i386_KEXEC_SRCS += kexec/arch/i386/x86-linux-setup.c +ifneq ($(host_os),mingw32msvc) i386_KEXEC_SRCS += kexec/arch/i386/crashdump-x86.c +endif dist += kexec/arch/i386/Makefile $(i386_KEXEC_SRCS) \ kexec/arch/i386/kexec-x86.h kexec/arch/i386/crashdump-x86.h \kexec/arch/i386/kexec-x86.c +2
-0@@ -32,6 +32,7 @@#include "crashdump-x86.h" #include <arch/options.h> +#ifndef __MINGW32__static struct memory_range memory_range[MAX_MEMORY_RANGES ];/* Return a sorted list of memory ranges. */ @@ -113,6 +114,7 @@ int get_memory_ranges(struct memory_range **range, int *ranges, *ranges = memory_ranges;return 0 ; } +#endif /* !defined(__MINGW32__) */ struct file_type file_type[] = { {"multiboot-x86" , multiboot_x86_probe, multiboot_x86_load,kexec/arch/i386/x86-linux-setup.c +4
-0@@ -23,8 +23,10 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#ifndef __MINGW32__#include <sys/ioctl.h> #include <linux/fb.h> +#endif #include <unistd.h> #include <x86/x86-linux.h> #include "../../kexec.h" @@ -101,6 +103,7 @@ void setup_linux_bootloader_parameters(int setup_linux_vesafb (struct x86_linux_param_header *real_mode) { +#ifndef __MINGW32__struct fb_fix_screeninfo fix;struct fb_var_screeninfo var;int fd;@@ -153,6 +156,7 @@ int setup_linux_vesafb(struct x86_linux_param_header *real_mode) out:close (fd); +#endif /* !defined(__MINGW32__) */ return -1 ; }kexec/kexec-syscall.h +7
-0@@ -1,6 +1,8 @@#ifndef KEXEC_SYSCALL_H #define KEXEC_SYSCALL_H +#ifndef __MINGW32__ +#define __LIBRARY__#include <syscall.h> #include <sys/syscall.h> @@ -69,6 +71,11 @@ static inline long kexec_reboot(void) return (long) syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_KEXEC, 0); } +#else /* defined(__MINGW32__) */ +extern long kexec_load (void *entry,unsigned long nr_segments, +struct kexec_segment *segments,unsigned long flags); +extern long kexec_reboot (void ); +#endif /* defined(__MINGW32__) */ #define KEXEC_ON_CRASH 0x00000001#define KEXEC_ARCH_MASK 0xffff0000kexec/kexec.c +4
-0@@ -804,6 +804,7 @@ static int kexec_loaded(void)/* check we retained the initrd */ void check_reuse_initrd (void ) { +#ifndef __MINGW32__FILE * fp;char * line =NULL ;size_t len =0 ;@@ -814,11 +815,14 @@ void check_reuse_initrd(void)die ("unable to open /proc/cmdline\n" ); read =getline (&line, &len, fp); if (strstr(line, "retain_initrd") == NULL) +#endif die ("unrecoverable error: current boot didn't " "retain the initrd for reuse.\n" ); +#ifndef __MINGW32__if (line)free (line);fclose (fp); +#endif }int main (int argc,char *argv[])kexec/kexec.h +10
-0@@ -8,7 +8,13 @@#include <stdint.h> #define USE_BSD #include <byteswap.h> +#ifdef __MINGW32__ +#include <sys/param.h> +extern int getpagesize (void ); +#define sync () +#else #include <endian.h> +#endif #define _GNU_SOURCE#include "kexec-elf.h" @@ -217,7 +223,11 @@ extern unsigned long add_buffer_phys_virt(struct kexec_info *info, int buf_end, int phys);extern void arch_reuse_initrd (void ); +#ifdef __MINGW32__ +#define ifdown () +#else extern int ifdown (void ); +#endif extern unsigned char purgatory[];extern size_t purgatory_size;kexec/win32.c new file +204
-0@@ -0,0 +1,214 @@ +#include "kexec.h" +#include "kexec-syscall.h" +#include <errno.h> +#include <stddef.h> +#define _WIN32_WINNT 0x0501 +#include <windows.h> +#include <ddk/ntddk.h> + +#define IOCTL_LOAD_KERNEL CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS) + +struct kexec_user_segment { +size_t bufsz; +unsigned long mem; +size_t memsz; +}; + +struct kexec_user_buffer { +unsigned long entry; +unsigned long kexec_flags; +int nr_segments; +struct kexec_user_segment segments[0 ]; +}; + +int getpagesize (void ) +{ +SYSTEM_INFO sysinfo; +GetNativeSystemInfo (&sysinfo); +return sysinfo.dwPageSize; +} + +long physical_arch (void ) +{ +SYSTEM_INFO sysinfo; +GetNativeSystemInfo (&sysinfo); +switch (sysinfo.wProcessorArchitecture) { +case PROCESSOR_ARCHITECTURE_INTEL : +/* For compatibility with older patches +* use KEXEC_ARCH_DEFAULT instead of KEXEC_ARCH_386 here. +*/ +return KEXEC_ARCH_DEFAULT ; + +case PROCESSOR_ARCHITECTURE_AMD64 : +return KEXEC_ARCH_X86_64 ; + } +fprintf (stderr,"Unsupported machine type: %d\n" , + sysinfo.wProcessorArchitecture); +return -1 ; +} + +int get_memory_ranges (struct memory_range **range,int *ranges, +unsigned long kexec_flags) +{ +static struct memory_range *memory_range; +static int memory_ranges; + +HKEY key =HKEY_LOCAL_MACHINE ; +char path[] ="HARDWARE\\RESOURCEMAP\\System Resources\\Physical Memory\\.Translated" ; +char *next = path; +char *slash; +LONG result; +DWORD size, type; +void *buf =0 ; +CM_RESOURCE_LIST *resource_list; +CM_PARTIAL_RESOURCE_LIST *partial_list; +int i; + +if (memory_range) + { + *range = memory_range; + *ranges = memory_ranges; +return 0 ; + } + +while ((slash =strchr (next,'\\' ))) + { +HKEY subkey; + *slash ='\0' ; + result =RegOpenKeyEx (key, next,0 ,KEY_READ , &subkey); +RegCloseKey (key); +if (result !=ERROR_SUCCESS ) + { +fprintf (stderr,"get_memory_ranges: registry key '%s' not found\n" , next); +return -1 ; + } + key = subkey; + next = slash +1 ; + } + +if ((result =RegQueryValueEx (key, next,0 ,0 ,0 , &size)) ==ERROR_SUCCESS ) + { + buf =malloc (size); +if (!buf) + { +RegCloseKey (key); +fprintf (stderr,"get_memory_ranges: %s\n" ,strerror (errno)); +return -1 ; + } + result =RegQueryValueEx (key, next,0 , &type, buf, &size); + } +RegCloseKey (key); +if (result !=ERROR_SUCCESS ) + { +fprintf (stderr,"get_memory_ranges: registry key '%s' not found\n" , next); + goto fail; + } +if (type !=REG_RESOURCE_LIST ) + { +fprintf (stderr,"get_memory_ranges: registry key '%s' has wrong type\n" , next); + goto fail; + } + resource_list = buf; + partial_list = &resource_list->List[0 ].PartialResourceList; + if(size < offsetof(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors) || + resource_list->Count != 1 || + size < (char *) (partial_list->PartialDescriptors + partial_list->Count) - (char *) buf) + { +fprintf (stderr,"get_memory_ranges: registry key '%s' is too small\n" , next); + goto fail; + } + + memory_ranges = partial_list->Count; + memory_range =malloc (sizeof (*memory_range) * memory_ranges); +if (!memory_range) + { +fprintf (stderr,"get_memory_ranges: %s\n" ,strerror (errno)); + goto fail; + } +for (i =0 ; i < memory_ranges; ++i) + { +if (partial_list->PartialDescriptors[i].Type != CmResourceTypeMemory) + { +free (memory_range); + memory_range =0 ; +fprintf (stderr,"get_memory_ranges: range %d is not memory\n" , i +1 ); + goto fail; + } + memory_range[i].start = partial_list->PartialDescriptors[i].u.Memory.Start.QuadPart; + memory_range[i].end = memory_range[i].start + partial_list->PartialDescriptors[i].u.Memory.Length; + memory_range[i].type =RANGE_RAM ; + } + + *range = memory_range; + *ranges = memory_ranges; +return 0 ; + +fail: +free (buf); +return -1 ; +} + +long kexec_load (void *entry,unsigned long nr_segments, +struct kexec_segment *segments,unsigned long flags) +{ +struct kexec_user_buffer *image; +long size =sizeof (*image) + nr_segments *sizeof (*image->segments); +DWORD bytes_returned; +char *tmp; +int i, success; + +for (i =0 ; i < nr_segments; ++i) + size += segments[i].bufsz; + + image =malloc (size); +if (!image) +return -1 ; + + image->entry = (unsigned long ) entry; + image->kexec_flags = flags; + image->nr_segments = nr_segments; + tmp = (char *) (image->segments + nr_segments); +for (i =0 ; i < nr_segments; ++i) + { + image->segments[i].bufsz = segments[i].bufsz; + image->segments[i].mem = (unsigned long ) segments[i].mem; + image->segments[i].memsz = segments[i].memsz; +memcpy (tmp, segments[i].buf, segments[i].bufsz); + tmp += segments[i].bufsz; + } + +HANDLE device =CreateFile (TEXT ("\\\\.\\kexec" ), +/* open mode */ 0 , +FILE_SHARE_READ |FILE_SHARE_WRITE , +/* security attributes */ NULL , +OPEN_EXISTING , +/* file attributes */ 0 , +/* template file */ NULL ); + + success = device !=INVALID_HANDLE_VALUE &&DeviceIoControl (device, +IOCTL_LOAD_KERNEL , + image, size, +NULL ,0 , &bytes_returned, +/* async structure */ (LPOVERLAPPED )NULL ); + +CloseHandle (device); +free (image); +return success ?0 :-1 ; +} + +long kexec_reboot (void ) +{ + errno =ENOSYS ; +return -1 ; +} +
kexec/win32.c line 214
Quoted 10 lines
kexec/win32.c new file +10
-0+int load_crashdump_segments (struct kexec_info *info,char * mod_cmdline, +unsigned long max_addr,unsigned long min_base) +{ +return -1 ; +} + +int is_crashkernel_mem_reserved (void ) +{ +return 0 ; +}
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Quoted 3 lines · Simon Horman
Firstly, thanks for your work in not only getting this port up and going, but methodically posted patches relating to it. You have made my job very easy :-)
I tried. I'm happy to hear I succeeded. :-)
Quoted 5 lines
The patch looks a little invasive, but I guess that is to be expected given the nature of what you re doing. I wonder if there will be other equally different ports (by which I mean its the first time the code has been made to work outside of some Linux environment) and thus whether it is worth abstracting some of these things somehow. Just a thought.
Someone contacted me off-list about doing the same thing for MacOS X, which my employer wants as well. And I could imagine interest in similar work for various BSDs and others. So yes, making the code base more portable would make some people happy.
There were a few cases where I added #ifdefs and Makefile conditionals that might affect other porters. Here are some suggestions for improving the kexec-tools' portability; I hope somebody else can pick them up...
The largest affected pieces of code were for crashdump kernel loading. I have no idea how to hook the BSOD in Windows. :-) Other platforms will probably have the same problem. Allowing all crashdump support to be disabled at compile time would be an independent helpful patch.
Some code is architecture-specific on Linux but may be platform-generic elsewhere. The get_memory_ranges function is an example: I think the copy in win32.c will work on all architectures that Windows supports, but /proc/iomem apparently is formatted a little differently on different Linux architectures. The physical_arch function I recently introduced should be another example, though its implementation is presently a bit kludged. I don't know how best to structure the code when some implementations should be in arch/ and some shouldn't.
I think get_memory_ranges could stand to be completely refactored. First, the kexec-tools only require RANGE_RAM, AFAICT, so parsing more information out of /proc/iomem is wasted effort and extra maintenance cost. Then, most implementations are very similar. Looking over all the implementations and seeing how they can be unified would help.
Finally, there are a handful of features that are not very portable and may not be so useful on other platforms anyway:
- shutdown/reboot
- current video mode detection
- reusing kernel command line or initrd
- bringing down network interfaces
Making it easier to omit those features at compile-time would help with porting. I chose minimal-patch approaches for all of these, rather than clean fixes.
Quoted 1 line
I'm not opposed to the patch as it is.
Awesome! I have very little time left to clean it up further, though like you I wish I were offering a less-invasive patch.
Quoted 2 lines
Can you advise if there is any way to cross compile this code on a Linux (i686) box?
Oh, I meant to mention that. I did all this development on a Debian x86-64 box; I cross-compiled everything for 32-bit targets as that's all I cared about. So my configure command is:
./configure --host=i586-mingw32msvc --target=i486-linux-gnu \
--build=x86_64-linux-gnu TARGET_CC="gcc -m32"(I overrode TARGET_CC because I don't have an "i486-linux-gnu-gcc", just the 64-bit GCC with "-m32".)
Quoted 3 lines
The licence in
include/byteswap.h. How does that effect the licencing of the rest of the code? Is it going to cause any distributions - I am thinking about Debian - to have a cow?
I meant to mention that too. :-) Apparently the Cygwin license mentioned there can be found here:
http://cygwin.com/license.html
It's GPLv2, with a special exception for linking with code that meets the OSI's Open Source definition.
If anyone is concerned, byteswap.h can be rewritten from scratch in a few minutes. :-) Last I checked, GCC on x86 generates the special x86 byte-swap instructions when fed the naive shift/or C implementation, so byteswap.h doesn't need to be anything fancy.
Quoted 1 line
Lastly, I'm a big fan of <= 80 character wide lines.
OK. I'll resubmit with 80-column line limits and the kernel brace style.
Jamey
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec