File init.c changed (mode: 100644) (index 90888b1..c373242) |
20 |
20 |
#endif |
#endif |
21 |
21 |
|
|
22 |
22 |
#include "modules.h" |
#include "modules.h" |
|
23 |
|
#include "uevent.h" |
23 |
24 |
#include "globals.h" |
#include "globals.h" |
24 |
25 |
|
|
25 |
26 |
#ifdef DEBUG |
#ifdef DEBUG |
|
... |
... |
k_u8 *g_dprintf_buf; |
27 |
28 |
k_i g_console; |
k_i g_console; |
28 |
29 |
#endif |
#endif |
29 |
30 |
|
|
30 |
|
static k_i uevent_sock; |
|
31 |
|
|
|
32 |
31 |
static void sigs_setup(void) |
static void sigs_setup(void) |
33 |
32 |
{ |
{ |
|
33 |
|
OUTC(PRE "setting up signals..."); |
34 |
34 |
k_ul mask=(~0); |
k_ul mask=(~0); |
35 |
35 |
k_l r=sysc(rt_sigprocmask,4,K_SIG_BLOCK,&mask,0,sizeof(mask)); |
k_l r=sysc(rt_sigprocmask,4,K_SIG_BLOCK,&mask,0,sizeof(mask)); |
36 |
36 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
37 |
|
OUTC(PRE "ERROR:unable to block all signals (except KILL and STOP ;) )\n"); |
|
38 |
|
sysc(exit_group,1,-1); |
|
39 |
|
} |
|
40 |
|
} |
|
41 |
|
|
|
42 |
|
static void uevent_setup(void) |
|
43 |
|
{ |
|
44 |
|
uevent_sock=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
|
45 |
|
K_NETLINK_KOBJECT_UEVENT); |
|
46 |
|
if(K_ISERR(uevent_sock)){ |
|
47 |
|
OUT(PRE "ERROR:unable to create uevent netlink socket:%d\n",uevent_sock); |
|
|
37 |
|
OUTC("ERROR:unable to block all signals (except KILL and STOP ;) )\n"); |
48 |
38 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
49 |
39 |
} |
} |
|
40 |
|
OUTC("done\n"); |
50 |
41 |
} |
} |
51 |
42 |
|
|
52 |
43 |
void _start(void) |
void _start(void) |
53 |
44 |
{ |
{ |
54 |
45 |
# ifdef DEBUG |
# ifdef DEBUG |
55 |
|
//FIXME:put the debug buffer in static section |
|
56 |
46 |
k_l r=sysc(open,3,"/dev/console",K_O_WRONLY,0); |
k_l r=sysc(open,3,"/dev/console",K_O_WRONLY,0); |
57 |
47 |
if(K_ISERR(r)) sysc(exit_group,1,-1); |
if(K_ISERR(r)) sysc(exit_group,1,-1); |
58 |
48 |
g_console=(k_i)r; |
g_console=(k_i)r; |
59 |
|
r=sysc(mmap,6,0, K_PAGE_SIZE, K_PROT_READ|K_PROT_WRITE, |
|
60 |
|
K_MAP_PRIVATE|K_MAP_ANONYMOUS|K_MAP_POPULATE,0,0); |
|
61 |
|
if(K_ISERR(r)){ |
|
62 |
|
OUTC(PRE "ERROR:unable to mmap a memory page for formatted output\n"); |
|
63 |
|
sysc(exit_group,1,-1); |
|
64 |
|
} |
|
65 |
|
g_dprintf_buf=(k_u8*)r;//just one page should be enough for formatted output |
|
|
49 |
|
|
|
50 |
|
static k_u8 dprintf_buf[DPRINTF_BUF_SZ]; |
|
51 |
|
g_dprintf_buf=dprintf_buf; |
66 |
52 |
# endif |
# endif |
|
53 |
|
sigs_setup(); |
|
54 |
|
proc_mount(); |
|
55 |
|
sys_mount(); |
67 |
56 |
sigs_setup(); |
sigs_setup(); |
68 |
57 |
uevent_setup(); |
uevent_setup(); |
|
58 |
|
uevent_recv_thread_start(); |
69 |
59 |
modules_load(); |
modules_load(); |
|
60 |
|
while(1); |
70 |
61 |
sysc(exit_group,1,0); |
sysc(exit_group,1,0); |
71 |
62 |
} |
} |
File makefile changed (mode: 100644) (index a47a4aa..07787c4) |
... |
... |
include conf.mk |
3 |
3 |
.PHONY:all dirs clean am_i_root help uevent_monitor |
.PHONY:all dirs clean am_i_root help uevent_monitor |
4 |
4 |
|
|
5 |
5 |
DIRS=\ |
DIRS=\ |
|
6 |
|
$(S_DIR) \ |
6 |
7 |
$(OBJ_DIR) \ |
$(OBJ_DIR) \ |
7 |
8 |
$(MODULES_DIR) \ |
$(MODULES_DIR) \ |
8 |
|
$(CPIO_DIR)/dev |
|
|
9 |
|
$(CPIO_DIR)/dev \ |
|
10 |
|
$(CPIO_DIR)/proc \ |
|
11 |
|
$(CPIO_DIR)/sys |
|
12 |
|
|
9 |
13 |
|
|
10 |
14 |
OBJS=\ |
OBJS=\ |
11 |
15 |
$(OBJ_DIR)/init.o \ |
$(OBJ_DIR)/init.o \ |
12 |
|
$(OBJ_DIR)/modules.o |
|
|
16 |
|
$(OBJ_DIR)/modules.o \ |
|
17 |
|
$(OBJ_DIR)/uevent.o |
13 |
18 |
|
|
14 |
19 |
ifdef DEBUG |
ifdef DEBUG |
15 |
20 |
ULINUX_DEBUG_OBJS=\ |
ULINUX_DEBUG_OBJS=\ |
|
... |
... |
ulinux/arch: |
40 |
45 |
|
|
41 |
46 |
#=============================================================================== |
#=============================================================================== |
42 |
47 |
ifdef DEBUG |
ifdef DEBUG |
43 |
|
$(OBJ_DIR)/mem.o:ulinux/arch/utils/mem.c |
|
44 |
|
$(CC) $(CFLAGS) -c $< -o $@ |
|
45 |
|
|
|
46 |
|
$(OBJ_DIR)/string.o:ulinux/utils/ascii/string/string.c |
|
47 |
|
$(CC) $(CFLAGS) -c $< -o $@ |
|
48 |
|
|
|
49 |
|
$(OBJ_DIR)/vsprintf.o:ulinux/utils/ascii/string/vsprintf.c |
|
50 |
|
$(CC) $(CFLAGS) -c $< -o $@ |
|
|
48 |
|
$(S_DIR)/mem.s:ulinux/arch/utils/mem.c |
|
49 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
50 |
|
$(OBJ_DIR)/mem.o:$(S_DIR)/mem.s |
|
51 |
|
$(AS) $(ASFLAGS) $< -o $@ |
|
52 |
|
|
|
53 |
|
$(S_DIR)/string.s:ulinux/utils/ascii/string/string.c |
|
54 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
55 |
|
$(OBJ_DIR)/string.o:$(S_DIR)/string.s |
|
56 |
|
$(AS) $(ASFLAGS) $< -o $@ |
|
57 |
|
|
|
58 |
|
$(S_DIR)/vsprintf.s:ulinux/utils/ascii/string/vsprintf.c |
|
59 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
60 |
|
$(OBJ_DIR)/vsprintf.o:$(S_DIR)/vsprintf.s |
|
61 |
|
$(AS) $(ASFLAGS) $< -o $@ |
51 |
62 |
endif |
endif |
52 |
63 |
#=============================================================================== |
#=============================================================================== |
53 |
64 |
|
|
|
... |
... |
$(BUILD_DIR)/initramfs.cpio:$(CPIO_DIR)/init $(CPIO_DIR)/dev/console |
58 |
69 |
chown -R 0:0 $(CPIO_DIR) |
chown -R 0:0 $(CPIO_DIR) |
59 |
70 |
DEST_FILE=$$(realpath $(BUILD_DIR))/initramfs.cpio;\ |
DEST_FILE=$$(realpath $(BUILD_DIR))/initramfs.cpio;\ |
60 |
71 |
cd $(CPIO_DIR);\ |
cd $(CPIO_DIR);\ |
61 |
|
find . -depth -print | cpio --format=newc --create >$${DEST_FILE} |
|
|
72 |
|
find . -print | cpio --format=newc --create >$${DEST_FILE} |
62 |
73 |
|
|
63 |
74 |
$(BUILD_DIR)/initramfs.cpio.xz:$(BUILD_DIR)/initramfs.cpio |
$(BUILD_DIR)/initramfs.cpio.xz:$(BUILD_DIR)/initramfs.cpio |
64 |
|
xz --force --check=crc32 --extreme $< |
|
|
75 |
|
xz --force --check=crc32 --extreme --stdout $< >$@ |
|
76 |
|
|
|
77 |
|
$(S_DIR)/modules.s:modules.c modules_list.h |
|
78 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
79 |
|
$(OBJ_DIR)/modules.o:$(S_DIR)/modules.s |
|
80 |
|
$(AS) $(ASFLAGS) $< -o $@ |
65 |
81 |
|
|
66 |
|
$(OBJ_DIR)/modules.o:modules.c modules_list.h |
|
67 |
|
$(CC) $(CFLAGS) -c $< -o $@ |
|
|
82 |
|
$(S_DIR)/uevent.s:uevent.c |
|
83 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
84 |
|
$(OBJ_DIR)/uevent.o:$(S_DIR)/uevent.s |
|
85 |
|
$(AS) $(ASFLAGS) $< -o $@ |
68 |
86 |
|
|
69 |
|
$(OBJ_DIR)/init.o:init.c modules.h |
|
70 |
|
$(CC) $(CFLAGS) -c $< -o $@ |
|
|
87 |
|
$(S_DIR)/init.s:init.c modules.h |
|
88 |
|
$(CC) $(CFLAGS) $< -o $@ |
|
89 |
|
$(OBJ_DIR)/init.o:$(S_DIR)/init.s |
|
90 |
|
$(AS) $(ASFLAGS) $< -o $@ |
71 |
91 |
|
|
72 |
92 |
$(CPIO_DIR)/init:$(OBJS) |
$(CPIO_DIR)/init:$(OBJS) |
73 |
93 |
$(LD) $(LDFLAGS) $(OBJS) --output $@ |
$(LD) $(LDFLAGS) $(OBJS) --output $@ |
|
... |
... |
clean: |
82 |
102 |
|
|
83 |
103 |
#=============================================================================== |
#=============================================================================== |
84 |
104 |
$(BUILD_DIR)/uevent_monitor:uevent_monitor.c $(ULINUX_DEBUG_OBJS) |
$(BUILD_DIR)/uevent_monitor:uevent_monitor.c $(ULINUX_DEBUG_OBJS) |
85 |
|
$(CC) $(CFLAGS) -c $< -o /tmp/uevent_monitor.o |
|
86 |
|
$(LD) $(LDFLAGS) /tmp/uevent_monitor.o $(ULINUX_DEBUG_OBJS) --output $@ |
|
|
105 |
|
$(CC) $(CFLAGS) -fverbose-asm -S $< -o $(S_DIR)/uevent_monitor.s |
|
106 |
|
$(AS) $(S_DIR)/uevent_monitor.s -o $(OBJ_DIR)/uevent_monitor.o |
|
107 |
|
$(LD) $(LDFLAGS) $(OBJ_DIR)/uevent_monitor.o $(ULINUX_DEBUG_OBJS) --output $@ |
87 |
108 |
|
|
88 |
109 |
uevent_monitor:dirs ulinux/arch $(BUILD_DIR)/uevent_monitor |
uevent_monitor:dirs ulinux/arch $(BUILD_DIR)/uevent_monitor |
89 |
110 |
#=============================================================================== |
#=============================================================================== |
File modules.c changed (mode: 100644) (index 63757dd..9f9901e) |
... |
... |
static void module_load(k_u8 *m) |
25 |
25 |
{ |
{ |
26 |
26 |
k_l fd=sysc(open,3,m,K_O_RDONLY,0); |
k_l fd=sysc(open,3,m,K_O_RDONLY,0); |
27 |
27 |
if(K_ISERR(fd)){ |
if(K_ISERR(fd)){ |
28 |
|
OUTC(PRE " unable to open module\n"); |
|
|
28 |
|
OUTC("unable to open module\n"); |
29 |
29 |
goto err; |
goto err; |
30 |
30 |
} |
} |
31 |
31 |
|
|
32 |
32 |
struct k_stat m_stat; |
struct k_stat m_stat; |
33 |
33 |
k_l r=sysc(fstat,2,fd,&m_stat); |
k_l r=sysc(fstat,2,fd,&m_stat); |
34 |
34 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
35 |
|
OUTC(PRE " unable to stat module\n"); |
|
|
35 |
|
OUTC("unable to stat module\n"); |
36 |
36 |
goto err; |
goto err; |
37 |
37 |
} |
} |
38 |
38 |
|
|
39 |
39 |
k_l addr=sysc(mmap,6,0,m_stat.st_size,K_PROT_READ, |
k_l addr=sysc(mmap,6,0,m_stat.st_size,K_PROT_READ, |
40 |
40 |
K_MAP_PRIVATE|K_MAP_POPULATE,fd,0); |
K_MAP_PRIVATE|K_MAP_POPULATE,fd,0); |
41 |
41 |
if(K_ISERR(addr)){ |
if(K_ISERR(addr)){ |
42 |
|
OUTC(PRE " unable to mmap module\n"); |
|
|
42 |
|
OUTC("unable to mmap module\n"); |
43 |
43 |
goto err; |
goto err; |
44 |
44 |
} |
} |
45 |
45 |
return; |
return; |
|
... |
... |
void modules_load(void) |
53 |
53 |
k_u8 **m=modules_list; |
k_u8 **m=modules_list; |
54 |
54 |
|
|
55 |
55 |
while(*m!=0){ |
while(*m!=0){ |
56 |
|
OUT(PRE "loading module '%s'...\n",*m); |
|
|
56 |
|
OUT(PRE "loading module '%s'...",*m); |
57 |
57 |
module_load(*m); |
module_load(*m); |
58 |
|
OUTC(PRE "module loaded"); |
|
|
58 |
|
OUTC("done\n"); |
59 |
59 |
++m; |
++m; |
60 |
60 |
} |
} |
61 |
61 |
} |
} |
File uevent.c added (mode: 100644) (index 0000000..e36d58f) |
|
1 |
|
//****************************************************************************** |
|
2 |
|
//*this code is protected by the GNU affero GPLv3 |
|
3 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
4 |
|
//* <digital.ragnarok AT gmail dot com> |
|
5 |
|
//****************************************************************************** |
|
6 |
|
#include <ulinux/compiler_types.h> |
|
7 |
|
#include <ulinux/arch/sysc.h> |
|
8 |
|
#include <ulinux/arch/types.h> |
|
9 |
|
#include <ulinux/error.h> |
|
10 |
|
#include <ulinux/socket/socket.h> |
|
11 |
|
#include <ulinux/socket/msg.h> |
|
12 |
|
#include <ulinux/socket/netlink.h> |
|
13 |
|
#include <ulinux/epoll.h> |
|
14 |
|
#include <ulinux/utils/mem.h> |
|
15 |
|
#ifdef DEBUG |
|
16 |
|
#include <ulinux/file.h> |
|
17 |
|
#include <ulinux/stat.h> |
|
18 |
|
#include <ulinux/mmap.h> |
|
19 |
|
#include <ulinux/signal/signal.h> |
|
20 |
|
|
|
21 |
|
#include <stdarg.h> |
|
22 |
|
#include <ulinux/utils/ascii/string/vsprintf.h> |
|
23 |
|
#endif |
|
24 |
|
|
|
25 |
|
#include "globals.h" |
|
26 |
|
static k_i ep_fd=-1; |
|
27 |
|
static k_i s=-1; |
|
28 |
|
|
|
29 |
|
void uevent_setup(void) |
|
30 |
|
{ |
|
31 |
|
OUTC(PRE "setting up uevent..."); |
|
32 |
|
ep_fd=(k_i)sysc(epoll_create1,1,0); |
|
33 |
|
if(K_ISERR(ep_fd)){ |
|
34 |
|
OUT("ERROR:unable to create epoll fd (%d)\n",ep_fd); |
|
35 |
|
sysc(exit_group,1,-1); |
|
36 |
|
} |
|
37 |
|
|
|
38 |
|
//---------------------------------------------------------------------------- |
|
39 |
|
|
|
40 |
|
s=(k_i)sysc(socket,3,K_PF_NETLINK,K_SOCK_RAW|K_SOCK_NONBLOCK, |
|
41 |
|
K_NETLINK_KOBJECT_UEVENT); |
|
42 |
|
if(K_ISERR(s)){ |
|
43 |
|
OUT("ERROR:unable to create uevent netlink socket:%d\n",s); |
|
44 |
|
sysc(exit_group,1,-1); |
|
45 |
|
} |
|
46 |
|
|
|
47 |
|
//---------------------------------------------------------------------------- |
|
48 |
|
|
|
49 |
|
k_i recv_buf_sz=128*1024*1024; |
|
50 |
|
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
|
51 |
|
sizeof(recv_buf_sz)); |
|
52 |
|
if(K_ISERR(r)){ |
|
53 |
|
OUT("ERROR:unable to force the size of the socket buffer:%ld\n",r); |
|
54 |
|
sysc(exit_group,1,-1); |
|
55 |
|
} |
|
56 |
|
|
|
57 |
|
//---------------------------------------------------------------------------- |
|
58 |
|
|
|
59 |
|
//uevent groups? only one: 1 |
|
60 |
|
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
|
61 |
|
r=sysc(bind,3,s,&addr,sizeof(addr)); |
|
62 |
|
if(K_ISERR(r)){ |
|
63 |
|
OUT("ERROR:unable to bind address to uevent netlink socket:%ld\n",r); |
|
64 |
|
sysc(exit_group,1,-1); |
|
65 |
|
} |
|
66 |
|
|
|
67 |
|
//---------------------------------------------------------------------------- |
|
68 |
|
|
|
69 |
|
struct k_epoll_event ep_evt; |
|
70 |
|
u_memset(&ep_evt,0,sizeof(ep_evt)); |
|
71 |
|
ep_evt.events=K_EPOLLIN; |
|
72 |
|
ep_evt.data.fd=s; |
|
73 |
|
r=sysc(epoll_ctl,4,ep_fd,K_EPOLL_CTL_ADD,s,&ep_evt); |
|
74 |
|
if(K_ISERR(r)){ |
|
75 |
|
OUT("ERROR:unable to register uevent netlink socket to epoll (%ld)\n", |
|
76 |
|
r); |
|
77 |
|
sysc(exit_group,1,-1); |
|
78 |
|
} |
|
79 |
|
OUTC("done\n"); |
|
80 |
|
} |
|
81 |
|
|
|
82 |
|
static void uevent_rcv(k_i s) |
|
83 |
|
{ |
|
84 |
|
k_u8 buf[8192]; |
|
85 |
|
u_memset(buf,0,sizeof(buf)); |
|
86 |
|
|
|
87 |
|
struct k_io_vec io_vec; |
|
88 |
|
io_vec.base=buf; |
|
89 |
|
io_vec.len=sizeof(buf); |
|
90 |
|
|
|
91 |
|
struct k_msg_hdr msg; |
|
92 |
|
u_memset(&msg,0,sizeof(msg)); |
|
93 |
|
msg.iov=&io_vec; |
|
94 |
|
msg.iov_len=1; |
|
95 |
|
|
|
96 |
|
k_l r; |
|
97 |
|
do{ |
|
98 |
|
r=sysc(recvmsg,3,s,&msg,0); |
|
99 |
|
}while(r==-K_EINTR); |
|
100 |
|
if(K_ISERR(r)){ |
|
101 |
|
OUT("ERROR:unable to receive the uevent(%ld)\n",r); |
|
102 |
|
sysc(exit_group,1,-1); |
|
103 |
|
} |
|
104 |
|
if(msg.flgs&K_MSG_TRUNC){ |
|
105 |
|
OUT("ERROR:the uevent was truncated(flags=0x%x)\n",msg.flgs); |
|
106 |
|
sysc(exit_group,1,-1); |
|
107 |
|
} |
|
108 |
|
OUTC("uevent received:\n"); |
|
109 |
|
k_i len=r; |
|
110 |
|
k_u8 *p=&buf[0]; |
|
111 |
|
while(len){ |
|
112 |
|
if(*p) OUT("%c",*p); else OUTC("\n"); |
|
113 |
|
++p; |
|
114 |
|
len--; |
|
115 |
|
} |
|
116 |
|
OUTC("\n"); |
|
117 |
|
} |
|
118 |
|
|
|
119 |
|
static void uevent_recv(void) |
|
120 |
|
{ |
|
121 |
|
OUTC(PRE "receiving uevent...\n"); |
|
122 |
|
while(1){ |
|
123 |
|
k_l r; |
|
124 |
|
static struct k_epoll_event evts[1];//uevent netlink event |
|
125 |
|
do{ |
|
126 |
|
u_memset(evts,0,sizeof(evts)); |
|
127 |
|
r=sysc(epoll_wait,4,ep_fd,evts,1,-1); |
|
128 |
|
}while(r==-K_EINTR); |
|
129 |
|
if(K_ISERR(r)){ |
|
130 |
|
OUT(PRE "ERROR:error epolling fds (%ld)\n",r); |
|
131 |
|
sysc(exit_group,1,-1); |
|
132 |
|
} |
|
133 |
|
k_l i=0; |
|
134 |
|
while(i<r){ |
|
135 |
|
if(evts[i].data.fd==s){ |
|
136 |
|
if(evts[i].events&K_EPOLLIN){ |
|
137 |
|
uevent_rcv(s); |
|
138 |
|
}else{ |
|
139 |
|
OUT(PRE "ERROR:unmanaged epolling event on uevent netlink socket" |
|
140 |
|
" n=%ld events=%u\n", i,evts[i].events); |
|
141 |
|
sysc(exit_group,1,-1); |
|
142 |
|
} |
|
143 |
|
} |
|
144 |
|
++i; |
|
145 |
|
} |
|
146 |
|
} |
|
147 |
|
} |
|
148 |
|
|
|
149 |
|
void uevent_recv_thread_start(void) |
|
150 |
|
{ |
|
151 |
|
k_l r=sysc(clone,5,K_,0,NULL,NULL,NULL); |
|
152 |
|
if(K_ISERR(r)){ |
|
153 |
|
PERR("FATAL:error precloning process slot %d with error %ld\n",slot,r); |
|
154 |
|
return -1; |
|
155 |
|
} |
|
156 |
|
if(r==0) goto preclone_entry_setup; |
|
157 |
|
|
|
158 |
|
_preclones[slot].s=s[1]; |
|
159 |
|
sysc(close,1,s[0]); |
|
160 |
|
_preclones[slot].pid=(k_i)r; |
|
161 |
|
return 0; |
|
162 |
|
|
|
163 |
|
preclone_entry_setup: |
|
164 |
|
_slot=slot; |
|
165 |
|
sysc(close,1,s[1]);//close parent unix socket |
|
166 |
|
_parent_sock=s[0]; |
|
167 |
|
|
|
168 |
|
sysc(close,1,0);//for the connexion socket |
|
169 |
|
sysc(close,1,1);//for the connexion socket |
|
170 |
|
//keep stderr |
|
171 |
|
|
|
172 |
|
sysc(close,1,_sigs_fd);//don't care of parent signal |
|
173 |
|
sysc(close,1,_epfd);//don't use parent epoll |
|
174 |
|
|
|
175 |
|
_preclone_entry(); |
|
176 |
|
return -1; |
|
177 |
|
} |
File uevent_monitor.c changed (mode: 100644) (index 359a60e..b2b537a) |
|
1 |
|
//****************************************************************************** |
|
2 |
|
//*this code is protected by the GNU affero GPLv3 |
|
3 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
4 |
|
//* <digital.ragnarok AT gmail dot com> |
|
5 |
|
//****************************************************************************** |
1 |
6 |
#include <ulinux/compiler_types.h> |
#include <ulinux/compiler_types.h> |
2 |
7 |
#include <ulinux/arch/sysc.h> |
#include <ulinux/arch/sysc.h> |
3 |
8 |
#include <ulinux/arch/types.h> |
#include <ulinux/arch/types.h> |
|
... |
... |
void _start(void) |
72 |
77 |
|
|
73 |
78 |
k_i ep_fd=(k_i)sysc(epoll_create1,1,0); |
k_i ep_fd=(k_i)sysc(epoll_create1,1,0); |
74 |
79 |
if(K_ISERR(ep_fd)){ |
if(K_ISERR(ep_fd)){ |
75 |
|
ERR("FATAL:unable to create epoll fd (%d)\n",ep_fd); |
|
|
80 |
|
ERR("ERROR:unable to create epoll fd (%d)\n",ep_fd); |
76 |
81 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
77 |
82 |
} |
} |
78 |
83 |
|
|
|
... |
... |
void _start(void) |
87 |
92 |
|
|
88 |
93 |
//---------------------------------------------------------------------------- |
//---------------------------------------------------------------------------- |
89 |
94 |
|
|
|
95 |
|
//why that big (stolen from udev)? |
|
96 |
|
//moreover it can be skipped most of the time |
|
97 |
|
//must be priviledge |
|
98 |
|
k_i recv_buf_sz=128*1024*1024; |
|
99 |
|
k_l r=sysc(setsockopt,5,s,K_SOL_SOCKET,K_SO_RCVBUFFORCE,&recv_buf_sz, |
|
100 |
|
sizeof(recv_buf_sz)); |
|
101 |
|
if(K_ISERR(r)){ |
|
102 |
|
ERR("ERROR:unable to force the size of the socket buffer (%ld)\n",r); |
|
103 |
|
sysc(exit_group,1,-1); |
|
104 |
|
} |
|
105 |
|
|
|
106 |
|
//---------------------------------------------------------------------------- |
|
107 |
|
|
90 |
108 |
//uevent groups? only one: 1 |
//uevent groups? only one: 1 |
91 |
109 |
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
struct k_sockaddr_nl addr={K_AF_NETLINK,0,0,1}; |
92 |
|
k_l r=sysc(bind,3,s,&addr,sizeof(addr)); |
|
|
110 |
|
r=sysc(bind,3,s,&addr,sizeof(addr)); |
93 |
111 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
94 |
112 |
ERR("ERROR:unable to bind address to uevent netlink socket:%ld\n",r); |
ERR("ERROR:unable to bind address to uevent netlink socket:%ld\n",r); |
95 |
113 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
|
... |
... |
void _start(void) |
108 |
126 |
} |
} |
109 |
127 |
|
|
110 |
128 |
//---------------------------------------------------------------------------- |
//---------------------------------------------------------------------------- |
111 |
|
// |
|
|
129 |
|
|
112 |
130 |
while(1){ |
while(1){ |
113 |
131 |
static struct k_epoll_event evts[1];//uevent netlink event |
static struct k_epoll_event evts[1];//uevent netlink event |
114 |
132 |
do{ |
do{ |
|
... |
... |
void _start(void) |
116 |
134 |
r=sysc(epoll_wait,4,ep_fd,evts,1,-1); |
r=sysc(epoll_wait,4,ep_fd,evts,1,-1); |
117 |
135 |
}while(r==-K_EINTR); |
}while(r==-K_EINTR); |
118 |
136 |
if(K_ISERR(r)){ |
if(K_ISERR(r)){ |
119 |
|
ERR("FATAL:error epolling fds (%ld)\n",r); |
|
|
137 |
|
ERR("ERROR:error epolling fds (%ld)\n",r); |
120 |
138 |
sysc(exit_group,1,-1); |
sysc(exit_group,1,-1); |
121 |
139 |
} |
} |
122 |
140 |
k_l i=0; |
k_l i=0; |
File ulinux/archs/x86_64/utils/mem.c changed (mode: 100644) (index 9196740..366278a) |
7 |
7 |
#include <ulinux/arch/types.h> |
#include <ulinux/arch/types.h> |
8 |
8 |
#include <stddef.h> |
#include <stddef.h> |
9 |
9 |
|
|
|
10 |
|
//XXX:need a way to get the target CPUID flags in order to select the proper |
|
11 |
|
//path at compilation time and not runtime |
10 |
12 |
void u_memcpy(void *d,void *s,k_ul len) |
void u_memcpy(void *d,void *s,k_ul len) |
11 |
13 |
{ |
{ |
12 |
14 |
__builtin_memcpy(d,s,len);//use gcc builtin for this arch |
__builtin_memcpy(d,s,len);//use gcc builtin for this arch |
|
... |
... |
void *memcpy(void *to,const void *from,size_t len) |
20 |
22 |
while(len--) *d++=*s++; |
while(len--) *d++=*s++; |
21 |
23 |
return to; |
return to; |
22 |
24 |
} |
} |
|
25 |
|
|
|
26 |
|
void u_memset(void *d,k_u8 c,k_ul len) |
|
27 |
|
{ |
|
28 |
|
__builtin_memset(d,c,len);//use gcc builtin for this arch |
|
29 |
|
} |
|
30 |
|
|
|
31 |
|
//a memset implementation is needed anyway if gcc decides not to use its builtin |
|
32 |
|
void *memset(void *to,int c,size_t len) |
|
33 |
|
{ |
|
34 |
|
k_u8 *d=to; |
|
35 |
|
while(len--) *d++=c; |
|
36 |
|
return to; |
|
37 |
|
} |
File ulinux/sched.h added (mode: 100644) (index 0000000..c27483c) |
|
1 |
|
#ifndef ULINUX_SCHED_H |
|
2 |
|
#define ULINUX_SCHED_H |
|
3 |
|
//****************************************************************************** |
|
4 |
|
//*this code is protected by the GNU affero GPLv3 |
|
5 |
|
//*author:Sylvain BERTRAND <sylvain.bertrand AT gmail dot com> |
|
6 |
|
//* <digital.ragnarok AT gmail dot com> |
|
7 |
|
//****************************************************************************** |
|
8 |
|
#define K_CSIGNAL 0x000000ff//signal mask to be sent at exit |
|
9 |
|
#define K_CLONE_VM 0x00000100//set if vm shared between processes |
|
10 |
|
#define K_CLONE_FS 0x00000200//set if fs info shared between |
|
11 |
|
//processes |
|
12 |
|
#define K_CLONE_FILES 0x00000400//set if open files shared between |
|
13 |
|
//processes |
|
14 |
|
#define K_CLONE_SIGHAND 0x00000800//set if signal handlers and blocked |
|
15 |
|
//signals shared |
|
16 |
|
#define K_CLONE_PTRACE 0x00002000//set if we want to let tracing |
|
17 |
|
//continue on the child too |
|
18 |
|
#define K_CLONE_VFORK 0x00004000//set if the parent wants the child to |
|
19 |
|
//wake it up on mm_release |
|
20 |
|
#define K_CLONE_PARENT 0x00008000//set if we want to have the same |
|
21 |
|
//parent as the cloner |
|
22 |
|
#define K_CLONE_THREAD 0x00010000//same thread group? |
|
23 |
|
#define K_CLONE_NEWNS 0x00020000//new namespace group? |
|
24 |
|
#define K_CLONE_SYSVSEM 0x00040000//share system v sem_undo semantics |
|
25 |
|
#define K_CLONE_SETTLS 0x00080000//create a new tls for the child |
|
26 |
|
#define K_CLONE_PARENT_SETTID 0x00100000//set the tid in the parent |
|
27 |
|
#define K_CLONE_CHILD_CLEARTID 0x00200000//clear the tid in the child |
|
28 |
|
#define K_CLONE_DETACHED 0x00400000//unused, ignored |
|
29 |
|
#define K_CLONE_UNTRACED 0x00800000//set if the tracing process can't |
|
30 |
|
//force clone_ptrace on this clone |
|
31 |
|
#define K_CLONE_CHILD_SETTID 0x01000000//set the tid in the child |
|
32 |
|
//0x02000000 was previously the unused clone_stopped (start in stopped state) |
|
33 |
|
//and is now available for re-use. |
|
34 |
|
#define K_CLONE_NEWUTS 0x04000000//new utsname group? |
|
35 |
|
#define K_CLONE_NEWIPC 0x08000000//new ipcs |
|
36 |
|
#define K_CLONE_NEWUSER 0x10000000//new user namespace |
|
37 |
|
#define K_CLONE_NEWPID 0x20000000//new pid namespace |
|
38 |
|
#define K_CLONE_NEWNET 0x40000000//new network namespace |
|
39 |
|
#define K_CLONE_IO 0x80000000//clone io context |
|
40 |
|
#endif |
File ulinux/utils/ascii/string/vsprintf.c changed (mode: 100644) (index 3d1e9a8..ca45280) |
... |
... |
k_i u_a_dprintf(k_i f,k_u8 *buf,k_ul sz,k_u8 *fmt,...) |
922 |
922 |
k_ul len=u_a_vsnprintf(buf,sz,fmt,args); |
k_ul len=u_a_vsnprintf(buf,sz,fmt,args); |
923 |
923 |
va_end(args); |
va_end(args); |
924 |
924 |
|
|
925 |
|
k_l r=sysc(write,3,f,buf,len); |
|
926 |
|
if(K_ISERR(r)) return -2; |
|
|
925 |
|
//k_l r=sysc(write,3,f,buf,len); |
|
926 |
|
//if(K_ISERR(r)) return -2; |
|
927 |
|
k_l r; |
|
928 |
|
do{ |
|
929 |
|
r=sysc(write,3,f,buf,len); |
|
930 |
|
}while(r==-K_EINTR||r==-K_EAGAIN); |
|
931 |
|
if(K_ISERR(r)||(r!=(k_l)len)) return -2; |
927 |
932 |
return 0; |
return 0; |
928 |
933 |
} |
} |