Author Topic: webkitgtk problem  (Read 15364 times)

Offline skid

  • Jr. Member
  • *
  • Posts: 6
webkitgtk problem
« on: January 01, 2015, 03:37:08 PM »
i tried to convert the "one window browser" code from https://wiki.gnome.org/Projects/WebKitGtk/ProgrammingGuide/Tutorial#One-Window_Browser
the code compiles and runs, but nothing happends

Code: [Select]
[bits 64]
global main

; functions
extern webkit_web_view_new
extern webkit_web_view_load_uri
extern gtk_init
extern gtk_main
extern gtk_window_new
extern gtk_widget_show_all
extern gtk_container_add
extern gtk_window_set_default_size
extern gtk_widget_grab_focus
;extern g_signal_connect

section .data
mainwindow dq 0
web_view dq 0
uri db "http://www.google.com"

section .text

main:
mov rdi, 0
push rdi
call gtk_init
add rsp, 4

mov rdi, 0 ;GTK_WINDOW_TOPLEVEL
push rdi
call gtk_window_new
mov [mainwindow], rax
add rsp, 4

jmp $
mov rdi, [mainwindow]
mov rbx, 800
mov rcx, 600
push rdi
push rbx
push rcx
call gtk_window_set_default_size
add rsp, 4

mov rdi,0
push rdi
call webkit_web_view_new
mov [web_view], rax
add rsp, 4

mov rdi, [mainwindow]
mov rsi, [web_view]
push rdi
push rsi
call gtk_container_add
add rsp, 4

mov rdi, [web_view]
push rdi
call gtk_widget_grab_focus
add rsp, 4

mov rdi, [mainwindow]
push rdi
call gtk_widget_show_all
add rsp, 4

mov rdi, 0
push rdi
call gtk_main

gdb segfault 0x00007ffff087b7f4 in g_object_new () from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0

i put a jmp $ before the gtk_grabfocus_all call without segfault

i guess one problem lies in web_view

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: webkitgtk problem
« Reply #1 on: January 01, 2015, 03:58:08 PM »
i guess one problem lies in web_view

Hi!

Well, yes, problem is certainly that web_view ,no other thing to blame, stop using it, try different kit.
Encryptor256's Investigation \ Research Department.

Offline skid

  • Jr. Member
  • *
  • Posts: 6
