External SIGSEGV when using System.move lazarus / 32-Linux ---------------------------------------------------------------------- safa · 2016-01-07 21:07 Hi, I'm using System.Move function to copy data from a memoryStream to a pointer, this way: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i data:=fpmmap(nil,filesize,prot_read or prot_write, map_shared, fp, 0);IDHTTP1.Get(url, stream);System.move(stream,data^,fileSize);fpMunmap(data,fileSize);   data is declared as a pointer, stream is a TMemoryStream, when I execute the code, I get the exception External SIGSEGV, ans the windows of the assembler shows SYSTEM_MOVE, what's wrong with my code? ---------------------------------------------------------------------- balazsszekely · 2016-01-07 21:29 Did you know there is a Stream.Memory pointer? Why don't you use it? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IDHTTP1.Get(Url, Stream);if Stream.Size > 0begin  Stream.Postion := 0;  System.Move(Stream.Memory^, Data^, Stream.Size);end;or Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i IDHTTP1.Get(Url, Stream);if Stream.Size > 0begin  Stream.Postion := 0;  Stream.ReadBuffer(Data^, Stream.Size);end; ---------------------------------------------------------------------- safa · 2016-01-07 22:32 I'm getting the same error ---------------------------------------------------------------------- Cyrax · 2016-01-07 22:36 Try to change file mapping functions to instance of TFileStream class. ---------------------------------------------------------------------- balazsszekely · 2016-01-08 05:46 Perhaps we can help, if you describe what exactly are you trying to achieve. Did you see your other memory mapping related thread? http://forum.lazarus.freepascal.org/index.php/topic,31000.msg197811.ht ml#msg197811 ---------------------------------------------------------------------- safa · 2016-01-08 17:16 Quote from: GetMem on January 08, 2016, 06:46:27 amPerhaps we can help, if you describe what exactly are you trying to achieve. Did you see your other memory mapping related thread? http://forum.lazarus.freepascal.org/index.php/topic,31000.msg197811.ht ml#msg197811 In fact, I took a look at your suggestions (windows map file), and I'm about to try the code in my app. I want to create a multi-plateforme application that requires using map file, so I need to know how to create a map file in windows and linux. Now the thing is: creating a map file in windows is not a problem unless when I use Lazarus, it's a bit different that's why I posted my question, creating a map file in Debian is a bit difficult because I couldn't find a useful tutorial online, except this one : http://www.freepascal.org/docs-html/rtl/baseunix/fpmmap.html , but it shows only how to create a map file, it doesnt show how a secondary thread opens a view and writes data in it, cause in my app: the map file is created by  a main thread, then this one sends the map file to secondary threads, these threads write data simultaneously using views. Now, there are some tutos available in C, I'll try to translate them. Well, i'm gonna start with creating the map file in windows (I'm gonna help myself with your suggestions), then I'll turn to Debian, that's the whole thing. I whish I was clear in my explanation ---------------------------------------------------------------------- balazsszekely · 2016-01-08 17:35 Hi safa, Quote I whish I was clear in my explanation Yes, it's clear now! I saw that you try to download something from the net, with indy, then map it to a memory file. To simulate your situation, I created a small php script, wich returns a json, nothing fancy here: Code: PHP  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i FName = "John";  $People->LName  = "Smith";     $People->Age = "29";   echo json_encode($People);?>Save the script as "Lazarus.php", then copy to your local/remote htdocs folder. Make sure the server is running. Now from lazarus(this is for linux, not windows): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses BaseUnix, Unix; function GetDataFromURL(const AURL: String; var AMs: TMemoryStream): Boolean;var  IdHTTP: TIdHTTP;begin  Result := False;  IdHTTP := TIdHTTP.Create(nil);  try    IdHTTP.Get(AURL, AMs);    Result := AMs.Size > 0;    if Result then      AMs.Position := 0;  finally    IdHTTP.Free;  end;end; function WriteTextToFile(const AFileName, AText: String): Boolean;var  Len: LongInt;  hFile: CInt;begin  Result := False;  hFile := fpOpen(AFileName, O_WRONLY or O_CREAT);  if hFile <> -1 then  begin    Len := Length(AText);    Result := fpWrite(hfile, AText[1], Len) > -1;    FpClose(hFile);  end;end; procedure TForm1.Button1Click(Sender: TObject);var  URL, FileName: String;  Ms: TMemoryStream;  Str: String;  hFile: CInt;  Len: LongInt;  mMap: Pointer;begin  URL := 'http://localhost/Lazarus.php';  FileName := ExtractFilePath(Application.ExeName) + 'test.txt';  Ms := TMemoryStream.Create;  try    if GetDataFromURL(URL, Ms) then    begin       Len := Ms.Size div SizeOf(Char);       SetLength(Str, Len);       Move(MS.Memory^, Pointer(Str)^, Len);       if WriteTextToFile(FileName, Str) then       begin         hFile := fpOpen(FileName, O_RDWR OR O_SYNC);         if hFile <> -1  then       begin           mMap := fpmmap(nil, Ms.Size, PROT_READ or PROT_WRITE, MAP_SHARED, hFile, 0);           if LongInt(mMap) <> -1 then           begin              ShowMessage('Memory mapped file succesfully created!');              //do whatever you have to do with the memory file              fpMUnMap(mMap, Len);            end;         fpClose(hFile);          end;       end;    end;  finally    Ms.Free;  end;end; The map file is successfully created, you have to implement the parallel access from other thread/process. QuoteNow, there are some tutos available in C, I'll try to translate them.Yes, I agree. For linux, you will have to translate a few things from C Hope this helps! regards, GetMem ---------------------------------------------------------------------- safa · 2016-01-09 10:39 Quote from: GetMem on January 08, 2016, 06:35:08 pmThe map file is successfully created, you have to implement the parallel access from other thread/process. Yes, it works fine, so what I understood is that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i hFile := fpOpen(FileName, O_RDWR OR O_SYNC); :opens a local file. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mMap := fpmmap(nil, Ms.Size, PROT_READ or PROT_WRITE, MAP_SHARED, hFile, 0); :creates the map file. well, thats is what the principal thread is supposed to do, in windows it's something like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  FHandle := CreateFile(PChar(FileName), FILE_READ_DATA or FILE_WRITE_DATA, 0, nil, CREATE_ALWAYS, 0, 0);Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i hMap := CreateFileMapping(FHandle, nil, PAGE_READWRITE, 0, 0, nil);, where   FHandle type is: hFile, and hMap type is THandle. So you showed me how to create a map file using a local file. And know I have to implement this in Linux: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Http.Request.Range := Format('%d-%d',[View.Offset, View.Offset +View.Size -1]);Data := MapViewOfFile(MapFile, FILE_MAP_WRITE, View.HiOffset, View.LoOffset, View.Size);Http.Get(URL, Stream);CopyMemory(Data, Stream.Memory, View.Size);UnmapViewOfFile(Data); And it's all about: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Data := MapViewOfFile(MapFile, FILE_MAP_WRITE, View.HiOffset, View.LoOffset, View.Size);Now, it's getting clearer, about SIGSEG exception, I guess I figured things out, this exception is raised when DATA is not assigned, and it wasn't because of the value of 'fp'. And, now I'm getting the same error when trying the code above on Windows.Of course the exception is relevant to: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Data := MapViewOfFile(MapFile, FILE_MAP_WRITE, View.HiOffset, View.LoOffset, View.Size); But I can't figure things out. If you'd like to help, I'll post the code. ---------------------------------------------------------------------- matthius · 2016-04-02 18:44 External SIGSEGV when using System.move on www.extended.in on Linux i386. ---------------------------------------------------------------------- ab1jx · 2016-05-06 04:11 A SIGSEGV is because you tried to access memory that wasn't allocated to the process.  Usually due to a bad pointer, buffer overrun, too high a subscript in an array, etc.  If it dumped core you should be able to tell from that. ---------------------------------------------------------------------- matthius · 2016-08-30 18:09 OK