Re: webkitgtk problem
« Reply #2 on: January 01, 2015, 09:01:15 PM »
like what? (that wouldn't cause similar problems)

besides, the problem is with gtk, same problem with hello gtk apps.
« Last Edit: January 01, 2015, 09:54:17 PM by skid »

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: webkitgtk problem
« Reply #3 on: January 02, 2015, 03:08:12 AM »
Wow, you are all over the place with that  code!  Maybe start with the basics and learn calling conventions.

gtk_init takes 2 parameters:
Code: [Select]
void gtk_init (int *argc, char ***argv);Your only filling in argc.

gtk_main takes no parameters but you are filling in (unnecessarily) rdi.

All of those pushes and pop are also unnecessarily.  You are doing it to align the stack, but since your main function gets called from someplace else, all that is needed is a sub rsp, 8 at the beginning.

I haven't really looked at the other function calls, but  what are you doing here:
Code: [Select]
mov rdi, [mainwindow]
mov rbx, 800
mov rcx, 600
push rdi
push rbx
push rcx
call gtk_window_set_default_size
add rsp, 4

Parameters are not pushed onto the stack but put in registers.  I will assume this is for *nix and not Windows since you are using rdi.  Parameters are passed left to right:
rdi, rsi, rdx, rcx, r8, r9, and anymore are pushed onto the stack.

Code: [Select]
void gtk_window_set_default_size (GtkWindow *window, gint width, gint height);Would be called like this:
Code: [Select]
    mov     rdx, 600
    mov     rsi, 800
    mov     rdi, [window]
    call    gtk_window_set_default_size

You cannot just use whatever registers you feel like, you have to follow the ABI for your OS.  I am downloading the webkit devel files and will show how its done.


Offline skid

  • Jr. Member
  • *
  • Posts: 6
Re: webkitgtk problem
« Reply #4 on: January 02, 2015, 03:30:35 AM »
thanks i'm new to 64bit assembly, couldn't compile 32 bit version.

Offline Gunner

  • Jr. Member
  • *
  • Posts: 74
  • Country: us
    • Gunners Software
Re: webkitgtk problem
« Reply #5 on: January 02, 2015, 04:00:49 AM »
Code: [Select]
extern gtk_init, gtk_window_new, gtk_window_set_default_size
extern gtk_container_add, gtk_widget_grab_focus, gtk_widget_show_all
extern g_signal_connect_data, gtk_main_quit, gtk_widget_destroy
extern gtk_main, exit, webkit_web_view_new, webkit_web_view_load_uri

GTK_WINDOW_TOPLEVEL         equ 0
NULL                        equ 0

section .rodata
szURL       db "http://www.webkitgtk.org/", 0
szDestroy   db "destroy", 0
szClose     db "close", 0

global main
section .text
main:

    ; use this to pass argc and argv to gtk_init
    ;~ sub     rsp, 8 * 3
   
    ;~ mov     [rsp + 8], rdi                  ; argc
    ;~ mov     [rsp], rsi                      ; argv
    ;~ mov     rsi, rsp       
    ;~ lea     rdi, [rsp + 8]
    ;~ call    gtk_init
    ;~
   
    sub     rsp, 8                          ; align stack
   
    ;~ Initialize GTK+
    mov     rsi, 0
    mov     rdi, 0
    call    gtk_init
   
    ;~ Create an 800x600 window that will contain the browser instance
    mov     rdi, GTK_WINDOW_TOPLEVEL
    call    gtk_window_new
    mov     r15, rax
   
    mov     rdx, 400
    mov     rsi, 400
    mov     rdi, rax
    call    gtk_window_set_default_size

    ;~ Create a browser instance
    call    webkit_web_view_new
    mov     r14, rax
   
    ;~ Put the browser area into the main window
    mov     rsi, rax
    mov     rdi, r15
    call    gtk_container_add
   
    ;~ Set up callbacks so that if either the main window or the browser instance is
    ;~ closed, the program will exit
    mov     r9, 0
    mov     r8, 0
    mov     rcx, NULL
    mov     rdx, gtk_main_quit
    mov     rsi, szDestroy
    mov     rdi, r15
    call    g_signal_connect_data

    mov     r9, 0
    mov     r8, 0   
    mov     rcx, r15
    mov     rdx, closeWebViewCb
    mov     rsi, szClose
    mov     rdi, r14
    call    g_signal_connect_data
   
    ;~ Load a web page into the browser instance
    mov     rsi, szURL
    mov     rdi, r14
    call    webkit_web_view_load_uri
   
    ;~ Make sure that when the browser area becomes visible, it will get mouse
    ;~ and keyboard events
    mov     rdi, r14
    call    gtk_widget_grab_focus
   
    ;~ Make sure the main window and all its contents are visible
    mov     rdi, r15
    call    gtk_widget_show_all
   
    ;~ Run the main GTK+ event loop
    call    gtk_main
   
    mov     rdi, 0
    call    exit
   
closeWebViewCb:
    sub     rsp, 8
   
    mov     rdi, rsi
    call    gtk_widget_destroy
   
    add     rsp, 8
    ret

Direct translation from https://wiki.gnome.org/Projects/WebKitGtk/ProgrammingGuide/Tutorial
« Last Edit: January 02, 2015, 04:02:31 AM by Gunner »

Offline skid

  • Jr. Member
  • *
  • Posts: 6
Re: webkitgtk problem
« Reply #6 on: January 02, 2015, 04:45:05 AM »
[deleted]
« Last Edit: January 02, 2015, 06:52:38 AM by skid »

Offline skid

  • Jr. Member
  • *
  • Posts: 6
Re: webkitgtk problem
« Reply #7 on: January 02, 2015, 05:55:23 AM »
deleted
« Last Edit: January 02, 2015, 06:23:59 AM by skid »

Offline skid

  • Jr. Member
  • *
  • Posts: 6
Re: webkitgtk problem
« Reply #8 on: January 02, 2015, 07:10:23 AM »
thanks alot gunner, got any pointer to a good x64 assembly calling conventions?

posting code for further reference:
Code: [Select]
global main

extern gtk_window_new, gtk_window_set_default_size
extern gtk_widget_grab_focus, gtk_widget_show_all, gtk_widget_destroy
extern gtk_container_add
extern gtk_main, gtk_main_quit, gtk_init
extern g_signal_connect_data

extern webkit_web_view_new, webkit_web_view_load_uri

GTK_WINDOW_TOPLEVEL         equ 0
NULL                        equ 0

section .rodata
uri       db "http://www.google.com", 0
kill   db "destroy", 0
die     db "close", 0

section .data
main_window dq 0
web_view    dq 0

section .text
main

    ; use this to pass argc and argv to gtk_init
    ;~ sub     rsp, 8 * 3
   
    ;~ mov     [rsp + 8], rdi                  ; argc
    ;~ mov     [rsp], rsi                      ; argv
    ;~ mov     rsi, rsp       
    ;~ lea     rdi, [rsp + 8]
    ;~ call    gtk_init
    ;~
   
    sub     rsp, 8                          ; align stack
   
    ;~ Initialize GTK+
    mov     rsi, 0
    mov     rdi, 0
    call    gtk_init
   
    mov     rdi, 0 ;GTK_WINDOW_TOPLEVEL
    call    gtk_window_new
    mov     [main_window], rax
   
    mov     rdx, 600
    mov     rsi, 800
    mov     rdi, rax
    call    gtk_window_set_default_size

    ;~ Create a browser instance
    call    webkit_web_view_new
    mov [web_view], rax


    ;~ Put the browser area into the main window
    mov     rsi, [web_view]
    mov     rdi, [main_window]
    call    gtk_container_add
   
    ;~ Set up callbacks so that if either the main window or the browser instance is
    ;~ closed, the program will exit
    mov     r9, 0
    mov     r8, 0
    mov     rcx, NULL
    mov     rdx, gtk_main_quit
    mov     rsi, kill
    mov     rdi, r15
    call    g_signal_connect_data

    mov     r9, 0
    mov     r8, 0   
    mov     rcx, r15
    mov     rdx, closeWebViewCb
    mov     rsi, die
    mov     rdi, r14
    call    g_signal_connect_data
   
    ;~ Load a web page into the browser instance
    mov     rsi, uri
    mov     rdi, [web_view]
    call    webkit_web_view_load_uri
   
    ;~ Make sure that when the browser area becomes visible, it will get mouse
    ;~ and keyboard events
    mov     rdi, [web_view]
    call    gtk_widget_grab_focus
   
    ;~ Make sure the main window and all its contents are visible
    mov     rdi, [main_window]
    call    gtk_widget_show_all
   
    ;~ Run the main GTK+ event loop
    call    gtk_main
   
    mov     rdi, 0
    call    exit
   
closeWebViewCb:
    sub     rsp, 8
   
    mov     rdi, rsi
    call    gtk_widget_destroy
   
    add     rsp, 8
    ret
[ret]

special greetings to the first replier
« Last Edit: January 02, 2015, 07:13:01 AM by skid »